@surething/cockpit 1.0.206 → 1.0.207
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/.next-prod/BUILD_ID +1 -1
- package/.next-prod/app-path-routes-manifest.json +1 -1
- package/.next-prod/build-manifest.json +2 -2
- package/.next-prod/prerender-manifest.json +3 -3
- package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_global-error.html +1 -1
- package/.next-prod/server/app/_global-error.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_not-found.html +2 -2
- package/.next-prod/server/app/_not-found.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app-paths-manifest.json +1 -1
- package/.next-prod/server/middleware-build-manifest.js +1 -1
- package/.next-prod/server/pages/404.html +2 -2
- package/.next-prod/server/pages/500.html +1 -1
- package/.next-prod/server/server-reference-manifest.json +1 -1
- package/.next-prod/static/chunks/{5660-9ffe0abe675caac1.js → 5660-9053823b3dfa50f5.js} +1 -1
- package/.next-prod/trace +12 -12
- package/.next-prod/trace-build +1 -1
- package/package.json +1 -1
- /package/.next-prod/static/{VAwjvIwxO_lfKwd6A4ptI → Uvhbo45hauczMddOCJnSX}/_buildManifest.js +0 -0
- /package/.next-prod/static/{VAwjvIwxO_lfKwd6A4ptI → Uvhbo45hauczMddOCJnSX}/_ssgManifest.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5660],{1058:(e,t,r)=>{r.d(t,{_:()=>o});var n=r(12115),s=r(90717);function o({cwd:e,filePath:t}){let[r,l]=(0,n.useState)([]),[a,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),u=(0,n.useCallback)(async()=>{if(e&&t){i(!0),d(null);try{let r=await fetch(`/api/comments?cwd=${encodeURIComponent(e)}&filePath=${encodeURIComponent(t)}`);if(r.ok){let e=await r.json();l(e.comments||[])}else d("Failed to load comments")}catch(e){d(e instanceof Error?e.message:"Unknown error")}finally{i(!1)}}},[e,t]);(0,n.useEffect)(()=>{u()},[u]),(0,n.useEffect)(()=>(0,s.zL)(()=>{u()}),[u]);let h=(0,n.useCallback)(async(r,n,s,o)=>{try{let a=await fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,startLine:r,endLine:n,content:s,...o?{selectedText:o}:{}})});if(a.ok){let e=await a.json();return l(t=>[...t,e.comment]),e.comment}}catch(e){console.error("Failed to add comment:",e)}return null},[e,t]),m=(0,n.useCallback)(async(t,r)=>{try{let n=await fetch("/api/comments",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,id:t,content:r})});if(n.ok){let e=await n.json();return l(r=>r.map(r=>r.id===t?e.comment:r)),!0}}catch(e){console.error("Failed to update comment:",e)}return!1},[e]),x=(0,n.useCallback)(async t=>{try{if((await fetch(`/api/comments?cwd=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:"DELETE"})).ok)return l(e=>e.filter(e=>e.id!==t)),!0}catch(e){console.error("Failed to delete comment:",e)}return!1},[e]),f=(0,n.useCallback)(e=>r.filter(t=>e>=t.startLine&&e<=t.endLine),[r]);return{comments:r,isLoading:a,error:c,addComment:h,updateComment:m,deleteComment:x,refresh:u,getCommentsForLine:f}}},2228:(e,t,r)=>{r.d(t,{ProjectItem:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-6 h-6 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"4"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function a({index:e,name:t,cwd:r,isActive:i,collapsed:c,hasUnread:d,isLoading:u,onClick:h,onRemove:m,onOpenNote:x}){let{t:f}=(0,o.Bd)(),[p,g]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1 rounded-lg cursor-pointer transition-colors relative ${c?"justify-center":""} ${i?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary hover:text-foreground"}`,onClick:h,onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),title:r,children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(l,{number:e+1,isActive:i}),d&&!i&&!u&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),u&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"})]}),!c&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"flex-1 truncate text-sm",children:t}),!u&&i?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}):null]}),p&&!c&&(0,n.jsxs)("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-0.5",children:[x&&(0,n.jsx)("button",{className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",onClick:e=>{e.stopPropagation(),x()},title:f("workspace.projectNotes"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{className:"p-1 rounded hover:bg-red-500/20 text-muted-foreground hover:text-red-500 transition-colors",onClick:e=>{e.stopPropagation(),m()},title:f("workspace.closeProject"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]})}},3292:(e,t,r)=>{r.d(t,{P:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)([]),r=(0,n.useCallback)(()=>{fetch("/api/pinned-sessions").then(e=>e.json()).then(e=>t(e.sessions||[])).catch(()=>{})},[]);(0,n.useEffect)(()=>{r()},[r]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type==="PINNED_SESSIONS_CHANGED"&&r()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[r]);let s=(0,n.useCallback)(e=>{t(e),fetch("/api/pinned-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessions:e})}).catch(()=>{});try{window.parent.postMessage({type:"PINNED_SESSIONS_CHANGED"},"*")}catch{}},[]),o=(0,n.useCallback)(t=>e.some(e=>e.sessionId===t),[e]),l=(0,n.useCallback)((t,r,n)=>{e.some(e=>e.sessionId===t)||s([...e,{sessionId:t,cwd:r,customTitle:n}])},[e,s]),a=(0,n.useCallback)(t=>{s(e.filter(e=>e.sessionId!==t))},[e,s]),i=(0,n.useCallback)((t,r)=>{s(e.map(e=>e.sessionId===t?{...e,customTitle:r}:e))},[e,s]);return{pinnedSessions:e,isPinned:o,pinSession:l,unpinSession:a,updateTitle:i,reorder:(0,n.useCallback)(e=>{s(e)},[s]),reload:r}}},7320:(e,t,r)=>{r.d(t,{G:()=>a,t:()=>l});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,range:r,codeContent:a,container:i,onSubmit:c,onClose:d}){let{t:u}=(0,o.Bd)(),[h,m]=(0,s.useState)(""),[x,f]=(0,s.useState)(!1),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0}),j=a?.split("\n").slice(0,5).join("\n"),y=!!a&&a.split("\n").length>5;return(0,s.useEffect)(()=>{if(p.current&&i){let r=i.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>v({x:s,y:o}))}},[e,t,i]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{x||!p.current||p.current.contains(e.target)||d()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d,x]),(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,n.jsx)("div",{className:"px-3 py-2 bg-amber-9/10 border-b border-border",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-amber-11",children:u("comments.addComment")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:r.start,end:r.end})})]})}),a&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,y&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:g,value:h,onChange:e=>m(e.target.value),placeholder:u("comments.inputPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:x,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!x&&h.trim()&&(f(!0),c(h.trim()))),"Escape"!==e.key||x||d()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:u(x?"comments.submitting":"comments.enterSubmit")})]})]})}function a({x:e,y:t,range:r,filePath:l,codeContent:i,container:c,onSubmit:d,onClose:u,isChatLoading:h}){let{t:m}=(0,o.Bd)(),[x,f]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&c){let r=c.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>v({x:s,y:o}))}},[e,t,c]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&u()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u]);let j=i?.split("\n").slice(0,5).join("\n"),y=!!i&&i.split("\n").length>5;return(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-brand/10 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-brand",children:m("comments.askAI")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:m("comments.lineRange",{start:r.start,end:r.end})})]}),l&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:l})]}),i&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,y&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:g,value:x,onChange:e=>f(e.target.value),placeholder:m("comments.inputQuestion"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:h,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!h&&x.trim()&&(d(x.trim()),u())),"Escape"===e.key&&u()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:m(h?"comments.aiGenerating":"comments.enterSend")})]})]})}},8648:(e,t,r)=>{r.d(t,{NoteModal:()=>w});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(13439),i=r(37795),c=r(43561),d=r(5989),u=r(76065),h=r(43203),m=r(6268),x=r(48434),f=r(44695),p=r(59265),g=r(26932);function b(e){return e.storage.markdown.getMarkdown()}function v(){return[{label:l.A.t("slashCommands.heading1"),icon:"H1",description:l.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:l.A.t("slashCommands.heading2"),icon:"H2",description:l.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:l.A.t("slashCommands.heading3"),icon:"H3",description:l.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:l.A.t("slashCommands.bulletList"),icon:"•",description:l.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:l.A.t("slashCommands.orderedList"),icon:"1.",description:l.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:l.A.t("slashCommands.taskList"),icon:"☑",description:l.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:l.A.t("slashCommands.blockquote"),icon:"❝",description:l.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:l.A.t("slashCommands.codeBlock"),icon:"<>",description:l.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:l.A.t("slashCommands.table"),icon:"▦",description:l.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:l.A.t("slashCommands.horizontalRule"),icon:"──",description:l.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:l.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:l.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function j({editor:e,query:t,position:r,onClose:o}){let[l,a]=(0,s.useState)(0),i=(0,s.useRef)(null),c=v().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>a(0))},[t]);let d=r=>{e.chain().focus().deleteRange({from:e.state.selection.from-t.length-1,to:e.state.selection.from}).run(),r.action(e),o()};return((0,s.useEffect)(()=>{let e=e=>{"ArrowDown"===e.key?(e.preventDefault(),a(e=>(e+1)%c.length)):"ArrowUp"===e.key?(e.preventDefault(),a(e=>(e-1+c.length)%c.length)):"Enter"===e.key?(e.preventDefault(),c[l]&&d(c[l])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,l,o]),0===c.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lg py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:c.map((e,t)=>(0,n.jsxs)("button",{className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors ${t===l?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"}`,onClick:()=>d(e),onMouseEnter:()=>a(t),children:[(0,n.jsx)("span",{className:"w-6 text-center text-xs font-mono flex-shrink-0",children:e.icon}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium",children:e.label}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:e.description})]})]},e.label))})}v();var y=r(76043);function w({isOpen:e,onClose:t,projectCwd:r,projectName:v}){let{t:k}=(0,o.Bd)(),[N,C]=(0,s.useState)(!0),[S,L]=(0,s.useState)(!1),M=(0,s.useRef)(null),E=(0,s.useRef)(!1),[T,$]=(0,s.useState)(null),R=(0,s.useRef)(null),P=r?`/api/note?cwd=${encodeURIComponent(r)}`:"/api/note",B=(0,s.useCallback)(async e=>{L(!0);try{await fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e})}),E.current=!1}catch(e){console.error("Failed to save note:",e)}finally{L(!1)}},[P]),I=(0,s.useCallback)(e=>{E.current=!0,M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{B(e)},5e3)},[B]),D=(0,a.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:{levels:[1,2,3]}}),c.A.configure({placeholder:()=>l.A.t("editor.placeholder")}),d.XI.configure({resizable:!0}),u.H,h.n,m.A,x._,p.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),f.L.configure({nested:!0}),g.o.configure({html:!0,transformCopiedText:!0,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},handleClick:(e,t,r)=>{if(r.metaKey||r.ctrlKey){let r=e.state.doc.resolve(t).marks().find(e=>"link"===e.type.name)?.attrs;if(r?.href)return window.open(r.href,"_blank","noopener,noreferrer"),!0}return!1},handleKeyDown:(e,t)=>{if("Backspace"===t.key&&F.current){let e=F.current;if(e.isActive("codeBlock")){let{$from:t}=e.state.selection,r=t.node(t.depth);if("codeBlock"===r.type.name&&""===r.textContent)return e.chain().focus().toggleCodeBlock().run(),!0}}return"/"!==t.key||T||setTimeout(()=>{if(!F.current)return;let{from:e}=F.current.state.selection;if("/"===F.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){R.current=e;let t=F.current.view.coordsAtPos(e);$({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(I(b(e)),null!==R.current){let{from:t}=e.state.selection;if(t<R.current)$(null),R.current=null;else{let r=e.state.doc.textBetween(R.current,t,"\n");r.includes(" ")||r.includes("\n")?($(null),R.current=null):$(e=>e?{...e,query:r}:null)}}}}),F=(0,s.useRef)(D);(0,s.useEffect)(()=>{F.current=D},[D]),(0,s.useEffect)(()=>{e&&D&&(C(!0),$(null),R.current=null,fetch(P).then(e=>e.json()).then(e=>{D.commands.setContent(e.content||""),E.current=!1}).catch(e=>console.error("Failed to load note:",e)).finally(()=>C(!1)))},[e,D,P]);let A=(0,s.useCallback)(()=>{M.current&&(clearTimeout(M.current),M.current=null),E.current&&D&&B(b(D)),$(null),R.current=null,t()},[D,B,t]);return((0,s.useEffect)(()=>()=>{M.current&&clearTimeout(M.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(T?($(null),R.current=null):A())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,A,T]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:A}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v?k("editor.noteTitle",{name:v}):k("editor.noteUntitled")}),S&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:k("editor.saving")})]}),(0,n.jsx)("button",{onClick:A,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(y.NoteToolbar,{editor:D}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:N?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:k("common.loading")})}):(0,n.jsx)(a.$Z,{editor:D})})]}),T&&D&&(0,n.jsx)(j,{editor:D,query:T.query,position:T.position,onClose:()=>{$(null),R.current=null}})]}):null}},12786:(e,t,r)=>{r.d(t,{L:()=>s,Mu:()=>o});var n=r(41463);function s(){return!("u"<typeof navigator)&&(/Mac|iPhone|iPad/.test(navigator.platform||"")||navigator.userAgentData?.platform==="macOS")}function o(){return s()?"⌘":"Ctrl+"}n.platform,n.platform,n.platform},17196:(e,t,r)=>{r.d(t,{Np:()=>d,ZD:()=>i,b8:()=>c,kS:()=>l,sQ:()=>a});var n=r(67014);let s=null,o=["typescript","tsx","javascript","jsx","html","css","scss","json","yaml","python","go","rust","java","ruby","php","bash","shell","markdown","sql","c","cpp","swift","kotlin","dart","lua","graphql","xml"];function l(){return s||(s=(0,n.O_)({themes:["github-dark","github-light"],langs:[...o]})),s}function a(e){let t=e.split("/").pop()?.toLowerCase()||"",r=t.split(".").pop()?.toLowerCase();if(".env"===t||t.startsWith(".env.")||"dockerfile"===t||t.startsWith("dockerfile.")||"makefile"===t)return"bash";let n={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",html:"html",htm:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",py:"python",go:"go",rs:"rust",java:"java",kt:"kotlin",rb:"ruby",php:"php",cs:"cpp",cpp:"cpp",c:"c",h:"c",sh:"bash",bash:"bash",zsh:"bash",md:"markdown",mdx:"markdown",sql:"sql",swift:"swift",dart:"dart",lua:"lua",graphql:"graphql",gql:"graphql",toml:"yaml",sass:"scss",less:"css",scala:"java",r:"python",vim:"bash",env:"bash"}[r||""]||"text";return o.includes(n)?n:"text"}function i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function c(e){return e.map(e=>e.color?`<span style="color:${e.color}">${i(e.content)}</span>`:i(e.content)).join("")}function d(e,t,r,n){if(!t)return[];let s=[],o=r?t:t.toLowerCase();for(let t=0;t<e.length;t++){let l=r?e[t]:e[t].toLowerCase(),a=0;for(;;){let e=l.indexOf(o,a);if(-1===e)break;let r=e+o.length;if(n){let n=e>0?l[e-1]:" ",o=r<l.length?l[r]:" ",a=!/\w/.test(n),i=!/\w/.test(o);a&&i&&s.push({lineIndex:t,startCol:e,endCol:r})}else s.push({lineIndex:t,startCol:e,endCol:r});a=e+1}}return s}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>d});var n=r(95155),s=r(12115),o=r(79114),l=r(3238),a=r(34075),i=r(12786),c=r(53853);function d({isOpen:e,onClose:t}){let{t:r,i18n:u}=(0,o.Bd)(),{theme:h,setTheme:m}=(0,l.D)(),x=(0,c.G)(),[f,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(""),[v,j]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&fetch("/api/settings").then(e=>e.json()).then(e=>{e.language&&j(e.language)}).catch(()=>{})},[e]);let y=(0,s.useCallback)(e=>{j(e),fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({language:e})}).catch(()=>{});let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;u.changeLanguage(t)},[u]),w=x?"installed":"not-installed",k=x?.version??null;if((0,s.useEffect)(()=>{e&&fetch("/api/version").then(e=>e.json()).then(e=>{e.version&&b(e.version)}).catch(()=>{})},[e]),(0,s.useEffect)(()=>{e&&fetch("/api/extension/version").then(e=>e.json()).then(e=>{e.path&&p(e.path)}).catch(()=>{})},[e]),!e)return null;let N=[{value:"system",label:r("settings.themeSystem"),icon:"\uD83D\uDCBB"},{value:"light",label:r("settings.themeLight"),icon:"☀️"},{value:"dark",label:r("settings.themeDark"),icon:"\uD83C\uDF19"}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("settings.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.theme")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:N.map(e=>(0,n.jsxs)("button",{onClick:()=>m(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${h===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.language")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{value:"auto",label:r("settings.languageAuto"),icon:"\uD83C\uDF10"},{value:"en",label:"English",icon:"\uD83C\uDDFA\uD83C\uDDF8"},{value:"zh",label:"中文",icon:"\uD83C\uDDE8\uD83C\uDDF3"}].map(e=>(0,n.jsxs)("button",{onClick:()=>y(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${v===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.browserExtension")}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${"installed"===w?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===w&&`${r("settings.extensionInstalled")}${k?` (v${k})`:""}`,"not-installed"===w&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==w&&(0,n.jsxs)("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-md p-2 space-y-1",children:[(0,n.jsx)("p",{className:"font-medium text-foreground",children:r("settings.installSteps")}),(0,n.jsxs)("p",{children:[r("settings.step1")," ",(0,n.jsx)("code",{className:"px-1 py-0.5 bg-muted rounded text-foreground",children:"chrome://extensions"})]}),(0,n.jsx)("p",{children:r("settings.step2")}),(0,n.jsx)("p",{children:r("settings.step3")}),(0,i.L)()&&(0,n.jsx)("p",{dangerouslySetInnerHTML:{__html:r("settings.step4mac")}})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>{let e=f||"chrome-extension";navigator.clipboard.writeText(e),(0,a.oR)(r("toast.copiedName",{name:e}))},className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:r("settings.copyExtensionPath")}),"installed"===w&&(0,n.jsx)("button",{onClick:()=>{x?.id&&window.chrome?.runtime?.sendMessage&&(window.chrome.runtime.sendMessage(x.id,{type:"reload"}),(0,a.oR)(r("toast.pluginReloading")))},className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-muted transition-colors",children:r("settings.reloadExtension")})]}),f&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:f})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.about")}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground space-y-1",children:[(0,n.jsxs)("p",{children:["Cockpit",g?` v${g}`:""]}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>d});var n=r(95155),s=r(12115),o=r(94287),l=r(64428),a=r(79114);function i({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function c({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:a,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),h=(0,s.useRef)(null),m=(0,s.useRef)(null),[x,f]=(0,s.useState)({top:0,right:0}),p=(0,l.F2)();(0,s.useEffect)(()=>{if(!d)return;let e=e=>{m.current&&!m.current.contains(e.target)&&h.current&&!h.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let g=n=>{u(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?a?.():"deepseek"===n?i?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:h,onClick:()=>{if(!d&&h.current){let e=h.current.getBoundingClientRect(),t=p?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;f({top:e.bottom+4-n,right:s-(e.right-r)})}u(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"New tab",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),d&&(0,n.jsx)(l.ZL,{children:(0,n.jsxs)("div",{ref:m,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:x.top,right:x.right},children:[(0,n.jsxs)("button",{onClick:()=>g("claude"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}),"Claude Code"]}),(0,n.jsxs)("button",{onClick:()=>g("claude2"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-orange-500 flex-shrink-0"}),"Claude 2"]}),(0,n.jsxs)("button",{onClick:()=>g("codex"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 flex-shrink-0"}),"OpenAI Codex"]}),(0,n.jsxs)("button",{onClick:()=>g("deepseek"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"}),"Deepseek"]}),(0,n.jsxs)("button",{onClick:()=>g("kimi"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500 flex-shrink-0"}),"Kimi"]}),(0,n.jsxs)("button",{onClick:()=>g("ollama"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-violet-500 flex-shrink-0"}),"Ollama"]})]})})]})}function d({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:l,isPinned:u,onTogglePin:h,onSwitchTab:m,onCloseTab:x,onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j,onDragStart:y,onDragOver:w,onDrop:k,onDragEnd:N}){let{t:C}=(0,a.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((a,c)=>(0,n.jsx)(o.m,{content:a.title,delay:200,className:"flex-1 min-w-16 max-w-32",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>y(c),onDragOver:e=>w(e,c),onDrop:()=>k(c),onDragEnd:N,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg transition-colors ${a.id===t?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary"} ${s===c?"opacity-50":""} ${l===c?"border-l-2 border-brand":""}`,onClick:()=>m(a.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(i,{number:c+1,isActive:a.id===t}),a.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!a.isLoading&&r.has(a.id)&&a.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),h&&u?.(a.id)&&!a.isLoading&&!(r.has(a.id)&&a.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(a.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:C("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),h&&!u?.(a.id)&&!a.isLoading&&!(r.has(a.id)&&a.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(a.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:C("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:a.title}),"claude2"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-orange-500/15 text-orange-400 font-medium leading-relaxed",children:"C2"}),"codex"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-emerald-500/15 text-emerald-400 font-medium leading-relaxed",children:"CX"}),"kimi"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-blue-500/15 text-blue-400 font-medium leading-relaxed",children:"KM"}),"ollama"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-violet-500/15 text-violet-400 font-medium leading-relaxed",children:"OL"}),"deepseek"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-sky-500/15 text-sky-400 font-medium leading-relaxed",children:"DS"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x(a.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:C("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},a.id)),(0,n.jsx)(c,{onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j})]})})}},37614:(e,t,r)=>{r.d(t,{t:()=>l});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,comment:r,container:a,onClose:i,onUpdateComment:c,onDeleteComment:d}){let{t:u}=(0,o.Bd)(),[h,m]=(0,s.useState)(!1),[x,f]=(0,s.useState)(r.content),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&a){let r=a.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>b({x:s,y:o}))}},[e,t,a]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i]);let v=async()=>{x.trim()&&(await c(r.id,x.trim()),m(!1))},j=async()=>{await d(r.id),i()};return(0,n.jsx)("div",{ref:p,className:"absolute z-[200] w-96 bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:(0,n.jsx)("div",{className:"p-3",children:h?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("textarea",{value:x,onChange:e=>f(e.target.value),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:3,autoFocus:!0,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),v()),"Escape"===e.key&&(m(!1),f(r.content))}}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>{m(!1),f(r.content)},className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground",children:u("common.cancel")}),(0,n.jsx)("button",{onClick:v,className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90",children:u("common.save")})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:r.content}),(0,n.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:r.startLine,end:r.endLine})}),(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:()=>m(!0),className:"p-1 rounded hover:bg-accent text-muted-foreground",title:u("common.edit"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{onClick:j,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-red-9",title:u("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]})]})})})}},38408:(e,t,r)=>{r.d(t,{Cv:()=>$,XO:()=>R});var n=r(95155),s=r(12115),o=r(79114),l=r(47650),a=r(70188),i=r(7320),c=r(56978),d=r(17196),u=r(89109),h=r(37614),m=r(69809),x=r(64428);function f({blame:e,onClick:t}){let{t:r}=(0,o.Bd)(),l=(0,s.useRef)(null),a=(0,s.useRef)(null),i=(0,x.F2)(),c=(0,s.useRef)(!1),d=(0,s.useRef)(!1),u=(0,s.useRef)(null),h=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(e);(0,s.useEffect)(()=>{g.current=e},[e]);let b=(0,s.useRef)(t);(0,s.useEffect)(()=>{b.current=t},[t]);let v=(0,s.useCallback)(()=>{let e,t=a.current,r=l.current;if(!t||!r)return;let n=r.getBoundingClientRect(),s=t.getBoundingClientRect(),o=i?.getBoundingClientRect(),c=o?.left??0,d=o?.top??0,u=o?.width??window.innerWidth,h=o?.height??window.innerHeight,m=n.left-c;m+s.width>u-8&&(m=u-s.width-8),m<8&&(m=8);let x=n.top-d,f=n.bottom-d;(e=x-s.height-4<0?f+4:x-s.height-4)+s.height>h-8&&(e=h-s.height-8),t.style.left=`${m}px`,t.style.top=`${e}px`},[i]),j=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),h.current&&(clearTimeout(h.current),h.current=null),c.current=!1,d.current=!1,a.current&&(a.current.style.display="none"),p.current&&(document.removeEventListener("mousedown",p.current.down),document.removeEventListener("mouseup",p.current.up),p.current=null)},[]),y=(0,s.useCallback)(()=>{let e=a.current;if(!e||c.current)return;c.current=!0,e.style.left="-9999px",e.style.top="-9999px",e.style.display="block",requestAnimationFrame(()=>requestAnimationFrame(v));let t=0,r=0,n=e=>{t=e.clientX,r=e.clientY},s=e=>{if(!(Math.abs(e.clientX-t)>5||Math.abs(e.clientY-r)>5)){let t;t=e.target,a.current?.contains(t)||l.current?.contains(t)||j()}};document.addEventListener("mousedown",n),document.addEventListener("mouseup",s),p.current={down:n,up:s}},[v,j]),w=(0,s.useCallback)(()=>{if(u.current&&clearTimeout(u.current),h.current&&(clearTimeout(h.current),h.current=null),c.current)return;let e=window.getSelection();(!e||e.isCollapsed)&&(u.current=setTimeout(y,500))},[y]),k=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),c.current&&(h.current=setTimeout(()=>{d.current||j()},200))},[j]),N=(0,s.useCallback)(()=>{d.current=!0,h.current&&(clearTimeout(h.current),h.current=null)},[]),C=(0,s.useCallback)(()=>{d.current=!1,j()},[j]),S=(0,s.useCallback)(e=>{e.stopPropagation();let t=window.getSelection();t&&t.toString().length>0&&a.current?.contains(t.anchorNode)||(b.current?.(g.current),j())},[j]);(0,s.useEffect)(()=>()=>j(),[j]);let L=e.message.split("\n")[0]||"",M=e.message.split("\n").slice(1).join("\n").trim();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{ref:l,className:"select-none text-xs text-muted-foreground/50 ml-6 cursor-default hover:text-muted-foreground/80",onMouseEnter:w,onMouseLeave:k,children:[e.author.split(" ")[0],", ",function(e){let t=m.A.t,r=Math.floor((Date.now()-1e3*e)/1e3);if(r<60)return t("common.justNow");let n=Math.floor(r/60);if(n<60)return t("common.minutesAgo",{count:n});let s=Math.floor(n/60);if(s<24)return t("common.hoursAgo",{count:s});let o=Math.floor(s/24);if(o<30)return t("common.daysAgo",{count:o});let l=Math.floor(o/30);return l<12?t("common.monthsAgo",{count:l}):t("common.yearsAgo",{count:Math.floor(l/12)})}(e.time)," \xb7 ",L]}),(0,n.jsx)(x.ZL,{children:(0,n.jsxs)("div",{ref:a,className:"fixed z-[9999] bg-card border border-border rounded-lg shadow-xl p-3 text-xs text-foreground whitespace-pre-wrap max-w-md select-text",style:{display:"none",minWidth:280,cursor:"text"},"data-inline-blame-tip":"",onMouseEnter:N,onMouseLeave:C,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("span",{className:"font-mono text-brand",children:e.hash}),(0,n.jsx)("span",{className:"text-muted-foreground",children:e.author}),(0,n.jsx)("span",{className:"text-muted-foreground/60",children:new Date(1e3*e.time).toLocaleString()})]}),(0,n.jsx)("div",{className:"font-medium",children:L}),M&&(0,n.jsx)("div",{className:"mt-1 text-muted-foreground",children:M}),(0,n.jsx)("div",{className:"mt-2 text-[11px] text-brand border-t border-border pt-2 cursor-pointer hover:underline",onClick:S,children:r("codeViewer.clickToViewDetails")})]})})]})}let p=[{bg:"rgba(59, 130, 246, 0.15)",border:"rgb(59, 130, 246)"},{bg:"rgba(16, 185, 129, 0.15)",border:"rgb(16, 185, 129)"},{bg:"rgba(245, 158, 11, 0.15)",border:"rgb(245, 158, 11)"},{bg:"rgba(239, 68, 68, 0.15)",border:"rgb(239, 68, 68)"},{bg:"rgba(168, 85, 247, 0.15)",border:"rgb(168, 85, 247)"},{bg:"rgba(236, 72, 153, 0.15)",border:"rgb(236, 72, 153)"},{bg:"rgba(20, 184, 166, 0.15)",border:"rgb(20, 184, 166)"},{bg:"rgba(249, 115, 22, 0.15)",border:"rgb(249, 115, 22)"}];function g(e,t){let r,n=document.caretRangeFromPoint(e.clientX,e.clientY);if(!n||!t.contains(n.startContainer))return 1;let s=n.startContainer,o=n.startOffset,l=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),a=1;for(;r=l.nextNode();){if(r===s){a+=o;break}a+=r.textContent?.length||0}return a}let b=(0,s.memo)(function({virtualKey:e,lineNum:t,highlightedHtml:r,hasComments:l,firstComment:a,lineCommentsCount:i,isInRange:c,showLineNumbers:d,lineNumChars:u,commentsEnabled:h,virtualItemSize:m,virtualItemStart:x,onCommentBubbleClick:p,onCmdClick:b,onTokenHover:v,onTokenHoverLeave:j,flashLine:y,blameLine:w,showBlameInfo:k,blameAuthorColor:N,isBlameHovered:C,onBlameClick:S,onBlameMouseEnter:L,onBlameMouseLeave:M,inlineBlameData:E,onInlineBlameClick:T,isCursorLine:$,cursorCol:R}){let{t:P}=(0,o.Bd)(),B=(0,s.useMemo)(()=>$&&null!=R?function(e,t){let r=0,n=0;for(;n<e.length;){if("<"===e[n]){let t=e.indexOf(">",n);if(-1!==t){n=t+1;continue}}if(r===t){let t;if("&"===e[n]){let r=e.indexOf(";",n);t=-1!==r&&r-n<10?r+1:n+1}else t=n+1;let r=e.substring(n,t);return e.substring(0,n)+'<span class="vi-char-cursor">'+r+"</span>"+e.substring(t)}if("&"===e[n]){let t=e.indexOf(";",n);n=-1!==t&&t-n<10?t+1:n+1}else n++;r++}return e+'<span class="vi-char-cursor"> </span>'}(r,R):r,[r,$,R]),I=(0,s.useCallback)(e=>{if(!e.metaKey||!b)return;e.preventDefault(),e.stopPropagation();let r=e.currentTarget,n=g(e,r);window.getSelection()?.removeAllRanges(),b(t,n)},[t,b]),D=(0,s.useCallback)(e=>{if(!v||0!==e.buttons)return;let r=window.getSelection();if(r&&!r.isCollapsed)return;let n=e.target;if("SPAN"!==n.tagName||!n.style.color)return;let s=e.currentTarget,o=g(e,s),l=n.getBoundingClientRect();v(t,o,{x:l.left,y:l.bottom+4})},[t,v]),F=(0,s.useCallback)(()=>{w&&S&&S(w)},[w,S]),A=(0,s.useCallback)(e=>{w&&L&&L(w,e)},[w,L]);return(0,n.jsxs)("div",{"data-line":t,style:{position:"absolute",top:0,left:0,width:"100%",height:`${m}px`,transform:`translateY(${x}px)`,backgroundColor:C&&N?N.bg:void 0},className:`flex ${y===t?"flash-line":""} ${$?"vi-cursor-line":""} ${c?"bg-blue-9/20":l?"bg-amber-9/10":"hover:bg-accent/50"}`,children:[(0,n.jsxs)("div",{className:"flex shrink-0 sticky left-0 z-[2] bg-secondary",style:{backgroundColor:C&&N?N.bg:void 0},children:[w&&N&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-1 flex-shrink-0",style:{backgroundColor:N.border}}),(0,n.jsx)("div",{className:"w-48 flex-shrink-0 px-2 flex items-center gap-2 border-r border-border text-muted-foreground cursor-pointer hover:bg-accent/50",onMouseEnter:A,onMouseLeave:M,onClick:F,title:P("codeViewer.clickToViewCommit"),children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"font-medium",style:{color:N.border},children:w.hash}),(0,n.jsx)("span",{className:"truncate flex-1",children:w.author.split(" ")[0]})]}):null})]}),d&&(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center justify-end gap-0.5 pr-2 select-none border-r border-border font-variant-tabular ${c?"bg-blue-9/30 text-blue-11":"bg-card/50 text-slate-9"}`,children:[h&&l&&a&&(0,n.jsx)("button",{onClick:e=>p(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:P("codeViewer.nComments",{count:i}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),h&&!l&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"text-right",style:{minWidth:`${u}ch`},children:t})]})]}),(0,n.jsxs)("span",{className:"flex-1 px-3 whitespace-pre select-text",onClick:I,onMouseOver:D,onMouseLeave:j,"data-code-content":!0,children:[(0,n.jsx)("span",{dangerouslySetInnerHTML:{__html:B}}),E&&(0,n.jsx)(f,{blame:E,onClick:T})]})]},e)});var v=r(64702),j=r(1058),y=r(90717),w=r(48347);function k(e,t,r){let n,s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o=0;for(;(n=s.nextNode())&&n!==t;)o+=n.textContent.length;return o+r}function N(e,t){let r,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=t,o=null;for(;r=n.nextNode();){o=r;let e=r.textContent.length;if(s<=e)return{node:r,offset:s};s-=e}return o?{node:o,offset:o.textContent.length}:null}var C=r(82292),S=r(34075);let L="white-space:pre;padding:0 12px;min-height:20px;line-height:20px";function M(e){let t=window.getSelection();if(!t?.rangeCount)return null;let r=t.getRangeAt(0),n=r.startContainer;for(;n&&n.parentElement!==e;)n=n.parentElement;if(!n)return null;let s=Array.from(e.children).indexOf(n);if(s<0)return null;let o=document.createRange();return o.selectNodeContents(n),o.setEnd(r.startContainer,r.startOffset),{line:s,offset:o.toString().length}}function E(e,t){let r,n=e.children[t.line];if(!n)return;let s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=t.offset;for(;r=s.nextNode();){let e=r.textContent?.length||0;if(o<=e){let e=window.getSelection(),t=document.createRange();t.setStart(r,o),t.collapse(!0),e?.removeAllRanges(),e?.addRange(t);return}o-=e}let l=window.getSelection(),a=document.createRange();a.selectNodeContents(n),a.collapse(!1),l?.removeAllRanges(),l?.addRange(a)}function T(e){return e.map(e=>`<div style="${L}">${e}</div>`).join("")}let $=(0,s.forwardRef)(function({content:e,filePath:t,showLineNumbers:r=!0,showSearch:m=!0,className:x="",cwd:f,enableComments:g=!1,scrollToLine:$=null,scrollToLineAlign:R="center",onScrollToLineComplete:P,highlightKeyword:B=null,visibleLineRef:I,onCmdClick:D,onTokenHover:F,onTokenHoverLeave:A,onTokenHoverCancel:O,blameLines:W,inlineBlameLines:z,onSelectCommit:H,editable:_=!1,initialMtime:q,onEditorClose:V,onSaved:U,onEditorStateChange:K,viMode:J=!1,onContentMutate:X,onEnterInsertMode:Y,onViSave:Q,viStateRef:G,initialCursorLine:Z,initialCursorCol:ee,onInitialCursorSet:et,onContentSearch:er},en){let{t:es}=(0,o.Bd)(),eo=(0,s.useRef)(e),el=(0,s.useRef)(!1),[ea,ei]=(0,s.useState)(!1),[ec,ed]=(0,s.useState)(!1),[eu,eh]=(0,s.useState)(()=>e.split("\n").length),em=(0,s.useRef)(e.split("\n").length),[ex,ef]=(0,s.useState)({show:!1}),ep=(0,s.useRef)(null),eg=(0,s.useRef)(null),eb=(0,s.useRef)(q),ev=(0,s.useRef)(null),ej=(0,s.useRef)(!1),ey=(0,s.useRef)(!1),{parentRef:ew,containerRef:ek,searchInputRef:eN,floatingToolbarRef:eC,suppressHoverRef:eS,bumpToolbarRef:eL,savedSelectionRef:eM,highlightedLines:eE,isMounted:eT,cmdHeld:e$,flashLine:eR,isSearchVisible:eP,searchQuery:eB,caseSensitive:eI,wholeWord:eD,currentMatchIndex:eF,viewingComment:eA,addCommentInput:eO,sendToAIInput:eW,aiBridge:ez,commentsEnabled:eH,updateComment:e_,deleteComment:eq,lines:eV,matches:eU,rowData:eK,virtualizer:eJ,commentsByEndLine:eX,linesWithComments:eY,setIsSearchVisible:eQ,setSearchQuery:eG,setCaseSensitive:eZ,setWholeWord:e0,setViewingComment:e1,setAddCommentInput:e2,setSendToAIInput:e5,goToNextMatch:e4,goToPrevMatch:e3,handleSearchKeyDown:e6,handleCommentBubbleClick:e8,handleToolbarAddComment:e9,handleToolbarSendToAI:e7,handleToolbarSearch:te,handleCommentSubmit:tt,handleSendToAISubmit:tr,getHighlightedLineHtml:tn,suppressMatchScrollRef:ts,inlineBlameLineRef:to,inlineBlameVersion:tl}=function({content:e,filePath:t,showSearch:r=!0,cwd:n,enableComments:o=!1,scrollToLine:l=null,scrollToLineAlign:a="center",onScrollToLineComplete:i,visibleLineRef:u,onContentSearch:h}){let[m,x]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,w.r)();(0,s.useEffect)(()=>{x(!0)},[]);let[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),M=(0,s.useRef)(null),[E,T]=(0,s.useState)(!1),[$,R]=(0,s.useState)(""),[P,B]=(0,s.useState)(!1),[I,D]=(0,s.useState)(!1),[F,A]=(0,s.useState)(0),[O,W]=(0,s.useState)(0),z=(0,s.useRef)(!1),[H,_]=(0,s.useState)(null),q=(0,s.useRef)(null),V=(0,s.useRef)(()=>{}),U=(0,s.useRef)(!1),K=(0,s.useRef)(null),[J,X]=(0,s.useState)(null),[Y,Q]=(0,s.useState)(null),G=(0,s.useRef)(null),[Z,ee]=(0,s.useState)(0),et=o&&!!n,{comments:er,addComment:en,updateComment:es,deleteComment:eo,refresh:el}=(0,j._)({cwd:n||"",filePath:t}),ea=(0,s.useMemo)(()=>e.split("\n"),[e]),ei=(0,c.C)(ea,t),ec=(0,s.useMemo)(()=>{let e=new Map;for(let t of er){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[er]),ed=(0,s.useMemo)(()=>{let e=new Set;for(let t of er)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[er]),eu=(0,s.useMemo)(()=>(0,d.Np)(ea,$,P,I),[ea,$,P,I]);(0,s.useEffect)(()=>{eu.length>0&&A(0)},[eu.length,$,P,I]);let eh=(0,s.useMemo)(()=>{let e=[];for(let t=0;t<ea.length;t++)e.push({type:"code",lineIndex:t});return e},[ea.length]),em=(0,v.Te)({count:eh.length,getScrollElement:()=>f.current,estimateSize:()=>20,overscan:10});(0,s.useEffect)(()=>{if(!u)return;let e=f.current;if(!e)return;let t=()=>{if(!em.range)return;let t=e.scrollTop;for(let e of em.getVirtualItems())if(e.start>=t){let t=eh[e.index];t?.type==="code"&&(u.current=t.lineIndex+1);return}};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[u,eh]),(0,s.useEffect)(()=>{let e=e=>{"Meta"===e.key&&C(!0)},t=e=>{"Meta"===e.key&&C(!1)},r=()=>C(!1);return window.addEventListener("keydown",e),window.addEventListener("keyup",t),window.addEventListener("blur",r),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t),window.removeEventListener("blur",r)}},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),T(!0),setTimeout(()=>g.current?.focus(),0)),"Escape"===e.key&&(E?(T(!1),R("")):Y?Q(null):J?X(null):q.current?(q.current=null,V.current()):H&&_(null))},t=p.current;if(t)return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[r,E,Y,J,H]),(0,s.useEffect)(()=>{if(z.current){z.current=!1;return}if(eu.length>0&&F>=0&&F<eu.length){let e=eu[F],t=eh.findIndex(t=>"code"===t.type&&t.lineIndex===e.lineIndex);t>=0&&em.scrollToIndex(t,{align:"center"})}},[F,eu,em,eh,O]);let ex=(0,s.useCallback)(()=>{0!==eu.length&&(A(e=>(e+1)%eu.length),W(e=>e+1))},[eu.length]),ef=(0,s.useCallback)(()=>{0!==eu.length&&(A(e=>(e-1+eu.length)%eu.length),W(e=>e+1))},[eu.length]),ep=(0,s.useRef)(l);ep.current=l,(0,s.useEffect)(()=>{if(null!==ep.current&&ep.current>0&&eh.length>0){let e=ep.current,t=e-1,r=eh.findIndex(e=>"code"===e.type&&e.lineIndex===t);if(r>=0){let t=()=>{em.scrollToIndex(r,{align:a}),"center"===a&&(M.current&&clearTimeout(M.current),L(e),M.current=setTimeout(()=>L(null),500)),i?.()};"start"===a?requestAnimationFrame(t):setTimeout(t,150)}}},[l,a,eh.length,em,i]);let eg=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ef():ex()),"Escape"===e.key&&(T(!1),R(""))},[ex,ef]),eb=(0,s.useCallback)((e,t)=>{et&&(t.stopPropagation(),_({comment:e,x:t.clientX,y:t.clientY}),q.current=null,V.current(),X(null),Q(null))},[et]);(0,s.useEffect)(()=>{if(!et)return;let e=f.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,K.current=null,U.current=!0,q.current&&(q.current=null,V.current())},o=e=>{t=!1;let s=e.target;if(s.closest?.(".floating-toolbar"))return;let o=Math.abs(e.clientX-r)>5||Math.abs(e.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed){U.current=!1,q.current&&(q.current=null,V.current());return}let a=l.toString();if(!a.trim()||!o){U.current=!1,q.current&&(q.current=null,V.current());return}let i=l.getRangeAt(0),c=f.current;if(!c||!c.contains(i.commonAncestorContainer))return;let d=i.startContainer,u=i.endContainer,h=e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t)return null;let r=t.closest("[data-line]");return r?parseInt(r.getAttribute("data-line")||"0",10):null},m=h(d),x=h(u);if(m&&x){let t=Math.min(m,x),r=Math.max(m,x);q.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},selectedText:a},U.current=!0,V.current();let n=d.nodeType===Node.TEXT_NODE?d.parentElement?.closest("[data-line]"):d.closest("[data-line]"),s=u.nodeType===Node.TEXT_NODE?u.parentElement?.closest("[data-line]"):u.closest("[data-line]");n&&s&&(K.current={startLine:m,startOffset:k(n,i.startContainer,i.startOffset),endLine:x,endOffset:k(s,i.endContainer,i.endOffset)})}},l=()=>{if(t||!q.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(q.current=null,K.current=null,U.current=!1,V.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[et]),(0,s.useEffect)(()=>{let e=f.current;if(!e)return;let t=t=>{let r,n;if(!e.contains(t.target)){if(t.target.closest?.("[data-inline-blame-tip]"))return;null!==G.current&&(G.current=null,ee(e=>e+1));return}let s=window.getSelection();if(s&&!s.isCollapsed&&s.toString().trim())return;let o=(r=t.target,(n=r.closest?.("[data-line]"))?parseInt(n.getAttribute("data-line")||"0",10):null);o!==G.current&&(G.current=o,requestAnimationFrame(()=>ee(e=>e+1)))};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]);let ev=(0,s.useCallback)(()=>{let e=q.current;e&&(X({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),q.current=null,V.current())},[]),ej=(0,s.useCallback)(()=>{let e=q.current;if(!e)return;let t=e.selectedText;Q({x:e.x,y:e.y,range:e.range,codeContent:t}),q.current=null,V.current()},[]),ey=(0,s.useCallback)(()=>{let e=q.current;if(!e||!h)return;let t=e.selectedText.trim();q.current=null,V.current(),t&&h(t)},[h]),ew=(0,s.useCallback)(async e=>{J&&(await en(J.range.start,J.range.end,e),X(null))},[J,en]),ek=(0,s.useCallback)(async e=>{if(Y&&b&&n)try{let r=await (0,y.$3)(n),s=[];for(let e of r)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:Y.range.start,endLine:Y.range.end,codeContent:Y.codeContent});let o=(0,y.Gw)(s,e);b.sendMessage(o),await (0,y.RP)(n),el(),Q(null)}catch(e){console.error("Failed to send to AI:",e)}},[Y,b,t,n,el]),eN=(0,s.useCallback)((e,t,r)=>{let n=ea[e];if(!n)return t;let s=[];if($&&eu.length>0)for(let t of eu.filter(t=>t.lineIndex===e)){let r=eu[F]?.lineIndex===e&&eu[F]?.startCol===t.startCol;s.push({start:t.startCol,end:t.endCol,cls:r?"hl-cur":"hl-m"})}if(r&&!$&&r.length>=1){let e=r.toLowerCase(),t=n.toLowerCase(),o=0;for(;-1!==(o=t.indexOf(e,o));)s.push({start:o,end:o+r.length,cls:"hl-kw"}),o+=1}if(0===s.length)return t;s.sort((e,t)=>e.start-t.start||e.end-t.end);let o=[],l=0;for(let e of s){if(e.start<l)continue;e.start>l&&o.push((0,d.ZD)(n.substring(l,e.start)));let t=(0,d.ZD)(n.substring(e.start,e.end));o.push(`<span class="${e.cls}">${t}</span>`),l=e.end}if(l<n.length&&o.push((0,d.ZD)(n.substring(l))),t!==(0,d.ZD)(n)){let e=t;for(let t of s){let r=n.substring(t.start,t.end),s=(0,d.ZD)(r),o=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=RegExp(`(?<=>)([^<]*?)(${o})`,""),a=`$1<span class="${t.cls}">${s}</span>`,i=e.replace(l,a);i.length>e.length+200||(e=i)}return e}return o.join("")},[$,eu,F,ea]);return{parentRef:f,containerRef:p,searchInputRef:g,floatingToolbarRef:q,suppressHoverRef:U,savedSelectionRef:K,highlightedLines:ei,isMounted:m,cmdHeld:N,flashLine:S,isSearchVisible:E,searchQuery:$,caseSensitive:P,wholeWord:I,currentMatchIndex:F,viewingComment:H,bumpToolbarRef:V,addCommentInput:J,sendToAIInput:Y,aiBridge:b,commentsEnabled:et,comments:er,updateComment:es,deleteComment:eo,lines:ea,matches:eu,rowData:eh,virtualizer:em,commentsByEndLine:ec,linesWithComments:ed,setIsSearchVisible:T,setSearchQuery:R,suppressMatchScrollRef:z,setCaseSensitive:B,setWholeWord:D,setViewingComment:_,setAddCommentInput:X,setSendToAIInput:Q,goToNextMatch:ex,goToPrevMatch:ef,handleSearchKeyDown:eg,handleCommentBubbleClick:eb,handleToolbarAddComment:ev,handleToolbarSendToAI:ej,handleToolbarSearch:ey,handleCommentSubmit:ew,handleSendToAISubmit:ek,getHighlightedLineHtml:eN,inlineBlameLineRef:G,inlineBlameVersion:Z}}({content:e,filePath:t,showSearch:m,cwd:f,enableComments:!_&&g,scrollToLine:_?null:$,scrollToLineAlign:_?"center":R,onScrollToLineComplete:_?void 0:P,visibleLineRef:_?void 0:I,onContentSearch:er}),ta=(0,a.iN)(),ti=(0,s.useRef)(null),tc=(0,s.useRef)(null),td=(0,s.useRef)({line:0,col:0}),tu=function({lines:e,enabled:t,onContentChange:r,onEnterInsert:n,onSave:o,getVisibleLineCount:l,scrollToLine:a,onSearchExecute:i,onSearchNext:c,onSearchPrev:d,onSearchClear:u}){let[h,m]=(0,s.useState)("normal"),[x,f]=(0,s.useState)(-1),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(!1),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)(""),[N,C]=(0,s.useState)(""),[S,L]=(0,s.useState)(""),M=(0,s.useRef)([]),E=(0,s.useRef)([]),T=(0,s.useRef)([]),$=(0,s.useRef)(null),R=(0,s.useRef)(e);(0,s.useEffect)(()=>{R.current=e}),(0,s.useEffect)(()=>{0!==e.length&&queueMicrotask(()=>f(t=>Math.min(t,e.length-1)))},[e.length]);let P=(0,s.useCallback)((e,t)=>Math.max(0,Math.min(t,Math.max(0,(R.current[e]??"").length-1))),[]),B=(0,s.useRef)(e.length);(0,s.useEffect)(()=>{let t=Math.abs(e.length-B.current);B.current=e.length,t>10&&(queueMicrotask(()=>{f(-1),g(0),v(!1)}),M.current=[],E.current=[],T.current=[])},[e]);let I=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null),y("")},[]),D=(0,s.useCallback)(()=>{$.current&&clearTimeout($.current),$.current=setTimeout(()=>{y(""),$.current=null},500)},[]),F=(0,s.useCallback)((e,t)=>{M.current.push(t),E.current=[],v(!0),r(e.join("\n"))},[r]),A=(0,s.useCallback)((e,t)=>{let r=Math.max(0,Math.min(e,R.current.length-1));f(r),g(P(r,t??0)),a(r,"auto")},[a,P]),O=(0,s.useCallback)(e=>{f(t=>{let r=Math.max(0,Math.min(t+e,R.current.length-1));return a(r,"auto"),g(e=>Math.max(0,Math.min(e,Math.max(0,(R.current[r]??"").length-1)))),r})},[a]),W=(0,s.useCallback)(()=>{let e=R.current,t=Math.min(x,e.length-1);if(0===e.length)return;let r=e[t];T.current=[r];let n=[...e];n.splice(t,1),0===n.length&&n.push("");let s=Math.min(t,n.length-1);F(n,{lineIndex:t,oldLines:[r],newLines:[],cursorLine:t}),f(s),g(0)},[x,F]),z=(0,s.useCallback)(()=>{let e=R.current,t=Math.min(x,e.length-1);e.length>0&&(T.current=[e[t]])},[x]),H=(0,s.useCallback)(()=>{let e=T.current;if(0===e.length)return;let t=R.current,r=Math.min(x,t.length-1)+1,n=[...t];n.splice(r,0,...e),F(n,{lineIndex:r,oldLines:[],newLines:[...e],cursorLine:x}),f(r),g(0),a(r,"auto")},[x,F,a]),_=(0,s.useCallback)(()=>{let e=R.current,t=Math.min(x,e.length-1),r=e[t];if(!r||0===r.length)return;let n=r.substring(1),s=[...e];s[t]=n,F(s,{lineIndex:t,oldLines:[r],newLines:[n],cursorLine:x})},[x,F]),q=(0,s.useCallback)(()=>{let e=M.current;if(0===e.length)return;let t=e.pop(),n=[...R.current];0===t.newLines.length&&t.oldLines.length>0?n.splice(t.lineIndex,0,...t.oldLines):0===t.oldLines.length&&t.newLines.length>0?(n.splice(t.lineIndex,t.newLines.length),0===n.length&&n.push("")):n.splice(t.lineIndex,t.newLines.length,...t.oldLines),E.current.push(t),r(n.join("\n")),f(Math.min(t.cursorLine,n.length-1)),a(Math.min(t.cursorLine,n.length-1),"auto"),0===e.length&&v(!1)},[r,a]),V=(0,s.useCallback)(()=>{let e=E.current;if(0===e.length)return;let t=e.pop(),n=[...R.current];0===t.newLines.length&&t.oldLines.length>0?(n.splice(t.lineIndex,t.oldLines.length),0===n.length&&n.push("")):0===t.oldLines.length&&t.newLines.length>0?n.splice(t.lineIndex,0,...t.newLines):n.splice(t.lineIndex,t.oldLines.length,...t.newLines),M.current.push(t),v(!0),r(n.join("\n"));let s=t.lineIndex+Math.max(0,t.newLines.length-1);f(Math.min(s,n.length-1)),a(Math.min(s,n.length-1),"auto")},[r,a]),U=(0,s.useCallback)(e=>{let t=R.current,r=Math.min(x,t.length-1);if("o"===e||"O"===e){let n="o"===e?r+1:r,s=[...t];s.splice(n,0,""),F(s,{lineIndex:n,oldLines:[],newLines:[""],cursorLine:x}),r=n,f(n)}m("insert"),n(r,p,e)},[x,p,F,n]),K=(0,s.useCallback)(()=>{m("normal"),I()},[I]),J=(0,s.useCallback)(()=>{m("command"),k("")},[]),X=(0,s.useCallback)(()=>{m("normal"),k("")},[]),Y=(0,s.useCallback)(()=>{m("search"),C("")},[]),Q=(0,s.useCallback)(()=>{m("normal"),C("")},[]),G=(0,s.useCallback)(e=>{let t=e.trim();if("w"===t){o?.(),m("normal"),k("");return}if("q"===t){m("normal"),k("");return}if("wq"===t){o?.(),m("normal"),k("");return}if("noh"===t||"nohlsearch"===t){u?.(),m("normal"),k("");return}let r=parseInt(t,10);if(!isNaN(r)&&r>0){let e=Math.min(r-1,R.current.length-1);f(e),a(e,"center"),m("normal"),k("");return}m("normal"),k("")},[o,u,a]),Z=(0,s.useCallback)(e=>{if(!e){m("normal"),C("");return}L(e),i?.(e),m("normal"),C("")},[i]),ee=(0,s.useCallback)(e=>{if(!t)return!1;let r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;if("insert"===h)return("Escape"===e.key||!!r)&&(K(),!0);if("command"===h)return!e.isComposing&&("Escape"===e.key||r?X():"Enter"===e.key?G(w):"Backspace"===e.key?0===w.length?X():k(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||k(t=>t+e.key),!0);if("search"===h)return!e.isComposing&&("Escape"===e.key||r?Q():"Enter"===e.key?Z(N):"Backspace"===e.key?0===N.length?Q():C(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||C(t=>t+e.key),!0);if(x<0&&(f(0),g(0)),e.metaKey)return!1;if(e.ctrlKey)return"d"===e.key?(O(Math.max(1,Math.floor(l()/2))),I(),!0):"u"===e.key?(O(-Math.max(1,Math.floor(l()/2))),I(),!0):"r"===e.key&&(V(),I(),!0);let n=e.key,s=j+n;if("g"===s)return y("g"),D(),!0;if("gg"===s)return A(0),I(),!0;if("d"===s)return y("d"),D(),!0;if("dd"===s)return W(),I(),!0;if("y"===s)return y("y"),D(),!0;if("yy"===s)return z(),I(),!0;if(j&&s!==n&&I(),"j"===n||"ArrowDown"===n)return O(1),!0;if("k"===n||"ArrowUp"===n)return O(-1),!0;if("h"===n||"ArrowLeft"===n)return g(e=>Math.max(0,e-1)),!0;if("l"===n||"ArrowRight"===n){let e=Math.max(0,(R.current[x]??"").length-1);return g(t=>Math.min(e,t+1)),!0}if("0"===n)return g(0),!0;if("$"===n)return g(Math.max(0,(R.current[x]??"").length-1)),!0;if("^"===n){let e=(R.current[x]??"").search(/\S/);return g(e>=0?e:0),!0}return"G"===n?(A(R.current.length-1),!0):"x"===n?(_(),!0):"p"===n?(H(),!0):"u"===n?(q(),!0):"i"===n||"a"===n||"I"===n||"A"===n||"o"===n||"O"===n?(U(n),!0):"/"===n?(Y(),!0):"n"===n?(c?.(),!0):"N"===n?(d?.(),!0):":"===n?(J(),!0):"Escape"!==n&&1===n.length},[t,h,j,w,N,x,K,U,J,X,Y,Q,G,Z,O,A,l,W,z,H,_,q,V,I,D,c,d]);return{state:{mode:h,cursorLine:x,cursorCol:p,isDirty:b,keyBuffer:j,commandInput:w,searchInput:N,lastSearch:S},handleKeyDown:ee,enterNormal:K,enterInsert:U,setCursorLine:f,setCursorCol:g,setCommandInput:k,setSearchInput:C,setIsDirty:v,clearUndoHistory:(0,s.useCallback)(()=>{M.current=[],E.current=[]},[])}}({lines:eV,enabled:J&&!_,onContentChange:e=>{X?.(e)},onEnterInsert:(e,t,r)=>{let n=t;if("a"===r)n=t+1;else if("A"===r)n=(eV[e]??"").length;else if("I"===r){let t=(eV[e]??"").search(/\S/);n=t>=0?t:0}else("o"===r||"O"===r)&&(n=0);td.current={line:e,col:n},Y?.(e)},onSave:Q,getVisibleLineCount:()=>{let e=ew.current;return e?Math.floor(e.clientHeight/20):20},scrollToLine:(e,t)=>{let r=eK.findIndex(t=>"code"===t.type&&t.lineIndex===e);r>=0&&eJ.scrollToIndex(r,{align:t||"auto"})},onSearchExecute:e=>{eG(e),eQ(!1)},onSearchNext:e4,onSearchPrev:e3,onSearchClear:()=>{eG("")}});(0,s.useEffect)(()=>{G&&(G.current={cursorLine:tu.state.cursorLine,cursorCol:tu.state.cursorCol})},[G,tu.state.cursorLine,tu.state.cursorCol]);let th=(0,s.useRef)(null);(0,s.useEffect)(()=>{J&&!_&&null!=Z&&t&&th.current!==t&&(th.current=t,tu.setCursorLine(Z-1),null!=ee&&tu.setCursorCol(ee-1),et?.())},[J,_,Z,ee,t]),(0,s.useEffect)(()=>{if(!J||_)return;let e=ek.current;if(!e)return;let t=e=>{let t=e.target;"TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable||tu.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[J,_,tu.handleKeyDown]),(0,s.useEffect)(()=>{if(!J||_)return;let e=ek.current;e&&"normal"===tu.state.mode&&requestAnimationFrame(()=>{let t=document.activeElement;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||e.focus()})},[J,_,tu.state.mode,e]);let tm=(0,s.useCallback)(e=>{if(!J||_)return;let t=e.target.closest("[data-line]");if(t){let r=parseInt(t.getAttribute("data-line"),10);if(!isNaN(r)){tu.setCursorLine(r-1);let n=t.querySelector("[data-code-content]");if(n){let t=document.caretRangeFromPoint(e.clientX,e.clientY);if(t&&n.contains(t.startContainer)){let e,s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=0;for(;e=s.nextNode();){if(e===t.startContainer){o+=t.startOffset;break}o+=e.textContent?.length||0}let l=eV[r-1]??"";tu.setCursorCol(Math.max(0,Math.min(o,Math.max(0,l.length-1))))}}}}let r=e.target;if("TEXTAREA"===r.tagName||"INPUT"===r.tagName||r.isContentEditable)return;let n=ek.current;n&&n.focus()},[J,_,tu.setCursorLine,tu.setCursorCol,eV]),tx=(0,s.useCallback)(e=>{J&&!_&&requestAnimationFrame(()=>{let e=window.getSelection(),t=e?.toString().trim();t&&/^\S+$/.test(t)&&(ts.current=!0,eG(t))})},[J,_,eG,ts]);(0,s.useEffect)(()=>{"command"===tu.state.mode?setTimeout(()=>ti.current?.focus(),0):"search"===tu.state.mode&&setTimeout(()=>tc.current?.focus(),0)},[tu.state.mode]),(0,s.useEffect)(()=>{let e=ew.current;if(!e)return;let t=()=>{(O??A)?.()};return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t)},[O,A]),(0,s.useEffect)(()=>{eO||eW?(eS.current=!0,A?.()):eC.current||(eS.current=!1)},[eO,eW,A]),(0,s.useLayoutEffect)(()=>{let e=eM.current;if(!e)return;let t=window.getSelection();if(t&&!t.isCollapsed)return;let r=ew.current;if(!r)return;let n=r.querySelector(`[data-line="${e.startLine}"]`),s=r.querySelector(`[data-line="${e.endLine}"]`);if(!n||!s)return;let o=N(n,e.startOffset),l=N(s,e.endOffset);if(o&&l)try{let e=document.createRange();e.setStart(o.node,o.offset),e.setEnd(l.node,l.offset),t?.removeAllRanges(),t?.addRange(e)}catch{}});let tf=(0,s.useCallback)((e,t,r)=>{eS.current||F?.(e,t,r)},[F]),tp=(0,s.useCallback)((e,t)=>{eS.current||D?.(e,t)},[D]),tg=Math.max(4,String(_?eu:eV.length).length),tb=(0,s.useMemo)(()=>{let e=0;for(let t of eV){let r=0;for(let e=0;e<t.length;e++)" "===t[e]?r+=2-r%2:r+=1;r>e&&(e=r)}return e},[eV]);(0,s.useEffect)(()=>{if(_){eo.current=e;let t=e.split("\n").length;em.current=t,eh(t),el.current=!1,ei(!1),ef({show:!1}),eb.current=q}},[_,e,q]),(0,s.useEffect)(()=>{if(!_)return;let t=ep.current;if(!t)return;let r=e.split("\n");t.innerHTML=T(r.map((e,t)=>eE[t]||(0,d.ZD)(e||" "))),requestAnimationFrame(()=>{let e,n;J?(e=Math.max(0,Math.min(td.current.line,r.length-1)),n=td.current.col):(e=Math.max(0,Math.min((I?.current??1)-1,r.length-1)),n=0),t.focus(),E(t,{line:e,offset:n});let s=I?.current??1;eg.current&&(eg.current.scrollTop=(s-1)*20)})},[_]),(0,s.useEffect)(()=>{_&&K?.({isDirty:ea,isSaving:ec})},[_,ea,ec,K]);let tv=(0,s.useCallback)(()=>{let e=ep.current;if(!e)return eo.current;let t=[];for(let r of e.childNodes){let e=r.textContent||"";t.push(" "===e?"":e)}return t.join("\n")},[]),tj=(0,s.useCallback)(()=>{ev.current&&clearTimeout(ev.current),ev.current=setTimeout(async()=>{let e=ep.current;if(e&&!ey.current){eo.current=tv();try{let r=await (0,d.kS)(),n=(0,d.sQ)(t),s=document.documentElement.classList.contains("dark"),o=eo.current.split("\n"),l=r.codeToTokens(o.join("\n"),{lang:n,theme:s?"github-dark":"github-light"}).tokens.map(e=>(0,d.b8)(e)),a=M(e);ej.current=!0,e.innerHTML=T(l),ej.current=!1,a&&E(e,a)}catch{}}},300)},[t,tv]);(0,s.useEffect)(()=>{if(_)return()=>{ev.current&&clearTimeout(ev.current)}},[_]);let ty=(0,s.useCallback)(()=>{let e=ep.current;if(!e)return;el.current||(el.current=!0,ei(!0));let t=e.children.length;t!==em.current&&(em.current=t,eh(t))},[]),tw=(0,s.useCallback)(()=>{ej.current||ey.current||(ty(),tj())},[ty,tj]),tk=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&("Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," ")),"Enter"===e.key)){e.preventDefault();let t=ep.current;if(!t)return;let r=window.getSelection();if(!r?.rangeCount)return;let n=r.getRangeAt(0);n.deleteContents();let s=n.startContainer;for(;s&&s.parentElement!==t;)s=s.parentElement;if(!s||!(s instanceof HTMLElement))return;let o=M(t),l=Array.from(t.children).indexOf(s),a=s.textContent||"",i=o?.offset??a.length,c=a.substring(0,i),u=a.substring(i);s.innerHTML=(0,d.ZD)(c||" ");let h=document.createElement("div");h.setAttribute("style",L),h.innerHTML=(0,d.ZD)(u||" "),s.after(h),E(t,{line:l+1,offset:0}),ty(),tj()}},[ty,tj]),tN=(0,s.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)},[]),tC=(0,s.useCallback)(async(e=!1)=>{if(f){eo.current=tv(),ed(!0);try{let r=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:f,path:t,content:eo.current,expectedMtime:e?void 0:eb.current})}),n=await r.json();if(409===r.status&&n.conflict){try{let e=await fetch(`/api/files/text?cwd=${encodeURIComponent(f)}&path=${encodeURIComponent(t)}`),r=await e.json();ef({show:!0,diskContent:e.ok&&"string"==typeof r.content?r.content:void 0})}catch{ef({show:!0})}return}if(!r.ok)throw Error("Failed to save file");n.mtime&&(eb.current=n.mtime),el.current=!1,ei(!1),ef({show:!1}),(0,S.oR)(es("toast.savedSuccess"),"success"),U?.()}catch(e){console.error("Error saving file:",e),(0,S.oR)(es("toast.saveFailed"),"error")}finally{ed(!1)}}},[f,t,tv,U]),tS=(0,s.useCallback)(async()=>{ea&&!ec&&await tC(!1)},[ea,ec,tC]),tL=(0,s.useCallback)(async()=>{ef({show:!1}),await tC(!0)},[tC]),tM=(0,s.useCallback)(()=>{if(void 0!==ex.diskContent){eo.current=ex.diskContent;let t=ex.diskContent.split("\n").length;em.current=t,eh(t);let r=ex.diskContent!==e;el.current=r,ei(r);let n=ep.current;n&&(n.innerHTML=T(ex.diskContent.split("\n").map(e=>(0,d.ZD)(e||" "))),tj())}ef({show:!1}),U?.()},[ex.diskContent,e,U,tj]),tE=(0,s.useCallback)(()=>{let e=eg.current;return e?Math.floor(e.scrollTop/20)+1:I?.current??1},[I]),tT=(0,s.useCallback)(async()=>{(!ea||await (0,S.lJ)(es("codeViewer.unsavedConfirm"),{danger:!0,confirmText:es("codeViewer.discardChanges"),cancelText:es("codeViewer.continueEditing")}))&&V?.(tE())},[ea,V,tE]);(0,s.useEffect)(()=>{if(!_)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),tS())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[_,tS]);let t$=(0,s.useCallback)(()=>{let e=tv();X?.(e);let t=ep.current,r=t?M(t):null,n=tE();if(tu.enterNormal(),r){tu.setCursorLine(r.line);let t=e.split("\n")[r.line]??"";tu.setCursorCol(Math.max(0,Math.min(r.offset,Math.max(0,t.length-1))))}else tu.setCursorLine(Math.max(0,n-1));V?.(n)},[tv,X,tE,V,tu]);(0,s.useEffect)(()=>{if(!_)return;let e=e=>{let t="Escape"===e.key,r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;(t||J&&r)&&(e.preventDefault(),e.stopPropagation(),J?el.current?(0,S.lJ)(es("codeViewer.unsavedExitConfirm"),{danger:!0,confirmText:es("codeViewer.discardChanges"),cancelText:es("codeViewer.continueEditing")}).then(e=>{e&&t$()}):t$():tT())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[_,J,tT,t$]),(0,s.useImperativeHandle)(en,()=>({save:tS,close:tT,get isDirty(){return ea},get isSaving(){return ec}}),[tS,tT,ea,ec]);let tR=!!(W&&W.length>0),tP=(0,s.useMemo)(()=>{if(!W)return new Map;let e=[...new Set(W.map(e=>e.author))],t=new Map;return e.forEach((e,r)=>{t.set(e,p[r%p.length])}),t},[W]),[tB,tI]=(0,s.useState)(null),[tD,tF]=(0,s.useState)(null);(0,s.useEffect)(()=>{tI(null),tF(null)},[W]);let tA=(0,s.useCallback)((e,t)=>{tI(e.author);let r=t.currentTarget.getBoundingClientRect();tF({line:e,x:r.right+8,y:r.top})},[]),tO=(0,s.useCallback)(()=>{tI(null),tF(null)},[]),tW=(0,s.useCallback)(e=>{H&&(H({hash:e.hashFull,shortHash:e.hash,author:e.author,authorEmail:e.authorEmail,date:new Date(1e3*e.time).toISOString(),subject:e.message.split("\n")[0]||"",body:e.message.split("\n").slice(1).join("\n").trim(),time:e.time}),tF(null))},[H]),tz=`${tg+2}ch`;return(0,n.jsxs)("div",{ref:ek,className:`h-full flex flex-col outline-none ${x}`,tabIndex:0,onClick:tm,onDoubleClick:tx,children:[_&&ex.show&&(0,n.jsxs)("div",{className:"px-4 py-2 bg-amber-500/15 border-b border-amber-500/30 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("svg",{className:"w-5 h-5 text-amber-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1",children:es("codeViewer.fileModifiedExternally")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:tM,className:"px-3 py-1 text-sm rounded border border-border hover:bg-accent transition-colors",children:es("codeViewer.useDiskVersion")}),(0,n.jsx)("button",{onClick:tL,className:"px-3 py-1 text-sm rounded bg-amber-500 text-white hover:bg-amber-600 transition-colors",children:es("codeViewer.forceOverwrite")})]})]}),!_&&m&&eP&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:eN,type:"text",value:eB,onChange:e=>eG(e.target.value),onKeyDown:e6,placeholder:es("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("button",{onClick:()=>eZ(!eI),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eI?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:es("codeViewer.caseSensitive"),children:"Aa"}),(0,n.jsx)("button",{onClick:()=>e0(!eD),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eD?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:es("codeViewer.wholeWordMatch"),children:"[ab]"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:eU.length>0?`${eF+1}/${eU.length}`:es("common.noMatch")}),(0,n.jsx)("button",{onClick:e3,disabled:0===eU.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:es("common.previous"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,n.jsx)("button",{onClick:e4,disabled:0===eU.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:es("common.next"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,n.jsx)("button",{onClick:()=>{eQ(!1),eG("")},className:"p-1 rounded hover:bg-accent",title:es("common.close"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),_?(0,n.jsx)("div",{ref:eg,className:"flex-1 overflow-auto bg-secondary",children:(0,n.jsxs)("div",{className:"flex",style:{minHeight:"100%"},children:[(0,n.jsx)("div",{className:"flex-shrink-0 font-mono text-sm select-none sticky left-0 z-[2] bg-secondary",style:{width:tz},children:Array.from({length:eu},(e,t)=>(0,n.jsx)("div",{className:"text-right text-muted-foreground/50 pr-3",style:{height:20,lineHeight:"20px"},children:t+1},t))}),(0,n.jsx)("div",{ref:ep,contentEditable:!0,suppressContentEditableWarning:!0,onInput:tw,onKeyDown:tk,onPaste:tN,onCompositionStart:()=>{ey.current=!0},onCompositionEnd:()=>{ey.current=!1,tw()},spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",className:"flex-1 font-mono text-sm outline-none",style:{caretColor:"var(--foreground)",tabSize:2}})]})}):(0,n.jsx)("div",{ref:ew,className:`flex-1 overflow-auto font-mono text-sm bg-secondary${e$?" cmd-held-container":""}`,children:(0,n.jsx)("div",{style:{height:`${eJ.getTotalSize()}px`,minWidth:"100%",width:tR?`calc(${tg+tb+10}ch + 13rem)`:`${tg+tb+10}ch`,position:"relative"},children:eJ.getVirtualItems().map(e=>{let t=eK[e.index];if("code"!==t.type)return null;let s=t.lineIndex,o=s+1,l=eE[s]||(0,d.ZD)(eV[s]||""),a=tn(s,l,B),i=eY.has(o),c=eX.get(o),u=c?.[0],h=!!(eO&&o>=eO.range.start&&o<=eO.range.end),m=tl>=0?to.current:null,x=!_&&z&&m===o?z[s]??null:null,f=tR?W[s]:void 0,p=tR&&s>0?W[s-1]:void 0,g=!!f&&(!p||p.hash!==f.hash),v=f?tP.get(f.author):void 0;return(0,n.jsx)(b,{virtualKey:e.key,lineNum:o,highlightedHtml:a,hasComments:i,firstComment:u,lineCommentsCount:c?.length,isInRange:h,showLineNumbers:r,lineNumChars:tg,commentsEnabled:eH,virtualItemSize:e.size,virtualItemStart:e.start,onCommentBubbleClick:e8,onCmdClick:tp,onTokenHover:tf,onTokenHoverLeave:A,flashLine:eR,blameLine:f,showBlameInfo:g,blameAuthorColor:v,isBlameHovered:!!(f&&tB===f.author),onBlameClick:tW,onBlameMouseEnter:tA,onBlameMouseLeave:tO,inlineBlameData:x,onInlineBlameClick:tW,isCursorLine:J&&!_&&tu.state.cursorLine===s,cursorCol:J&&!_&&tu.state.cursorLine===s?tu.state.cursorCol:void 0},e.key)})})}),J&&(0,n.jsxs)("div",{className:"vi-status-bar flex-shrink-0 h-6 bg-card border-t border-border flex items-center px-3 text-xs font-mono select-none",children:["normal"===tu.state.mode&&(0,n.jsx)("span",{className:"text-green-11 font-medium",children:"NORMAL"}),"insert"===tu.state.mode&&(0,n.jsx)("span",{className:"text-blue-11 font-medium",children:"INSERT"}),"command"===tu.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:":"}),(0,n.jsx)("input",{ref:ti,value:tu.state.commandInput,onChange:e=>tu.setCommandInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tu.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),"search"===tu.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:"/"}),(0,n.jsx)("input",{ref:tc,value:tu.state.searchInput,onChange:e=>tu.setSearchInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tu.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),tu.state.keyBuffer&&"normal"===tu.state.mode&&(0,n.jsx)("span",{className:"ml-2 text-muted-foreground",children:tu.state.keyBuffer}),tu.state.isDirty&&("normal"===tu.state.mode||"command"===tu.state.mode)&&(0,n.jsx)("span",{className:"ml-2 text-amber-11",children:"[+]"}),(0,n.jsxs)("span",{className:"ml-auto text-muted-foreground",children:[tu.state.cursorLine+1,":",tu.state.cursorCol+1]})]}),eT&&ta&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[!_&&(0,n.jsx)(u.f,{floatingToolbarRef:eC,bumpRef:eL,container:ta,onAddComment:e9,onSendToAI:e7,onSearch:er?te:void 0,isChatLoading:ez?.isLoading}),!_&&eO&&(0,n.jsx)(i.t,{x:eO.x,y:eO.y,range:eO.range,codeContent:eO.codeContent,container:ta,onSubmit:tt,onClose:()=>e2(null)}),!_&&eW&&(0,n.jsx)(i.G,{x:eW.x,y:eW.y,range:eW.range,filePath:t,codeContent:eW.codeContent,container:ta,onSubmit:tr,onClose:()=>e5(null),isChatLoading:ez?.isLoading}),!_&&eA&&(0,n.jsx)(h.t,{x:eA.x,y:eA.y,comment:eA.comment,container:ta,onClose:()=>e1(null),onUpdateComment:e_,onDeleteComment:eq}),tD&&(0,n.jsxs)("div",{className:"fixed z-50 bg-card border border-border rounded-lg shadow-lg p-3 max-w-lg",style:{left:Math.min(tD.x,window.innerWidth-450),top:Math.max(8,Math.min(tD.y,window.innerHeight-200))},children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 rounded text-xs font-mono font-medium text-white flex-shrink-0",style:{backgroundColor:tP.get(tD.line.author)?.border||"#666"},children:tD.line.hash}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground",children:tD.line.author}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:tD.line.authorEmail})]})]}),(0,n.jsx)("div",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:tD.line.message}),(0,n.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground border-t border-border pt-2",children:[(0,C.fw)(tD.line.time)," \xb7 ",new Date(1e3*tD.line.time).toLocaleString(),(0,n.jsx)("span",{className:"ml-2 text-brand",children:es("codeViewer.clickToViewDetails")})]})]})]}),ta)]})});function R({content:e,filePath:t,className:r=""}){let o=(0,s.useMemo)(()=>e.split("\n"),[e]),l=(0,c.C)(o,t),a=Math.max(4,String(o.length).length);return(0,n.jsx)("pre",{className:`overflow-auto text-sm font-mono bg-secondary p-2 ${r}`,children:o.map((e,t)=>(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsx)("span",{className:"text-slate-9 select-none pr-4 text-right",style:{minWidth:`${a+2}ch`},children:t+1}),(0,n.jsx)("span",{className:"flex-1",dangerouslySetInnerHTML:{__html:l[t]||(0,d.ZD)(e||" ")}})]},t))})}},41474:(e,t,r)=>{r.d(t,{F:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)(()=>"u"<typeof document||"visible"===document.visibilityState);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}},43430:(e,t,r)=>{r.d(t,{Workspace:()=>D});var n=r(95155),s=r(12115),o=r(79114),l=r(69958),a=r(76288),i=r(83678),c=r(21484);let d={"claude-opus-4-6":{label:"Opus 4.6",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"},"claude-opus-4-5-20251101":{label:"Opus 4.5",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#fb923c"},"claude-sonnet-4-6":{label:"Sonnet 4.6",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#3b82f6"},"claude-sonnet-4-5-20250929":{label:"Sonnet 4.5",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#60a5fa"},"claude-haiku-4-5-20251001":{label:"Haiku 4.5",input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}},u={label:"",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#94a3b8"};function h(e){if(d[e])return d[e];let t=e.toLowerCase();return t.includes("opus")?{...u,input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"}:t.includes("haiku")?{...u,input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}:u}function m(e){let t=d[e];return t?t.label:e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function x(e){return(d[e]??h(e)).color}function f(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function p(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function g({data:e,height:t=200,formatValue:r=f}){let o=(0,s.useRef)(null),l=(0,s.useRef)(null),[a,i]=(0,s.useState)(null),c=(0,s.useRef)([]),d=(0,s.useCallback)(()=>{let n=o.current,s=l.current;if(!n||!s)return;let a=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*a,n.height=t*a,n.style.width=`${i}px`,n.style.height=`${t}px`;let d=n.getContext("2d");d.scale(a,a),d.clearRect(0,0,i,t);let{labels:u,datasets:h}=e;if(0===u.length)return;let m=i-50-12,x=t-8-28,f=function(e){if(e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),r=e/t;return r<=1?t:r<=2?2*t:r<=5?5*t:10*t}(Math.max(1,...u.map((e,t)=>h.reduce((e,r)=>e+r.data[t],0))));d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="10px ui-monospace, monospace",d.textAlign="right",d.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+x-t/f*x;d.fillText(r(t),44,s),d.strokeStyle=(p="--border",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),d.lineWidth=.5,d.beginPath(),d.moveTo(50,s),d.lineTo(50+m,s),d.stroke()}let g=m/u.length,b=Math.max(4,Math.min(.6*g,32)),v=[];u.forEach((e,t)=>{let r=50+t*g+(g-b)/2,s=0;h.forEach(n=>{var o,l,a,i,c,u;let h=n.data[t];if(h<=0)return;let m=h/f*x,p=8+x-s-m;d.fillStyle=n.color,o=d,l=r,a=p,i=b,u=2,(c=m)<1||(u=Math.min(u,c/2,i/2),o.beginPath(),o.moveTo(l+u,a),o.lineTo(l+i-u,a),o.quadraticCurveTo(l+i,a,l+i,a+u),o.lineTo(l+i,a+c-u),o.quadraticCurveTo(l+i,a+c,l+i-u,a+c),o.lineTo(l+u,a+c),o.quadraticCurveTo(l,a+c,l,a+c-u),o.lineTo(l,a+u),o.quadraticCurveTo(l,a,l+u,a),o.fill()),v.push({x:r,y:p,w:b,h:m,label:e,value:h,dataset:n.label,color:n.color}),s+=m}),d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="9px ui-monospace, monospace",d.textAlign="center",d.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&d.fillText(e,r+b/2,8+x+6)}),c.current=v},[e,t,r]);(0,s.useEffect)(()=>{d();let e=new ResizeObserver(()=>d());return l.current&&e.observe(l.current),()=>e.disconnect()},[d]);let u=(0,s.useCallback)(e=>{let t=o.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,s=e.clientY-t.top,l=c.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);l?i({x:e.clientX-t.left,y:l.y-4,content:`${l.dataset}: ${r(l.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:l,className:"relative w-full text-muted-foreground",children:[(0,n.jsx)("canvas",{ref:o,className:"w-full",style:{height:t},onMouseMove:u,onMouseLeave:()=>i(null)}),a&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lg border border-border whitespace-nowrap z-10",style:{left:a.x,top:a.y,transform:"translate(-50%, -100%)"},children:a.content})]})}function b({hourCounts:e}){let{t}=(0,o.Bd)(),r=Math.max(1,...Object.values(e)),s=Array.from({length:24},(e,t)=>t);return(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:t("tokenStats.activeHours")}),(0,n.jsx)("div",{className:"flex gap-[2px] items-end h-16",children:s.map(s=>{let o=e[String(s)]||0,l=o/r;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:s,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*l)}px`,backgroundColor:l>0?`rgba(59, 130, 246, ${.2+.8*l})`:"var(--muted)"}}),s%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:s})]},s)})})]})}function v({isOpen:e,onClose:t}){var r;let l,a,{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(null),[u,y]=(0,s.useState)(!0),[w,k]=(0,s.useState)("day"),[N,C]=(0,s.useState)("tokens"),[S,L]=(0,s.useState)("claude");(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>y(!0)),fetch(`/api/claude-stats?engine=${S}`).then(e=>e.json()).then(e=>{e.error||queueMicrotask(()=>d(e))}).catch(()=>{}).finally(()=>queueMicrotask(()=>y(!1))))},[e,S]);let M=(0,s.useMemo)(()=>c?.modelUsage?Object.entries(c.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:m(e),color:x(e),usage:t,cost:(r=h(e),t.inputTokens/1e6*r.input+t.outputTokens/1e6*r.output+t.cacheReadInputTokens/1e6*r.cacheRead+t.cacheCreationInputTokens/1e6*r.cacheWrite),totalTokens:t.inputTokens+t.outputTokens+t.cacheReadInputTokens+t.cacheCreationInputTokens}}).sort((e,t)=>t.cost-e.cost):[],[c]),E=(0,s.useMemo)(()=>M.reduce((e,t)=>e+t.cost,0),[M]),T=(0,s.useMemo)(()=>M.map(e=>e.id),[M]),$=(0,s.useMemo)(()=>{let e={};for(let t of M)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[M]),{activityChart:R,tokenChart:P,costChart:B}=(0,s.useMemo)(()=>{let e=c?.dailyActivity||[],t=c?.dailyModelTokens||[];if("day"===w){let r=e.slice(-60),n=t.slice(-60),s={labels:r.map(e=>e.date.slice(5)),datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messageCount),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:"#22c55e"}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:T.map(e=>({label:m(e),data:n.map(t=>t.tokensByModel[e]||0),color:x(e)}))},costChart:{labels:o,datasets:T.map(e=>({label:m(e),data:n.map(t=>(t.tokensByModel[e]||0)*($[e]||0)),color:x(e)}))}}}if("week"===w){let r=function(e,t){let r=new Map;for(let t of e){let e=new Date(t.date),n=new Date(e);n.setDate(e.getDate()-e.getDay());let s=n.toISOString().slice(0,10),o=s.slice(5);r.has(s)||r.set(s,{label:o,messages:0,sessions:0,tools:0,tokensByModel:{}});let l=r.get(s);l.messages+=t.messageCount,l.sessions+=t.sessionCount,l.tools+=t.toolCallCount}for(let e of t){let t=new Date(e.date),n=new Date(t);n.setDate(t.getDate()-t.getDay());let s=n.toISOString().slice(0,10);r.has(s)||r.set(s,{label:s.slice(5),messages:0,sessions:0,tools:0,tokensByModel:{}});let o=r.get(s);for(let[t,r]of Object.entries(e.tokensByModel))o.tokensByModel[t]=(o.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:T.map(e=>({label:m(e),data:r.map(t=>t.tokensByModel[e]||0),color:x(e)}))},costChart:{labels:n,datasets:T.map(e=>({label:m(e),data:r.map(t=>(t.tokensByModel[e]||0)*($[e]||0)),color:x(e)}))}}}let r=function(e,t){let r=new Map;for(let t of e){let e=t.date.slice(0,7);r.has(e)||r.set(e,{label:e,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(e);n.messages+=t.messageCount,n.sessions+=t.sessionCount,n.tools+=t.toolCallCount}for(let e of t){let t=e.date.slice(0,7);r.has(t)||r.set(t,{label:t,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(t);for(let[t,r]of Object.entries(e.tokensByModel))n.tokensByModel[t]=(n.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:T.map(e=>({label:m(e),data:r.map(t=>t.tokensByModel[e]||0),color:x(e)}))},costChart:{labels:n,datasets:T.map(e=>({label:m(e),data:r.map(t=>(t.tokensByModel[e]||0)*($[e]||0)),color:x(e)}))}}},[c,w,T,$,i]);if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]),!e)return null;let I=[{key:"day",label:i("tokenStats.day")},{key:"week",label:i("tokenStats.week")},{key:"month",label:i("tokenStats.month")}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-xl w-full max-w-4xl mx-4 max-h-[90vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("tokenStats.title")}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:["claude","claude2"].map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${S===e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{d(null),L(e)},children:"claude"===e?"Claude":"Claude 2"},e))}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:I.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${w===e.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>k(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:u?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(j,{label:i("tokenStats.totalSessions"),value:String(c.totalSessions??0)}),(0,n.jsx)(j,{label:i("tokenStats.totalMessages"),value:f(c.totalMessages??0)}),(0,n.jsx)(j,{label:i("tokenStats.equivalentApiCost"),value:p(E),highlight:!0}),(0,n.jsx)(j,{label:i("tokenStats.longestSession"),value:c.longestSession?(l=Math.floor((r=c.longestSession.duration)/36e5),a=Math.floor(r%36e5/6e4),l>0?`${l}h ${a}m`:`${a}m`):"-"}),(0,n.jsx)(j,{label:i("tokenStats.firstUse"),value:c.firstSessionDate?c.firstSessionDate.slice(0,10):"-"})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.activityTrend")}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-[10px]",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#3b82f6"}}),i("tokenStats.messages")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#22c55e"}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(g,{data:R,height:180})})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.byModel")}),(0,n.jsxs)("div",{className:"flex bg-muted rounded-md p-0.5",children:[(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"tokens"===N?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===N?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:M.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:e.color}}),e.label]},e.id))})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(g,{data:"tokens"===N?P:B,height:180,formatValue:"tokens"===N?f:p})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("tokenStats.modelCostDetail")}),(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"bg-muted/50 text-muted-foreground",children:[(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium",children:i("tokenStats.model")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Input"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Output"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Read"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Write"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.share")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.equivalentCost")})]})}),(0,n.jsxs)("tbody",{children:[M.map(e=>(0,n.jsxs)("tr",{className:"border-t border-border",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.label]})}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:E>0?`${(e.cost/E*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:p(e.cost)})]},e.id)),(0,n.jsxs)("tr",{className:"border-t-2 border-border bg-muted/30",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-medium text-foreground",children:i("tokenStats.total")}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(M.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(M.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(M.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(M.reduce((e,t)=>e+t.usage.cacheCreationInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:"100%"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-bold text-foreground",children:p(E)})]})]})]})})]}),c.hourCounts&&Object.keys(c.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(b,{hourCounts:c.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function j({label:e,value:t,highlight:r}){return(0,n.jsxs)("div",{className:"bg-muted/30 rounded-lg px-3 py-2.5",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground",children:e}),(0,n.jsx)("div",{className:`text-sm font-semibold mt-0.5 ${r?"text-brand":"text-foreground"}`,children:t})]})}var y=r(8648),w=r(34075),k=r(45048),N=r(38408);function C({skillId:e,onClose:t}){let[r,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(!0),[i,c]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return a(!0),fetch(`/api/skills/content?id=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{t||o(e)}).catch(e=>console.error("Failed to load skill content",e)).finally(()=>{t||a(!1)}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let d=(0,s.useCallback)(async()=>{if(r?.path)try{await navigator.clipboard.writeText(r.path),(0,w.oR)("Path copied","success")}catch{(0,w.oR)("Failed to copy","error")}},[r]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-4xl h-[85vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:r?.name?`/${r.name}`:"Skill Preview"}),(0,n.jsx)("button",{onClick:d,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),r?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:r.path})]}),(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>c("preview"),className:`px-3 py-1 transition-colors ${"preview"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Preview"}),(0,n.jsx)("button",{onClick:()=>c("source"),className:`px-3 py-1 transition-colors ${"source"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Source"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors flex-shrink-0",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:l?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"Loading..."}):r&&r.valid?"preview"===i?(0,n.jsx)("div",{className:"px-6 py-4",children:(0,n.jsx)(k.T,{content:r.content})}):(0,n.jsx)(N.XO,{content:r.content,filePath:r.path,className:"min-h-full"}):(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"File cannot be read."})})]})]})}var S=r(88371);function L({isOpen:e,onClose:t}){let[r,o]=(0,s.useState)([]),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(!1),[h,m]=(0,s.useState)(""),[x,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(null),b=(0,s.useCallback)(async()=>{a(!0);try{let e=await fetch("/api/skills");if(e.ok){let t=await e.json();o(t)}}catch(e){console.error("Failed to load skills",e)}finally{a(!1)}},[]);(0,s.useEffect)(()=>{e&&b()},[e,b]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!p){if(d){u(!1),m("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,d,p]);let v=(0,s.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):r},[r,i]),j=(0,s.useCallback)(async()=>{let e=h.trim();if(e){f(!0);try{let t=await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})});if(!t.ok){let e=await t.json().catch(()=>({}));(0,w.oR)(e.error||"Failed to add skill","error");return}(0,w.oR)("Skill added","success"),m(""),u(!1),await b(),(0,S.k)()}catch(e){console.error(e),(0,w.oR)("Failed to add skill","error")}finally{f(!1)}}},[h,b]),y=(0,s.useCallback)(async e=>{try{if(!(await fetch(`/api/skills/${encodeURIComponent(e)}`,{method:"DELETE"})).ok)return void(0,w.oR)("Failed to delete","error");o(t=>t.filter(t=>t.id!==e)),(0,S.k)()}catch(e){console.error(e),(0,w.oR)("Failed to delete","error")}},[]),k=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,w.oR)("Path copied","success")}catch{(0,w.oR)("Failed to copy","error")}},[]);return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-3xl h-[80vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:"Skills"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsxs)("svg",{className:"w-4 h-4 absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-4.35-4.35"})]}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Search skills...",className:"w-full pl-8 pr-3 py-1.5 text-sm border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"})]}),(0,n.jsx)("button",{onClick:()=>u(!0),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 active:scale-95 transition-all",children:"+ Add Skill"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:l?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:"Loading..."}):0===v.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:0===r.length?'No skills yet. Click "Add Skill" to add one.':"No skills match your search."}):v.map(e=>(0,n.jsx)(M,{skill:e,onPreview:()=>g(e.id),onDelete:()=>y(e.id),onCopyPath:()=>k(e.path)},e.id))})]})]}),d&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:()=>{x||(u(!1),m(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:"Add Skill"}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:"Absolute path to SKILL.md"}),(0,n.jsx)("input",{type:"text",value:h,onChange:e=>m(e.target.value),onKeyDown:e=>{"Enter"!==e.key||x||j()},placeholder:"/Users/you/.../skills/foo/SKILL.md",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{u(!1),m("")},disabled:x,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",children:"Cancel"}),(0,n.jsx)("button",{onClick:j,disabled:x||!h.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:x?"Adding...":"Add"})]})]})]}),p&&(0,n.jsx)(C,{skillId:p,onClose:()=>g(null)})]}):null}function M({skill:e,onPreview:t,onDelete:r,onCopyPath:o}){let[l,a]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:`border border-border rounded-lg p-3 bg-card hover:bg-accent/30 transition-colors ${e.valid?"":"opacity-60"}`,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"w-9 h-9 flex-shrink-0 flex items-center justify-center rounded-md bg-brand/10 text-brand text-lg",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground",children:["/",e.name]}),e.description&&(0,n.jsx)("span",{className:"text-sm text-muted-foreground line-clamp-2",children:e.description}),!e.valid&&(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:"Invalid"})]}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 truncate",children:e.argumentHint}),(0,n.jsx)("div",{className:"flex items-center gap-1 mt-1",children:(0,n.jsx)("button",{onClick:o,className:"text-xs text-muted-foreground hover:text-foreground font-mono truncate text-left",title:"Copy path",children:e.path})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Preview",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})}),l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{a(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:"Confirm"}),(0,n.jsx)("button",{onClick:()=>a(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:"Cancel"})]}):(0,n.jsx)("button",{onClick:()=>a(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:"Delete",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M1 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})]})]})})}var E=r(47650);let T=[],$=[];function R(){$.forEach(e=>e())}function P(e){T=T.filter(t=>t.id!==e),R()}function B({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return $.push(t),()=>{$=$.filter(e=>e!==t)}},[]),T}();return 0===t.length?null:(0,E.createPortal)((0,n.jsx)("div",{className:"fixed bottom-4 left-4 z-[100] flex flex-col gap-2 pointer-events-none",children:t.map(t=>(0,n.jsx)(I,{item:t,onNavigate:e,onRemove:P},t.id))}),document.body)}function I({item:e,onNavigate:t,onRemove:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),c=(0,s.useRef)(void 0),d=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(c.current=setTimeout(d,5e3),()=>clearTimeout(c.current)),[d]);let u=(0,s.useCallback)(()=>{clearTimeout(c.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),h=(0,s.useCallback)(()=>{clearTimeout(c.current)},[]),m=(0,s.useCallback)(()=>{c.current=setTimeout(d,2e3)},[d]);return(0,n.jsxs)("div",{className:`pointer-events-auto bg-card border border-border rounded-lg shadow-lg px-3 py-2.5 min-w-[260px] max-w-[340px] cursor-pointer hover:bg-accent transition-all ${a?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:a?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:h,onMouseLeave:m,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-green-9 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:e.projectName}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:l("common.done")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"ml-auto p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.message&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-1 ml-6",children:e.message})]})}function D({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[d,u]=(0,s.useState)([]),[h,m]=(0,s.useState)(0),[x,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[b,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(null),[E,$]=(0,s.useState)(!1),[P,I]=(0,s.useState)(!1),[F,A]=(0,s.useState)(new Set),O=(0,s.useRef)(new Map),W=(0,s.useRef)(new Map),z=(0,s.useRef)(new Map),H=(0,s.useRef)(null),_=(0,s.useCallback)(async()=>{try{let e=await fetch("/api/projects");if(e.ok){let t=await e.json();u(t.projects||[]),m(t.activeIndex||0),f(t.collapsed||!1)}}catch(e){console.error("Failed to load projects:",e)}finally{I(!0)}},[]),q=(0,s.useCallback)(async(e,t,r)=>{try{await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projects:e,activeIndex:t,collapsed:r})})}catch(e){console.error("Failed to save projects:",e)}},[]);(0,s.useEffect)(()=>{let e=d[h]?.cwd;e&&A(t=>t.has(e)?t:new Set(t).add(e))},[h,d]),(0,s.useEffect)(()=>{for(let[e,t]of O.current.entries()){let r=d[h]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r},"*")}},[h,d]),(0,s.useEffect)(()=>{_()},[_]);let V=(0,s.useCallback)((e,t)=>{let r=new URL(window.location.href);r.searchParams.set("cwd",e),t?r.searchParams.set("sessionId",t):r.searchParams.delete("sessionId"),window.history.replaceState({},"",r.toString());let n=e.split("/").filter(Boolean).pop();document.title=n?`Cockpit - ${n}`:"Cockpit"},[]),U=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!P||U.current||!e)return;U.current=!0,t&&(W.current.set(e,{sessionId:t}),z.current.set(e,t));let r=d.findIndex(t=>t.cwd===e);if(r>=0)r!==h&&(m(r),q(d,r,x));else{let t=[...d,{cwd:e}],r=t.length-1;u(t),m(r),q(t,r,x)}V(e,t)},[P,e,t,d,h,x,q,V]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r}=e.data;z.current.set(t,r);let n=d[h];n?.cwd===t&&V(t,r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:r,sessionId:n,lastUserMessage:s}=e.data,o=d[h];if(o?.cwd!==r){var t;let e;t={projectName:r.split("/").pop()||r,message:s,cwd:r,sessionId:n},e=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,T=[...T,{...t,id:e}],R()}}if(e.data?.type==="OPEN_TOKEN_STATS"&&k(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&(M(e.data.cwd),C(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){H.current=h;let t=e.data.cwd,r=d.findIndex(e=>e.cwd===t);r>=0&&r!==h&&m(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==H.current&&H.current!==h&&m(H.current),H.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r}=e.data,n=r||"";z.current.set(t,n);let s=d.findIndex(e=>e.cwd===t);if(s>=0){if(n){let e=O.current.get(t);e?.contentWindow&&e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:n},"*")}s!==h&&(m(s),q(d,s,x))}else{let e=[...d,{cwd:t}],r=e.length-1;u(e),m(r),q(e,r,x),n&&W.current.set(t,{sessionId:n})}V(t,n)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[d,h,x,V,q]);let K=(0,s.useCallback)(e=>{m(e),q(d,e,x);let t=d[e];if(t?.cwd){let e=z.current.get(t.cwd);V(t.cwd,e)}},[d,x,q,V]),J=(0,s.useCallback)(e=>{let t=d.filter((t,r)=>r!==e),r=h;e<h?r=h-1:e===h&&r>=t.length&&(r=Math.max(0,t.length-1)),u(t),m(r),q(t,r,x)},[d,h,x,q]),X=(0,s.useCallback)(e=>{let t=d[h],r=e.findIndex(e=>e.cwd===t?.cwd);u(e),m(r>=0?r:0),q(e,r>=0?r:0,x)},[d,h,x,q]),Y=(0,s.useCallback)(()=>{let e=!x;f(e),q(d,h,e)},[d,h,x,q]),Q=(0,s.useCallback)((e,t)=>{z.current.set(e,t);let r=d.findIndex(t=>t.cwd===e);if(r>=0){let n=O.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),m(r),q(d,r,x)}else{let r=[...d,{cwd:e}],n=r.length-1;u(r),m(n),q(r,n,x),W.current.set(e,{sessionId:t,switchToAgent:!0})}V(e,t),g(!1)},[d,x,q,V]),G=(0,s.useCallback)((e,t)=>{z.current.set(e,t);let r=d.findIndex(t=>t.cwd===e);if(r>=0){let n=O.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),r!==h&&(m(r),q(d,r,x))}else{let r=[...d,{cwd:e}],n=r.length-1;u(r),m(n),q(r,n,x),W.current.set(e,{sessionId:t,switchToAgent:!0})}V(e,t)},[d,h,x,q,V]),Z=(0,s.useCallback)(e=>{let t=W.current.get(e);if(t){let r=O.current.get(e);r?.contentWindow&&r.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t.sessionId,switchToAgent:t.switchToAgent},"*"),W.current.delete(e)}},[]);return P?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(l.ProjectSidebar,{projects:d,activeIndex:h,collapsed:x,currentCwd:d[h]?.cwd,onSelectProject:K,onRemoveProject:J,onReorderProjects:X,onToggleCollapse:Y,onOpenSessionBrowser:()=>g(!0),onOpenSettings:()=>j(!0),onOpenNote:e=>{M(e??null),C(!0)},onOpenSkills:()=>$(!0),onSwitchProject:G,onAddProject:e=>{let t=d.findIndex(t=>t.cwd===e);if(t>=0)m(t),q(d,t,x);else{let t=[...d,{cwd:e}],r=t.length-1;u(t),m(r),q(t,r,x)}}}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===d.length?(0,n.jsx)(a.EmptyState,{onSelectSession:Q}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:d.map((e,t)=>F.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?O.current.set(e.cwd,t):O.current.delete(e.cwd)},src:`/project?cwd=${encodeURIComponent(e.cwd)}`,onLoad:()=>Z(e.cwd),className:`absolute inset-0 w-full h-full border-0 ${t===h?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd))})}),(0,n.jsx)(i.SessionBrowser,{isOpen:p,onClose:()=>g(!1),onSelectSession:Q,onAddProject:e=>{let t=d.findIndex(t=>t.cwd===e);if(t>=0)m(t),q(d,t,x);else{let t=[...d,{cwd:e}],r=t.length-1;u(t),m(r),q(t,r,x)}g(!1)}}),(0,n.jsx)(c.SettingsModal,{isOpen:b,onClose:()=>j(!1)}),(0,n.jsx)(v,{isOpen:w,onClose:()=>k(!1)}),(0,n.jsx)(y.NoteModal,{isOpen:N,onClose:()=>{C(!1),M(null)},projectCwd:S,projectName:S?S.split("/").pop():null}),(0,n.jsx)(L,{isOpen:E,onClose:()=>$(!1)}),(0,n.jsx)(B,{onNavigate:G})]}):(0,n.jsx)("div",{className:"h-screen flex items-center justify-center bg-card",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:r("workspace.loadingText")})]})})}},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>i});var n=r(95155),s=r(12115),o=r(79114),l=r(69809);function a(e){return"auto"!==e&&e?e:navigator.language.startsWith("zh")?"zh":"en"}function i({children:e}){return(0,s.useEffect)(()=>{fetch("/api/settings").then(e=>e.json()).then(e=>{let t=a(e.language||"auto");l.A.language!==t&&l.A.changeLanguage(t)}).catch(()=>{let e=a("auto");l.A.language!==e&&l.A.changeLanguage(e)})},[]),(0,s.useEffect)(()=>{let e=e=>(function(e){for(let t of document.querySelectorAll("iframe"))try{t.contentWindow?.postMessage({type:"cockpit:language-change",lang:e},"*")}catch{}})(e);return l.A.on("languageChanged",e),()=>{l.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&l.A.language!==e.data.lang&&l.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:l.A,children:e})}},48347:(e,t,r)=>{r.d(t,{H:()=>l,r:()=>a});var n=r(95155),s=r(12115);let o=(0,s.createContext)(null);function l({value:e,children:t}){return(0,n.jsx)(o.Provider,{value:e,children:t})}function a(){return(0,s.useContext)(o)}},53853:(e,t,r)=>{r.d(t,{G:()=>u,f:()=>h});var n=r(12115);function s(){if("u"<typeof document)return null;let e=document.querySelector('meta[name="cockpit-bridge"]');if(!e)return null;let t=e.dataset.id,r=e.dataset.version;return t?{id:t,version:r||"unknown"}:null}let o=null,l=new Set;function a(){l.forEach(e=>e())}function i(e){l.add(e);let t=s();return t&&!o&&(o=t,Promise.resolve().then(a)),()=>{l.delete(e)}}function c(){return o}function d(){return null}if("u">typeof document&&(o=s()),"u">typeof MutationObserver&&"u">typeof document){let e=new MutationObserver(()=>{let e=s();e&&(!o||e.id!==o.id||e.version!==o.version)&&(o=e,a())}),t=document.head||document.documentElement;t&&e.observe(t,{childList:!0})}function u(){return(0,n.useSyncExternalStore)(i,c,d)}function h(){return o??s()}},56978:(e,t,r)=>{r.d(t,{C:()=>o});var n=r(12115),s=r(17196);function o(e,t){let[r,o]=(0,n.useState)([]),[l,a]=(0,n.useState)(!1),i=(0,n.useRef)("");(0,n.useEffect)(()=>{let e=()=>{a(document.documentElement.classList.contains("dark"))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let c=e.join("\n");return(0,n.useEffect)(()=>{if(0===e.length)return;let r=`${c}:${t}:${l}`;if(r===i.current)return;i.current=r,o(e.map(e=>(0,s.ZD)(e||" ")));let n=!1;return(async()=>{try{let r=await (0,s.kS)();if(n)return;let a=(0,s.sQ)(t),i=e.join("\n"),c=r.codeToTokens(i,{lang:a,theme:l?"github-dark":"github-light"}),d=[];for(let e=0;e<c.tokens.length;e++)if(d[e]=(0,s.b8)(c.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),n))return;o(d)}catch(e){console.error("Line highlight error:",e)}})(),()=>{n=!0}},[c,t,l]),r}},58490:(e,t,r)=>{r.d(t,{TabManager:()=>nQ});var n=r(95155),s=r(12115),o=r(79114);function l({isOpen:e,onClose:t,cwd:r,onSelectSession:a}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,h]=(0,s.useState)(!1),[m,x]=(0,s.useState)(null),[f,p]=(0,s.useState)(""),g=(0,s.useRef)(null),b=(0,s.useCallback)(async()=>{if(r){h(!0),x(null);try{let e=r.replace(/\//g,"-"),t=await fetch(`/api/sessions/projects/${encodeURIComponent(e)}`);if(!t.ok)throw Error("Failed to load sessions");let n=await t.json();d(n)}catch(e){x(e instanceof Error?e.message:"Unknown error")}finally{h(!1)}}},[r]);(0,s.useEffect)(()=>{e&&(b(),setTimeout(()=>{g.current?.focus()},100))},[e,b]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let v=c.filter(e=>{if(!f)return!0;let t=f.toLowerCase();return e.title.toLowerCase().includes(t)||e.firstMessages.some(e=>e.toLowerCase().includes(t))||e.lastMessages.some(e=>e.toLowerCase().includes(t))});return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-6xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("sessions.sessionList")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:r,children:r})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsx)("input",{ref:g,type:"text",placeholder:i("sessions.searchSessions"),value:f,onChange:e=>p(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[u&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:i("sessions.loadingSessions")})]})}),m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:m})}),!u&&!m&&0===v.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:i(f?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!u&&!m&&v.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:v.map(e=>(0,n.jsxs)("div",{onClick:()=>{let n;return n=(e.path.split("/").pop()||"").replace(".jsonl",""),void(a?(a(n,e.title),t()):window.parent.postMessage({type:"OPEN_PROJECT",cwd:r,sessionId:n},"*"))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:e.title,children:e.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[e.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),e.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},e.path))})]})]})]}):null}var a=r(47650),i=r(64428),c=r(64702),d=r(1058),u=r(90717),h=r(70188),m=r(48347),x=r(7320);function f(e,t){let r=e.split("\n"),n=t.split("\n"),s=[],o=r.length,l=n.length,a=Array(o+1).fill(null).map(()=>Array(l+1).fill(0));for(let e=1;e<=o;e++)for(let t=1;t<=l;t++)r[e-1]===n[t-1]?a[e][t]=a[e-1][t-1]+1:a[e][t]=Math.max(a[e-1][t],a[e][t-1]);let i=o,c=l,d=[];for(;i>0||c>0;)i>0&&c>0&&r[i-1]===n[c-1]?(d.push({type:"unchanged",content:r[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||a[i][c-1]>=a[i-1][c])?(d.push({type:"added",content:n[c-1],newLineNum:c}),c--):(d.push({type:"removed",content:r[i-1],oldLineNum:i}),i--);for(;d.length>0;)s.push(d.pop());return s}var p=r(34075),g=r(56978),b=r(17196);function v({lines:e,containerRef:t}){let r=(0,s.useRef)(null),[o,l]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:s}=e,o=r.current?.clientHeight||0;if(n<=s)l({top:0,height:o});else{let e=o/n;l({top:t*e,height:s*e})}};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),()=>{e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}},[t]),0===e.length)return null;let a=100/e.length;return(0,n.jsxs)("div",{ref:r,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let n=t.current,s=r.current;if(!n||!s)return;let o=s.getBoundingClientRect(),l=(e.clientY-o.top)/o.height*n.scrollHeight-n.clientHeight/2;n.scrollTo({top:Math.max(0,l),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,n.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*a}%`,height:`${Math.max(a,.5)}%`,minHeight:"2px"}},t)),(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${o.top}px`,height:`${Math.max(o.height,10)}px`}})]})}var j=r(89109),y=r(37614);function w(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}let k=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:l,onSearch:a,isChatLoading:i}){let[c,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let u=(0,s.useMemo)(()=>e.current,[c]);return(0,n.jsx)(j.w,{x:u?.x??0,y:u?.y??0,visible:!!u,container:r,onAddComment:o,onSendToAI:l,onSearch:a,isChatLoading:i})});function N({oldContent:e,newContent:t,filePath:r,isNew:l=!1,isDeleted:i=!1,cwd:j,enableComments:C=!1,onPreview:S,previewLabel:L,onContentSearch:M,targetLine:E,compact:T=!1,symbols:$}){let{t:R}=(0,o.Bd)(),P=L??R("common.preview"),B=(0,s.useMemo)(()=>f(e,t),[e,t]),I=(0,s.useRef)(null),D=(0,s.useRef)(null),F=(0,s.useRef)(null),A=(0,s.useRef)(!1),[O,W]=(0,s.useState)(!1),z=(0,h.iN)(),H=(0,m.r)(),_=C&&!!j,{comments:q,addComment:V,updateComment:U,deleteComment:K,refresh:J}=(0,d._)({cwd:j||"",filePath:r}),[X,Y]=(0,s.useState)(null),Q=(0,s.useRef)(null),G=(0,s.useRef)(()=>{}),[Z,ee]=(0,s.useState)(null),[et,er]=(0,s.useState)(null);(0,s.useEffect)(()=>{W(!0)},[]);let en=(0,s.useMemo)(()=>{let e=new Set;for(let t of q)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[q]),es=(0,s.useMemo)(()=>{let e=new Map;for(let t of q){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[q]);(0,s.useEffect)(()=>{if(!_)return;let e=F.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,Q.current&&(Q.current=null,G.current())},o=e=>{t=!1;let s=e.target;if(s.closest?.(".floating-toolbar"))return;let o=Math.abs(e.clientX-r)>5||Math.abs(e.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed||!l.toString().trim()||!o){Q.current&&(Q.current=null,G.current());return}let a=l.getRangeAt(0),i=F.current;if(!i||!i.contains(a.commonAncestorContainer))return;let c=e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;for(;t&&t!==i;){let e=t.closest("[data-new-line]");if(e)return parseInt(e.getAttribute("data-new-line")||"0",10);t=t.parentElement}return null},d=c(a.startContainer),u=c(a.endContainer);if(d&&u){let t=Math.min(d,u),r=Math.max(d,u),n=[],s=0;for(let e of B)("unchanged"===e.type||"added"===e.type)&&++s>=t&&s<=r&&n.push(e.content);let o=n.join("\n");Q.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},codeContent:o},G.current()}},l=()=>{if(t||!Q.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(Q.current=null,G.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[_,B]);let eo=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),Q.current=null,G.current(),ee(null),er(null)},[]),el=(0,s.useCallback)(()=>{let e=Q.current;e&&(ee({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),Q.current=null,G.current())},[]),ea=(0,s.useCallback)(()=>{let e=Q.current;e&&(er({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),Q.current=null,G.current())},[]),ei=(0,s.useCallback)(()=>{let e=Q.current;if(!e||!M)return;let t=e.codeContent.trim();Q.current=null,G.current(),t&&M(t)},[M]),ec=(0,s.useCallback)(async e=>{if(et&&H&&j)try{let t=await (0,u.$3)(j),n=[];for(let e of t)n.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});n.push({filePath:r,startLine:et.range.start,endLine:et.range.end,codeContent:et.codeContent});let s=(0,u.Gw)(n,e);H.sendMessage(s),await (0,u.RP)(j),J(),er(null)}catch(e){console.error("Failed to send to AI:",e)}},[et,H,r,j,J]),ed=(0,s.useCallback)(async e=>{Z&&(await V(Z.range.start,Z.range.end,e),ee(null))},[Z,V]);(0,s.useEffect)(()=>{let e=D.current,t=F.current;if(!e||!t)return;let r=(e,t)=>{A.current||(A.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{A.current=!1}))},n=()=>r(e,t),s=()=>r(t,e);return e.addEventListener("scroll",n),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",n),t.removeEventListener("scroll",s)}},[]);let{leftLines:eu,rightLines:eh}=(0,s.useMemo)(()=>{let e=[],t=[],r=0,n=0;for(let s=0;s<B.length;s++){let o=B[s];if("unchanged"===o.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});r++,n++,e.push({lineNum:r,content:o.content,type:"unchanged",originalIdx:s}),t.push({lineNum:n,content:o.content,type:"unchanged",originalIdx:s})}else"removed"===o.type?(r++,e.push({lineNum:r,content:o.content,type:"removed",originalIdx:s})):"added"===o.type&&(n++,t.push({lineNum:n,content:o.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[B]),em=(0,s.useMemo)(()=>B.map(e=>e.content),[B]),ex=(0,g.C)(em,r),[ef,ep]=(0,s.useState)(()=>new Map);(0,s.useEffect)(()=>{ep(new Map)},[eu,eh]);let eg=(0,s.useMemo)(()=>$??[],[$]),{rows:eb,gaps:ev}=(0,s.useMemo)(()=>T?function(e,t,r,n=[]){let s=e.length,o=r=>"unchanged"!==e[r].type||"unchanged"!==t[r].type,l=new Set;for(let e=0;e<s;e++){if(!o(e))continue;let t=Math.max(0,e-3),r=Math.min(s-1,e+3);for(let e=t;e<=r;e++)l.add(e)}let a=[];for(let e=0;e<s;e++){if(l.has(e))continue;let t=e;for(;e<s&&!l.has(e);)e++;a.push({id:a.length,startIdx:t,endIdx:e-1}),e--}for(let e of a){let t=r.get(e.id)??{topRevealed:0,bottomRevealed:0},n=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,n)),o=Math.max(0,Math.min(t.bottomRevealed,n-s));for(let t=e.startIdx;t<e.startIdx+s;t++)l.add(t);for(let t=e.endIdx-o+1;t<=e.endIdx;t++)l.add(t)}let i=[];for(let e=0;e<s;e++){let r;if(l.has(e)){i.push({kind:"diff",idx:e});continue}let o=e;for(;e<s&&!l.has(e);)e++;let c=e-1;e--;let d=a.find(e=>e.startIdx<=o&&c<=e.endIdx);if(!d)continue;let u=c-o+1,h=Math.min(20,u);if(n.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){r=function(e,t){let r=null;for(let n of e)n.startLine<=t&&t<=n.endLine&&(!r||n.endLine-n.startLine<r.endLine-r.startLine)&&(r=n);return r}(n,s)??void 0;break}}i.push({kind:"gap-expand",gapId:d.id,direction:"up",revealCount:h}),i.push({kind:"gap-label",gapId:d.id,hiddenCount:u,enclosingFn:r}),i.push({kind:"gap-expand",gapId:d.id,direction:"down",revealCount:h})}return{rows:i,gaps:a}}(eu,eh,ef,eg):{rows:eu.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[T,eu,eu,eh,ef,eg]),ej=(0,s.useCallback)((e,t)=>{let r=ev.find(t=>t.id===e);r&&ep(n=>{let s=n.get(e)??{topRevealed:0,bottomRevealed:0},o=r.endIdx-r.startIdx+1-s.topRevealed-s.bottomRevealed;if(o<=0)return n;let l=Math.min(20,o),a="up"===t?{...s,topRevealed:s.topRevealed+l}:{...s,bottomRevealed:s.bottomRevealed+l};return new Map(n).set(e,a)})},[ev]),ey=(0,s.useCallback)(e=>{for(let t of ev)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ev]),ew=(0,s.useCallback)(e=>eb[e]?.kind==="gap-label"?28:20,[eb]),ek=(0,c.Te)({count:eb.length,getScrollElement:()=>I.current,estimateSize:ew,overscan:20}),eN=l?"w-1/4":i?"w-3/4":"w-1/2",eC=l?"w-3/4":i?"w-1/4":"w-1/2",eS=(0,s.useMemo)(()=>eb.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=eu[e.idx],r=eh[e.idx];return"removed"===t.type?{type:"removed"}:r?.type==="added"?{type:"added"}:{type:"unchanged"}}),[eb,eu,eh]),eL=ek.getTotalSize(),eM=ek.getVirtualItems();return(0,s.useEffect)(()=>{if(!E)return;let e=("after"===E.side?eh:eu).findIndex(e=>e.lineNum===E.line);if(-1===e)return;let t=eb.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=ey(e);if(null!==t){let e=ev.find(e=>e.id===t);if(!e)return;let r=e.endIdx-e.startIdx+1;ep(e=>{let n=e.get(t)??{topRevealed:0,bottomRevealed:0};if(n.topRevealed+n.bottomRevealed>=r)return e;let s=new Map(e);return s.set(t,{topRevealed:r,bottomRevealed:0}),s})}return}let r=requestAnimationFrame(()=>{ek.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(r)},[E,eu,eh,eb]),(0,n.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,n.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,n.jsx)("div",{className:`${eN} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:l?"(New File)":i?"Deleted":"Old"}),(0,n.jsxs)("div",{className:`${eC} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,n.jsx)("span",{className:"block text-center",children:i?"(Deleted)":"New"}),(0,n.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[S&&(0,n.jsx)("button",{onClick:S,className:"text-muted-foreground hover:text-foreground transition-colors",children:P}),!i&&t&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,p.oR)(R("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:R("common.copy")})]})]}),(0,n.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:I,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,n.jsxs)("div",{className:"flex",style:{height:`${eL}px`},children:[(0,n.jsx)("div",{ref:D,className:`${eN} overflow-x-auto border-r border-border`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eM.map(e=>{let t=eb[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let r="gap-label"===t.kind;return(0,n.jsx)("div",{ref:ek.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:r?"bg-accent border-y border-border":""},e.key)}let r=eu[t.idx];return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===r.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:r.lineNum||""}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r.originalIdx>=0&&ex[r.originalIdx]||(0,b.ZD)(r.content||" ")}})]},e.key)})})}),(0,n.jsx)("div",{ref:F,className:`${eC} overflow-x-auto`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eM.map(e=>{let t=eb[e.index];if("gap-expand"===t.kind)return(0,n.jsx)("button",{ref:ek.measureElement,"data-index":e.index,type:"button",onClick:()=>ej(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,n.jsx)("span",{className:"select-none",children:R("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:R("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,n.jsx)("span",{className:"truncate min-w-0 font-medium",title:w(t.enclosingFn),children:w(t.enclosingFn)})]})]},e.key);let r=eh[t.idx],s=r?.lineNum||0,o=s>0&&en.has(s),l=es.get(s),a=l?.[0],i=Z&&s>=Z.range.start&&s<=Z.range.end,c=et&&s>=et.range.start&&s<=et.range.end,d=i||c;return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${d?"bg-blue-9/20":o?"bg-amber-9/10":r?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${d?"bg-blue-9/30":""}`,style:{width:_?"52px":"40px"},children:[_&&s>0&&o&&a&&(0,n.jsx)("button",{onClick:e=>eo(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:R("codeViewer.nComments",{count:l?.length}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),_&&s>0&&!o&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r?.originalIdx>=0&&ex[r.originalIdx]||(0,b.ZD)(r?.content||" ")}})]},e.key)})})})]})}),(0,n.jsx)(v,{lines:eS,containerRef:I})]}),O&&z&&(0,a.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(k,{floatingToolbarRef:Q,bumpRef:G,container:z,onAddComment:el,onSendToAI:ea,onSearch:M?ei:void 0,isChatLoading:H?.isLoading??!1}),Z&&(0,n.jsx)(x.t,{x:Z.x,y:Z.y,range:Z.range,codeContent:Z.codeContent,container:z,onSubmit:ed,onClose:()=>ee(null)}),et&&(0,n.jsx)(x.G,{x:et.x,y:et.y,range:et.range,container:z,onSubmit:ec,onClose:()=>er(null)}),X&&(0,n.jsx)(y.t,{x:X.x,y:X.y,comment:X.comment,container:z,onClose:()=>Y(null),onUpdateComment:U,onDeleteComment:K})]}),z)]})}function C({oldContent:e,newContent:t,filePath:r}){let o=(0,s.useMemo)(()=>f(e,t),[e,t]),l=(0,s.useRef)(null),a=(0,s.useMemo)(()=>o.map(e=>e.content),[o]),i=(0,g.C)(a,r),d=(0,c.Te)({count:o.length,getScrollElement:()=>l.current,estimateSize:()=>20,overscan:20});return(0,n.jsx)("div",{ref:l,className:"font-mono text-sm overflow-auto h-full",children:(0,n.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=o[e.index];return(0,n.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,n.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,n.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:i[e.index]||(0,b.ZD)(t.content||" ")}})]},e.key)})})})}let S={ts:"#3178c6",tsx:"#3178c6",js:"#f1e05a",jsx:"#61dafb",mjs:"#f1e05a",cjs:"#f1e05a",html:"#e44d26",css:"#563d7c",scss:"#cd6799",sass:"#cd6799",less:"#1d365d",vue:"#41b883",svelte:"#ff3e00",json:"#cbcb41",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4121",xml:"#e37933",env:"#ecd53f",md:"#519aba",mdx:"#519aba",txt:"#89898a",py:"#3572a5",go:"#00add8",rs:"#dea584",java:"#b07219",kt:"#a97bff",kts:"#a97bff",c:"#555555",h:"#555555",cpp:"#f34b7d",hpp:"#f34b7d",rb:"#701516",php:"#4f5d95",sh:"#89e051",bash:"#89e051",zsh:"#89e051",png:"#a074c4",jpg:"#a074c4",jpeg:"#a074c4",gif:"#a074c4",svg:"#ffb13b",webp:"#a074c4",ico:"#a074c4",lock:"#89898a",gitignore:"#f14e32",dockerfile:"#2496ed",sql:"#e38c00",graphql:"#e535ab",gql:"#e535ab",default:"#8a8a8a"},L={"package.json":"#cb3837","package-lock.json":"#cb3837","tsconfig.json":"#3178c6","jsconfig.json":"#f1e05a",".gitignore":"#f14e32",".eslintrc":"#4b32c3",".eslintrc.js":"#4b32c3",".eslintrc.json":"#4b32c3",".prettierrc":"#56b3b4",dockerfile:"#2496ed",".env":"#ecd53f",".env.local":"#ecd53f",".env.development":"#ecd53f",".env.production":"#ecd53f","readme.md":"#519aba",license:"#d4af37",makefile:"#6d8086","cargo.toml":"#dea584","go.mod":"#00add8","go.sum":"#00add8","requirements.txt":"#3572a5","yarn.lock":"#2c8ebb","pnpm-lock.yaml":"#f9ad00","vite.config.ts":"#646cff","vite.config.js":"#646cff","next.config.js":"#000000","next.config.mjs":"#000000","tailwind.config.js":"#38bdf8","tailwind.config.ts":"#38bdf8"};function M({name:e,className:t="",size:r=16}){let s,o=L[s=e.toLowerCase()]?L[s]:S[e.split(".").pop()?.toLowerCase()||""]||S.default,l=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===l||"tsx"===l&&e.includes("component")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:o})]}):["md","mdx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,n.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:o}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:o,strokeWidth:"2",fill:"none"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:o}),(0,n.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:o}),(0,n.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"html"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,n.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===l||".gitignore"===e.toLowerCase()?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:o}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,n.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===l||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:o}),(0,n.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"env"===l||e.startsWith(".env")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:o}),(0,n.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"vue"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:o}),(0,n.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.5",fill:"none"})]})}function E({status:e}){let{label:t,className:r}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,n.jsx)("span",{className:`text-xs font-bold ${r}`,children:t})}let T=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let h=o===t.path,m=l.has(t.path),x=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):a(t)},[t,a,i]),f=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(e,t.path,t.isDirectory)},[t.path,t.isDirectory,c]);return t.isDirectory?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*r+8}px`},onClick:x,onContextMenu:f,children:[(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:m?"▼":"▶"}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),u&&u(t)]}),m&&t.children.map(t=>(0,n.jsx)(e,{node:t,level:r+1,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d,renderActions:u},t.path))]}):(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${h?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:x,onContextMenu:f,children:[(0,n.jsx)(M,{name:t.name,size:16,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:`text-sm flex-1 truncate ${h?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,n.jsx)(E,{status:t.status}),d&&void 0!==t.additions&&void 0!==t.deletions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,n.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),u&&u(t)]})});function $({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,cwd:a,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:m}=(0,o.Bd)(),x=d??m("gitFileTree.noFiles"),{contextMenu:f,showContextMenu:p,hideContextMenu:g}=(0,h.Ee)();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:x}):(0,n.jsxs)("div",{className:u||"py-1",children:[e.map(e=>(0,n.jsx)(T,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,onContextMenu:p,showChanges:i,renderActions:c},e.path)),f&&(0,n.jsx)(h.ft,{x:f.x,y:f.y,path:f.path,cwd:a,isDirectory:f.isDirectory,onClose:g})]})}function R(e){let t=[];for(let r of e){let e=r.path.split("/"),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,l=e.slice(0,t+1).join("/"),a=n.find(e=>e.name===s);a||(a={name:s,path:l,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(a)),o||(n=a.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t}function P(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function B(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}var I=r(69809);function D(e){try{let t=JSON.parse(e);return _(t,0)}catch{return e}}let F="#79c0ff",A="#a5d6ff",O="#ff7b72",W="#8b949e",z=(e,t)=>s.createElement("span",{style:{color:e}},t);function H({label:e,labelColor:t,value:r,indent:n}){let[o,l]=s.useState(!1),[a,i]=s.useState({x:0,y:0}),c="string"==typeof r&&r.replace(/\\n/g,"\n").split("\n").length>3,d={onMouseDown:e=>{i({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-a.x,r=e.clientY-a.y;t*t+r*r>25||(e.stopPropagation(),l(e=>!e))},style:{cursor:"pointer"}};if(c&&o&&"string"==typeof r){let n=r.replace(/\\n/g,"\n").split("\n")[0],o=r.replace(/\\n/g,"\n").split("\n").length;return s.createElement("span",d,z(t,e),z(W,": "),z(A,n),z("#6e7681",` ${I.A.t("toolCall.foldedLines",{count:o})}`))}let u=s.createElement(s.Fragment,null,z(t,e),z(W,": "),_(r,n));return c?s.createElement("span",d,u):u}function _(e,t){let r=" ".repeat(t);if(null===e)return z(O,"null");if(void 0===e)return z(O,"undefined");if("string"==typeof e)return z(A,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+r));if("number"==typeof e)return z("#79c0ff",String(e));if("boolean"==typeof e)return z(O,String(e));if(Array.isArray(e))return 0===e.length?z(W,"[]"):s.createElement(s.Fragment,null,z(W,"["),"\n",...e.map((n,o)=>s.createElement("span",{key:o},r+" ",s.createElement(H,{label:`[${o}]`,labelColor:F,value:n,indent:t+1}),o<e.length-1?s.createElement(s.Fragment,null,z(W,","),"\n"):"\n")),r,z(W,"]"));if("object"==typeof e){let n=Object.entries(e);return 0===n.length?z(W,"{}"):s.createElement(s.Fragment,null,z(W,"{"),"\n",...n.map(([e,o],l)=>s.createElement("span",{key:e},r+" ",s.createElement(H,{label:e,labelColor:F,value:o,indent:t+1}),l<n.length-1?s.createElement(s.Fragment,null,z(W,","),"\n"):"\n")),r,z(W,"}"))}return String(e)}let q=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function V(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return q.has(t)}function U(e){return e.toLowerCase().endsWith(".md")}let K="json-search-highlight-style";function J(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(0),h=(0,s.useRef)(null),m=(0,s.useRef)([]),x=(0,s.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),m.current=[];let r=e.current;if(!r||!n){c(0),u(0);return}!function(){if(document.getElementById(K))return;let e=document.createElement("style");e.id=K,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let s=r.textContent||"",o=l?n:n.toLowerCase(),a=l?s:s.toLowerCase(),i=[],d=0;for(;d<a.length;){let e=a.indexOf(o,d);if(-1===e)break;i.push([e,e+o.length]),d=e+1}if(0===i.length){c(0),u(0);return}let h=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),x=0,f=0,p=[],g=null,b=0;for(;(t=h.nextNode())&&f<i.length;){let e=t.textContent?.length||0,r=x,n=x+e;for(;f<i.length;){let[e,s]=i[f];if(e>=n)break;if(!g)if(e>=r)(g=document.createRange()).setStart(t,e-r),b=s;else break;if(b<=n)g.setEnd(t,b-r),p.push(g),g=null,f++;else break}x=n}m.current=p,c(p.length),u(e=>p.length>0?Math.min(e,p.length-1):0),CSS.highlights&&p.length>0&&CSS.highlights.set("json-search",new Highlight(...p))},[e,n,l]),f=(0,s.useCallback)((e,t)=>{let r=e.getBoundingClientRect();(t.top<r.top||t.bottom>r.bottom)&&(e.scrollTop+=t.top-r.top-r.height/2+t.height/2)},[]),p=(0,s.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let r=m.current[t];if(!r||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(r));let n=r.getBoundingClientRect(),s=e.current?.parentElement;s&&f(s,n)},[e,f]);(0,s.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,s.useEffect)(()=>{p(d)},[d,i,p]),(0,s.useEffect)(()=>{let t=e.current;if(!t||!n)return;let r=new MutationObserver(()=>x());return r.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>r.disconnect()},[e,n,x]),(0,s.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),m.current=[])},[t]),(0,s.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let g=(0,s.useCallback)(()=>{0!==i&&u(e=>(e+1)%i)},[i]),b=(0,s.useCallback)(()=>{0!==i&&u(e=>(e-1+i)%i)},[i]),v=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>h.current?.focus(),0)},[]),j=(0,s.useCallback)(()=>{r(!1),o(""),u(0)},[]),y=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?b():g()),"Escape"===e.key&&(e.preventDefault(),j())},[g,b,j]);return{isVisible:t,query:n,setQuery:o,caseSensitive:l,setCaseSensitive:a,matchCount:i,currentIndex:d,searchInputRef:h,open:v,close:j,goToNext:g,goToPrev:b,handleKeyDown:y}}function X({search:e}){return e.isVisible?s.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},s.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:I.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),s.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:I.A.t("codeViewer.caseSensitive")},"Aa"),s.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:I.A.t("common.noMatch")),s.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:I.A.t("common.previous")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),s.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:I.A.t("common.next")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),s.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:I.A.t("common.close")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}function Y({isOpen:e,onClose:t,commit:r,cwd:l,embedded:a=!1,initialFilePath:i,onContentSearch:c}){let{t:d}=(0,o.Bd)(),[u,h]=(0,s.useState)([]),[m,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),M=(0,s.useRef)(null),E=J(M);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&S){e.preventDefault(),E.open();return}if("Escape"===e.key){if(E.isVisible)return void E.close();if(S)return void L(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,S,E]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{h([]),x([]),b(null),j(null),w(!0)}),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];h(t);let n=R(t);if(x(n),p(new Set(P(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{b(e),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error)},0)}}).catch(console.error).finally(()=>w(!1)))},[e,r,l,i]);let T=(0,s.useCallback)(e=>{r&&(b(e),C(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>C(!1)))},[l,r]),B=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),I=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,l,a;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),l=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${l}:${a}`:`${e.getFullYear()}-${s}-${o} ${l}:${a}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]);if(!e||!r)return null;let F=(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border bg-secondary flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-2",children:r.subject}),r.body&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground whitespace-pre-wrap mb-3 max-h-32 overflow-y-auto border-l-2 border-border pl-3",children:r.body}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.hash")}),(0,n.jsx)("span",{className:"font-mono bg-accent px-1.5 py-0.5 rounded",children:r.hash})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-slate-9",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.date")}),(0,n.jsx)("span",{children:I}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-slate-9",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.files")}),(0,n.jsx)("span",{children:d("commitDetail.nChanges",{count:u.length})})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto overflow-x-hidden",children:y?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:d("commitDetail.loadingFiles")}):(0,n.jsx)($,{files:m,selectedPath:g?.path||null,expandedPaths:f,onSelect:e=>e.file&&T(e.file),onToggle:B,cwd:l,showChanges:!0,emptyMessage:d("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:k?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:d("commitDetail.loadingDiff")}):v?(0,n.jsx)(N,{oldContent:v.oldContent,newContent:v.newContent,filePath:v.filePath,isNew:v.isNew,isDeleted:v.isDeleted,cwd:l,enableComments:!0,onPreview:!v.isDeleted&&v.filePath.endsWith(".json")?()=>L({content:v.newContent,filePath:v.filePath}):void 0,previewLabel:d("common.readable"),onContentSearch:c}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:d("commitDetail.selectFileToView")})})]})]}),A=S&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>L(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:S.filePath}),(0,n.jsx)("button",{onClick:()=>L(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(X,{search:E}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:M,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:D(S.content)})})]})});return a?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title:d("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),F,A]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("commitDetail.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),F,A]})})}let Q={M:{text:"text-amber-11",bg:"bg-amber-9/20"},A:{text:"text-green-11",bg:"bg-green-9/20"},D:{text:"text-red-11",bg:"bg-red-9/20"},"?":{text:"text-slate-9",bg:"bg-slate-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},G=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:l,onToggle:a,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:h,hasChangedChildren:m}=e,x=h?Q[h]:null,f=(0,s.useCallback)(()=>{d.isDirectory?a(d.path):l(d.path)},[d.isDirectory,d.path,l,a]),p=(0,s.useCallback)(e=>{i(e,d.path,d.isDirectory)},[d.path,d.isDirectory,i]),g=!d.isDirectory&&(".env"===d.name||d.name.startsWith(".env.")),b=h?x.text:m?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!d.isDirectory?"text-brand":"text-foreground";return(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 cursor-pointer hover:bg-accent ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[d.isDirectory?o?(0,n.jsxs)("svg",{className:"w-4 h-4 flex-shrink-0 text-muted-foreground animate-spin",viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):(0,n.jsx)("svg",{className:`w-4 h-4 flex-shrink-0 text-muted-foreground transition-transform ${r?"rotate-90":""}`,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M6 4 L10 8 L6 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)(M,{name:d.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":d.isSymlink&&d.symlinkTarget?`${d.path} → ${d.symlinkTarget}`:d.path,children:d.name}),d.isSymlink&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:"→"}),h&&(0,n.jsx)("span",{className:`text-xs font-mono px-1 rounded ${x.text} ${x.bg} flex-shrink-0`,children:h}),d.isDirectory&&m&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),c?.(d)]})});function Z({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:l=null,loadingDirs:a,onSelect:i,onToggle:d,cwd:u,shouldScrollToSelected:m=!1,onScrolledToSelected:x,className:f,renderActions:p,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y}){let w=(0,s.useRef)(null),{contextMenu:k,showContextMenu:N,hideContextMenu:C}=(0,h.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let l=[];for(let a of t){if(null!==n&&!n.has(a.path))continue;let t=s?.get(a.path),i=a.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(a.path,s):void 0;l.push({node:a,level:o,gitStatus:t,hasChangedChildren:i}),a.isDirectory&&a.children&&r.has(a.path)&&l.push(...e(a.children,r,n,s,o+1))}return l})(e,r,o,l),[e,r,o,l]),L=(0,c.Te)({count:S.length,getScrollElement:()=>w.current,estimateSize:()=>26,overscan:10}),M=(0,s.useRef)(x);return(M.current=x,(0,s.useEffect)(()=>{if(m&&t&&S.length>0){let e=S.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{L.scrollToIndex(e,{align:"center"}),M.current?.()},150);return()=>clearTimeout(t)}}},[m,t,S,L]),0===S.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:w,className:f||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${L.getTotalSize()}px`,width:"100%",position:"relative"},children:L.getVirtualItems().map(e=>{let s=S[e.index];return(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},children:(0,n.jsx)(G,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:a?.has(s.node.path),onSelect:i,onToggle:d,onContextMenu:N,renderActions:p})},s.node.path)})}),k&&(0,n.jsx)(h.ft,{x:k.x,y:k.y,path:k.path,cwd:u,isDirectory:k.isDirectory,onClose:C,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y})]})}var ee=r(38408),et=r(82292),er=r(45048),en=r(97251),es=r(47176),eo=r(79968);function el(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let r=t.closest("[data-source-start]");if(!r)return null;let n=r.getAttribute("data-source-start"),s=r.getAttribute("data-source-end");return n&&s?{start:parseInt(n,10),end:parseInt(s,10)}:null}let ea=[en.W];function ei({content:e,filePath:t,cwd:r,onClose:l,sourceFile:i}){let c=i||(r&&t.startsWith(r)?t.slice(r.endsWith("/")?r.length:r.length+1):t),{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(()=>{}),v=(0,h.iN)(),w=(0,m.r)(),{comments:k,addComment:N,updateComment:C,deleteComment:S,refresh:L}=(0,d._)({cwd:r,filePath:t}),[M,E]=(0,s.useState)(!1),[T,$]=(0,s.useState)(null),[R,P]=(0,s.useState)(null),[B,I]=(0,s.useState)(null),D=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>E(!0))},[]),(0,s.useEffect)(()=>{let e=p.current;if(!e)return;let t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,g.current&&(g.current=null,b.current())},o=s=>{t=!1;let o=s.target;if(o.closest?.(".floating-toolbar")||o.closest?.("[data-comment-card]"))return;let l=Math.abs(s.clientX-r)>5||Math.abs(s.clientY-n)>5,a=window.getSelection();if(!a||a.isCollapsed){g.current=null,b.current();return}let i=a.toString();if(!i.trim()||!l){g.current=null,b.current();return}let c=a.getRangeAt(0);if(!e.contains(c.commonAncestorContainer))return;let d=el(c.startContainer),u=el(c.endContainer);if(d&&u){let e=Math.min(d.start,u.start),t=Math.max(d.end,u.end);g.current={x:s.clientX,y:s.clientY,range:{start:e,end:t},selectedText:i},b.current()}},l=()=>{if(t||!g.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(g.current=null,b.current())};return e.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[]);let F=(0,s.useCallback)(()=>{let e=g.current;e&&($({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),A=(0,s.useCallback)(()=>{let e=g.current;e&&(P({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),O=(0,s.useCallback)(async e=>{T&&(await N(T.range.start,T.range.end,e),$(null))},[T,N]),W=(0,s.useCallback)(async e=>{if(R&&w)try{let n=await (0,u.$3)(r),s=[];for(let e of n)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});let o=Math.max(0,R.range.start-1),l=Math.min(D.length,R.range.end),a=D.slice(o,l).join("\n");s.push({filePath:t,startLine:R.range.start,endLine:R.range.end,codeContent:a});let i=(0,u.Gw)(s,e);w.sendMessage(i),await (0,u.RP)(r),L(),P(null)}catch(e){console.error("Failed to send to AI:",e)}},[R,w,t,r,D,L]),z=(0,s.useMemo)(()=>{if(0===k.length)return[];let e=new Map;for(let t of k){let r=`${t.startLine}-${t.endLine}`;e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[k]),[H,_]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===z.length||!p.current)return void queueMicrotask(()=>_([]));let e=setTimeout(()=>{let e=p.current;if(!e)return;let t=[],r=e.querySelectorAll("[data-source-start]");for(let n of z){let s=null,o=1/0;for(let e of r){let t=parseInt(e.getAttribute("data-source-start"),10),r=parseInt(e.getAttribute("data-source-end"),10);if(t<=n.startLine&&r>=n.endLine){let n=r-t;n<o&&(o=n,s=e)}}if(s){let r=e.getBoundingClientRect(),o=s.getBoundingClientRect();t.push({key:n.key,top:o.top-r.top+e.scrollTop,comments:n.comments})}}_(t)},100);return()=>clearTimeout(e)},[z,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(R){P(null),e.stopPropagation();return}if(T){$(null),e.stopPropagation();return}if(g.current){g.current=null,b.current(),e.stopPropagation();return}if(B){I(null),e.stopPropagation();return}l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[R,T,B,l]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:t}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(eo.ShareReviewToggle,{content:e,sourceFile:c}),(0,n.jsx)("button",{onClick:l,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(es.l,{content:e,containerRef:p}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:p,children:[(0,n.jsx)("div",{className:"p-6",children:(0,n.jsx)(er.T,{content:e,rehypePlugins:ea})}),H.map(({key:e,top:t,comments:r})=>(0,n.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),I({comment:r[0],x:e.clientX,y:e.clientY})},children:(0,n.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:r.length})},e))]})]}),M&&v&&(0,a.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:g,bumpRef:b,container:v,onAddComment:F,onSendToAI:A,isChatLoading:w?.isLoading}),T&&(0,n.jsx)(x.t,{x:T.x,y:T.y,range:T.range,codeContent:T.codeContent,container:v,onSubmit:O,onClose:()=>$(null)}),R&&(0,n.jsx)(x.G,{x:R.x,y:R.y,range:R.range,filePath:t,codeContent:R.codeContent,container:v,onSubmit:W,onClose:()=>P(null),isChatLoading:w?.isLoading}),B&&(0,n.jsx)(y.t,{x:B.x,y:B.y,comment:B.comment,container:v,onClose:()=>I(null),onUpdateComment:C,onDeleteComment:S})]}),v)]})}function ec({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),l=o>=0?e.slice(0,o+1):"",a=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],l="",a=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==a&&l&&(o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-${s}`):(0,n.jsx)("span",{children:l},`${t}-${s}`)),l=""),a=c,l+=e[s]}return l&&o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-end`):(0,n.jsx)("span",{children:l},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[l&&i(l,0,"text-muted-foreground"),i(a,l.length,"text-foreground")]})}function ed({files:e,fileIndex:t,recentFiles:r,onSelectFile:l,onClose:a}){let{t:c}=(0,o.Bd)(),[d,u]=(0,s.useState)(""),[h,m]=(0,s.useState)(0),x=(0,s.useRef)(null),f=(0,s.useRef)(null),p=(0,s.useMemo)(()=>{let r,n;return t??(r=[],(n=e=>{for(let t of e)t.isDirectory&&t.children?n(t.children):t.isDirectory||r.push(t.path)})(e),r)},[t,e]),g=(0,s.useMemo)(()=>{if(!d.trim()){let e=new Set(r);return[...r.map(e=>({path:e,score:0,matchedIndices:[]})),...p.filter(t=>!e.has(t)).slice(0,50).map(e=>({path:e,score:0,matchedIndices:[]}))]}let e=[];for(let t of p){let n=function(e,t){let r=e.toLowerCase(),n=t.toLowerCase(),s=[],o=0,l=0,a=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),a===i-1&&(l+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(l+=10),i>e.lastIndexOf("/")&&(l+=3),e[i]===t[o]&&(l+=1),a=i,o++);return o<n.length?null:(l-=.1*e.length,{path:e,score:l,matchedIndices:s})}(t,d.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[d,p,r]),b=(0,s.useCallback)(e=>{u(e),m(0)},[]);(0,s.useEffect)(()=>{x.current?.focus()},[]),(0,s.useEffect)(()=>{if(f.current){let e=f.current.children[h];e?.scrollIntoView({block:"nearest"})}},[h]);let v=(0,s.useCallback)(e=>{l(e),a()},[l,a]),j=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing)switch(e.key){case"ArrowDown":e.preventDefault(),m(e=>Math.min(e+1,g.length-1));break;case"ArrowUp":e.preventDefault(),m(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),g[h]&&v(g[h].path);break;case"Escape":e.preventDefault(),a()}},[g,h,v,a]);return(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:a,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-2xl overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref:x,value:d,onChange:e=>b(e.target.value),onKeyDown:j,placeholder:c("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",autoCorrect:"off",spellCheck:"false"}),(0,n.jsx)("kbd",{className:"text-[10px] text-muted-foreground px-1.5 py-0.5 rounded border border-border bg-secondary",children:"ESC"})]}),(0,n.jsx)("div",{ref:f,className:"flex-1 overflow-y-auto py-1",children:0===g.length?(0,n.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:c("quickFileOpen.noMatch")}):g.map((e,t)=>(0,n.jsxs)("div",{className:`px-3 py-1.5 flex items-center gap-2 cursor-pointer transition-colors ${t===h?"bg-brand/15 text-foreground":"hover:bg-accent text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(M,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(ec,{path:e.path,matchedIndices:e.matchedIndices}),!d.trim()&&r.includes(e.path)&&(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground px-1.5 py-0.5 rounded bg-secondary flex-shrink-0",children:c("quickFileOpen.recent")})]},e.path))}),(0,n.jsxs)("div",{className:"px-3 py-1.5 border-t border-border flex items-center gap-3 text-[10px] text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"↑↓"})," ",c("quickFileOpen.selectHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Enter"})," ",c("quickFileOpen.openHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Esc"})," ",c("quickFileOpen.closeHint")]})]})]})})})}var eu=r(84626),eh=r(41474),em=r(61878),ex=r(33210),ef=r(48368),ep=r(91958),eg=r(45916),eb=r(31794),ev=r(69048),ej=r(97567),ey=r(68806),ew=r(52475);function ek({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(ef.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(eg.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(eb.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(ev.A,{className:s});case"class":return(0,n.jsx)(ej.A,{className:s});case"interface":return(0,n.jsx)(ey.A,{className:s});default:return(0,n.jsx)(ew.A,{className:s})}}let eN=new Map,eC=new Map;async function eS(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){eN.clear(),eC.clear();return}let t=`${e}::`;for(let e of eN.keys())e.startsWith(t)&&eN.delete(e);for(let e of eC.keys())e.startsWith(t)&&eC.delete(e)}(e);else{let e=eN.get(n);if(e)return e;let t=eC.get(n);if(t)return t}let s=(async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);let l=await o.json();return eN.set(n,l),l})().finally(()=>eC.delete(n));return eC.set(n,s),s}function eL(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let l=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),eS(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?l(e,t,!1):n({state:"idle"})},[e,t,l]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&l(e,t,!0)},[e,t,l])}}var eM=r(3238),eE=r(50538),eT=r(94287);function e$({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-l border-border flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground font-mono min-w-0",children:[(0,n.jsx)(eE.A,{className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:0===e.length?s("blockViewer.history.title"):`${s("blockViewer.history.title")} \xb7 ${e.length}/15`})]}),e.length>0&&(0,n.jsx)(eT.m,{content:s("blockViewer.history.clear"),children:(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",children:(0,n.jsx)(ex.A,{className:"w-3 h-3"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:s("blockViewer.history.empty")}):e.map((e,r)=>{var s;let o;return(0,n.jsx)(eT.m,{content:`${e.qname} \xb7 ${e.filePath}`,children:(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:bg-secondary/60 transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(ek,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]})},`${e.filePath}::${e.qname}::${r}`)})})]})}function eR(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}let eP=new Set(["function","class","method"]);function eB(e){return eP.has(e.kind)}function eI({functions:e,currentQname:t,onSelect:r}){let{t:l}=(0,o.Bd)(),a=(0,s.useMemo)(()=>e.filter(eB),[e]);return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-r border-border flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground font-mono truncate",children:0===a.length?l("blockViewer.toc.title"):`${l("blockViewer.toc.title")} \xb7 ${a.length}`}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:l("blockViewer.toc.empty")}):a.map(e=>{let s=t===e.qualifiedName;return(0,n.jsx)(eT.m,{content:`${e.qualifiedName} \xb7 L${e.startLine}`,children:(0,n.jsxs)("button",{onClick:()=>r(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-center gap-1.5 min-w-0 ${s?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(ek,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs font-mono truncate ${s?"font-semibold text-brand":""}`,children:e.name})]})},e.qualifiedName)})})]})}function eD(e,t,r){if(!document.contains(e))return null;let n=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!n)return null;let s=n.closest("[data-line]");if(!s||!t.contains(s)||r&&!s.closest(r))return null;let o=s.getAttribute("data-line");if(!o)return null;let l=parseInt(o,10);return Number.isFinite(l)?l:null}var eF=r(96035);function eA({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,onCommentClick:l}){let a=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=a.get(n.endLine);e?e.push(n):a.set(n.endLine,[n])}return 0===a.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(a.entries()).map(([e,r])=>{let a=o+(e-t)*s,i=r[0],c=r.length-1;return(0,n.jsx)(eT.m,{content:1===r.length?i.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>l(i,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-sm transition-colors",style:{top:`${a+s/2-8}px`},children:[(0,n.jsx)(eF.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]})},e)})})}function eO(e,t){for(let r=0;r<e.blocks.length;r++){let n=e.blocks[r];if(t>=n.startLine&&t<=n.endLine)return e.prefix[r]+(t-n.startLine)}return null}function eW({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let l,a=(0,s.useRef)(null),i=(0,s.useMemo)(()=>(function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[0];for(let e of t){let t=Math.max(0,e.endLine-e.startLine+1);r.push(r[r.length-1]+t)}return{blocks:t,prefix:r,total:r[r.length-1]}})(t),[t]),c=(0,s.useMemo)(()=>{if(i.total<=0||0===e.size)return[];let t=[];for(let r of e){let e=i.blocks.find(e=>r>=e.startLine&&r<=e.endLine);e&&t.push({line:r,qname:e.qname})}t.sort((e,t)=>e.line-t.line);let r=[],n=null;for(let e of t)n&&e.line===n.end+1&&e.qname===n.qname?n.end=e.line:(n&&r.push(n),n={start:e.line,end:e.line,qname:e.qname});return n&&r.push(n),r},[e,i]);if(i.total<=0)return null;let d=(e,t)=>{let r=eO(i,e),n=eO(i,t);return null===r||null===n?null:{top:r/i.total*100,heightPct:(n-r+1)/i.total*100}};return(0,n.jsxs)("div",{ref:a,onClick:e=>{let t=a.current;if(!t)return;let r=t.getBoundingClientRect();if(r.height<=0)return;let n=function(e,t){if(e.total<=0)return null;let r=Math.max(0,Math.min(e.total-1,t));for(let t=0;t<e.blocks.length;t++){let n=e.prefix[t],s=e.prefix[t+1];if(r>=n&&r<s){let s=e.blocks[t];return{qname:s.qname,line:s.startLine+Math.round(r-n)}}}return null}(i,(e.clientY-r.top)/r.height*i.total);if(!n)return;let s=n.line,l=c.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(l)return void o(l.qname,s);if(c.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=eO(i,s);if(null!==t){let r=null,n=1/0;for(let e of c){let s=eO(i,e.start),o=eO(i,e.end);if(null===s||null===o)continue;let l=t<s?s-t:t>o?t-o:0;l<n&&(r=e,n=l)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let d=i.blocks.find(e=>e.qname===n.qname);d&&o(d.qname,d.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[c.map(e=>{let t=d(e.start,e.end);return t?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${t.top}%`,height:`${t.heightPct}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`):null}),r&&r.end>=r.start&&((l=d(r.start,r.end))?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${l.top}%`,height:`${Math.max(1.2,l.heightPct)}%`}}):null)]})}function ez(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eH({symbol:e,fileSource:t,hasChange:r,onHighlighted:o,comments:l,onCommentClick:a,addedLines:i}){let{resolvedTheme:c}=(0,eM.D)(),d=(0,s.useMemo)(()=>(0,b.sQ)(e.filePath),[e.filePath]),[u,h]=(0,s.useState)(null),[m,x]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!t)return void h(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,b.kS)()).codeToTokens(n,{lang:d,theme:"dark"===c?"github-dark":"github-light"}).tokens.map((t,r)=>{let n=e.startLine+r,s=i?.has(n)??!1;return`<div class="flex${s?" bg-green-9/15":""}" style="min-width:max-content" data-line="${n}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${n}</span><span class="whitespace-pre">${(0,b.b8)(t)}</span></div>`}).join("");r||(h(s),x(null))}catch(e){r||x(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,d,c,e.filePath,i]),(0,s.useEffect)(()=>{(null!==u||null!==m)&&o(e.qualifiedName)},[u,m,e.qualifiedName,o]),(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-secondary/40 text-xs",children:[(0,n.jsx)(ek,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:[e.kind," \xb7 L",e.startLine,"-",e.endLine]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${eq}px`},children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),m&&(0,n.jsx)("span",{className:"text-red-11",children:m}),u&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:u}})]}),l&&l.length>0&&a&&(0,n.jsx)(eA,{comments:l,startLine:e.startLine,endLine:e.endLine,lineHeight:eq,bodyTopOffset:eV+eU,onCommentClick:a})]})}function e_({side:e,pin:t,accent:r,onClick:s}){let o,l,a,i,c,d,u,h=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="ext",a="text-muted-foreground/60",i=t.name,c=t.packageSpec,d="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="method",a="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,c=null,d="method (unresolved)",u=h>0?`at line${h>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",l="self",a="text-muted-foreground/70",i=t.external.name,c=null,d="same-file",u=h>0?`at line${h>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",l=e,a="in"===e?"text-amber-11":"text-green-11",i=t.external.name,c=ez(t.external.filePath),d="in"===e?"caller":"callee",u=t.external.filePath);let m=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${m} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors flex items-center gap-1.5`,"data-tooltip":`${d}${u?" \xb7 "+u:""}`,children:[(0,n.jsx)("span",{className:`${a} text-[9px] uppercase tracking-wider font-semibold flex-shrink-0`,children:l}),(0,n.jsxs)("span",{className:"truncate flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:i}),c&&(0,n.jsx)("span",{className:"text-muted-foreground/70 ml-1",children:c}),h>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60 ml-1",children:["\xb7",h,"\xd7"]})]})]})}let eq=18,eV=29,eU=8;function eK(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function eJ(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function eX(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function eY({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:l,onHighlighted:a,comments:i,onCommentClick:c,accentQnames:d,addedLines:u}){let h=function(e,t){if(0===e.length)return[];let r=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});r.sort((e,t)=>e.line-t.line||e.i-t.i);let n=Array(e.length).fill(0),s=-1/0;for(let{i:e,line:o}of r){let r=Math.max(eV+eU+(o-t.startLine)*eq,s);n[e]=r,s=r+22}return n}(o,e);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:"w-44 flex-shrink-0 flex flex-col gap-1 pt-1",children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(e_,{side:"in",pin:t,accent:eJ(t,d),onClick:()=>l(t,e)},eK("in",t)))}),(0,n.jsx)(eH,{symbol:e,fileSource:t,hasChange:r,onHighlighted:a,comments:i,onCommentClick:c,addedLines:u}),(0,n.jsx)("div",{className:"w-44 flex-shrink-0 relative",children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${h[r]}px`},children:(0,n.jsx)(e_,{side:"out",pin:t,accent:eJ(t,d),onClick:()=>l(t,e)})},eK("out",t)))})]})}function eQ({cwd:e,onSelect:t,onClose:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(""),[c,d]=(0,s.useState)({files:[],symbols:[]}),[u,h]=(0,s.useState)(0),[m,x]=(0,s.useState)(!1),f=(0,s.useMemo)(()=>[...c.files,...c.symbols],[c]);(0,s.useEffect)(()=>{let t=a.trim();if(!t)return void d({files:[],symbols:[]});x(!0);let r=setTimeout(async()=>{try{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await fetch(`/api/projectGraph/search?${r}`);if(n.ok){let e=await n.json();d(e),h(0)}}finally{x(!1)}},120);return()=>clearTimeout(r)},[a,e]);let p=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==f.length){if("ArrowDown"===e.key)e.preventDefault(),h(e=>Math.min(e+1,f.length-1));else if("ArrowUp"===e.key)e.preventDefault(),h(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=f[u];r&&t(r)}}},[f,u,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-2xl overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(em.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:a,onChange:e=>i(e.target.value),onKeyDown:p,placeholder:l("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),m&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===f.length&&a&&!m&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:l("blockViewer.search.noResults","No matches")}),(0,n.jsx)(eG,{label:l("blockViewer.search.files","Files"),hits:c.files,startIdx:0,activeIdx:u,onSelect:t,setActive:h}),(0,n.jsx)(eG,{label:l("blockViewer.search.symbols","Symbols"),hits:c.symbols,startIdx:c.files.length,activeIdx:u,onSelect:t,setActive:h})]})]})})}function eG({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:l}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let a=r+t,i=a===s;return(0,n.jsxs)("button",{onMouseEnter:()=>l(a),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.target.kind?(0,n.jsx)(ef.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(ek,{kind:e.target.symbolKind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function eZ({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:l,enableComments:a=!1,onContentSearch:i,onFocalChange:c,qnameFilter:h,qnameFilterFile:f,accentQnames:p,accentFile:g,addedLines:b,addedLinesFile:v,headerExtraLeft:w,headerExtraRight:k}){let{t:N}=(0,o.Bd)(),[C,S]=(0,s.useState)(null),L=C??t??null;(0,s.useEffect)(()=>{S(null)},[t]),(0,s.useEffect)(()=>{c?.(L)},[L,c]);let{state:M,refresh:E}=eL(e,L),[T,$]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!L)return void $(null);let t=!1;return $(null),(async()=>{try{let r=new URLSearchParams({cwd:e,path:L}),n=await fetch(`/api/files/text?${r}`);if(!n.ok)return;let s=await n.json();t||$({content:s.content,mtimeMs:s.mtimeMs})}catch(e){console.error("[BlockViewer] failed to load file source for",L,e)}})(),()=>{t=!0}},[e,L]);let R=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!T||"ready"!==M.state)return;let e=M.data.mtimeMs;!e||T.mtimeMs<=e||R.current!==T.mtimeMs&&(R.current=T.mtimeMs,E())},[T,M,E]);let[P,B]=(0,s.useState)([]),[I,D]=(0,s.useState)(!1),[F,A]=(0,s.useState)(null),O=(0,s.useRef)(0),W=(0,s.useRef)(0),[z,H]=(0,s.useState)(()=>new Set),_="ready"===M.state?M.data.filePath:null;(0,s.useEffect)(()=>{H(new Set)},[_]);let q=(0,s.useCallback)(e=>{H(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),D(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let V=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;O.current+=1,A({filePath:e,qname:"__imports__",nonce:O.current});return}let r=eX(t),n=eX(e.external);B(e=>eR(eR(e,r),n)),S(n.filePath),O.current+=1,A({filePath:n.filePath,qname:n.qname,nonce:O.current})},[]),U=(0,s.useCallback)(e=>{S(e.filePath),O.current+=1,A({filePath:e.filePath,qname:e.qname,nonce:O.current})},[]),K=(0,s.useCallback)(e=>{D(!1),S(e.target.filePath),"symbol"===e.target.kind&&(O.current+=1,A({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.line,nonce:O.current}))},[]),J=(0,s.useCallback)((e,t)=>{L&&(O.current+=1,A({filePath:L,qname:e,line:t,nonce:O.current}))},[L]),[X,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!X)return;let e=null,t=()=>{e=null;let t=X.getBoundingClientRect();if(t.height<=0)return;let r=X.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let l=Number(r),a=Number(o);if(!Number.isFinite(l)||!Number.isFinite(a))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let c=Math.max(0,t.top-i.top),d=Math.min(i.height,t.bottom-i.top),u=a-l+1,h=Math.floor(c/i.height*u),m=Math.ceil(d/i.height*u)-1,x=l+Math.max(0,h),f=l+Math.min(u-1,Math.max(0,m));x<n&&(n=x),f>s&&(s=f)}),n===1/0||s===-1/0?G(null):G(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),X.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(X);let s=new MutationObserver(r);return s.observe(X,{childList:!0,subtree:!0}),()=>{X.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[X]);let Z=(0,s.useMemo)(()=>{if("ready"!==M.state||!Q)return null;let e=M.data.functions;if(0===e.length)return null;let t=(Q.start+Q.end)/2;for(let r of e)if(r.startLine<=t&&t<=r.endLine)return r.qualifiedName;let r=null;for(let t of e)t.startLine<=Q.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[M,Q]),ee=a&&!!e&&!!L,et=(0,m.r)(),{comments:er,addComment:en,updateComment:es,deleteComment:eo,refresh:el}=(0,d._)({cwd:e,filePath:L??""}),[ea,ei]=(0,s.useState)(null),{toolbar:ec,clearToolbar:ed}=function({enabled:e,container:t,bodyScope:r}){let[n,o]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!e||!t)return;let n=!1,s=0,l=0,a=e=>{n=!0,s=e.clientX,l=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||o(e=>e?null:e)},i=e=>{n=!1;let a=e.target;if(a?.closest?.(".floating-toolbar"))return;let i=Math.abs(e.clientX-s)>5||Math.abs(e.clientY-l)>5,c=window.getSelection();if(!c||c.isCollapsed||!c.toString().trim()||!i)return void o(e=>e?null:e);let d=c.getRangeAt(0);if(!t.contains(d.commonAncestorContainer))return void o(e=>e?null:e);let u=eD(d.startContainer,t,r),h=eD(d.endContainer,t,r);if(null==u||null==h)return void o(e=>e?null:e);let m=Math.min(u,h),x=Math.max(u,h);o({x:e.clientX,y:e.clientY,range:{start:m,end:x},selectedText:c.toString()})},c=()=>{if(n)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||o(e=>e?null:e)};return t.addEventListener("mousedown",a),document.addEventListener("mouseup",i),document.addEventListener("selectionchange",c),()=>{t.removeEventListener("mousedown",a),document.removeEventListener("mouseup",i),document.removeEventListener("selectionchange",c)}},[e,t,r]),{toolbar:n,clearToolbar:()=>o(null)}}({enabled:ee,container:ea}),[eu,eh]=(0,s.useState)(null),[em,ex]=(0,s.useState)(null),[ef,ep]=(0,s.useState)(null),eg=(0,s.useCallback)(()=>{ec&&(eh({x:ec.x,y:ec.y,range:ec.range,codeContent:ec.selectedText}),ed())},[ec,ed]),eb=(0,s.useCallback)(()=>{ec&&(ex({x:ec.x,y:ec.y,range:ec.range,codeContent:ec.selectedText}),ed())},[ec,ed]),ev=(0,s.useCallback)(()=>{if(!ec||!i)return;let e=ec.selectedText.trim();ed(),e&&i(e)},[ec,i,ed]),ej=(0,s.useCallback)(async e=>{eu&&(await en(eu.range.start,eu.range.end,e,eu.codeContent),eh(null))},[eu,en]),ey=(0,s.useCallback)(async t=>{if(em&&et&&e&&L)try{let r=(await (0,u.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:L,startLine:em.range.start,endLine:em.range.end,codeContent:em.codeContent});let n=(0,u.Gw)(r,t);et.sendMessage(n),await (0,u.RP)(e),el(),ex(null)}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[em,et,e,L,el]),ew=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ep({comment:e,x:t.clientX,y:t.clientY}),ed(),eh(null),ex(null)},[ed]);if((0,s.useEffect)(()=>{let e;if(!F||W.current>=F.nonce||"ready"!==M.state||!T||M.data.filePath!==F.filePath)return;if(f&&f===M.data.filePath&&h){let t=0;for(let e of M.data.functions)h.has(e.qualifiedName)&&t++;e=Math.max(1,t)}else e=Math.max(1,M.data.functions.length);if(z.size<e)return;W.current=F.nonce;let t=null,r=requestAnimationFrame(()=>{let e=F.qname.indexOf(">"),r=e>=0?F.qname.slice(0,e):F.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof F.line){let e=n.querySelector(`[data-line="${F.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"instant",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"instant",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[F,M,T,z,h,f]),!L)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:null,fileCount:null,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:N("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:N("blockViewer.empty.hint","or press ⌘K to search.")})]}),I&&(0,n.jsx)(eQ,{cwd:e,onSelect:K,onClose:()=>D(!1)})]});if("idle"===M.state||"loading"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N("blockViewer.fileMode.loading","Loading…")})]});if("notFound"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:N("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),I&&(0,n.jsx)(eQ,{cwd:e,onSelect:K,onClose:()=>D(!1)})]});if("error"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:M.message}),(0,n.jsx)("button",{onClick:E,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:N("blockViewer.retry","Retry")})]})]});let ek=M.data,eN=ek.functions;if(0===eN.length&&T){let e=Math.max(1,T.content.split("\n").length);eN=[{filePath:ek.filePath,qualifiedName:"__file__",name:ez(ek.filePath),kind:"unknown",startLine:1,endLine:e}]}let eC=f&&f===ek.filePath,eS=g&&g===ek.filePath,eM=v&&v===ek.filePath;eC&&h&&(eN=eN.filter(e=>h.has(e.qualifiedName)));let eE=eS?p:void 0,eT=eM?b:void 0,eP=e0(ek.upstreamCalls),eB=e0(ek.downstreamCalls),eF=new Map(eN.map(e=>[e.qualifiedName,e])),eA=new Map,eO=new Map;for(let e of ek.intraCalls){let t=eF.get(e.to),r=eF.get(e.from);if(t){let r=eA.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eA.set(e.from,[n])}if(r){let t=eO.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):eO.set(e.to,[n])}}let eH=new Map;for(let e of ek.externalCalls??[]){let t=eH.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):eH.set(e.focalQname,[r])}let e_=new Map;for(let e of ek.methodCalls??[]){let t=e_.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):e_.set(e.focalQname,[r])}let eq=r.has(ek.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:ek.fileCount,functionCount:ek.functions.length,upstreamCount:ek.upstreamCalls.length,downstreamCount:ek.downstreamCalls.length,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{ref:ei,className:"flex-1 relative min-h-0 flex",children:[(0,n.jsx)(eI,{functions:eN,currentQname:Z,onSelect:J}),(0,n.jsx)("div",{ref:Y,className:"flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eN.map(e=>{let t,r,s,o,l,a;return(0,n.jsx)(eY,{symbol:e,fileSource:T?.content??null,hasChange:eq,upstream:(t=eP.get(e.qualifiedName),r=eO.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eB.get(e.qualifiedName),o=eA.get(e.qualifiedName),l=e_.get(e.qualifiedName),a=eH.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...l??[],...a??[]]),onPinClick:V,onHighlighted:q,comments:ee?er:void 0,onCommentClick:ee?ew:void 0,accentQnames:eE,addedLines:eT},e.qualifiedName)})})}),ee&&ec&&ea&&(0,n.jsx)(j.w,{x:ec.x,y:ec.y,visible:!0,container:ea,onAddComment:eg,onSendToAI:eb,onSearch:i?ev:void 0,isChatLoading:et?.isLoading}),ee&&eu&&(0,n.jsx)(x.t,{x:eu.x,y:eu.y,range:eu.range,codeContent:eu.codeContent,container:ea,onSubmit:ej,onClose:()=>eh(null)}),ee&&em&&L&&(0,n.jsx)(x.G,{x:em.x,y:em.y,range:em.range,filePath:L,codeContent:em.codeContent,container:ea,onSubmit:ey,onClose:()=>ex(null),isChatLoading:et?.isLoading}),ee&&ef&&(0,n.jsx)(y.t,{x:ef.x,y:ef.y,comment:ef.comment,container:ea,onClose:()=>ep(null),onUpdateComment:es,onDeleteComment:eo}),eT&&eT.size>0&&eN.length>0&&(0,n.jsx)(eW,{addedLines:eT,blockRanges:eN.map(e=>({qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine})),viewportRange:Q,onJumpToLine:J}),(0,n.jsx)(e$,{entries:P,onSelect:U,onClear:()=>B([])}),I&&(0,n.jsx)(eQ,{cwd:e,onSelect:K,onClose:()=>D(!1)})]})]})}function e0(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function e1({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:l,onSwitchToCode:a,onSearch:i,onRefresh:c,refreshDisabled:d,extraLeft:u,extraRight:h}){let{t:m}=(0,o.Bd)(),x={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:l??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between bg-secondary/30 gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof l&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",l," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(x)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[h&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:h(x)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":m("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(em.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:c,disabled:d,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":m("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(ep.A,{className:"w-3 h-3"})}),a&&(0,n.jsx)("button",{onClick:a,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:"Code"})]})]})}function e2(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function e5(e){return e.replace(/\s+/g," ").trim()}function e4(e,t){return e?`${e}>${t}`:t}function e3(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function e6(e,t,r,n,s=[],o){return{qualifiedName:e4(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e2(e5(e.text)),children:s,params:o}}function e8(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}function e9(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";default:return null}}var e7=r(14066);let te="/tree-sitter",tt=null,tr=new Map;async function tn(e){let t,r=await (!(t=tr.get(e))&&(t=(async()=>(await (!tt&&(tt=e7.iX.init({locateFile:e=>`${te}/${e}`})),tt),e7.TM.load(`${te}/tree-sitter-${e}.wasm`)))(),tr.set(e,t)),t),n=new e7.iX;return n.setLanguage(r),n}function ts(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function to(e){return!ts(e)&&"__file__"!==e.qualifiedName}async function tl(e,t){if(!e)return[];let r=e9(t);if(!r)return null;let n=(await tn(r)).parse(e);if(!n)return null;try{return function(e){let t=[],r=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,contentHash:e2(e5(t.map(e=>e.text).join("\n"))),children:[]}}(e);r&&t.push(r);for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);n&&t.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[e6(t,e3(t),"function",r,[],e8(t))];case"class_declaration":case"abstract_class_declaration":{let e=e3(t),n=e4(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(e6(s,e3(s),"method",t,[],e8(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(e6(s,e3(s),"method",t,[],e8(e)))}}}return r}(t.childForFieldName("body"),n);return[e6(t,e,"class",r,s)]}case"interface_declaration":return[e6(t,e3(t),"interface",r)];case"type_alias_declaration":return[e6(t,e3(t),"type",r)];case"enum_declaration":return[e6(t,e3(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),l=s.childForFieldName("value");if(!o)continue;let a=o.text,i=l&&("arrow_function"===l.type||"function_expression"===l.type),c=i&&l?e8(l):void 0;if(r.push(e6(e,a,i?"function":"const",t,[],c)),l&&"object"===l.type&&!i){let e=t?`${t}>${a}`:a;for(let t=0;t<l.namedChildCount;t++){let n=l.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(e6(n,t.text,"method",e,[],e8(s)))}else if("method_definition"===n.type){let t=e3(n);t&&r.push(e6(n,t,"method",e,[],e8(n)))}}}}}return r}(t,r);case"class_definition":{let e=e3(t),n=e4(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(e6(o,e3(o),"method",r,[],e8(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...e6(t,e3(t),"method",r,[],e8(t)),startLine:o.startPosition.row+1,contentHash:e2(e5(o.text))});else if(t?.type==="class_definition"){let s=e3(t),l=e4(r,s),a=e(t.childForFieldName("body"),l);n.push({...e6(t,s,"class",r,a),startLine:o.startPosition.row+1,contentHash:e2(e5(o.text))})}}else if("class_definition"===o.type){let t=e3(o),s=e4(r,t),l=e(o.childForFieldName("body"),s);n.push(e6(o,t,"class",r,l))}}}return n}(t.childForFieldName("body"),n);return[e6(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:e2(e5(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:e4(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e2(e5(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,l=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&l.push(t)}}if(0===l.length||!o)return[];let a=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=a?`${a} ${o}`:o;return l.map((e,r)=>e6(e,l.length>1?`${i} #${r+1}`:i,"function",t,[],e8(e)))}(t,r)),e}default:return[]}}(n,void 0,!1))}return t.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],l=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,contentHash:e2(e5(s)),children:[]})},a=-1;for(let e=1;e<=n;e++)s[e]?a>=0&&(l(a,e-1),a=-1):a<0&&(a=e);return a>=0&&l(a,n),o}(e,t)),t}(n.rootNode)}finally{n.delete()}}async function ta(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of f(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!e9(r))return{addedLines:o};let[l,a]=await Promise.all([tl(n?"":e,r),tl(s?"":t,r)]),i=a??[],c=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}((l??[]).filter(to),i.filter(to)),d=new Set;for(let e of c)"deleted"!==e.changeKind&&d.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(ts(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(i,o))d.add(e);return{changedQnames:d,addedLines:o}}function ti({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:l=!1,isDeleted:a=!1,changedFiles:i,fileGitStatusMap:c,enableComments:d=!1,onContentSearch:u,headerExtraLeft:h,headerExtraRight:m}){let[x,f]=(0,s.useState)(t);(0,s.useEffect)(()=>{f(t)},[t]);let[p,g]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return g(null),(async()=>{try{let s=await tc(x,t,r,o,l,a,i,c,e);if(n||!s)return;let d=await ta(s.oldContent,s.newContent,x,s.isNew,s.isDeleted);if(n)return;g(d)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[x,t,r,o,l,a,i,c,e]),(0,n.jsx)(eZ,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:d,qnameFilter:p?.changedQnames,qnameFilterFile:x,accentQnames:p?.changedQnames,accentFile:x,addedLines:p?.addedLines,addedLinesFile:x,onFocalChange:e=>e&&f(e),onContentSearch:u,headerExtraLeft:h,headerExtraRight:m})}async function tc(e,t,r,n,s,o,l,a,i){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!l.has(e))return null;let c=a?.get(e);if(!c)return null;let d=new URLSearchParams({cwd:i,file:e,type:c}),u=await fetch(`/api/git/diff?${d}`);if(!u.ok)return null;let h=await u.json();return{oldContent:h.oldContent,newContent:h.newContent,isNew:h.isNew??!1,isDeleted:h.isDeleted??!1}}function td(e){let{refreshKey:t,className:r="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:l}=e,a="absPath"in e&&"string"==typeof e.absPath,i=a?void 0:e.cwd,c=a?void 0:e.path,d=a?e.absPath:void 0,[u,h]=(0,s.useState)({kind:"loading"}),m=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++m.current;return h({kind:"loading"}),(async()=>{if(a){if(e!==m.current)return;h({kind:"ready",etag:null,size:0});return}try{let t=`/api/files/stat?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}`,r=await fetch(t,{cache:"no-store"});if(e!==m.current)return;if(!r.ok)return void h({kind:"error",message:`stat failed (${r.status})`});let n=await r.json();if(e!==m.current)return;if(!n.exists)return void h({kind:"missing"});if("too-large"===n.category)return void h({kind:"too-large",size:n.size??0});if("image"!==n.category)return void h({kind:"error",message:`Not an image (${n.category})`});let s=n.etag||`t-${n.mtimeMs??Date.now()}`;h({kind:"ready",etag:s,size:n.size??0})}catch(t){if(e!==m.current)return;h({kind:"error",message:t instanceof Error?t.message:"Unknown error"})}})(),()=>{m.current++}},[a,i,c,d,t]),"loading"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(u.size/1024/1024)," MB)"]})});if("error"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:u.message})});let x=a?`/api/file?path=${encodeURIComponent(d)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}&v=${encodeURIComponent(u.etag)}`;return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("img",{src:x,alt:l??(c||d),className:o})})}function tu({cwd:e,selected:t,diff:r,showMarkdownPreview:l,setShowMarkdownPreview:a,changedFiles:i,fileGitStatusMap:c,onContentSearch:d,locateInTree:u,jsonPreview:h,setJsonPreview:m,jsonPreviewSearch:x,jsonPreviewPreRef:f}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)("file"),[j,y]=(0,s.useState)("compact"),w=t.file.path,k=(0,et.u)(w),{state:C}=eL(e,w),S=(0,s.useMemo)(()=>{if("ready"===C.state)return C.data.functions.filter(eB).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[C]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[k||"map"!==b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:w}),(0,n.jsx)(eT.m,{content:g("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${w}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(eT.m,{content:g("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(w)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${"staged"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?g("fileBrowser.staged"):g("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!k&&"file"===b&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["compact","full"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e)},className:`px-2 py-0.5 text-xs transition-colors ${j===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("compact"===e?"diffViewer.compact":"diffViewer.full")},e))}),!k&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-xs transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:k?(0,n.jsx)(td,{cwd:e,path:w,className:"p-4 flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:w}):(0,n.jsx)(N,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===j,symbols:S,onPreview:!r.isDeleted&&U(w)?()=>a(!0):!r.isDeleted&&w.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:w.endsWith(".json")?g("common.readable"):g("common.preview"),onContentSearch:d})})]}):(0,n.jsx)(ti,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:c,enableComments:!0,onContentSearch:d,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=c.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eT.m,{content:g("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(eT.m,{content:g("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?g("fileBrowser.staged"):g("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})}),l&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>a(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ei,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>a(!1)})})}),h&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>m(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:h.filePath}),(0,n.jsx)("button",{onClick:()=>m(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(X,{search:x}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:f,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:D(h.content)})})]})})]})}function th({branches:e,selectedBranch:t,onSelect:r,isLoading:l,pinnedBranches:a=[]}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1),[u,h]=(0,s.useState)(""),m=(0,s.useRef)(null),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{m.current&&!m.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{c&&x.current&&x.current.focus()},[c]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=a.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],y=e=>{r(e),d(!1),h("")};return(0,n.jsxs)("div",{className:"relative",ref:m,children:[(0,n.jsxs)("button",{onClick:()=>d(!c),disabled:l,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-slate-9 transition-transform ${c?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lg max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:x,type:"text",value:u,onChange:e=>h(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground placeholder-slate-9"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>y(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}function tm(e){let t=e.split(".").pop()?.toLowerCase();return t?["ts","tsx","js","jsx","mjs","cjs"].includes(t)?"typescript":["py","pyi"].includes(t)?"python":null:null}function tx(e){return e.replace(/^\([^)]+\)\s*/,"")}let tf=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:l,container:a,onMouseEnter:i,onMouseLeave:c,onFindReferences:d,onSearch:u},h){let{t:m}=(0,o.Bd)(),x=(0,s.useRef)(null);(0,s.useImperativeHandle)(h,()=>x.current,[]);let f=a.getBoundingClientRect(),p=r-f.left,g=l-f.top,b=(0,s.useMemo)(()=>tx(e),[e]),v=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,l=0,a=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=a.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},l++));let a=t[0];/^["']/.test(a)?s.push((0,n.jsx)("span",{className:"text-green-400",children:a},l++)):/^\d+$/.test(a)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:a},l++)):r.test(a)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:a},l++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:a},l++)),o=t.index+a.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},l++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!x.current)return;let e=x.current,t=a.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=l-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,l,a]),(0,n.jsxs)("div",{ref:x,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-xl px-3 py-2 pointer-events-none",style:{left:p,top:g},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:v}),t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap",children:t})]}),(d||u)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1.5"}),(0,n.jsxs)("div",{className:"flex items-center gap-3 pointer-events-auto",onMouseEnter:i,onMouseLeave:c,children:[d&&(0,n.jsx)("button",{onClick:d,className:"text-[11px] text-brand hover:underline cursor-pointer",children:m("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(function(e){let t=tx(e),r=t.match(/^(?:function|const|let|var|class|interface|type|enum|async function)\s+([a-zA-Z_$][\w$]*)/);if(r)return r[1];let n=e.match(/\([^)]+\)\s+(?:[\w$]+\.)*([a-zA-Z_$][\w$]*)/);if(n)return n[1];let s=t.match(/([a-zA-Z_$][\w$]*)/);return s?s[1]:t.split(/[(\s:]/)[0]}(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:m("hoverTooltip.search")})]})]})]})});function tp({references:e,loading:t,onSelect:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)();if(t!==l.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let l=(0,b.sQ)(r.file);if("text"!==l)try{let e=n.codeToTokens(r.lineText,{lang:l,theme:s}),a=(0,b.b8)(e.tokens[0]||[]);a&&o.set(t,a)}catch{}}t===l.current&&r(o)})()},[e,n]),t}(e),c=[],d=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=d.get(r.file);void 0===n&&(n=c.length,d.set(r.file,n),c.push({file:r.file,items:[]})),c[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[a("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("references.notFound")}):c.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function tg({results:e,loading:t,totalMatches:r,onSelect:l,onClose:a}){let{t:i}=(0,o.Bd)(),c=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)(),o=new Map;for(let t of e){let e=(0,b.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let l=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),a=(0,b.b8)(t.tokens[0]||[]);a&&o.set(l,a)}catch{}}}t===l.current&&r(o)})()},[e,n]),t}(e);return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[i("searchResults.title")," ",!t&&i("searchResults.nMatches",{count:r})]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.noResults")}):e.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=c.get(s);return(0,n.jsxs)("button",{onClick:()=>l(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}var tb=r(63728);function tv({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:l,initialSearchQuery:c,searchQueryTrigger:d}){var u;let m,x,f,g,b,v,{t:j}=(0,o.Bd)(),{activeView:y}=(0,tb.R8)(),[w,k]=(0,s.useState)(r),[C,S]=(0,s.useState)("code"),L=(0,s.useRef)(null),M=(0,s.useRef)(!1),[E,T]=(0,s.useState)(null),[F,A]=(0,s.useState)(null),[O,W]=(0,s.useState)(!1),z=(0,s.useRef)(1),H=(0,s.useRef)(null),[_,q]=(0,s.useState)(null),V=(0,s.useRef)(null),[K,Q]=(0,s.useState)({isDirty:!1,isSaving:!1}),[G,er]=(0,s.useState)(!1),[en,es]=(0,s.useState)(!1),[eo,el]=(0,s.useState)(null),ea=(0,s.useRef)(null),ec=J(ea),em=(0,s.useRef)(null),ex=J(em),ef=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);try{let r=await fetch("/api/lsp/definition",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:n,column:s})});return(await r.json()).definitions||[]}catch(e){return console.error("[useLSP] definition error:",e),[]}finally{r(!1)}},[e]),loading:t}}(t),ep=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),l=(0,s.useRef)(0),a=(0,s.useRef)(!1),i=(0,s.useRef)(null),c=(0,s.useRef)({x:0,y:0}),d=(0,s.useCallback)(e=>{i.current=e},[]);(0,s.useEffect)(()=>{let e=e=>{c.current.x=e.clientX,c.current.y=e.clientY};return document.addEventListener("mousemove",e),()=>document.removeEventListener("mousemove",e)},[]);let u=(0,s.useRef)(!1),h=(0,s.useRef)(null),m=(0,s.useCallback)(()=>{let e=i.current;e&&u.current&&(e.style.pointerEvents="none"),u.current=!1,h.current&&(i.current?.removeEventListener("mouseleave",h.current),h.current=null)},[]),x=(0,s.useCallback)(()=>{let e=i.current;if(!e||u.current)return;u.current=!0,a.current=!0,e.style.pointerEvents="auto";let t=()=>{a.current=!1,m(),l.current++,r(null)};h.current=t,e.addEventListener("mouseleave",t)},[m]),f=(0,s.useCallback)((t,s,a,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let c=++l.current;n.current=setTimeout(async()=>{try{let n=await fetch("/api/lsp/hover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:s,column:a})}),o=await n.json();if(c!==l.current)return;o.hover&&o.hover.displayString&&r({...o.hover,x:i.x,y:i.y,filePath:t,line:s,column:a})}catch{}},300)},[e]),p=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),l.current++,o.current=setTimeout(function(){if(a.current)return;let e=i.current;if(e){let t=e.getBoundingClientRect(),{x:r,y:n}=c.current;if(r>=t.left&&r<=t.right&&n>=t.top&&n<=t.bottom)return void x()}r(null)},150)},[x]),g=(0,s.useCallback)(()=>{a.current=!0,o.current&&clearTimeout(o.current)},[]),b=(0,s.useCallback)(()=>{a.current=!1,l.current++,r(null)},[]),v=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),a.current=!1,m(),l.current++,r(null)},[m]);return(0,s.useEffect)(()=>{t||m()},[t,m]),{hoverInfo:t,onTokenMouseEnter:f,onTokenMouseLeave:p,onCardMouseEnter:g,onCardMouseLeave:b,clearHover:v,setTooltipEl:d}}(t),eg=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(!1);return{references:t,loading:n,visible:l,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),a(!0);try{let o=await fetch("/api/lsp/references",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:n,column:s})}),l=await o.json();r(l.references||[])}catch(e){console.error("[useLSP] references error:",e),r([])}finally{o(!1)}},[e]),closeReferences:(0,s.useCallback)(()=>{a(!1),r([])},[])}}(t),eb=(m=(0,s.useRef)([]),x=(0,s.useRef)([]),f=(0,s.useCallback)(e=>{m.current.push(e),m.current.length>50&&(m.current=m.current.slice(-50)),x.current=[]},[]),g=(0,s.useCallback)(e=>{if(0===m.current.length)return null;let t=m.current.pop();return x.current.push(e),x.current.length>50&&(x.current=x.current.slice(-50)),t},[]),b=(0,s.useCallback)(e=>{if(0===x.current.length)return null;let t=x.current.pop();return m.current.push(e),m.current.length>50&&(m.current=m.current.slice(-50)),t},[]),{push:f,goBack:g,goForward:b,canGoBack:(0,s.useCallback)(()=>m.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>x.current.length>0,[])}),ev=(0,eh.F)(),ej=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(new Set),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[h,m]=(0,s.useState)(null),[x,f]=(0,s.useState)(new Set),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(""),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(!1),[M,E]=(0,s.useState)(null),T=(0,s.useRef)(null),[$,R]=(0,s.useState)(!1),[P,B]=(0,s.useState)(null),[I,D]=(0,s.useState)("center"),[F,A]=(0,s.useState)(null),[O,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(!1),[_,q]=(0,s.useState)([]),[V,U]=(0,s.useState)(!1),[K,J]=(0,s.useState)(null),[X,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(!1),[Z,ee]=(0,s.useState)(!1),er=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),en=(0,s.useMemo)(()=>(0,et.v3)(er),[er]),es=(0,s.useMemo)(()=>new Set((0,et.tW)(en)),[en]),eo=(0,s.useMemo)(()=>b?n?(0,et.KH)(n,b,j):(0,et.q3)(t,b,j):null,[t,n,b,j]);(0,s.useEffect)(()=>{if(!eo||0===eo.size)return void g(null);let e=new Set;if(n){let t=new Set(n);for(let r of eo)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&eo.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}g(e)},[eo,t,n]);let el=p??x,ea=(0,s.useRef)(null),ei=(0,s.useCallback)(t=>{ea.current&&clearTimeout(ea.current),ea.current=setTimeout(async()=>{try{await fetch("/api/files/expanded",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,paths:Array.from(t)})})}catch(e){console.error("Error saving expanded paths:",e)}},500)},[e]),ec=(0,s.useCallback)(async()=>{C(!0),E(null);try{let t=await fetch(`/api/files/init?cwd=${encodeURIComponent(e)}`),n=await t.json();n.error?E(n.error):(r(n.files||[]),n.expandedPaths&&Array.isArray(n.expandedPaths)&&f(new Set(n.expandedPaths)))}catch(e){console.error("Error loading files:",e),E("Failed to load files")}finally{C(!1)}},[e]),ed=(0,s.useCallback)(async()=>{try{let t=await fetch(`/api/files/index?cwd=${encodeURIComponent(e)}`),r=await t.json();r.paths&&o(r.paths)}catch(e){console.error("Error loading file index:",e)}},[e]),eu=(0,s.useCallback)(async t=>{a(e=>new Set([...e,t]));try{let n=await fetch(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),s=await n.json();s.children&&r(e=>{if(!t){let t=new Map(e.map(e=>[e.path,e]));return s.children.map(e=>{let r=t.get(e.path);return r?.children&&e.isDirectory?{...e,children:r.children}:e})}let r=structuredClone(e),n=(0,et.MB)(r,t);return n&&(n.children=s.children),r})}catch(e){console.error("Error loading directory:",e)}finally{a(e=>{let r=new Set(e);return r.delete(t),r})}},[e]),eh=(0,s.useRef)(l);eh.current=l,(0,s.useEffect)(()=>{for(let e of p??x){let r=(0,et.MB)(t,e);r&&r.isDirectory&&!r.children&&!eh.current.has(e)&&eu(e)}},[t,x,p,eu]);let em=(0,s.useCallback)(async()=>{try{let t=await fetch(`/api/files/recent?cwd=${encodeURIComponent(e)}`),r=await t.json();c(r.files||[])}catch(e){console.error("Error loading recent files:",e)}},[e]),ex=(0,s.useCallback)(async t=>{c(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)});try{await fetch("/api/files/recent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,file:t})})}catch(e){console.error("Error adding to recent files:",e)}},[e]),ef=(0,s.useCallback)((t,r,n,s)=>{c(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),fetch("/api/files/recent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,file:t,scrollLine:r,cursorLine:n,cursorCol:s})}).catch(()=>{})},[e]),ep=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),eg=(0,s.useCallback)(async t=>{let r=t||d;if(r){U(!0),J(null);try{let t=await fetch(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(r)}`),n=await t.json();n.error?J(n.error):q(n.blame||[])}catch(e){console.error("Error loading blame:",e),J("Failed to load blame info")}finally{U(!1)}}},[e,d]),eb=(0,s.useCallback)(async t=>{L(!0),m(null),H(!1),q([]),J(null),Y(null);try{let r=await fetch(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),n=await r.json();if(!r.ok)return void m({type:"error",message:n?.error||"Failed to stat file"});if(!n.exists)return void m({type:"error",message:"File not found"});if("dir"===n.kind)return void m({type:"error",message:"Path is a directory"});switch(n.category){case"image":m({type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}});break;case"binary":m({type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break;case"too-large":m({type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs});break;default:{let r=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"});if(409===r.status){let e=await r.json().catch(()=>({}));m({type:"binary",message:e?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break}if(!r.ok){let e=await r.json().catch(()=>({}));m({type:"error",message:e?.error||"Failed to load file"});break}let s=await r.json();m({type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}})}}ex(t),eg(t)}catch(e){console.error("Error loading file content:",e),m({type:"error",message:"Failed to load file"})}finally{L(!1)}},[e,ex,eg]),ev=(0,s.useCallback)(()=>{z?H(!1):(H(!0),0===_.length&&eg())},[z,_.length,eg]),ej=(0,s.useCallback)((e,t)=>{if(!e)return;if(u(e),B(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(B(t.scrollLine),D("start"),A(t.cursorLine??null),W(t.cursorCol??null)):(D("center"),A(null),W(null))}else D("center"),A(null),W(null);eb(e);let r=e.split("/");if(r.length>1){let e=[];for(let t=1;t<r.length;t++)e.push(r.slice(0,t).join("/"));f(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ei(r),n?r:t})}},[eb,ei,i]),ey=(0,s.useCallback)(e=>{if(p)g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!x.has(e);if(f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ei(r),r}),r){let r=(0,et.MB)(t,e);r&&r.isDirectory&&!r.children&&eu(e)}}},[p,ei,x,t,eu]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:l,expandedPaths:x,setExpandedPaths:f,searchTreeExpandedPaths:p,setSearchTreeExpandedPaths:g,effectiveExpandedPaths:el,searchQuery:b,setSearchQuery:v,searchExactMatch:j,setSearchDirExact:y,matchedPaths:eo,creatingItem:w,setCreatingItem:k,isLoadingFiles:N,fileError:M,searchInputRef:T,shouldScrollToSelected:$,setShouldScrollToSelected:R,targetLineNumber:P,setTargetLineNumber:B,targetScrollAlign:I,setTargetScrollAlign:D,initialCursorLine:F,initialCursorCol:O,setInitialCursorLine:A,setInitialCursorCol:W,selectedPath:d,setSelectedPath:u,fileContent:h,setFileContent:m,isLoadingContent:S,recentFiles:i,recentFilePaths:er,setRecentFiles:c,recentFilesTree:en,recentTreeDirPaths:es,showBlame:z,setShowBlame:H,blameLines:_,isLoadingBlame:V,blameError:K,blameSelectedCommit:X,setBlameSelectedCommit:Y,showMarkdownPreview:Q,setShowMarkdownPreview:G,showEditor:Z,setShowEditor:ee,saveExpandedPaths:ei,loadFiles:ec,loadFileIndex:ed,loadDirectory:eu,loadRecentFiles:em,addToRecentFiles:ex,updateRecentFilePosition:ef,getRecentFilePosition:ep,loadFileContent:eb,loadBlame:eg,handleToggleBlame:ev,handleSelectFile:ej,handleToggle:ey}}({cwd:t});u=ej.selectedPath,v=(0,s.useRef)(null),(0,s.useEffect)(()=>{!u||u===v.current||tm(u)&&(v.current=u,fetch("/api/lsp/warmup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,filePath:u})}).catch(()=>{}))},[t,u]);let ey=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,l]=(0,s.useState)([]),[a,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(new Set),[m,x]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){l([]),p(null);return}if(n.length<2)return void d(I.A.t("fileBrowser.searchMinChars"));i(!0),d(null);try{let n=new URLSearchParams({cwd:e,q:r,caseSensitive:String(m.caseSensitive),wholeWord:String(m.wholeWord),regex:String(m.regex),fileType:m.fileType}),s=await fetch(`/api/files/search?${n}`),o=await s.json();if(o.error)throw Error(o.error);l(o.results),p({totalFiles:o.totalFiles,totalMatches:o.totalMatches,truncated:o.truncated});let a=new Set(o.results.map(e=>e.path));h(a),o.results.length>0&&t?.()}catch(e){d(e instanceof Error?e.message:"Search failed"),l([])}finally{i(!1)}},[e,m,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:a,searchError:c,searchExpandedPaths:u,searchOptions:m,setSearchOptions:x,searchStats:f,contentSearchInputRef:g,performContentSearch:b,handleSearchToggle:(0,s.useCallback)(e=>{h(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>er(!0)}),ew=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(!1),[a,i]=(0,s.useState)(null),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(null),[m,x]=(0,s.useState)(!1),[f,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)([]),[j,y]=(0,s.useState)([]),w=(0,s.useMemo)(()=>{let e=new Set([...P(b),...P(j)]);for(let t of f)e.delete(t);return e},[b,j,f]),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(0),L=(0,s.useCallback)(async()=>{l(!0),i(null);try{let t=`/api/git/status?cwd=${encodeURIComponent(e)}`,r=await fetch(t);if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to fetch git status")}let s=await r.json();n(s);let o=R(s.staged),l=R(s.unstaged);v(o),y(l)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{l(!1)}},[e]),M=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),E=(0,s.useCallback)((e,r)=>{d({file:e,type:r}),t(e.path)},[t]),T=(0,s.useCallback)(async t=>{try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t]})})).ok)throw Error("Failed to stage file");await L(),(0,p.oR)(I.A.t("toast.staged"),"success")}catch(e){console.error("Error staging file:",e),(0,p.oR)(I.A.t("toast.stageFailed"),"error")}},[e,L]),$=(0,s.useCallback)(async t=>{try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t]})})).ok)throw Error("Failed to unstage file");await L(),(0,p.oR)(I.A.t("toast.unstaged"),"success")}catch(e){console.error("Error unstaging file:",e),(0,p.oR)(I.A.t("toast.unstageFailed"),"error")}},[e,L]),B=(0,s.useCallback)(async t=>{if(0!==t.length)try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t})})).ok)throw Error("Failed to stage files");await L(),(0,p.oR)(I.A.t("toast.stagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error staging files:",e),(0,p.oR)(I.A.t("toast.stageFailed"),"error")}},[e,L]),D=(0,s.useCallback)(async t=>{if(0!==t.length)try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t})})).ok)throw Error("Failed to unstage files");await L(),(0,p.oR)(I.A.t("toast.unstagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error unstaging files:",e),(0,p.oR)(I.A.t("toast.unstageFailed"),"error")}},[e,L]),F=(0,s.useCallback)(async t=>{if(0!==t.length)try{let r=t.filter(e=>"untracked"===e.status).map(e=>e.path),n=t.filter(e=>"untracked"!==e.status).map(e=>e.path);if(r.length>0&&!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r,isUntracked:!0})})).ok)throw Error("Failed to discard untracked files");if(n.length>0&&!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:n,isUntracked:!1})})).ok)throw Error("Failed to discard tracked files");await L(),(0,p.oR)(I.A.t("toast.discardedNFiles",{count:t.length}),"success")}catch(e){console.error("Error discarding files:",e),(0,p.oR)(I.A.t("toast.discardFailed"),"error")}},[e,L]),A=(0,s.useCallback)(async()=>{if(r?.unstaged.length)try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r.unstaged.map(e=>e.path)})})).ok)throw Error("Failed to stage all files");await L(),(0,p.oR)(I.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error staging all files:",e),(0,p.oR)(I.A.t("toast.stageFailed"),"error")}},[e,r,L]),O=(0,s.useCallback)(async()=>{if(r?.staged.length)try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r.staged.map(e=>e.path)})})).ok)throw Error("Failed to unstage all files");await L(),(0,p.oR)(I.A.t("toast.unstagedNFiles",{count:r.staged.length}),"success")}catch(e){console.error("Error unstaging all files:",e),(0,p.oR)(I.A.t("toast.unstageFailed"),"error")}},[e,r,L]),W=(0,s.useCallback)(async t=>{try{let r="untracked"===t.status;if(!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t.path],isUntracked:r})})).ok)throw Error("Failed to discard file");await L(),(0,p.oR)(r?I.A.t("toast.deletedFile"):I.A.t("toast.discardedChanges"),"success")}catch(e){console.error("Error discarding file:",e),(0,p.oR)(I.A.t("toast.discardFailed"),"error")}},[e,L]),z=(0,s.useCallback)(async()=>{if(r?.unstaged.length&&await (0,p.lJ)(I.A.t("git.discardAllConfirm",{count:r.unstaged.length}),{danger:!0}))try{let t=r.unstaged.filter(e=>"untracked"===e.status).map(e=>e.path),n=r.unstaged.filter(e=>"untracked"!==e.status).map(e=>e.path);n.length>0&&await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:n,isUntracked:!1})}),t.length>0&&await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t,isUntracked:!0})}),await L(),(0,p.oR)(I.A.t("toast.discardedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error discarding all:",e),(0,p.oR)(I.A.t("toast.discardFailed"),"error")}},[e,r,L]);return(0,s.useEffect)(()=>{c?(async()=>{x(!0);try{let t=new URLSearchParams({file:c.file.path,type:c.type});t.set("cwd",e);let r=await fetch(`/api/git/diff?${t}`);if(!r.ok)throw Error("Failed to fetch diff");let n=await r.json();h(n)}catch(e){console.error("Error fetching diff:",e)}finally{x(!1)}})():h(null)},[c,e,C]),{status:r,setStatus:n,statusLoading:o,statusError:a,statusSelectedFile:c,statusDiff:u,statusDiffLoading:m,statusExpandedPaths:w,stagedTree:b,setStagedTree:v,unstagedTree:j,setUnstagedTree:y,showStatusDiffPreview:k,setShowStatusDiffPreview:N,fetchStatus:L,handleStatusToggle:M,handleStatusFileSelect:E,handleStage:T,handleUnstage:$,handleStageFiles:B,handleUnstageFiles:D,handleDiscardFiles:F,handleStageAll:A,handleUnstageAll:O,handleDiscardFile:W,handleDiscardAll:z,refreshDiff:(0,s.useCallback)(()=>S(e=>e+1),[])}}({cwd:t,addToRecentFiles:ej.addToRecentFiles}),ek=(0,s.useMemo)(()=>{let e=new Set;if(ew.status){for(let t of ew.status.staged)e.add(t.path);for(let t of ew.status.unstaged)e.add(t.path)}return e},[ew.status]),eN=(0,s.useMemo)(()=>{let e=new Map;if(ew.status){for(let t of ew.status.staged)e.set(t.path,"staged");for(let t of ew.status.unstaged)e.set(t.path,"unstaged")}return e},[ew.status]),eC=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(""),[a,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)([]),[m,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!0),[E,T]=(0,s.useState)(!1),[$,B]=(0,s.useState)(!1),[D,F]=(0,s.useState)(null),A=(0,s.useRef)(null),[O,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(!1),[_,q]=(0,s.useState)(""),[V,U]=(0,s.useState)(""),[K,J]=(0,s.useState)([]),[X,Y]=(0,s.useState)([]),[Q,G]=(0,s.useState)(new Set),[Z,ee]=(0,s.useState)(null),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(!1),[el,ea]=(0,s.useState)(!1),ei=(0,s.useCallback)(()=>{w(!0),F(null),fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{e.error?(F("Failed to get branches"===e.error?I.A.t("git.notGitRepo"):e.error),n(null)):e.local&&e.current?(n(e),l(e.current),e.upstream&&q(e.upstream)):(F(I.A.t("git.cannotGetBranches")),n(null))}).catch(e=>{console.error(e),F(I.A.t("git.getBranchesFailed")),n(null)}).finally(()=>w(!1))},[e]),ec=(0,s.useCallback)(t=>{N(!0),d(null),h([]),x([]),b(null),j(null),M(!0),fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${et.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];i(t),M(t.length>=et.B_)}).catch(console.error).finally(()=>N(!1))},[e]),ed=(0,s.useCallback)(()=>{if(C||!L||!o)return;S(!0);let t=a.length;fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(o)}&limit=${et.B_}&offset=${t}`).then(e=>e.json()).then(e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),M(t.length>=et.B_)}).catch(console.error).finally(()=>S(!1))},[e,o,a.length,C,L]),eu=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ed()},[ed]),eh=(0,s.useCallback)(t=>{d(t),b(null),j(null),T(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${t.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];h(t);let r=R(t);x(r),p(new Set(P(r)))}).catch(console.error).finally(()=>T(!1))},[e]),em=(0,s.useCallback)(r=>{c&&(b(r),t(r.path),B(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${c.hash}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>B(!1)))},[e,c,t]),ex=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ef=(0,s.useCallback)(t=>{eo(!0),ee(null),en(null),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{let t=e.files||[];J(t);let r=R(t);Y(r),G(new Set(P(r)))}).catch(console.error).finally(()=>eo(!1))},[e]),ep=(0,s.useCallback)(r=>{ee(r),t(r.path),ea(!0),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(V)}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>en(e)).catch(console.error).finally(()=>ea(!1))},[e,V,t]),eg=(0,s.useCallback)(e=>{G(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eb=(0,s.useCallback)(e=>{if(H(e),e){let e="origin/main";U(e),ef(e)}else J([]),Y([]),ee(null),en(null),U("")},[_,ef]);return{branches:r,selectedBranch:o,setSelectedBranch:l,commits:a,setCommits:i,selectedCommit:c,setSelectedCommit:d,historyFiles:u,historyFileTree:m,historyExpandedPaths:f,historySelectedFile:g,historyFileDiff:v,isLoadingBranches:y,isLoadingCommits:k,isLoadingMore:C,hasMoreCommits:L,setHasMoreCommits:M,isLoadingHistoryFiles:E,isLoadingHistoryDiff:$,historyError:D,commitListRef:A,tooltipPos:O,loadBranches:ei,loadCommits:ec,loadMoreCommits:ed,handleCommitListScroll:eu,handleSelectCommit:eh,handleSelectHistoryFile:em,handleHistoryToggle:ex,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{W({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{W(null)},[]),compareMode:z,toggleCompareMode:eb,compareBaseBranch:V,setCompareBaseBranch:U,upstreamBranch:_,compareFiles:K,compareFileTree:X,compareExpandedPaths:Q,compareSelectedFile:Z,compareFileDiff:er,isLoadingCompareFiles:es,isLoadingCompareDiff:el,handleSelectCompareFile:ep,handleCompareToggle:eg,loadCompareFiles:ef}}({cwd:t,addToRecentFiles:ej.addToRecentFiles}),eS=(0,s.useCallback)(e=>{ej.setFileContent(t=>t?.type==="text"?{...t,content:e}:t)},[ej]),eL=(0,s.useCallback)(e=>{ej.setShowEditor(!0)},[ej]),eM=(0,s.useCallback)(async()=>{if(ej.fileContent&&"text"===ej.fileContent.type&&ej.fileContent.content)try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:ej.selectedPath,content:ej.fileContent.content})});if(!e.ok)throw Error("Failed to save file");let r=await e.json();r.mtime&&ej.setFileContent(e=>e?.type==="text"?{...e,mtime:r.mtime}:e),(0,p.oR)(j("toast.savedSuccess"),"success")}catch{(0,p.oR)(j("toast.saveFailed"),"error")}},[t,ej]),eE=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e=z.current,t=H.current;e>0&&ej.updateRecentFilePosition(ej.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[ej]),eT=(0,s.useCallback)((e,t)=>{e!==ej.selectedPath&&eE(),ej.handleSelectFile(e,t)},[ej,eE]),e$=(0,s.useMemo)(()=>{let e=ey.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,et.v3)(r),s=new Set((0,et.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[ey.contentSearchResults]),[eR,eP]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{eP(e$.expandDirs)},[e$.expandDirs]);let eB=(0,s.useCallback)(e=>{eP(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eI=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=e$.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[e$.matchMap]),eD=G&&ey.contentSearchResults.length>0,eF=!!ej.selectedPath&&null!==tm(ej.selectedPath),eA=(0,s.useCallback)(async(e,r)=>{if(!ej.selectedPath||!eF)return;let n=await ef.goToDefinition(ej.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",l=s.file.startsWith(o)?s.file.slice(o.length):s.file;eb.push({filePath:ej.selectedPath,lineNumber:z.current}),l===ej.selectedPath?ej.setTargetLineNumber(s.line):eT(l,s.line)},[ej,t,eF,ef,eb]),eO=(0,s.useCallback)((e,t,r)=>{ej.selectedPath&&eF&&ep.onTokenMouseEnter(ej.selectedPath,e,t,r)},[ej.selectedPath,eF,ep]),eW=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;ej.selectedPath&&eb.push({filePath:ej.selectedPath,lineNumber:z.current}),n===ej.selectedPath?ej.setTargetLineNumber(e.line):eT(n,e.line)},[ej,t,eb]),ez=(0,s.useMemo)(()=>{if(!ew.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":return"A";case"deleted":return"D";case"renamed":return"R";case"untracked":return"?"}};for(let r of ew.status.staged)e.set(r.path,t(r.status));for(let r of ew.status.unstaged)e.set(r.path,t(r.status));return e},[ew.status]);(0,s.useEffect)(()=>{T(L.current)},[]),(0,s.useEffect)(()=>{k(r)},[r,l]),(0,s.useEffect)(()=>{c&&(k("search"),ey.setContentSearchQuery(c),ey.performContentSearch(c))},[d]);let eH=(0,s.useCallback)(e=>{k(e),ej.setBlameSelectedCommit(null),"history"===e&&eC.selectedBranch&&eC.loadCommits(eC.selectedBranch)},[ej,eC.selectedBranch,eC.loadCommits]),e_=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e={filePath:ej.selectedPath,lineNumber:z.current},t=eb.goBack(e);t&&(t.filePath===ej.selectedPath?ej.setTargetLineNumber(t.lineNumber):eT(t.filePath,t.lineNumber))},[ej,eb]),eq=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e={filePath:ej.selectedPath,lineNumber:z.current},t=eb.goForward(e);t&&(t.filePath===ej.selectedPath?ej.setTargetLineNumber(t.lineNumber):eT(t.filePath,t.lineNumber))},[ej,eb]),eV=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;try{await fetch("/api/files/clipboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:e})}),(0,p.oR)(j("toast.copiedName",{name:r}),"success")}catch{(0,p.oR)(j("toast.copyFailed"),"error")}},[t]),eU=(0,s.useCallback)(async e=>{try{let r=await fetch("/api/files/clipboard"),n=await r.json();if(!n.path)return void(0,p.oR)(j("toast.noFileToPaste"),"info");let s=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,targetDir:e,sourceAbsPath:n.path})}),o=await s.json();s.ok?((0,p.oR)(j("toast.pastedFile",{name:o.newName}),"success"),ej.loadDirectory(e),ej.loadFileIndex()):(0,p.oR)(o.error||j("toast.pasteFailed"),"error")}catch{(0,p.oR)(j("toast.pasteFailed"),"error")}},[t,ej]),eK=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===y;if(r&&t.ctrlKey&&!t.metaKey&&"Minus"===t.code){t.preventDefault(),t.shiftKey?eq():e_();return}if(r&&(t.metaKey||t.ctrlKey)&&"p"===t.key){t.preventDefault(),W(e=>!e);return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===w||"recent"===w)&&ej.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),eV(ej.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===w||"recent"===w)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),eU((0,et.S7)(ej.selectedPath,ej.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(eo){t.preventDefault(),ex.open();return}if(en&&ej.selectedPath?.endsWith(".json")){t.preventDefault(),ec.open();return}}if(r&&"Escape"===t.key){if(O)return void W(!1);if(ex.isVisible)return void ex.close();if(ec.isVisible)return void ec.close();if(eo)return void el(null);let t=Date.now();if(t-eK.current<3e3)return;eK.current=t,eg.visible?eg.closeReferences():G?er(!1):ej.blameSelectedCommit?ej.setBlameSelectedCommit(null):ej.showBlame?ej.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,ej.showBlame,ej.blameSelectedCommit,ej,O,eg.visible,eg.closeReferences,G,e_,eq,en,ec,eo,ex,w,eV,eU,y]),(0,s.useEffect)(()=>{ej.loadFiles(),ej.loadFileIndex(),ej.loadRecentFiles(),ew.fetchStatus(),eC.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{ew.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[ew.fetchStatus]);let eJ=(0,s.useRef)(ev);(0,s.useEffect)(()=>{ev&&!eJ.current&&(ej.loadFiles(),ej.loadFileIndex(),ej.loadRecentFiles(),ew.fetchStatus(),eC.loadBranches()),eJ.current=ev},[ev]),(0,s.useEffect)(()=>{eC.selectedBranch&&eC.loadCommits(eC.selectedBranch)},[eC.selectedBranch,eC.loadCommits]);let eX=(0,s.useRef)(w);(0,s.useEffect)(()=>{let e=eX.current;if(eX.current=w,("tree"===w||"recent"===w)&&ej.recentFiles.length>0){let t=ej.recentFiles[0].path;ej.selectedPath&&("status"!==e&&"history"!==e||ej.selectedPath===t)||(ej.setShouldScrollToSelected(!0),eT(t))}},[w,ej.recentFiles,ej.selectedPath,eT,ej]);let eY=(0,s.useRef)(eC.selectedBranch);eY.current=eC.selectedBranch;let eQ=(0,s.useRef)(ej.selectedPath);eQ.current=ej.selectedPath;let eG=(0,s.useRef)(ej.fileContent?.type);eG.current=ej.fileContent?.type;let e0=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!r)return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(fetch(`/api/files/init?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.error||ej.setFiles(e.files||[])})),o.push(fetch(`/api/files/index?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.paths&&ej.setFileIndex(e.paths)})),o.push(fetch(`/api/files/recent?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{ej.setRecentFiles(e.files||[])}))),n||s){o.push(fetch(`/api/git/status?cwd=${encodeURIComponent(t)}`).then(e=>{if(e.ok)return e.json().then(e=>{ew.setStatus(e);let t=R(e.staged),r=R(e.unstaged);ew.setStagedTree(t),ew.setUnstagedTree(r)})})),ew.refreshDiff(),n&&eC.loadBranches();let e=eY.current;e&&o.push(fetch(`/api/git/commits?cwd=${encodeURIComponent(t)}&branch=${encodeURIComponent(e)}&limit=${et.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];eC.setCommits(t),eC.setHasMoreCommits(t.length>=et.B_)}))}let l=eQ.current,a=eG.current;l&&"text"===a&&o.push(fetch(`/api/files/text?cwd=${encodeURIComponent(t)}&path=${encodeURIComponent(l)}`).then(e=>e.ok?e.json():null).then(e=>{e&&"string"==typeof e.content&&ej.setFileContent({type:"text",content:e.content,size:e.size,mtime:e.mtimeMs,...e.isSymlink?{isSymlink:!0,symlinkTarget:e.symlinkTarget}:{}})})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,eu.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:e0,enabled:ev});let e1=(0,s.useCallback)(e=>{let t=e.split("/");if(t.length>1){let e=[];for(let r=1;r<t.length;r++)e.push(t.slice(0,r).join("/"));ej.setExpandedPaths(t=>{let r=new Set(t);for(let t of e)r.add(t);return ej.saveExpandedPaths(r),r})}ej.setSelectedPath(e),ej.setShouldScrollToSelected(!0),k("tree")},[ej]);return(0,n.jsxs)(h.SU,{container:E,children:[(0,n.jsxs)("div",{ref:L,className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsxs)("div",{className:"w-80 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>eH("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eH("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eH("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eH("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eH("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.historyTab")})]}),"tree"===w&&(0,n.jsxs)("div",{className:"p-2 border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:ej.searchInputRef,type:"text",value:ej.searchQuery,onChange:e=>ej.setSearchQuery(e.target.value),placeholder:j("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),ej.searchQuery&&(0,n.jsx)("button",{onClick:()=>ej.setSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:j("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>ej.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${ej.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:ej.searchExactMatch?j("fileBrowser.exactMatchOn"):j("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>ej.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.refreshTree"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>ej.searchTreeExpandedPaths?ej.setSearchTreeExpandedPaths(new Set):ej.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.collapseAll"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})]})]}),"search"===w&&(0,n.jsxs)("div",{className:"p-2 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:ey.contentSearchInputRef,type:"text",value:ey.contentSearchQuery,onChange:e=>ey.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ey.performContentSearch(ey.contentSearchQuery)},placeholder:j("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),ey.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>ey.setContentSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:j("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>ey.performContentSearch(ey.contentSearchQuery),disabled:ey.isSearching||!ey.contentSearchQuery.trim(),className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",children:ey.isSearching?"...":j("common.search")})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-xs",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.caseSensitive,onChange:e=>ey.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.wholeWord,onChange:e=>ey.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.regex,onChange:e=>ey.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:ey.searchOptions.fileType,onChange:e=>ey.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:j("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===w&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:eC.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),(0,n.jsx)("span",{className:"truncate",children:eC.branches?.current||"HEAD"}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:"HEAD"})]}),(0,n.jsx)("button",{onClick:()=>eC.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:j("fileBrowser.compareModeOff"),children:j("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(th,{branches:eC.branches,selectedBranch:eC.compareBaseBranch,onSelect:e=>{eC.setCompareBaseBranch(e),eC.loadCompareFiles(e)},isLoading:eC.isLoadingBranches,pinnedBranches:["origin/main",...eC.upstreamBranch&&"origin/main"!==eC.upstreamBranch?[eC.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(th,{branches:eC.branches,selectedBranch:eC.selectedBranch,onSelect:e=>{eC.setSelectedBranch(e)},isLoading:eC.isLoadingBranches,pinnedBranches:["origin/main",...eC.upstreamBranch&&"origin/main"!==eC.upstreamBranch?[eC.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>eC.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-accent border border-border",title:j("fileBrowser.compareModeOn"),children:j("fileBrowser.compareMode")})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,n.jsxs)("div",{className:`flex-1 flex flex-col min-h-0 ${"tree"===w?"":"hidden"}`,children:[ej.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border bg-secondary flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:ej.creatingItem.parentPath?j("fileBrowser.createFileIn",{path:ej.creatingItem.parentPath}):j("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:j("fileBrowser.fileName"),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring",onCompositionStart:()=>{M.current=!0},onCompositionEnd:()=>{M.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(M.current)return;let r=e.target.value.trim();if(!r)return;let n=ej.creatingItem.parentPath,s=n?`${n}/${r}`:r;try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:s,content:""})});if(e.ok)(0,p.oR)(j("toast.createdFile",{name:r}),"success"),ej.setCreatingItem(null),ej.loadDirectory(n),ej.loadFileIndex(),n&&ej.setExpandedPaths(e=>new Set([...e,n])),eT(s);else{let t=await e.json();(0,p.oR)(t.error||j("toast.createFailed"),"error")}}catch(e){(0,p.oR)(j("toast.createFailed"),"error")}}else"Escape"===e.key&&ej.setCreatingItem(null)},onBlur:()=>ej.setCreatingItem(null)})]}),ej.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("common.loading")}):ej.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ej.fileError}):(0,n.jsx)(Z,{files:ej.files,selectedPath:ej.selectedPath,expandedPaths:ej.effectiveExpandedPaths,matchedPaths:ej.matchedPaths,gitStatusMap:ez,loadingDirs:ej.loadingDirs,onSelect:e=>{ej.setShouldScrollToSelected(!1),eT(e)},onToggle:ej.handleToggle,cwd:t,shouldScrollToSelected:ej.shouldScrollToSelected,onScrolledToSelected:()=>ej.setShouldScrollToSelected(!1),onCreateFile:e=>ej.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>A({path:e,isDirectory:t,name:r}),onRefresh:()=>ej.loadFiles(),onCopyFile:eV,onPaste:eU})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===w?"":"hidden"}`,children:ey.isSearching?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ey.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ey.searchError}):0===ey.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ey.contentSearchQuery?j("fileBrowser.noContentSearchResults"):j("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[ey.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-secondary border-b border-border flex-shrink-0",children:[j("fileBrowser.nFilesNMatches",{files:ey.searchStats.totalFiles,matches:ey.searchStats.totalMatches}),ey.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",j("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(Z,{files:e$.files,selectedPath:ej.selectedPath,expandedPaths:eR,onSelect:e=>{let t=e$.matchMap.get(e);eT(e,t?.matches[0]?.lineNumber),G||er(!0)},onToggle:eB,cwd:t,renderActions:eI,className:"flex-1 overflow-y-auto py-1 min-w-max"})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"recent"===w?"":"hidden"}`,children:0===ej.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noRecentFiles")}):(0,n.jsx)(Z,{files:ej.recentFilesTree,selectedPath:ej.selectedPath,expandedPaths:ej.recentTreeDirPaths,onSelect:eT,onToggle:et.tE,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===w?"":"hidden"}`,children:ew.statusLoading?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ew.statusError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center p-4",children:(0,n.jsx)("span",{className:"text-red-11 text-sm",children:ew.statusError})}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:j("fileBrowser.stagingArea",{count:ew.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>ew.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.refreshChanges"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),(ew.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:ew.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:j("fileBrowser.unstageAll")})]}),(0,n.jsx)($,{files:ew.stagedTree,selectedPath:ew.statusSelectedFile?.type==="staged"?ew.statusSelectedFile.file.path:null,expandedPaths:ew.statusExpandedPaths,onSelect:e=>e.file&&ew.handleStatusFileSelect(e.file,"staged"),onToggle:ew.handleStatusToggle,cwd:t,emptyMessage:j("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=B(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleUnstageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:j("fileBrowser.unstageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}return(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleUnstage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:j("fileBrowser.unstageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:j("fileBrowser.workspace",{count:ew.status?.unstaged.length||0})}),(ew.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:ew.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:j("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:ew.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:j("fileBrowser.stageAll")})]})]}),(0,n.jsx)($,{files:ew.unstagedTree,selectedPath:ew.statusSelectedFile?.type==="unstaged"?ew.statusSelectedFile.file.path:null,expandedPaths:ew.statusExpandedPaths,onSelect:e=>e.file&&ew.handleStatusFileSelect(e.file,"unstaged"),onToggle:ew.handleStatusToggle,cwd:t,emptyMessage:j("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=B(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleDiscardFiles(r)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:j("fileBrowser.discardNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleStageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:j("fileBrowser.stageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]})}return e.file?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleDiscardFile(e.file)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:j("fileBrowser.discardChanges"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleStage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:j("fileBrowser.stageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]}):null}})]})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"history"===w?"":"hidden"}`,children:eC.historyError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-muted-foreground",children:eC.historyError})]})}):eC.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:eC.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.loadingDiff")}):0===eC.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noDiffFiles")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:j("fileBrowser.nFilesChanged",{count:eC.compareFiles.length,branch:eC.compareBaseBranch})})}),(0,n.jsx)($,{files:eC.compareFileTree,expandedPaths:eC.compareExpandedPaths,onToggle:eC.handleCompareToggle,selectedPath:eC.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eC.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eC.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eC.handleCommitListScroll,children:eC.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.loadingCommits")}):0===eC.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eC.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>eC.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eC.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-slate-9",title:e.date,children:[e.relativeDate," \xb7 ",(0,et.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),eC.isLoadingMore&&(0,n.jsx)("div",{className:"p-3 text-center",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),!eC.hasMoreCommits&&eC.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:j("fileBrowser.allLoaded",{count:eC.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===w||"search"===w||"recent"===w)&&(ej.blameSelectedCommit?(0,n.jsx)(Y,{isOpen:!0,onClose:()=>ej.setBlameSelectedCommit(null),commit:ej.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:ej.selectedPath||void 0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):"map"===C?(0,n.jsx)(eZ,{cwd:t,highlightedFilePath:ej.selectedPath,changedFiles:ek,onSwitchToCode:()=>S("code"),enableComments:!0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)},headerExtraLeft:({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,p.oR)(j("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),e1(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]})}):ej.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex-shrink-0 flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:ej.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${ej.selectedPath}`),(0,p.oR)(j("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),e1(ej.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:ej.showEditor?(0,n.jsxs)(n.Fragment,{children:[K.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:j("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>V.current?.save(),disabled:!K.isDirty||K.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${K.isDirty&&!K.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:K.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):j("common.save")}),(0,n.jsx)("button",{onClick:()=>V.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.closeEdit"),children:j("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[ej.fileContent?.type==="text"&&ej.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(ej.fileContent.content),(0,p.oR)(j("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.copyFileContent"),children:j("common.copy")}),ej.selectedPath?.endsWith(".json")&&ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>es(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${en?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:j("fileBrowser.toggleJsonReadable"),children:j("common.readable")}),ej.fileContent?.type==="text"&&U(ej.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ej.setShowMarkdownPreview(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.previewMarkdown"),children:j("common.preview")}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:ej.handleToggleBlame,disabled:ej.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ej.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:j("fileBrowser.viewBlame"),children:ej.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>S("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("blockViewer.viewerToggle.toBlock"),children:j("common.codeMap")}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>ej.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.editFile"),children:j("common.edit")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:ej.isLoadingContent?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ej.fileContent?"text"===ej.fileContent.type&&"string"==typeof ej.fileContent.content?ej.showBlame&&ej.blameError?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-red-11",children:ej.blameError}),(0,n.jsx)("button",{onClick:()=>ej.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:j("fileBrowser.backToPreview")})]})}):ej.showBlame&&0===ej.blameLines.length&&ej.isLoadingBlame?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):en&&ej.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(X,{search:ec}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:ea,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:D(ej.fileContent.content)})})]}):(0,n.jsx)(ee.Cv,{ref:V,content:ej.fileContent.content,filePath:ej.selectedPath,cwd:t,enableComments:!0,scrollToLine:_??ej.targetLineNumber,scrollToLineAlign:null!=_?"start":ej.targetScrollAlign,onScrollToLineComplete:()=>{q(null),ej.setTargetLineNumber(null)},highlightKeyword:"search"===w?ey.contentSearchQuery:null,visibleLineRef:z,viStateRef:H,initialCursorLine:ej.initialCursorLine,initialCursorCol:ej.initialCursorCol,onInitialCursorSet:()=>{ej.setInitialCursorLine(null),ej.setInitialCursorCol(null)},onCmdClick:eF?eA:void 0,onTokenHover:eF?eO:void 0,onTokenHoverLeave:eF?ep.onTokenMouseLeave:void 0,onTokenHoverCancel:eF?ep.clearHover:void 0,blameLines:ej.showBlame&&ej.blameLines.length>0?ej.blameLines:void 0,inlineBlameLines:ej.blameLines.length>0?ej.blameLines:void 0,onSelectCommit:ej.setBlameSelectedCommit,editable:ej.showEditor,initialMtime:ej.fileContent.mtime,onEditorClose:e=>{ej.setShowEditor(!1),q(e)},onSaved:()=>{let e=z.current??1;ej.loadFileContent(ej.selectedPath),ej.setShowEditor(!1),q(e)},onEditorStateChange:Q,viMode:!0,onContentMutate:eS,onEnterInsertMode:eL,onViSave:eM,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):"image"===ej.fileContent.type&&ej.selectedPath?(0,n.jsx)(td,{cwd:t,path:ej.selectedPath,refreshKey:ej.fileContent.mtime,alt:ej.selectedPath}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("p",{children:ej.fileContent.message||j("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:j("fileBrowser.selectFileToPreview")})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("p",{children:j("fileBrowser.selectFileToPreview")})]})})),"status"===w&&(ew.statusSelectedFile&&ew.statusDiff?(0,n.jsx)(tu,{cwd:t,selected:ew.statusSelectedFile,diff:ew.statusDiff,showMarkdownPreview:ew.showStatusDiffPreview,setShowMarkdownPreview:ew.setShowStatusDiffPreview,changedFiles:ek,fileGitStatusMap:eN,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)},locateInTree:e1,jsonPreview:eo,setJsonPreview:el,jsonPreviewSearch:ex,jsonPreviewPreRef:em}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:j("fileBrowser.selectFileToViewDiff")})})),"history"===w&&!eC.historyError&&(eC.compareMode?eC.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:j("fileBrowser.loadingDiffContent")}):eC.compareFileDiff?(0,n.jsx)(N,{oldContent:eC.compareFileDiff.oldContent,newContent:eC.compareFileDiff.newContent,filePath:eC.compareFileDiff.filePath,isNew:eC.compareFileDiff.isNew,isDeleted:eC.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eC.compareFileDiff.isDeleted&&eC.compareFileDiff.filePath.endsWith(".json")?()=>el({content:eC.compareFileDiff.newContent,filePath:eC.compareFileDiff.filePath}):void 0,previewLabel:j("common.readable"),onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eC.compareFiles.length>0?j("fileBrowser.selectFileToViewDiff"):j("fileBrowser.clickCompareToLoad")})}):eC.selectedCommit?(0,n.jsx)(Y,{isOpen:!0,onClose:()=>eC.setSelectedCommit(null),commit:eC.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:j("fileBrowser.selectCommitToView")})}))]})]}),ej.showMarkdownPreview&&ej.fileContent?.type==="text"&&ej.selectedPath&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>ej.setShowMarkdownPreview(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ei,{content:ej.fileContent.content||"",filePath:ej.selectedPath,cwd:t,onClose:()=>ej.setShowMarkdownPreview(!1)})})}),O&&(0,n.jsx)(ed,{files:ej.files,fileIndex:ej.fileIndex,recentFiles:ej.recentFilePaths,onSelectFile:e=>{eT(e),ej.setShouldScrollToSelected(!0),k("tree")},onClose:()=>W(!1)}),(eD||eg.visible)&&(0,n.jsxs)("div",{className:`flex ${eg.visible&&eD?"":"flex-col"}`,children:[eD&&(0,n.jsx)("div",{className:eg.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tg,{results:ey.contentSearchResults,loading:ey.isSearching,totalMatches:ey.searchStats?.totalMatches??0,onSelect:(e,t)=>{ej.selectedPath&&eb.push({filePath:ej.selectedPath,lineNumber:z.current}),eT(e,t)},onClose:()=>er(!1)})}),eg.visible&&(0,n.jsx)("div",{className:eD?"flex-1 min-w-0":"",children:(0,n.jsx)(tp,{references:eg.references,loading:eg.loading,onSelect:eW,onClose:eg.closeReferences})})]})]}),F&&(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>A(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl p-4 max-w-sm w-full mx-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-2",children:j("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:j("fileBrowser.confirmDeleteMessage",{name:F.name}).split(/<\/?file>/g).map((e,t)=>1===t?(0,n.jsx)("span",{className:"font-mono text-foreground",children:e},t):e)}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>A(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:j("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=F;A(null);try{let n=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:e})});if(n.ok){(0,p.oR)(j("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";ej.loadDirectory(t),ej.loadFileIndex(),ej.selectedPath===e&&eT("")}else{let e=await n.json();(0,p.oR)(e.error||j("toast.deleteFailed"),"error")}}catch{(0,p.oR)(j("toast.deleteFailed"),"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:j("common.delete")})]})]})})}),ep.hoverInfo&&E&&(0,a.createPortal)((0,n.jsx)(tf,{ref:ep.setTooltipEl,displayString:ep.hoverInfo.displayString,documentation:ep.hoverInfo.documentation,x:ep.hoverInfo.x,y:ep.hoverInfo.y,container:E,onMouseEnter:ep.onCardMouseEnter,onMouseLeave:ep.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=ep.hoverInfo;ep.clearHover(),eg.findReferences(e,t,r)},onSearch:e=>{ep.clearHover(),k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}),E)]})}function tj({isOpen:e,onClose:t,cwd:r}){let l,{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[h,m]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,N]=(0,s.useState)(""),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)([]),[E,T]=(0,s.useState)(""),[$,R]=(0,s.useState)(!1),P=(0,s.useCallback)(async()=>{f(!0);try{let e=await fetch(`/api/git/worktree?cwd=${encodeURIComponent(r)}`);if(e.ok){let t=await e.json();c(t.worktrees),u(t.nextPath),m(t.nextRandomWord),t.gitUserName&&N(t.gitUserName)}}catch(e){console.error("Failed to load worktrees:",e),(0,p.oR)(a("toast.worktreeLoadFailed"),"error")}finally{f(!1)}},[r]),B=(0,s.useCallback)(e=>{let{local:t,remote:r}=e;return r.includes("origin/main")?"origin/main":r.includes("origin/master")?"origin/master":t.includes("main")?"main":t.includes("master")?"master":r.length>0?r[0]:t.length>0?t[0]:"main"},[]);(0,s.useEffect)(()=>{e&&(P(),j(null))},[e,P]);let I=async()=>{if(!d)return;let e="origin/main";try{let t=await fetch(`/api/git/branches?cwd=${encodeURIComponent(r)}`);if(t.ok){let r=await t.json();e=B(r)}}catch{}let t=h||function(){let e="bcdfghjklmnprstvwz",t=["a","e","i","o","u","ai","au","ea","ee","ia","io","oa","oo","ou","ui"],r="";for(let n=0;n<2;n++)r+=e[Math.floor(Math.random()*e.length)],r+=t[Math.floor(Math.random()*t.length)];return r}(),n=k?`${k}/${t}`:t;b(!0);try{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",cwd:r,path:d,newBranch:n,baseBranch:e})});if(t.ok)(0,p.oR)(a("toast.worktreeCreateSuccess",{name:n}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||a("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(a("toast.worktreeCreateFailed"),"error")}finally{b(!1)}},D=async()=>{R(!0),T(""),S(!0);try{let e=await fetch(`/api/git/branches?cwd=${encodeURIComponent(r)}`);if(e.ok){let t=await e.json(),r=new Set(i.map(e=>e.branch).filter(Boolean)),n=[...t.local.filter(e=>!r.has(e)),...t.remote.filter(e=>!r.has(e)&&!t.local.includes(e.replace(/^origin\//,"")))];M(n)}}catch{(0,p.oR)(a("toast.loadBranchFailed"),"error")}finally{R(!1)}},F=async e=>{if(d){S(!1),b(!0);try{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",cwd:r,path:d,branch:e})});if(t.ok)(0,p.oR)(a("toast.worktreeCreateSuccess",{name:e}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||a("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(a("toast.worktreeCreateFailed"),"error")}finally{b(!1)}}},A=async()=>{if(v){w(!0);try{let e=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"remove",cwd:r,path:v.path})});if(e.ok)(0,p.oR)(a("toast.worktreeDeleted"),"success"),j(null),P();else{let t=await e.json();(0,p.oR)(t.error||a("toast.worktreeDeleteFailed"),"error")}}catch(e){console.error("Failed to delete worktree:",e),(0,p.oR)(a("toast.worktreeDeleteFailed"),"error")}finally{w(!1)}}},O=async e=>{let t=e.isLocked?"unlock":"lock";try{let n=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,cwd:r,path:e.path})});if(n.ok)(0,p.oR)(e.isLocked?a("toast.worktreeUnlocked"):a("toast.worktreeLocked"),"success"),P();else{let e=await n.json();(0,p.oR)(e.error||a("toast.operationFailed"),"error")}}catch(e){console.error("Failed to toggle lock:",e),(0,p.oR)(a("toast.operationFailed"),"error")}};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[480px] max-h-[80vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:"Git Worktrees"}),(0,n.jsx)("button",{onClick:t,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:a("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:x?(0,n.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):(0,n.jsx)("div",{className:"space-y-2",children:i.map(e=>{let s=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${s?"border-brand bg-brand/5":"border-border hover:bg-accent cursor-pointer"}`,onClick:()=>{e.path!==r&&(window.parent.postMessage({type:"OPEN_PROJECT",cwd:e.path},"*"),t())},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${s?"bg-brand":"bg-muted-foreground/30"}`}),(0,n.jsx)("span",{className:"font-medium text-foreground truncate",children:e.branch||(e.isDetached?"detached":"unknown")}),e.isLocked&&(0,n.jsx)("span",{className:"text-amber-11",title:a("git.worktree.locked"),children:"\uD83D\uDD12"}),s&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",a("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),O(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?a("git.worktree.unlock"):a("git.worktree.lock"),children:e.isLocked?(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"})}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:a("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate pl-4",children:e.path}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),C&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-3 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("input",{value:E,onChange:e=>T(e.target.value),placeholder:a("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none placeholder:text-muted-foreground",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>S(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:a("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:$?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("common.loading")}):0===(l=L.filter(e=>e.toLowerCase().includes(E.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("git.worktree.noBranches")}):l.map(e=>(0,n.jsx)("button",{onClick:()=>F(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate",children:(0,n.jsx)("span",{className:`${e.startsWith("origin/")?"text-muted-foreground":"text-foreground"}`,children:e})},e))})]}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:a("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:D,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:a("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:I,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:g?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):a("git.worktree.addWorktree")})]})]}),v&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-black/50 rounded-lg",onClick:()=>j(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:a("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:a("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:a("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:v.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:a("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:v.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>j(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:a("common.cancel")}),(0,n.jsx)("button",{onClick:A,disabled:y,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:y?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):a("common.delete")})]})]})})]})}):null}var ty=r(67635),tw=r(73300),tk=r(20986),tN=r(9921),tC=r(66088),tS=r(42790);function tL(e){let t=function(e){let t=0xffffffff;for(let r=0;r<e.length;r++){t^=e.charCodeAt(r);for(let e=0;e<8;e++)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}(e),r="",n=t;for(let e=0;e<4;e++)r+=String.fromCharCode(97+n%26),n=Math.floor(n/26);return r}let tM=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)(async n=>{if(n.stopPropagation(),i)await l(),c(!1),(0,p.oR)(a("toast.disconnected",{id:e}));else{await r(),c(!0);let n=`${"3456"===window.location.port?"cock-dev":"cock"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,p.oR)(a("toast.copiedCommand",{command:n}))}},[i,e,t,r,l,a]);return(0,n.jsxs)("button",{onClick:d,className:"inline-flex items-center gap-1 text-[10px] font-mono leading-none px-1.5 py-0.5 rounded flex-shrink-0 transition-colors bg-muted/60 hover:bg-muted text-muted-foreground",title:i?a("shortIdBadge.clickToDisconnect"):a("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${i?"bg-green-500":"bg-muted-foreground/40"}`}),e]})});var tE=r(12786);let tT=(0,s.lazy)(()=>Promise.all([r.e(3888),r.e(1959)]).then(r.bind(r,71959)).then(e=>({default:e.XtermRenderer}))),t$={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},tR=/\x1b\[[0-9;]*m/g;function tP({output:e,query:t,mode:r,currentIdx:o,matchListRef:l}){let a=(0,s.useRef)(null);a.current||(a.current=new tS.v,a.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return l.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(tR,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=a.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],h=0,m=s.toLowerCase(),x=0;for(;x<m.length;){let e=m.indexOf(c,x);if(-1===e)break;e>h&&u.push((0,n.jsx)("span",{children:s.slice(h,e)},`t${h}`));let t=d++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{l.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+c.length)},`m${e}`)),x=h=e+c.length}return h<s.length&&u.push((0,n.jsx)("span",{children:s.slice(h)},`t${h}`)),(0,n.jsx)("div",{children:u},t)})})}let tB=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:l,output:a,exitCode:i,isRunning:c,selected:d,onSelect:u,onInterrupt:h,onStdin:m,onDelete:x,onRerun:f,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,onPtyResize:y,onToggleMaximize:w,maximized:k,expandedHeight:N,bubbleContentHeight:C,onTitleMouseDown:S}){let{t:L}=(0,o.Bd)(),M=(0,s.useRef)(null),E=(0,s.useRef)(null),T=(0,s.useRef)(!0),$=(0,s.useRef)(null),R=(0,s.useRef)(null),P=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(g),B=e&&t?tL(t+e):void 0,[I,D]=(0,s.useState)(!1),[F,A]=(0,s.useState)(""),O=(0,s.useRef)(null),W=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>O.current?v(e,O.current.write):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[v,e]),(0,s.useEffect)(()=>{if(!j||!e)return;let t=()=>O.current?j(e,O.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]);let[z,H]=(0,s.useState)(!1),[_,q]=(0,s.useState)(""),[V,U]=(0,s.useState)("search"),[K,J]=(0,s.useState)(0),X=(0,s.useRef)([]),Y=(0,s.useRef)(null),Q=(0,s.useRef)(0);(0,s.useEffect)(()=>{Y.current||(Y.current=new tS.v,Y.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=E.current;if(e&&Y.current){if(a.length<Q.current&&(Y.current=new tS.v,Y.current.use_classes=!0,Q.current=0,e.innerHTML=""),a.length>Q.current){let t=a.slice(Q.current),r=Y.current.ansi_to_html(t);Q.current=a.length,e.insertAdjacentHTML("beforeend",r)}if(M.current){let e=M.current.scrollHeight>M.current.clientHeight;D(e),e&&(M.current.scrollTop=M.current.scrollHeight)}}},[a]),(0,s.useEffect)(()=>(c&&T.current&&M.current&&(null!==$.current&&cancelAnimationFrame($.current),$.current=requestAnimationFrame(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight),$.current=null})),()=>{null!==$.current&&cancelAnimationFrame($.current)}),[a,c]),(0,s.useEffect)(()=>{if(!k)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),w?.())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[k,w]);let G=a?a.split("\n").length:0,Z=(0,s.useCallback)(()=>{H(!0),requestAnimationFrame(()=>W.current?.focus())},[]),ee=(0,s.useCallback)(()=>{H(!1),q(""),J(0),O.current?.clearSearch()},[]),et=(0,s.useCallback)(e=>{e.trim()&&(b?O.current?.findNext(e):J(e=>{let t=e+1,r=X.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(X.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),er=(0,s.useCallback)(e=>{e.trim()&&(b?O.current?.findPrevious(e):J(e=>{let t=e-1;if(t>=0)return X.current[t]?.scrollIntoView({block:"nearest"}),t;let r=X.current.length-1;return r>=0&&X.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[b]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),Z();return}if("Escape"===e.key&&z){e.preventDefault(),e.stopPropagation(),ee();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,z,Z,ee]);let en=k&&N?N-41:C??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground dark:text-slate-11 relative overflow-hidden border transition-colors cursor-pointer ${k?"rounded-none border-0":"rounded-2xl rounded-bl-md rounded-br-md"} ${k?"":d?"border-brand":"border-brand/30"}`,onClick:u,children:[k?(0,n.jsxs)("div",{onDoubleClick:()=>w?.(),className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41,flexShrink:0},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded bg-muted text-muted-foreground",children:">_"}),(0,n.jsx)("span",{className:"flex-1 text-xs text-muted-foreground truncate font-mono",children:l}),c&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse"}),L("console.runningText")]}),c&&h&&(0,n.jsx)("button",{onClick:h,className:"text-xs px-3 py-1 rounded-md font-medium bg-destructive text-destructive-foreground transition-all duration-150 hover:bg-destructive/80 hover:shadow-md active:scale-95 active:bg-destructive/70 cursor-pointer select-none",children:"Ctrl+C"}),(0,n.jsx)("button",{onClick:()=>w?.(),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.restoreTooltip",{modKey:(0,tE.Mu)()}),children:(0,n.jsx)(ex.A,{className:"w-4 h-4"})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>S?.(),onDoubleClick:e=>{e.stopPropagation(),w?.()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing ${d?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:">_"}),B&&e&&t&&(0,n.jsx)(tM,{shortId:B,type:"terminal",onRegister:()=>{fetch("/api/terminal/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tabId:t,commandId:e,command:l,projectCwd:r})}).catch(()=>{})},onUnregister:()=>{fetch("/api/terminal/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandId:e})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:l}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(l),(0,p.oR)(L("toast.copiedCmd"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyCommand"),children:(0,n.jsx)(ty.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),I&&!c&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:L("console.totalLines",{count:G})}),a&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=a.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,p.oR)(L("toast.copiedOutput"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyOutput"),children:(0,n.jsx)(tw.A,{className:"w-3.5 h-3.5"})}),f&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),f()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.rerun"),children:(0,n.jsx)(tk.A,{className:"w-3.5 h-3.5"})}),x&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:L("console.deleteRecord"),children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),z&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card",style:{flexShrink:0},children:[(0,n.jsx)(em.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:W,value:_,onChange:e=>{let t=e.target.value;q(t),J(0),b&&(t.trim()?O.current?.findNext(t):O.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?er(_):et(_))},placeholder:L("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}),!b&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>U("search"),className:`px-1.5 py-0.5 rounded transition-colors ${"search"===V?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:L("console.searchMode")}),(0,n.jsx)("button",{onClick:()=>U("filter"),className:`px-1.5 py-0.5 rounded transition-colors ${"filter"===V?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:L("console.filterMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>er(_),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.prevShiftEnter"),children:(0,n.jsx)(tN.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>et(_),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.nextEnter"),children:(0,n.jsx)(tC.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:ee,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsx)("div",{style:{height:en,overflow:"hidden"},children:(0,n.jsx)(s.Suspense,{fallback:(0,n.jsx)("div",{className:"px-4 py-2 text-xs text-muted-foreground",style:{height:en},children:L("console.loadingTerminal")}),children:(0,n.jsx)(tT,{ref:O,output:a,isRunning:c,onInput:m,onResize:y,maximized:k,height:en,directWrite:!!v})})}):(0,n.jsx)("div",{ref:M,className:"overflow-auto px-4 py-2",style:{height:en},onScroll:()=>{if(M.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=M.current;T.current=t-e-r<50}},children:z&&_.trim()?(0,n.jsx)(tP,{output:a,query:_,mode:V,currentIdx:K,matchListRef:X}):(0,n.jsx)("pre",{ref:E,className:"text-sm font-mono whitespace-pre-wrap break-words select-text"})}),c&&!k&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse flex-shrink-0"}),b?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-1",children:L("console.clickToInput")}):m?(0,n.jsx)("input",{ref:R,value:F,onChange:e=>A(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=t$[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),m(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),m(F+"\n"),A("")),"Tab"===e.key&&(e.preventDefault(),m(" "))},placeholder:L("console.stdinPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs font-mono text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:L("console.runningText")}),h&&(0,n.jsx)("button",{onClick:h,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),P&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:P})]}),!c&&void 0!==i&&!k&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${0===i?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:L("console.exitCode",{code:i})}),(0,n.jsx)("span",{className:"flex-1"}),P&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:P})]})]})})});var tI=r(68459),tD=r(51914);function tF({cwd:e,tabId:t,onClose:r,onSave:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)(""),[h,m]=(0,s.useState)(""),[x,f]=(0,s.useState)(!0),p=(0,s.useCallback)(async()=>{f(!0);try{let r=new URLSearchParams({cwd:e});t&&r.set("tabId",t);let n=await fetch(`/api/terminal/env?${r}`);if(n.ok){let e=await n.json();c(e.env||{})}}catch(e){console.error("Failed to load env:",e)}finally{f(!1)}},[e,t]);(0,s.useEffect)(()=>{p()},[p]);let g=()=>{d.trim()&&(c(e=>({...e,[d.trim()]:h})),u(""),m(""))},b=async()=>{try{(await fetch("/api/terminal/env",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:t,env:i})})).ok&&(l(i),r())}catch(e){console.error("Failed to save env:",e)}};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-lg font-semibold",children:a("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?a("envManager.tabScope"):a("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:x?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:a("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(i).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"flex-1 px-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void c(t=>({...t,[e]:r}))},placeholder:a("envManager.valuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>{c(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors",children:(0,n.jsx)(tI.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:a("envManager.varNamePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("input",{type:"text",value:h,onChange:e=>m(e.target.value),placeholder:a("envManager.varValuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("button",{onClick:g,disabled:!d.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(tD.A,{className:"w-4 h-4"})})]}),0===Object.keys(i).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:a("envManager.noVars")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:a("common.cancel")}),(0,n.jsx)("button",{onClick:b,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:a("common.save")})]})]})})}var tA=r(10762);function tO({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[h,m]=(0,s.useState)(!0),x=(0,s.useCallback)(async()=>{m(!0);try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();a(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}finally{m(!1)}},[]);(0,s.useEffect)(()=>{x()},[x]);let f=()=>{i.trim()&&d.trim()&&(a(e=>({...e,[i.trim()]:d.trim()})),c(""),u(""))},p=async()=>{try{(await fetch("/api/terminal/aliases",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({aliases:l})})).ok&&(t(l),e())}catch(e){console.error("Failed to save aliases:",e)}};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[(0,n.jsx)(tA.A,{className:"w-5 h-5"}),r("aliasManager.title")]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:r("aliasManager.description")})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:h?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:r("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(l).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2 group",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"})]}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void a(t=>({...t,[e]:r}))},placeholder:r("aliasManager.fullCommandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"})]}),(0,n.jsx)("button",{onClick:()=>{a(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100",children:(0,n.jsx)(tI.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:r("aliasManager.aliasPlaceholder"),className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),f())}})]}),(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:r("aliasManager.commandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),f())}})]}),(0,n.jsx)("button",{onClick:f,disabled:!i.trim()||!d.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(tD.A,{className:"w-4 h-4"})})]}),(0,n.jsxs)("div",{className:"mt-4 p-3 bg-accent rounded-lg",children:[(0,n.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,n.jsx)("strong",{children:r("aliasManager.usage")}),r("aliasManager.usageDesc")]}),(0,n.jsxs)("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ ll"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"ls -la"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ gs"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"git status"})]})]})]}),0===Object.keys(l).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:r("aliasManager.noAliases")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:e,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:p,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:r("common.save")})]})]})})}var tW=r(53961),tz=r(15813),tH=r(37595),t_=r(49698),tq=r(20232);let tV=new Map;function tU(e){tV.set(e.type,e)}function tK(e){return tV.get(e)}function tJ(e){for(let t of tV.values())if(t.match(e))return t;return null}var tX=r(53853);function tY(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.set("_cockpit","1"),t.toString()}catch{let t=e.includes("?")?"&":"?";return`${e}${t}_cockpit=1`}}function tQ(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.delete("_cockpit"),t.toString()}catch{return e.replace(/[?&]_cockpit=1/,"")}}async function tG(e){let t=(0,tX.f)()?.id??null;return!!t&&new Promise(r=>{try{let n=globalThis.chrome?.runtime;if(!n?.sendMessage)return void r(!1);let s=setTimeout(()=>r(!1),2e3);n.sendMessage(t,{type:"prepare-iframe",url:e},e=>{clearTimeout(s),r(e?.ok??!1)})}catch{r(!1)}})}function tZ(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function t0({url:e,id:t,selected:r,maximized:l,expandedHeight:a,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,onNewTab:h,timestamp:m,onTitleMouseDown:x,initialSleeping:f,onSleep:g,onWake:b}){let{t:v}=(0,o.Bd)(),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(e),[S,L]=(0,s.useState)(null),[M,E]=(0,s.useState)(f??!1),T=(0,s.useRef)(null),$=(0,s.useRef)(null),R=(0,s.useRef)(null);(0,s.useEffect)(()=>{C(e)},[e]);let P=(0,s.useRef)(!0),B=(0,s.useCallback)(()=>{M||(E(!0),L(null),g?.(t))},[M,t,g]),I=(0,s.useCallback)(()=>{T.current&&(clearTimeout(T.current),T.current=null)},[]),{shortId:D,connected:F,connect:A,disconnect:O}=function(e,t,r){let n=(0,s.useMemo)(()=>tL(e),[e]),[o,l]=(0,s.useState)(!1),a=(0,s.useRef)(null),i=(0,s.useRef)([]),c=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,s.useRef)(r);(0,s.useEffect)(()=>{u.current=r});let h=(0,s.useRef)([]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="cockpit:cmd-result"){let{reqId:t,ok:r,data:n,error:s}=e.data,o=a.current;o&&o.readyState===WebSocket.OPEN&&o.send(JSON.stringify({type:"browser:cmd-result",reqId:t,ok:r,data:n,error:s}));return}if(e.data?.type==="cockpit:prepare-screenshot"){let r=t.current;if(!r?.contentWindow)return;let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),window.parent.postMessage({type:"SCREENSHOT_PREPARE",cwd:n},"*"),requestAnimationFrame(()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(()=>{let t=r.getBoundingClientRect(),n=window.devicePixelRatio||1,s=t.x,o=t.y;try{let e=window;for(;e!==e.top;){let t=e.frameElement;if(t){let e=t.getBoundingClientRect();s+=e.x,o+=e.y}e=e.parent}}catch{}r.contentWindow?.postMessage({type:"cockpit:screenshot-bounds",reqId:e.data.reqId,bounds:{x:Math.round(s*n),y:Math.round(o*n),width:Math.round(t.width*n),height:Math.round(t.height*n),dpr:n}},"*")},150)})));return}if(e.data?.type==="cockpit:screenshot-done"){window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),window.parent.postMessage({type:"SCREENSHOT_DONE"},"*");return}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let m=(0,s.useCallback)(e=>{let r=t.current;if(!r?.contentWindow){let t=a.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"browser:cmd-result",reqId:e.reqId,ok:!1,error:"iframe not available (page may be sleeping)"}));return}r.contentWindow.postMessage({type:"cockpit:cmd",reqId:e.reqId,action:e.action,params:e.params},"*")},[t]);(0,s.useEffect)(()=>{if(!o)return;let r=!1;return d.current=!0,!function n(){if(r||!d.current)return;let s="https:"===window.location.protocol?"wss:":"ws:",o=new WebSocket(`${s}//${window.location.host}/ws/browser?fullId=${encodeURIComponent(e)}`);a.current=o,o.onopen=()=>{for(let e of h.current)e();if(h.current=[],i.current.length>0){for(let e of i.current)m(e);i.current=[]}},o.onmessage=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("browser:cmd"===r.type){let e=r;t.current?.contentWindow&&u.current?m(e):i.current.push(e)}},o.onclose=()=>{a.current=null,!r&&d.current&&(c.current=setTimeout(n,3e3))},o.onerror=()=>o.close()}(),()=>{r=!0,d.current=!1,c.current&&clearTimeout(c.current),a.current&&(a.current.close(),a.current=null),h.current=[]}},[o,e,t,m]),(0,s.useEffect)(()=>{if(r&&i.current.length>0){for(let e of i.current)m(e);i.current=[]}},[r,m]);let x=(0,s.useCallback)(()=>o&&a.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{h.current.push(e),o||l(!0)}),[o]);return{shortId:n,connected:o,connect:x,disconnect:(0,s.useCallback)(()=>{l(!1)},[])}}(t,R,!!S&&!M&&!j),W=(0,s.useRef)(F);W.current=F,(0,s.useEffect)(()=>{let e=$.current;if(!e||M)return;let t=new IntersectionObserver(([e])=>{P.current=e.isIntersecting,e.isIntersecting||W.current?I():(T.current&&clearTimeout(T.current),T.current=setTimeout(B,3e5))});return t.observe(e),()=>t.disconnect()},[M,B,I]),(0,s.useEffect)(()=>{M?O():F?I():P.current||(T.current&&clearTimeout(T.current),T.current=setTimeout(B,3e5))},[F,M,O,I,B]),(0,s.useEffect)(()=>{f&&L(null)},[]);let z=(0,s.useCallback)(()=>{E(!1),b?.(t);let r=tY(e);tZ(e)?L(r):tG(e).then(()=>L(r))},[e,t,b]);(0,s.useEffect)(()=>{if(!e||M){e||L(null);return}let t=tY(e);if(tZ(e))return void L(t);let r=!1;return tG(e).then(()=>{r||L(t)}),()=>{r=!0}},[e,M]);let H=(0,s.useCallback)(()=>y(!1),[]);(0,s.useEffect)(()=>{let e=$.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,l=()=>{o&&t&&(t.scrollTop=s)},a=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",l)},i=()=>{o=!1,t.removeEventListener("scroll",l),t.style.overflow=n};return e.addEventListener("mouseenter",a),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",a),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",l),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=$.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?h?.(tQ(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&C(tQ(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,h]);let _=(0,s.useCallback)(()=>{y(!1),k(v("browser.pageLoadFailed"))},[]),q=(0,s.useCallback)(()=>{if(M)return void z();let e=$.current?.querySelector("iframe");if(e&&S){y(!0),k(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[M,z,S]);(0,s.useEffect)(()=>{e&&!M&&(y(!0),k(null))},[e,M]);let V=(0,s.useCallback)(()=>{N&&window.open(N,"_blank")},[N]);(0,s.useEffect)(()=>{if(!r&&!l)return;let e=e=>{"Escape"===e.key&&l&&(e.stopPropagation(),u()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),u())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[l,r,u]);let U=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e}}(N),K=l&&a?a-41:i??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
|
|
1
|
+
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5660],{1058:(e,t,r)=>{r.d(t,{_:()=>o});var n=r(12115),s=r(90717);function o({cwd:e,filePath:t}){let[r,l]=(0,n.useState)([]),[a,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),u=(0,n.useCallback)(async()=>{if(e&&t){i(!0),d(null);try{let r=await fetch(`/api/comments?cwd=${encodeURIComponent(e)}&filePath=${encodeURIComponent(t)}`);if(r.ok){let e=await r.json();l(e.comments||[])}else d("Failed to load comments")}catch(e){d(e instanceof Error?e.message:"Unknown error")}finally{i(!1)}}},[e,t]);(0,n.useEffect)(()=>{u()},[u]),(0,n.useEffect)(()=>(0,s.zL)(()=>{u()}),[u]);let h=(0,n.useCallback)(async(r,n,s,o)=>{try{let a=await fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,startLine:r,endLine:n,content:s,...o?{selectedText:o}:{}})});if(a.ok){let e=await a.json();return l(t=>[...t,e.comment]),e.comment}}catch(e){console.error("Failed to add comment:",e)}return null},[e,t]),m=(0,n.useCallback)(async(t,r)=>{try{let n=await fetch("/api/comments",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,id:t,content:r})});if(n.ok){let e=await n.json();return l(r=>r.map(r=>r.id===t?e.comment:r)),!0}}catch(e){console.error("Failed to update comment:",e)}return!1},[e]),x=(0,n.useCallback)(async t=>{try{if((await fetch(`/api/comments?cwd=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:"DELETE"})).ok)return l(e=>e.filter(e=>e.id!==t)),!0}catch(e){console.error("Failed to delete comment:",e)}return!1},[e]),f=(0,n.useCallback)(e=>r.filter(t=>e>=t.startLine&&e<=t.endLine),[r]);return{comments:r,isLoading:a,error:c,addComment:h,updateComment:m,deleteComment:x,refresh:u,getCommentsForLine:f}}},2228:(e,t,r)=>{r.d(t,{ProjectItem:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-6 h-6 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"4"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function a({index:e,name:t,cwd:r,isActive:i,collapsed:c,hasUnread:d,isLoading:u,onClick:h,onRemove:m,onOpenNote:x}){let{t:f}=(0,o.Bd)(),[p,g]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1 rounded-lg cursor-pointer transition-colors relative ${c?"justify-center":""} ${i?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary hover:text-foreground"}`,onClick:h,onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),title:r,children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(l,{number:e+1,isActive:i}),d&&!i&&!u&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),u&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"})]}),!c&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"flex-1 truncate text-sm",children:t}),!u&&i?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}):null]}),p&&!c&&(0,n.jsxs)("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-0.5",children:[x&&(0,n.jsx)("button",{className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",onClick:e=>{e.stopPropagation(),x()},title:f("workspace.projectNotes"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{className:"p-1 rounded hover:bg-red-500/20 text-muted-foreground hover:text-red-500 transition-colors",onClick:e=>{e.stopPropagation(),m()},title:f("workspace.closeProject"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]})}},3292:(e,t,r)=>{r.d(t,{P:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)([]),r=(0,n.useCallback)(()=>{fetch("/api/pinned-sessions").then(e=>e.json()).then(e=>t(e.sessions||[])).catch(()=>{})},[]);(0,n.useEffect)(()=>{r()},[r]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type==="PINNED_SESSIONS_CHANGED"&&r()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[r]);let s=(0,n.useCallback)(e=>{t(e),fetch("/api/pinned-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessions:e})}).catch(()=>{});try{window.parent.postMessage({type:"PINNED_SESSIONS_CHANGED"},"*")}catch{}},[]),o=(0,n.useCallback)(t=>e.some(e=>e.sessionId===t),[e]),l=(0,n.useCallback)((t,r,n)=>{e.some(e=>e.sessionId===t)||s([...e,{sessionId:t,cwd:r,customTitle:n}])},[e,s]),a=(0,n.useCallback)(t=>{s(e.filter(e=>e.sessionId!==t))},[e,s]),i=(0,n.useCallback)((t,r)=>{s(e.map(e=>e.sessionId===t?{...e,customTitle:r}:e))},[e,s]);return{pinnedSessions:e,isPinned:o,pinSession:l,unpinSession:a,updateTitle:i,reorder:(0,n.useCallback)(e=>{s(e)},[s]),reload:r}}},7320:(e,t,r)=>{r.d(t,{G:()=>a,t:()=>l});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,range:r,codeContent:a,container:i,onSubmit:c,onClose:d}){let{t:u}=(0,o.Bd)(),[h,m]=(0,s.useState)(""),[x,f]=(0,s.useState)(!1),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0}),j=a?.split("\n").slice(0,5).join("\n"),y=!!a&&a.split("\n").length>5;return(0,s.useEffect)(()=>{if(p.current&&i){let r=i.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>v({x:s,y:o}))}},[e,t,i]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{x||!p.current||p.current.contains(e.target)||d()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d,x]),(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,n.jsx)("div",{className:"px-3 py-2 bg-amber-9/10 border-b border-border",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-amber-11",children:u("comments.addComment")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:r.start,end:r.end})})]})}),a&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,y&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:g,value:h,onChange:e=>m(e.target.value),placeholder:u("comments.inputPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:x,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!x&&h.trim()&&(f(!0),c(h.trim()))),"Escape"!==e.key||x||d()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:u(x?"comments.submitting":"comments.enterSubmit")})]})]})}function a({x:e,y:t,range:r,filePath:l,codeContent:i,container:c,onSubmit:d,onClose:u,isChatLoading:h}){let{t:m}=(0,o.Bd)(),[x,f]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&c){let r=c.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>v({x:s,y:o}))}},[e,t,c]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&u()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u]);let j=i?.split("\n").slice(0,5).join("\n"),y=!!i&&i.split("\n").length>5;return(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-brand/10 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-brand",children:m("comments.askAI")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:m("comments.lineRange",{start:r.start,end:r.end})})]}),l&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:l})]}),i&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,y&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:g,value:x,onChange:e=>f(e.target.value),placeholder:m("comments.inputQuestion"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:h,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!h&&x.trim()&&(d(x.trim()),u())),"Escape"===e.key&&u()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:m(h?"comments.aiGenerating":"comments.enterSend")})]})]})}},8648:(e,t,r)=>{r.d(t,{NoteModal:()=>w});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(13439),i=r(37795),c=r(43561),d=r(5989),u=r(76065),h=r(43203),m=r(6268),x=r(48434),f=r(44695),p=r(59265),g=r(26932);function b(e){return e.storage.markdown.getMarkdown()}function v(){return[{label:l.A.t("slashCommands.heading1"),icon:"H1",description:l.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:l.A.t("slashCommands.heading2"),icon:"H2",description:l.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:l.A.t("slashCommands.heading3"),icon:"H3",description:l.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:l.A.t("slashCommands.bulletList"),icon:"•",description:l.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:l.A.t("slashCommands.orderedList"),icon:"1.",description:l.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:l.A.t("slashCommands.taskList"),icon:"☑",description:l.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:l.A.t("slashCommands.blockquote"),icon:"❝",description:l.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:l.A.t("slashCommands.codeBlock"),icon:"<>",description:l.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:l.A.t("slashCommands.table"),icon:"▦",description:l.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:l.A.t("slashCommands.horizontalRule"),icon:"──",description:l.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:l.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:l.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function j({editor:e,query:t,position:r,onClose:o}){let[l,a]=(0,s.useState)(0),i=(0,s.useRef)(null),c=v().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>a(0))},[t]);let d=r=>{e.chain().focus().deleteRange({from:e.state.selection.from-t.length-1,to:e.state.selection.from}).run(),r.action(e),o()};return((0,s.useEffect)(()=>{let e=e=>{"ArrowDown"===e.key?(e.preventDefault(),a(e=>(e+1)%c.length)):"ArrowUp"===e.key?(e.preventDefault(),a(e=>(e-1+c.length)%c.length)):"Enter"===e.key?(e.preventDefault(),c[l]&&d(c[l])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,l,o]),0===c.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lg py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:c.map((e,t)=>(0,n.jsxs)("button",{className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors ${t===l?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"}`,onClick:()=>d(e),onMouseEnter:()=>a(t),children:[(0,n.jsx)("span",{className:"w-6 text-center text-xs font-mono flex-shrink-0",children:e.icon}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium",children:e.label}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:e.description})]})]},e.label))})}v();var y=r(76043);function w({isOpen:e,onClose:t,projectCwd:r,projectName:v}){let{t:k}=(0,o.Bd)(),[N,C]=(0,s.useState)(!0),[S,L]=(0,s.useState)(!1),M=(0,s.useRef)(null),E=(0,s.useRef)(!1),[T,$]=(0,s.useState)(null),R=(0,s.useRef)(null),P=r?`/api/note?cwd=${encodeURIComponent(r)}`:"/api/note",B=(0,s.useCallback)(async e=>{L(!0);try{await fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e})}),E.current=!1}catch(e){console.error("Failed to save note:",e)}finally{L(!1)}},[P]),I=(0,s.useCallback)(e=>{E.current=!0,M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{B(e)},5e3)},[B]),D=(0,a.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:{levels:[1,2,3]}}),c.A.configure({placeholder:()=>l.A.t("editor.placeholder")}),d.XI.configure({resizable:!0}),u.H,h.n,m.A,x._,p.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),f.L.configure({nested:!0}),g.o.configure({html:!0,transformCopiedText:!0,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},handleClick:(e,t,r)=>{if(r.metaKey||r.ctrlKey){let r=e.state.doc.resolve(t).marks().find(e=>"link"===e.type.name)?.attrs;if(r?.href)return window.open(r.href,"_blank","noopener,noreferrer"),!0}return!1},handleKeyDown:(e,t)=>{if("Backspace"===t.key&&F.current){let e=F.current;if(e.isActive("codeBlock")){let{$from:t}=e.state.selection,r=t.node(t.depth);if("codeBlock"===r.type.name&&""===r.textContent)return e.chain().focus().toggleCodeBlock().run(),!0}}return"/"!==t.key||T||setTimeout(()=>{if(!F.current)return;let{from:e}=F.current.state.selection;if("/"===F.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){R.current=e;let t=F.current.view.coordsAtPos(e);$({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(I(b(e)),null!==R.current){let{from:t}=e.state.selection;if(t<R.current)$(null),R.current=null;else{let r=e.state.doc.textBetween(R.current,t,"\n");r.includes(" ")||r.includes("\n")?($(null),R.current=null):$(e=>e?{...e,query:r}:null)}}}}),F=(0,s.useRef)(D);(0,s.useEffect)(()=>{F.current=D},[D]),(0,s.useEffect)(()=>{e&&D&&(C(!0),$(null),R.current=null,fetch(P).then(e=>e.json()).then(e=>{D.commands.setContent(e.content||""),E.current=!1}).catch(e=>console.error("Failed to load note:",e)).finally(()=>C(!1)))},[e,D,P]);let A=(0,s.useCallback)(()=>{M.current&&(clearTimeout(M.current),M.current=null),E.current&&D&&B(b(D)),$(null),R.current=null,t()},[D,B,t]);return((0,s.useEffect)(()=>()=>{M.current&&clearTimeout(M.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(T?($(null),R.current=null):A())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,A,T]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:A}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v?k("editor.noteTitle",{name:v}):k("editor.noteUntitled")}),S&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:k("editor.saving")})]}),(0,n.jsx)("button",{onClick:A,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(y.NoteToolbar,{editor:D}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:N?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:k("common.loading")})}):(0,n.jsx)(a.$Z,{editor:D})})]}),T&&D&&(0,n.jsx)(j,{editor:D,query:T.query,position:T.position,onClose:()=>{$(null),R.current=null}})]}):null}},12786:(e,t,r)=>{r.d(t,{L:()=>s,Mu:()=>o});var n=r(41463);function s(){return!("u"<typeof navigator)&&(/Mac|iPhone|iPad/.test(navigator.platform||"")||navigator.userAgentData?.platform==="macOS")}function o(){return s()?"⌘":"Ctrl+"}n.platform,n.platform,n.platform},17196:(e,t,r)=>{r.d(t,{Np:()=>d,ZD:()=>i,b8:()=>c,kS:()=>l,sQ:()=>a});var n=r(67014);let s=null,o=["typescript","tsx","javascript","jsx","html","css","scss","json","yaml","python","go","rust","java","ruby","php","bash","shell","markdown","sql","c","cpp","swift","kotlin","dart","lua","graphql","xml"];function l(){return s||(s=(0,n.O_)({themes:["github-dark","github-light"],langs:[...o]})),s}function a(e){let t=e.split("/").pop()?.toLowerCase()||"",r=t.split(".").pop()?.toLowerCase();if(".env"===t||t.startsWith(".env.")||"dockerfile"===t||t.startsWith("dockerfile.")||"makefile"===t)return"bash";let n={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",html:"html",htm:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",py:"python",go:"go",rs:"rust",java:"java",kt:"kotlin",rb:"ruby",php:"php",cs:"cpp",cpp:"cpp",c:"c",h:"c",sh:"bash",bash:"bash",zsh:"bash",md:"markdown",mdx:"markdown",sql:"sql",swift:"swift",dart:"dart",lua:"lua",graphql:"graphql",gql:"graphql",toml:"yaml",sass:"scss",less:"css",scala:"java",r:"python",vim:"bash",env:"bash"}[r||""]||"text";return o.includes(n)?n:"text"}function i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function c(e){return e.map(e=>e.color?`<span style="color:${e.color}">${i(e.content)}</span>`:i(e.content)).join("")}function d(e,t,r,n){if(!t)return[];let s=[],o=r?t:t.toLowerCase();for(let t=0;t<e.length;t++){let l=r?e[t]:e[t].toLowerCase(),a=0;for(;;){let e=l.indexOf(o,a);if(-1===e)break;let r=e+o.length;if(n){let n=e>0?l[e-1]:" ",o=r<l.length?l[r]:" ",a=!/\w/.test(n),i=!/\w/.test(o);a&&i&&s.push({lineIndex:t,startCol:e,endCol:r})}else s.push({lineIndex:t,startCol:e,endCol:r});a=e+1}}return s}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>d});var n=r(95155),s=r(12115),o=r(79114),l=r(3238),a=r(34075),i=r(12786),c=r(53853);function d({isOpen:e,onClose:t}){let{t:r,i18n:u}=(0,o.Bd)(),{theme:h,setTheme:m}=(0,l.D)(),x=(0,c.G)(),[f,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(""),[v,j]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&fetch("/api/settings").then(e=>e.json()).then(e=>{e.language&&j(e.language)}).catch(()=>{})},[e]);let y=(0,s.useCallback)(e=>{j(e),fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({language:e})}).catch(()=>{});let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;u.changeLanguage(t)},[u]),w=x?"installed":"not-installed",k=x?.version??null;if((0,s.useEffect)(()=>{e&&fetch("/api/version").then(e=>e.json()).then(e=>{e.version&&b(e.version)}).catch(()=>{})},[e]),(0,s.useEffect)(()=>{e&&fetch("/api/extension/version").then(e=>e.json()).then(e=>{e.path&&p(e.path)}).catch(()=>{})},[e]),!e)return null;let N=[{value:"system",label:r("settings.themeSystem"),icon:"\uD83D\uDCBB"},{value:"light",label:r("settings.themeLight"),icon:"☀️"},{value:"dark",label:r("settings.themeDark"),icon:"\uD83C\uDF19"}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("settings.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.theme")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:N.map(e=>(0,n.jsxs)("button",{onClick:()=>m(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${h===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.language")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{value:"auto",label:r("settings.languageAuto"),icon:"\uD83C\uDF10"},{value:"en",label:"English",icon:"\uD83C\uDDFA\uD83C\uDDF8"},{value:"zh",label:"中文",icon:"\uD83C\uDDE8\uD83C\uDDF3"}].map(e=>(0,n.jsxs)("button",{onClick:()=>y(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${v===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.browserExtension")}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${"installed"===w?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===w&&`${r("settings.extensionInstalled")}${k?` (v${k})`:""}`,"not-installed"===w&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==w&&(0,n.jsxs)("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-md p-2 space-y-1",children:[(0,n.jsx)("p",{className:"font-medium text-foreground",children:r("settings.installSteps")}),(0,n.jsxs)("p",{children:[r("settings.step1")," ",(0,n.jsx)("code",{className:"px-1 py-0.5 bg-muted rounded text-foreground",children:"chrome://extensions"})]}),(0,n.jsx)("p",{children:r("settings.step2")}),(0,n.jsx)("p",{children:r("settings.step3")}),(0,i.L)()&&(0,n.jsx)("p",{dangerouslySetInnerHTML:{__html:r("settings.step4mac")}})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>{let e=f||"chrome-extension";navigator.clipboard.writeText(e),(0,a.oR)(r("toast.copiedName",{name:e}))},className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:r("settings.copyExtensionPath")}),"installed"===w&&(0,n.jsx)("button",{onClick:()=>{x?.id&&window.chrome?.runtime?.sendMessage&&(window.chrome.runtime.sendMessage(x.id,{type:"reload"}),(0,a.oR)(r("toast.pluginReloading")))},className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-muted transition-colors",children:r("settings.reloadExtension")})]}),f&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:f})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.about")}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground space-y-1",children:[(0,n.jsxs)("p",{children:["Cockpit",g?` v${g}`:""]}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>d});var n=r(95155),s=r(12115),o=r(94287),l=r(64428),a=r(79114);function i({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function c({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:a,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),h=(0,s.useRef)(null),m=(0,s.useRef)(null),[x,f]=(0,s.useState)({top:0,right:0}),p=(0,l.F2)();(0,s.useEffect)(()=>{if(!d)return;let e=e=>{m.current&&!m.current.contains(e.target)&&h.current&&!h.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let g=n=>{u(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?a?.():"deepseek"===n?i?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:h,onClick:()=>{if(!d&&h.current){let e=h.current.getBoundingClientRect(),t=p?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;f({top:e.bottom+4-n,right:s-(e.right-r)})}u(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"New tab",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),d&&(0,n.jsx)(l.ZL,{children:(0,n.jsxs)("div",{ref:m,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:x.top,right:x.right},children:[(0,n.jsxs)("button",{onClick:()=>g("claude"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}),"Claude Code"]}),(0,n.jsxs)("button",{onClick:()=>g("claude2"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-orange-500 flex-shrink-0"}),"Claude 2"]}),(0,n.jsxs)("button",{onClick:()=>g("codex"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 flex-shrink-0"}),"OpenAI Codex"]}),(0,n.jsxs)("button",{onClick:()=>g("deepseek"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"}),"Deepseek"]}),(0,n.jsxs)("button",{onClick:()=>g("kimi"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500 flex-shrink-0"}),"Kimi"]}),(0,n.jsxs)("button",{onClick:()=>g("ollama"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-violet-500 flex-shrink-0"}),"Ollama"]})]})})]})}function d({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:l,isPinned:u,onTogglePin:h,onSwitchTab:m,onCloseTab:x,onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j,onDragStart:y,onDragOver:w,onDrop:k,onDragEnd:N}){let{t:C}=(0,a.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((a,c)=>(0,n.jsx)(o.m,{content:a.title,delay:200,className:"flex-1 min-w-16 max-w-32",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>y(c),onDragOver:e=>w(e,c),onDrop:()=>k(c),onDragEnd:N,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg transition-colors ${a.id===t?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary"} ${s===c?"opacity-50":""} ${l===c?"border-l-2 border-brand":""}`,onClick:()=>m(a.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(i,{number:c+1,isActive:a.id===t}),a.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!a.isLoading&&r.has(a.id)&&a.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),h&&u?.(a.id)&&!a.isLoading&&!(r.has(a.id)&&a.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(a.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:C("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),h&&!u?.(a.id)&&!a.isLoading&&!(r.has(a.id)&&a.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(a.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:C("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:a.title}),"claude2"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-orange-500/15 text-orange-400 font-medium leading-relaxed",children:"C2"}),"codex"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-emerald-500/15 text-emerald-400 font-medium leading-relaxed",children:"CX"}),"kimi"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-blue-500/15 text-blue-400 font-medium leading-relaxed",children:"KM"}),"ollama"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-violet-500/15 text-violet-400 font-medium leading-relaxed",children:"OL"}),"deepseek"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-sky-500/15 text-sky-400 font-medium leading-relaxed",children:"DS"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x(a.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:C("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},a.id)),(0,n.jsx)(c,{onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j})]})})}},37614:(e,t,r)=>{r.d(t,{t:()=>l});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,comment:r,container:a,onClose:i,onUpdateComment:c,onDeleteComment:d}){let{t:u}=(0,o.Bd)(),[h,m]=(0,s.useState)(!1),[x,f]=(0,s.useState)(r.content),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&a){let r=a.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>b({x:s,y:o}))}},[e,t,a]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i]);let v=async()=>{x.trim()&&(await c(r.id,x.trim()),m(!1))},j=async()=>{await d(r.id),i()};return(0,n.jsx)("div",{ref:p,className:"absolute z-[200] w-96 bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:(0,n.jsx)("div",{className:"p-3",children:h?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("textarea",{value:x,onChange:e=>f(e.target.value),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:3,autoFocus:!0,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),v()),"Escape"===e.key&&(m(!1),f(r.content))}}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>{m(!1),f(r.content)},className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground",children:u("common.cancel")}),(0,n.jsx)("button",{onClick:v,className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90",children:u("common.save")})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:r.content}),(0,n.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:r.startLine,end:r.endLine})}),(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:()=>m(!0),className:"p-1 rounded hover:bg-accent text-muted-foreground",title:u("common.edit"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{onClick:j,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-red-9",title:u("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]})]})})})}},38408:(e,t,r)=>{r.d(t,{Cv:()=>$,XO:()=>R});var n=r(95155),s=r(12115),o=r(79114),l=r(47650),a=r(70188),i=r(7320),c=r(56978),d=r(17196),u=r(89109),h=r(37614),m=r(69809),x=r(64428);function f({blame:e,onClick:t}){let{t:r}=(0,o.Bd)(),l=(0,s.useRef)(null),a=(0,s.useRef)(null),i=(0,x.F2)(),c=(0,s.useRef)(!1),d=(0,s.useRef)(!1),u=(0,s.useRef)(null),h=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(e);(0,s.useEffect)(()=>{g.current=e},[e]);let b=(0,s.useRef)(t);(0,s.useEffect)(()=>{b.current=t},[t]);let v=(0,s.useCallback)(()=>{let e,t=a.current,r=l.current;if(!t||!r)return;let n=r.getBoundingClientRect(),s=t.getBoundingClientRect(),o=i?.getBoundingClientRect(),c=o?.left??0,d=o?.top??0,u=o?.width??window.innerWidth,h=o?.height??window.innerHeight,m=n.left-c;m+s.width>u-8&&(m=u-s.width-8),m<8&&(m=8);let x=n.top-d,f=n.bottom-d;(e=x-s.height-4<0?f+4:x-s.height-4)+s.height>h-8&&(e=h-s.height-8),t.style.left=`${m}px`,t.style.top=`${e}px`},[i]),j=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),h.current&&(clearTimeout(h.current),h.current=null),c.current=!1,d.current=!1,a.current&&(a.current.style.display="none"),p.current&&(document.removeEventListener("mousedown",p.current.down),document.removeEventListener("mouseup",p.current.up),p.current=null)},[]),y=(0,s.useCallback)(()=>{let e=a.current;if(!e||c.current)return;c.current=!0,e.style.left="-9999px",e.style.top="-9999px",e.style.display="block",requestAnimationFrame(()=>requestAnimationFrame(v));let t=0,r=0,n=e=>{t=e.clientX,r=e.clientY},s=e=>{if(!(Math.abs(e.clientX-t)>5||Math.abs(e.clientY-r)>5)){let t;t=e.target,a.current?.contains(t)||l.current?.contains(t)||j()}};document.addEventListener("mousedown",n),document.addEventListener("mouseup",s),p.current={down:n,up:s}},[v,j]),w=(0,s.useCallback)(()=>{if(u.current&&clearTimeout(u.current),h.current&&(clearTimeout(h.current),h.current=null),c.current)return;let e=window.getSelection();(!e||e.isCollapsed)&&(u.current=setTimeout(y,500))},[y]),k=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),c.current&&(h.current=setTimeout(()=>{d.current||j()},200))},[j]),N=(0,s.useCallback)(()=>{d.current=!0,h.current&&(clearTimeout(h.current),h.current=null)},[]),C=(0,s.useCallback)(()=>{d.current=!1,j()},[j]),S=(0,s.useCallback)(e=>{e.stopPropagation();let t=window.getSelection();t&&t.toString().length>0&&a.current?.contains(t.anchorNode)||(b.current?.(g.current),j())},[j]);(0,s.useEffect)(()=>()=>j(),[j]);let L=e.message.split("\n")[0]||"",M=e.message.split("\n").slice(1).join("\n").trim();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{ref:l,className:"select-none text-xs text-muted-foreground/50 ml-6 cursor-default hover:text-muted-foreground/80",onMouseEnter:w,onMouseLeave:k,children:[e.author.split(" ")[0],", ",function(e){let t=m.A.t,r=Math.floor((Date.now()-1e3*e)/1e3);if(r<60)return t("common.justNow");let n=Math.floor(r/60);if(n<60)return t("common.minutesAgo",{count:n});let s=Math.floor(n/60);if(s<24)return t("common.hoursAgo",{count:s});let o=Math.floor(s/24);if(o<30)return t("common.daysAgo",{count:o});let l=Math.floor(o/30);return l<12?t("common.monthsAgo",{count:l}):t("common.yearsAgo",{count:Math.floor(l/12)})}(e.time)," \xb7 ",L]}),(0,n.jsx)(x.ZL,{children:(0,n.jsxs)("div",{ref:a,className:"fixed z-[9999] bg-card border border-border rounded-lg shadow-xl p-3 text-xs text-foreground whitespace-pre-wrap max-w-md select-text",style:{display:"none",minWidth:280,cursor:"text"},"data-inline-blame-tip":"",onMouseEnter:N,onMouseLeave:C,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("span",{className:"font-mono text-brand",children:e.hash}),(0,n.jsx)("span",{className:"text-muted-foreground",children:e.author}),(0,n.jsx)("span",{className:"text-muted-foreground/60",children:new Date(1e3*e.time).toLocaleString()})]}),(0,n.jsx)("div",{className:"font-medium",children:L}),M&&(0,n.jsx)("div",{className:"mt-1 text-muted-foreground",children:M}),(0,n.jsx)("div",{className:"mt-2 text-[11px] text-brand border-t border-border pt-2 cursor-pointer hover:underline",onClick:S,children:r("codeViewer.clickToViewDetails")})]})})]})}let p=[{bg:"rgba(59, 130, 246, 0.15)",border:"rgb(59, 130, 246)"},{bg:"rgba(16, 185, 129, 0.15)",border:"rgb(16, 185, 129)"},{bg:"rgba(245, 158, 11, 0.15)",border:"rgb(245, 158, 11)"},{bg:"rgba(239, 68, 68, 0.15)",border:"rgb(239, 68, 68)"},{bg:"rgba(168, 85, 247, 0.15)",border:"rgb(168, 85, 247)"},{bg:"rgba(236, 72, 153, 0.15)",border:"rgb(236, 72, 153)"},{bg:"rgba(20, 184, 166, 0.15)",border:"rgb(20, 184, 166)"},{bg:"rgba(249, 115, 22, 0.15)",border:"rgb(249, 115, 22)"}];function g(e,t){let r,n=document.caretRangeFromPoint(e.clientX,e.clientY);if(!n||!t.contains(n.startContainer))return 1;let s=n.startContainer,o=n.startOffset,l=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),a=1;for(;r=l.nextNode();){if(r===s){a+=o;break}a+=r.textContent?.length||0}return a}let b=(0,s.memo)(function({virtualKey:e,lineNum:t,highlightedHtml:r,hasComments:l,firstComment:a,lineCommentsCount:i,isInRange:c,showLineNumbers:d,lineNumChars:u,commentsEnabled:h,virtualItemSize:m,virtualItemStart:x,onCommentBubbleClick:p,onCmdClick:b,onTokenHover:v,onTokenHoverLeave:j,flashLine:y,blameLine:w,showBlameInfo:k,blameAuthorColor:N,isBlameHovered:C,onBlameClick:S,onBlameMouseEnter:L,onBlameMouseLeave:M,inlineBlameData:E,onInlineBlameClick:T,isCursorLine:$,cursorCol:R}){let{t:P}=(0,o.Bd)(),B=(0,s.useMemo)(()=>$&&null!=R?function(e,t){let r=0,n=0;for(;n<e.length;){if("<"===e[n]){let t=e.indexOf(">",n);if(-1!==t){n=t+1;continue}}if(r===t){let t;if("&"===e[n]){let r=e.indexOf(";",n);t=-1!==r&&r-n<10?r+1:n+1}else t=n+1;let r=e.substring(n,t);return e.substring(0,n)+'<span class="vi-char-cursor">'+r+"</span>"+e.substring(t)}if("&"===e[n]){let t=e.indexOf(";",n);n=-1!==t&&t-n<10?t+1:n+1}else n++;r++}return e+'<span class="vi-char-cursor"> </span>'}(r,R):r,[r,$,R]),I=(0,s.useCallback)(e=>{if(!e.metaKey||!b)return;e.preventDefault(),e.stopPropagation();let r=e.currentTarget,n=g(e,r);window.getSelection()?.removeAllRanges(),b(t,n)},[t,b]),D=(0,s.useCallback)(e=>{if(!v||0!==e.buttons)return;let r=window.getSelection();if(r&&!r.isCollapsed)return;let n=e.target;if("SPAN"!==n.tagName||!n.style.color)return;let s=e.currentTarget,o=g(e,s),l=n.getBoundingClientRect();v(t,o,{x:l.left,y:l.bottom+4})},[t,v]),F=(0,s.useCallback)(()=>{w&&S&&S(w)},[w,S]),A=(0,s.useCallback)(e=>{w&&L&&L(w,e)},[w,L]);return(0,n.jsxs)("div",{"data-line":t,style:{position:"absolute",top:0,left:0,width:"100%",height:`${m}px`,transform:`translateY(${x}px)`,backgroundColor:C&&N?N.bg:void 0},className:`flex ${y===t?"flash-line":""} ${$?"vi-cursor-line":""} ${c?"bg-blue-9/20":l?"bg-amber-9/10":"hover:bg-accent/50"}`,children:[(0,n.jsxs)("div",{className:"flex shrink-0 sticky left-0 z-[2] bg-secondary",style:{backgroundColor:C&&N?N.bg:void 0},children:[w&&N&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-1 flex-shrink-0",style:{backgroundColor:N.border}}),(0,n.jsx)("div",{className:"w-48 flex-shrink-0 px-2 flex items-center gap-2 border-r border-border text-muted-foreground cursor-pointer hover:bg-accent/50",onMouseEnter:A,onMouseLeave:M,onClick:F,title:P("codeViewer.clickToViewCommit"),children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"font-medium",style:{color:N.border},children:w.hash}),(0,n.jsx)("span",{className:"truncate flex-1",children:w.author.split(" ")[0]})]}):null})]}),d&&(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center justify-end gap-0.5 pr-2 select-none border-r border-border font-variant-tabular ${c?"bg-blue-9/30 text-blue-11":"bg-card/50 text-slate-9"}`,children:[h&&l&&a&&(0,n.jsx)("button",{onClick:e=>p(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:P("codeViewer.nComments",{count:i}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),h&&!l&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"text-right",style:{minWidth:`${u}ch`},children:t})]})]}),(0,n.jsxs)("span",{className:"flex-1 px-3 whitespace-pre select-text",onClick:I,onMouseOver:D,onMouseLeave:j,"data-code-content":!0,children:[(0,n.jsx)("span",{dangerouslySetInnerHTML:{__html:B}}),E&&(0,n.jsx)(f,{blame:E,onClick:T})]})]},e)});var v=r(64702),j=r(1058),y=r(90717),w=r(48347);function k(e,t,r){let n,s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o=0;for(;(n=s.nextNode())&&n!==t;)o+=n.textContent.length;return o+r}function N(e,t){let r,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=t,o=null;for(;r=n.nextNode();){o=r;let e=r.textContent.length;if(s<=e)return{node:r,offset:s};s-=e}return o?{node:o,offset:o.textContent.length}:null}var C=r(82292),S=r(34075);let L="white-space:pre;padding:0 12px;min-height:20px;line-height:20px";function M(e){let t=window.getSelection();if(!t?.rangeCount)return null;let r=t.getRangeAt(0),n=r.startContainer;for(;n&&n.parentElement!==e;)n=n.parentElement;if(!n)return null;let s=Array.from(e.children).indexOf(n);if(s<0)return null;let o=document.createRange();return o.selectNodeContents(n),o.setEnd(r.startContainer,r.startOffset),{line:s,offset:o.toString().length}}function E(e,t){let r,n=e.children[t.line];if(!n)return;let s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=t.offset;for(;r=s.nextNode();){let e=r.textContent?.length||0;if(o<=e){let e=window.getSelection(),t=document.createRange();t.setStart(r,o),t.collapse(!0),e?.removeAllRanges(),e?.addRange(t);return}o-=e}let l=window.getSelection(),a=document.createRange();a.selectNodeContents(n),a.collapse(!1),l?.removeAllRanges(),l?.addRange(a)}function T(e){return e.map(e=>`<div style="${L}">${e}</div>`).join("")}let $=(0,s.forwardRef)(function({content:e,filePath:t,showLineNumbers:r=!0,showSearch:m=!0,className:x="",cwd:f,enableComments:g=!1,scrollToLine:$=null,scrollToLineAlign:R="center",onScrollToLineComplete:P,highlightKeyword:B=null,visibleLineRef:I,onCmdClick:D,onTokenHover:F,onTokenHoverLeave:A,onTokenHoverCancel:O,blameLines:W,inlineBlameLines:z,onSelectCommit:H,editable:_=!1,initialMtime:q,onEditorClose:V,onSaved:U,onEditorStateChange:K,viMode:J=!1,onContentMutate:X,onEnterInsertMode:Y,onViSave:Q,viStateRef:G,initialCursorLine:Z,initialCursorCol:ee,onInitialCursorSet:et,onContentSearch:er},en){let{t:es}=(0,o.Bd)(),eo=(0,s.useRef)(e),el=(0,s.useRef)(!1),[ea,ei]=(0,s.useState)(!1),[ec,ed]=(0,s.useState)(!1),[eu,eh]=(0,s.useState)(()=>e.split("\n").length),em=(0,s.useRef)(e.split("\n").length),[ex,ef]=(0,s.useState)({show:!1}),ep=(0,s.useRef)(null),eg=(0,s.useRef)(null),eb=(0,s.useRef)(q),ev=(0,s.useRef)(null),ej=(0,s.useRef)(!1),ey=(0,s.useRef)(!1),{parentRef:ew,containerRef:ek,searchInputRef:eN,floatingToolbarRef:eC,suppressHoverRef:eS,bumpToolbarRef:eL,savedSelectionRef:eM,highlightedLines:eE,isMounted:eT,cmdHeld:e$,flashLine:eR,isSearchVisible:eP,searchQuery:eB,caseSensitive:eI,wholeWord:eD,currentMatchIndex:eF,viewingComment:eA,addCommentInput:eO,sendToAIInput:eW,aiBridge:ez,commentsEnabled:eH,updateComment:e_,deleteComment:eq,lines:eV,matches:eU,rowData:eK,virtualizer:eJ,commentsByEndLine:eX,linesWithComments:eY,setIsSearchVisible:eQ,setSearchQuery:eG,setCaseSensitive:eZ,setWholeWord:e0,setViewingComment:e1,setAddCommentInput:e2,setSendToAIInput:e5,goToNextMatch:e4,goToPrevMatch:e3,handleSearchKeyDown:e6,handleCommentBubbleClick:e8,handleToolbarAddComment:e9,handleToolbarSendToAI:e7,handleToolbarSearch:te,handleCommentSubmit:tt,handleSendToAISubmit:tr,getHighlightedLineHtml:tn,suppressMatchScrollRef:ts,inlineBlameLineRef:to,inlineBlameVersion:tl}=function({content:e,filePath:t,showSearch:r=!0,cwd:n,enableComments:o=!1,scrollToLine:l=null,scrollToLineAlign:a="center",onScrollToLineComplete:i,visibleLineRef:u,onContentSearch:h}){let[m,x]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,w.r)();(0,s.useEffect)(()=>{x(!0)},[]);let[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),M=(0,s.useRef)(null),[E,T]=(0,s.useState)(!1),[$,R]=(0,s.useState)(""),[P,B]=(0,s.useState)(!1),[I,D]=(0,s.useState)(!1),[F,A]=(0,s.useState)(0),[O,W]=(0,s.useState)(0),z=(0,s.useRef)(!1),[H,_]=(0,s.useState)(null),q=(0,s.useRef)(null),V=(0,s.useRef)(()=>{}),U=(0,s.useRef)(!1),K=(0,s.useRef)(null),[J,X]=(0,s.useState)(null),[Y,Q]=(0,s.useState)(null),G=(0,s.useRef)(null),[Z,ee]=(0,s.useState)(0),et=o&&!!n,{comments:er,addComment:en,updateComment:es,deleteComment:eo,refresh:el}=(0,j._)({cwd:n||"",filePath:t}),ea=(0,s.useMemo)(()=>e.split("\n"),[e]),ei=(0,c.C)(ea,t),ec=(0,s.useMemo)(()=>{let e=new Map;for(let t of er){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[er]),ed=(0,s.useMemo)(()=>{let e=new Set;for(let t of er)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[er]),eu=(0,s.useMemo)(()=>(0,d.Np)(ea,$,P,I),[ea,$,P,I]);(0,s.useEffect)(()=>{eu.length>0&&A(0)},[eu.length,$,P,I]);let eh=(0,s.useMemo)(()=>{let e=[];for(let t=0;t<ea.length;t++)e.push({type:"code",lineIndex:t});return e},[ea.length]),em=(0,v.Te)({count:eh.length,getScrollElement:()=>f.current,estimateSize:()=>20,overscan:10});(0,s.useEffect)(()=>{if(!u)return;let e=f.current;if(!e)return;let t=()=>{if(!em.range)return;let t=e.scrollTop;for(let e of em.getVirtualItems())if(e.start>=t){let t=eh[e.index];t?.type==="code"&&(u.current=t.lineIndex+1);return}};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[u,eh]),(0,s.useEffect)(()=>{let e=e=>{"Meta"===e.key&&C(!0)},t=e=>{"Meta"===e.key&&C(!1)},r=()=>C(!1);return window.addEventListener("keydown",e),window.addEventListener("keyup",t),window.addEventListener("blur",r),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t),window.removeEventListener("blur",r)}},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),T(!0),setTimeout(()=>g.current?.focus(),0)),"Escape"===e.key&&(E?(T(!1),R("")):Y?Q(null):J?X(null):q.current?(q.current=null,V.current()):H&&_(null))},t=p.current;if(t)return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[r,E,Y,J,H]),(0,s.useEffect)(()=>{if(z.current){z.current=!1;return}if(eu.length>0&&F>=0&&F<eu.length){let e=eu[F],t=eh.findIndex(t=>"code"===t.type&&t.lineIndex===e.lineIndex);t>=0&&em.scrollToIndex(t,{align:"center"})}},[F,eu,em,eh,O]);let ex=(0,s.useCallback)(()=>{0!==eu.length&&(A(e=>(e+1)%eu.length),W(e=>e+1))},[eu.length]),ef=(0,s.useCallback)(()=>{0!==eu.length&&(A(e=>(e-1+eu.length)%eu.length),W(e=>e+1))},[eu.length]),ep=(0,s.useRef)(l);ep.current=l,(0,s.useEffect)(()=>{if(null!==ep.current&&ep.current>0&&eh.length>0){let e=ep.current,t=e-1,r=eh.findIndex(e=>"code"===e.type&&e.lineIndex===t);if(r>=0){let t=()=>{em.scrollToIndex(r,{align:a}),"center"===a&&(M.current&&clearTimeout(M.current),L(e),M.current=setTimeout(()=>L(null),500)),i?.()};"start"===a?requestAnimationFrame(t):setTimeout(t,150)}}},[l,a,eh.length,em,i]);let eg=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ef():ex()),"Escape"===e.key&&(T(!1),R(""))},[ex,ef]),eb=(0,s.useCallback)((e,t)=>{et&&(t.stopPropagation(),_({comment:e,x:t.clientX,y:t.clientY}),q.current=null,V.current(),X(null),Q(null))},[et]);(0,s.useEffect)(()=>{if(!et)return;let e=f.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,K.current=null,U.current=!0,q.current&&(q.current=null,V.current())},o=e=>{t=!1;let s=e.target;if(s.closest?.(".floating-toolbar"))return;let o=Math.abs(e.clientX-r)>5||Math.abs(e.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed){U.current=!1,q.current&&(q.current=null,V.current());return}let a=l.toString();if(!a.trim()||!o){U.current=!1,q.current&&(q.current=null,V.current());return}let i=l.getRangeAt(0),c=f.current;if(!c||!c.contains(i.commonAncestorContainer))return;let d=i.startContainer,u=i.endContainer,h=e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t)return null;let r=t.closest("[data-line]");return r?parseInt(r.getAttribute("data-line")||"0",10):null},m=h(d),x=h(u);if(m&&x){let t=Math.min(m,x),r=Math.max(m,x);q.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},selectedText:a},U.current=!0,V.current();let n=d.nodeType===Node.TEXT_NODE?d.parentElement?.closest("[data-line]"):d.closest("[data-line]"),s=u.nodeType===Node.TEXT_NODE?u.parentElement?.closest("[data-line]"):u.closest("[data-line]");n&&s&&(K.current={startLine:m,startOffset:k(n,i.startContainer,i.startOffset),endLine:x,endOffset:k(s,i.endContainer,i.endOffset)})}},l=()=>{if(t||!q.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(q.current=null,K.current=null,U.current=!1,V.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[et]),(0,s.useEffect)(()=>{let e=f.current;if(!e)return;let t=t=>{let r,n;if(!e.contains(t.target)){if(t.target.closest?.("[data-inline-blame-tip]"))return;null!==G.current&&(G.current=null,ee(e=>e+1));return}let s=window.getSelection();if(s&&!s.isCollapsed&&s.toString().trim())return;let o=(r=t.target,(n=r.closest?.("[data-line]"))?parseInt(n.getAttribute("data-line")||"0",10):null);o!==G.current&&(G.current=o,requestAnimationFrame(()=>ee(e=>e+1)))};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]);let ev=(0,s.useCallback)(()=>{let e=q.current;e&&(X({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),q.current=null,V.current())},[]),ej=(0,s.useCallback)(()=>{let e=q.current;if(!e)return;let t=e.selectedText;Q({x:e.x,y:e.y,range:e.range,codeContent:t}),q.current=null,V.current()},[]),ey=(0,s.useCallback)(()=>{let e=q.current;if(!e||!h)return;let t=e.selectedText.trim();q.current=null,V.current(),t&&h(t)},[h]),ew=(0,s.useCallback)(async e=>{J&&(await en(J.range.start,J.range.end,e),X(null))},[J,en]),ek=(0,s.useCallback)(async e=>{if(Y&&b&&n)try{let r=await (0,y.$3)(n),s=[];for(let e of r)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:Y.range.start,endLine:Y.range.end,codeContent:Y.codeContent});let o=(0,y.Gw)(s,e);b.sendMessage(o),await (0,y.RP)(n),el(),Q(null)}catch(e){console.error("Failed to send to AI:",e)}},[Y,b,t,n,el]),eN=(0,s.useCallback)((e,t,r)=>{let n=ea[e];if(!n)return t;let s=[];if($&&eu.length>0)for(let t of eu.filter(t=>t.lineIndex===e)){let r=eu[F]?.lineIndex===e&&eu[F]?.startCol===t.startCol;s.push({start:t.startCol,end:t.endCol,cls:r?"hl-cur":"hl-m"})}if(r&&!$&&r.length>=1){let e=r.toLowerCase(),t=n.toLowerCase(),o=0;for(;-1!==(o=t.indexOf(e,o));)s.push({start:o,end:o+r.length,cls:"hl-kw"}),o+=1}if(0===s.length)return t;s.sort((e,t)=>e.start-t.start||e.end-t.end);let o=[],l=0;for(let e of s){if(e.start<l)continue;e.start>l&&o.push((0,d.ZD)(n.substring(l,e.start)));let t=(0,d.ZD)(n.substring(e.start,e.end));o.push(`<span class="${e.cls}">${t}</span>`),l=e.end}if(l<n.length&&o.push((0,d.ZD)(n.substring(l))),t!==(0,d.ZD)(n)){let e=t;for(let t of s){let r=n.substring(t.start,t.end),s=(0,d.ZD)(r),o=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=RegExp(`(?<=>)([^<]*?)(${o})`,""),a=`$1<span class="${t.cls}">${s}</span>`,i=e.replace(l,a);i.length>e.length+200||(e=i)}return e}return o.join("")},[$,eu,F,ea]);return{parentRef:f,containerRef:p,searchInputRef:g,floatingToolbarRef:q,suppressHoverRef:U,savedSelectionRef:K,highlightedLines:ei,isMounted:m,cmdHeld:N,flashLine:S,isSearchVisible:E,searchQuery:$,caseSensitive:P,wholeWord:I,currentMatchIndex:F,viewingComment:H,bumpToolbarRef:V,addCommentInput:J,sendToAIInput:Y,aiBridge:b,commentsEnabled:et,comments:er,updateComment:es,deleteComment:eo,lines:ea,matches:eu,rowData:eh,virtualizer:em,commentsByEndLine:ec,linesWithComments:ed,setIsSearchVisible:T,setSearchQuery:R,suppressMatchScrollRef:z,setCaseSensitive:B,setWholeWord:D,setViewingComment:_,setAddCommentInput:X,setSendToAIInput:Q,goToNextMatch:ex,goToPrevMatch:ef,handleSearchKeyDown:eg,handleCommentBubbleClick:eb,handleToolbarAddComment:ev,handleToolbarSendToAI:ej,handleToolbarSearch:ey,handleCommentSubmit:ew,handleSendToAISubmit:ek,getHighlightedLineHtml:eN,inlineBlameLineRef:G,inlineBlameVersion:Z}}({content:e,filePath:t,showSearch:m,cwd:f,enableComments:!_&&g,scrollToLine:_?null:$,scrollToLineAlign:_?"center":R,onScrollToLineComplete:_?void 0:P,visibleLineRef:_?void 0:I,onContentSearch:er}),ta=(0,a.iN)(),ti=(0,s.useRef)(null),tc=(0,s.useRef)(null),td=(0,s.useRef)({line:0,col:0}),tu=function({lines:e,enabled:t,onContentChange:r,onEnterInsert:n,onSave:o,getVisibleLineCount:l,scrollToLine:a,onSearchExecute:i,onSearchNext:c,onSearchPrev:d,onSearchClear:u}){let[h,m]=(0,s.useState)("normal"),[x,f]=(0,s.useState)(-1),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(!1),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)(""),[N,C]=(0,s.useState)(""),[S,L]=(0,s.useState)(""),M=(0,s.useRef)([]),E=(0,s.useRef)([]),T=(0,s.useRef)([]),$=(0,s.useRef)(null),R=(0,s.useRef)(e);(0,s.useEffect)(()=>{R.current=e}),(0,s.useEffect)(()=>{0!==e.length&&queueMicrotask(()=>f(t=>Math.min(t,e.length-1)))},[e.length]);let P=(0,s.useCallback)((e,t)=>Math.max(0,Math.min(t,Math.max(0,(R.current[e]??"").length-1))),[]),B=(0,s.useRef)(e.length);(0,s.useEffect)(()=>{let t=Math.abs(e.length-B.current);B.current=e.length,t>10&&(queueMicrotask(()=>{f(-1),g(0),v(!1)}),M.current=[],E.current=[],T.current=[])},[e]);let I=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null),y("")},[]),D=(0,s.useCallback)(()=>{$.current&&clearTimeout($.current),$.current=setTimeout(()=>{y(""),$.current=null},500)},[]),F=(0,s.useCallback)((e,t)=>{M.current.push(t),E.current=[],v(!0),r(e.join("\n"))},[r]),A=(0,s.useCallback)((e,t)=>{let r=Math.max(0,Math.min(e,R.current.length-1));f(r),g(P(r,t??0)),a(r,"auto")},[a,P]),O=(0,s.useCallback)(e=>{f(t=>{let r=Math.max(0,Math.min(t+e,R.current.length-1));return a(r,"auto"),g(e=>Math.max(0,Math.min(e,Math.max(0,(R.current[r]??"").length-1)))),r})},[a]),W=(0,s.useCallback)(()=>{let e=R.current,t=Math.min(x,e.length-1);if(0===e.length)return;let r=e[t];T.current=[r];let n=[...e];n.splice(t,1),0===n.length&&n.push("");let s=Math.min(t,n.length-1);F(n,{lineIndex:t,oldLines:[r],newLines:[],cursorLine:t}),f(s),g(0)},[x,F]),z=(0,s.useCallback)(()=>{let e=R.current,t=Math.min(x,e.length-1);e.length>0&&(T.current=[e[t]])},[x]),H=(0,s.useCallback)(()=>{let e=T.current;if(0===e.length)return;let t=R.current,r=Math.min(x,t.length-1)+1,n=[...t];n.splice(r,0,...e),F(n,{lineIndex:r,oldLines:[],newLines:[...e],cursorLine:x}),f(r),g(0),a(r,"auto")},[x,F,a]),_=(0,s.useCallback)(()=>{let e=R.current,t=Math.min(x,e.length-1),r=e[t];if(!r||0===r.length)return;let n=r.substring(1),s=[...e];s[t]=n,F(s,{lineIndex:t,oldLines:[r],newLines:[n],cursorLine:x})},[x,F]),q=(0,s.useCallback)(()=>{let e=M.current;if(0===e.length)return;let t=e.pop(),n=[...R.current];0===t.newLines.length&&t.oldLines.length>0?n.splice(t.lineIndex,0,...t.oldLines):0===t.oldLines.length&&t.newLines.length>0?(n.splice(t.lineIndex,t.newLines.length),0===n.length&&n.push("")):n.splice(t.lineIndex,t.newLines.length,...t.oldLines),E.current.push(t),r(n.join("\n")),f(Math.min(t.cursorLine,n.length-1)),a(Math.min(t.cursorLine,n.length-1),"auto"),0===e.length&&v(!1)},[r,a]),V=(0,s.useCallback)(()=>{let e=E.current;if(0===e.length)return;let t=e.pop(),n=[...R.current];0===t.newLines.length&&t.oldLines.length>0?(n.splice(t.lineIndex,t.oldLines.length),0===n.length&&n.push("")):0===t.oldLines.length&&t.newLines.length>0?n.splice(t.lineIndex,0,...t.newLines):n.splice(t.lineIndex,t.oldLines.length,...t.newLines),M.current.push(t),v(!0),r(n.join("\n"));let s=t.lineIndex+Math.max(0,t.newLines.length-1);f(Math.min(s,n.length-1)),a(Math.min(s,n.length-1),"auto")},[r,a]),U=(0,s.useCallback)(e=>{let t=R.current,r=Math.min(x,t.length-1);if("o"===e||"O"===e){let n="o"===e?r+1:r,s=[...t];s.splice(n,0,""),F(s,{lineIndex:n,oldLines:[],newLines:[""],cursorLine:x}),r=n,f(n)}m("insert"),n(r,p,e)},[x,p,F,n]),K=(0,s.useCallback)(()=>{m("normal"),I()},[I]),J=(0,s.useCallback)(()=>{m("command"),k("")},[]),X=(0,s.useCallback)(()=>{m("normal"),k("")},[]),Y=(0,s.useCallback)(()=>{m("search"),C("")},[]),Q=(0,s.useCallback)(()=>{m("normal"),C("")},[]),G=(0,s.useCallback)(e=>{let t=e.trim();if("w"===t){o?.(),m("normal"),k("");return}if("q"===t){m("normal"),k("");return}if("wq"===t){o?.(),m("normal"),k("");return}if("noh"===t||"nohlsearch"===t){u?.(),m("normal"),k("");return}let r=parseInt(t,10);if(!isNaN(r)&&r>0){let e=Math.min(r-1,R.current.length-1);f(e),a(e,"center"),m("normal"),k("");return}m("normal"),k("")},[o,u,a]),Z=(0,s.useCallback)(e=>{if(!e){m("normal"),C("");return}L(e),i?.(e),m("normal"),C("")},[i]),ee=(0,s.useCallback)(e=>{if(!t)return!1;let r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;if("insert"===h)return("Escape"===e.key||!!r)&&(K(),!0);if("command"===h)return!e.isComposing&&("Escape"===e.key||r?X():"Enter"===e.key?G(w):"Backspace"===e.key?0===w.length?X():k(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||k(t=>t+e.key),!0);if("search"===h)return!e.isComposing&&("Escape"===e.key||r?Q():"Enter"===e.key?Z(N):"Backspace"===e.key?0===N.length?Q():C(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||C(t=>t+e.key),!0);if(x<0&&(f(0),g(0)),e.metaKey)return!1;if(e.ctrlKey)return"d"===e.key?(O(Math.max(1,Math.floor(l()/2))),I(),!0):"u"===e.key?(O(-Math.max(1,Math.floor(l()/2))),I(),!0):"r"===e.key&&(V(),I(),!0);let n=e.key,s=j+n;if("g"===s)return y("g"),D(),!0;if("gg"===s)return A(0),I(),!0;if("d"===s)return y("d"),D(),!0;if("dd"===s)return W(),I(),!0;if("y"===s)return y("y"),D(),!0;if("yy"===s)return z(),I(),!0;if(j&&s!==n&&I(),"j"===n||"ArrowDown"===n)return O(1),!0;if("k"===n||"ArrowUp"===n)return O(-1),!0;if("h"===n||"ArrowLeft"===n)return g(e=>Math.max(0,e-1)),!0;if("l"===n||"ArrowRight"===n){let e=Math.max(0,(R.current[x]??"").length-1);return g(t=>Math.min(e,t+1)),!0}if("0"===n)return g(0),!0;if("$"===n)return g(Math.max(0,(R.current[x]??"").length-1)),!0;if("^"===n){let e=(R.current[x]??"").search(/\S/);return g(e>=0?e:0),!0}return"G"===n?(A(R.current.length-1),!0):"x"===n?(_(),!0):"p"===n?(H(),!0):"u"===n?(q(),!0):"i"===n||"a"===n||"I"===n||"A"===n||"o"===n||"O"===n?(U(n),!0):"/"===n?(Y(),!0):"n"===n?(c?.(),!0):"N"===n?(d?.(),!0):":"===n?(J(),!0):"Escape"!==n&&1===n.length},[t,h,j,w,N,x,K,U,J,X,Y,Q,G,Z,O,A,l,W,z,H,_,q,V,I,D,c,d]);return{state:{mode:h,cursorLine:x,cursorCol:p,isDirty:b,keyBuffer:j,commandInput:w,searchInput:N,lastSearch:S},handleKeyDown:ee,enterNormal:K,enterInsert:U,setCursorLine:f,setCursorCol:g,setCommandInput:k,setSearchInput:C,setIsDirty:v,clearUndoHistory:(0,s.useCallback)(()=>{M.current=[],E.current=[]},[])}}({lines:eV,enabled:J&&!_,onContentChange:e=>{X?.(e)},onEnterInsert:(e,t,r)=>{let n=t;if("a"===r)n=t+1;else if("A"===r)n=(eV[e]??"").length;else if("I"===r){let t=(eV[e]??"").search(/\S/);n=t>=0?t:0}else("o"===r||"O"===r)&&(n=0);td.current={line:e,col:n},Y?.(e)},onSave:Q,getVisibleLineCount:()=>{let e=ew.current;return e?Math.floor(e.clientHeight/20):20},scrollToLine:(e,t)=>{let r=eK.findIndex(t=>"code"===t.type&&t.lineIndex===e);r>=0&&eJ.scrollToIndex(r,{align:t||"auto"})},onSearchExecute:e=>{eG(e),eQ(!1)},onSearchNext:e4,onSearchPrev:e3,onSearchClear:()=>{eG("")}});(0,s.useEffect)(()=>{G&&(G.current={cursorLine:tu.state.cursorLine,cursorCol:tu.state.cursorCol})},[G,tu.state.cursorLine,tu.state.cursorCol]);let th=(0,s.useRef)(null);(0,s.useEffect)(()=>{J&&!_&&null!=Z&&t&&th.current!==t&&(th.current=t,tu.setCursorLine(Z-1),null!=ee&&tu.setCursorCol(ee-1),et?.())},[J,_,Z,ee,t]),(0,s.useEffect)(()=>{if(!J||_)return;let e=ek.current;if(!e)return;let t=e=>{let t=e.target;"TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable||tu.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[J,_,tu.handleKeyDown]),(0,s.useEffect)(()=>{if(!J||_)return;let e=ek.current;e&&"normal"===tu.state.mode&&requestAnimationFrame(()=>{let t=document.activeElement;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||e.focus()})},[J,_,tu.state.mode,e]);let tm=(0,s.useCallback)(e=>{if(!J||_)return;let t=e.target.closest("[data-line]");if(t){let r=parseInt(t.getAttribute("data-line"),10);if(!isNaN(r)){tu.setCursorLine(r-1);let n=t.querySelector("[data-code-content]");if(n){let t=document.caretRangeFromPoint(e.clientX,e.clientY);if(t&&n.contains(t.startContainer)){let e,s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=0;for(;e=s.nextNode();){if(e===t.startContainer){o+=t.startOffset;break}o+=e.textContent?.length||0}let l=eV[r-1]??"";tu.setCursorCol(Math.max(0,Math.min(o,Math.max(0,l.length-1))))}}}}let r=e.target;if("TEXTAREA"===r.tagName||"INPUT"===r.tagName||r.isContentEditable)return;let n=ek.current;n&&n.focus()},[J,_,tu.setCursorLine,tu.setCursorCol,eV]),tx=(0,s.useCallback)(e=>{J&&!_&&requestAnimationFrame(()=>{let e=window.getSelection(),t=e?.toString().trim();t&&/^\S+$/.test(t)&&(ts.current=!0,eG(t))})},[J,_,eG,ts]);(0,s.useEffect)(()=>{"command"===tu.state.mode?setTimeout(()=>ti.current?.focus(),0):"search"===tu.state.mode&&setTimeout(()=>tc.current?.focus(),0)},[tu.state.mode]),(0,s.useEffect)(()=>{let e=ew.current;if(!e)return;let t=()=>{(O??A)?.()};return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t)},[O,A]),(0,s.useEffect)(()=>{eO||eW?(eS.current=!0,A?.()):eC.current||(eS.current=!1)},[eO,eW,A]),(0,s.useLayoutEffect)(()=>{let e=eM.current;if(!e)return;let t=window.getSelection();if(t&&!t.isCollapsed)return;let r=ew.current;if(!r)return;let n=r.querySelector(`[data-line="${e.startLine}"]`),s=r.querySelector(`[data-line="${e.endLine}"]`);if(!n||!s)return;let o=N(n,e.startOffset),l=N(s,e.endOffset);if(o&&l)try{let e=document.createRange();e.setStart(o.node,o.offset),e.setEnd(l.node,l.offset),t?.removeAllRanges(),t?.addRange(e)}catch{}});let tf=(0,s.useCallback)((e,t,r)=>{eS.current||F?.(e,t,r)},[F]),tp=(0,s.useCallback)((e,t)=>{eS.current||D?.(e,t)},[D]),tg=Math.max(4,String(_?eu:eV.length).length),tb=(0,s.useMemo)(()=>{let e=0;for(let t of eV){let r=0;for(let e=0;e<t.length;e++)" "===t[e]?r+=2-r%2:r+=1;r>e&&(e=r)}return e},[eV]);(0,s.useEffect)(()=>{if(_){eo.current=e;let t=e.split("\n").length;em.current=t,eh(t),el.current=!1,ei(!1),ef({show:!1}),eb.current=q}},[_,e,q]),(0,s.useEffect)(()=>{if(!_)return;let t=ep.current;if(!t)return;let r=e.split("\n");t.innerHTML=T(r.map((e,t)=>eE[t]||(0,d.ZD)(e||" "))),requestAnimationFrame(()=>{let e,n;J?(e=Math.max(0,Math.min(td.current.line,r.length-1)),n=td.current.col):(e=Math.max(0,Math.min((I?.current??1)-1,r.length-1)),n=0),t.focus(),E(t,{line:e,offset:n});let s=I?.current??1;eg.current&&(eg.current.scrollTop=(s-1)*20)})},[_]),(0,s.useEffect)(()=>{_&&K?.({isDirty:ea,isSaving:ec})},[_,ea,ec,K]);let tv=(0,s.useCallback)(()=>{let e=ep.current;if(!e)return eo.current;let t=[];for(let r of e.childNodes){let e=r.textContent||"";t.push(" "===e?"":e)}return t.join("\n")},[]),tj=(0,s.useCallback)(()=>{ev.current&&clearTimeout(ev.current),ev.current=setTimeout(async()=>{let e=ep.current;if(e&&!ey.current){eo.current=tv();try{let r=await (0,d.kS)(),n=(0,d.sQ)(t),s=document.documentElement.classList.contains("dark"),o=eo.current.split("\n"),l=r.codeToTokens(o.join("\n"),{lang:n,theme:s?"github-dark":"github-light"}).tokens.map(e=>(0,d.b8)(e)),a=M(e);ej.current=!0,e.innerHTML=T(l),ej.current=!1,a&&E(e,a)}catch{}}},300)},[t,tv]);(0,s.useEffect)(()=>{if(_)return()=>{ev.current&&clearTimeout(ev.current)}},[_]);let ty=(0,s.useCallback)(()=>{let e=ep.current;if(!e)return;el.current||(el.current=!0,ei(!0));let t=e.children.length;t!==em.current&&(em.current=t,eh(t))},[]),tw=(0,s.useCallback)(()=>{ej.current||ey.current||(ty(),tj())},[ty,tj]),tk=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&("Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," ")),"Enter"===e.key)){e.preventDefault();let t=ep.current;if(!t)return;let r=window.getSelection();if(!r?.rangeCount)return;let n=r.getRangeAt(0);n.deleteContents();let s=n.startContainer;for(;s&&s.parentElement!==t;)s=s.parentElement;if(!s||!(s instanceof HTMLElement))return;let o=M(t),l=Array.from(t.children).indexOf(s),a=s.textContent||"",i=o?.offset??a.length,c=a.substring(0,i),u=a.substring(i);s.innerHTML=(0,d.ZD)(c||" ");let h=document.createElement("div");h.setAttribute("style",L),h.innerHTML=(0,d.ZD)(u||" "),s.after(h),E(t,{line:l+1,offset:0}),ty(),tj()}},[ty,tj]),tN=(0,s.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)},[]),tC=(0,s.useCallback)(async(e=!1)=>{if(f){eo.current=tv(),ed(!0);try{let r=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:f,path:t,content:eo.current,expectedMtime:e?void 0:eb.current})}),n=await r.json();if(409===r.status&&n.conflict){try{let e=await fetch(`/api/files/text?cwd=${encodeURIComponent(f)}&path=${encodeURIComponent(t)}`),r=await e.json();ef({show:!0,diskContent:e.ok&&"string"==typeof r.content?r.content:void 0})}catch{ef({show:!0})}return}if(!r.ok)throw Error("Failed to save file");n.mtime&&(eb.current=n.mtime),el.current=!1,ei(!1),ef({show:!1}),(0,S.oR)(es("toast.savedSuccess"),"success"),U?.()}catch(e){console.error("Error saving file:",e),(0,S.oR)(es("toast.saveFailed"),"error")}finally{ed(!1)}}},[f,t,tv,U]),tS=(0,s.useCallback)(async()=>{ea&&!ec&&await tC(!1)},[ea,ec,tC]),tL=(0,s.useCallback)(async()=>{ef({show:!1}),await tC(!0)},[tC]),tM=(0,s.useCallback)(()=>{if(void 0!==ex.diskContent){eo.current=ex.diskContent;let t=ex.diskContent.split("\n").length;em.current=t,eh(t);let r=ex.diskContent!==e;el.current=r,ei(r);let n=ep.current;n&&(n.innerHTML=T(ex.diskContent.split("\n").map(e=>(0,d.ZD)(e||" "))),tj())}ef({show:!1}),U?.()},[ex.diskContent,e,U,tj]),tE=(0,s.useCallback)(()=>{let e=eg.current;return e?Math.floor(e.scrollTop/20)+1:I?.current??1},[I]),tT=(0,s.useCallback)(async()=>{(!ea||await (0,S.lJ)(es("codeViewer.unsavedConfirm"),{danger:!0,confirmText:es("codeViewer.discardChanges"),cancelText:es("codeViewer.continueEditing")}))&&V?.(tE())},[ea,V,tE]);(0,s.useEffect)(()=>{if(!_)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),tS())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[_,tS]);let t$=(0,s.useCallback)(()=>{let e=tv();X?.(e);let t=ep.current,r=t?M(t):null,n=tE();if(tu.enterNormal(),r){tu.setCursorLine(r.line);let t=e.split("\n")[r.line]??"";tu.setCursorCol(Math.max(0,Math.min(r.offset,Math.max(0,t.length-1))))}else tu.setCursorLine(Math.max(0,n-1));V?.(n)},[tv,X,tE,V,tu]);(0,s.useEffect)(()=>{if(!_)return;let e=e=>{let t="Escape"===e.key,r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;(t||J&&r)&&(e.preventDefault(),e.stopPropagation(),J?el.current?(0,S.lJ)(es("codeViewer.unsavedExitConfirm"),{danger:!0,confirmText:es("codeViewer.discardChanges"),cancelText:es("codeViewer.continueEditing")}).then(e=>{e&&t$()}):t$():tT())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[_,J,tT,t$]),(0,s.useImperativeHandle)(en,()=>({save:tS,close:tT,get isDirty(){return ea},get isSaving(){return ec}}),[tS,tT,ea,ec]);let tR=!!(W&&W.length>0),tP=(0,s.useMemo)(()=>{if(!W)return new Map;let e=[...new Set(W.map(e=>e.author))],t=new Map;return e.forEach((e,r)=>{t.set(e,p[r%p.length])}),t},[W]),[tB,tI]=(0,s.useState)(null),[tD,tF]=(0,s.useState)(null);(0,s.useEffect)(()=>{tI(null),tF(null)},[W]);let tA=(0,s.useCallback)((e,t)=>{tI(e.author);let r=t.currentTarget.getBoundingClientRect();tF({line:e,x:r.right+8,y:r.top})},[]),tO=(0,s.useCallback)(()=>{tI(null),tF(null)},[]),tW=(0,s.useCallback)(e=>{H&&(H({hash:e.hashFull,shortHash:e.hash,author:e.author,authorEmail:e.authorEmail,date:new Date(1e3*e.time).toISOString(),subject:e.message.split("\n")[0]||"",body:e.message.split("\n").slice(1).join("\n").trim(),time:e.time}),tF(null))},[H]),tz=`${tg+2}ch`;return(0,n.jsxs)("div",{ref:ek,className:`h-full flex flex-col outline-none ${x}`,tabIndex:0,onClick:tm,onDoubleClick:tx,children:[_&&ex.show&&(0,n.jsxs)("div",{className:"px-4 py-2 bg-amber-500/15 border-b border-amber-500/30 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("svg",{className:"w-5 h-5 text-amber-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1",children:es("codeViewer.fileModifiedExternally")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:tM,className:"px-3 py-1 text-sm rounded border border-border hover:bg-accent transition-colors",children:es("codeViewer.useDiskVersion")}),(0,n.jsx)("button",{onClick:tL,className:"px-3 py-1 text-sm rounded bg-amber-500 text-white hover:bg-amber-600 transition-colors",children:es("codeViewer.forceOverwrite")})]})]}),!_&&m&&eP&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:eN,type:"text",value:eB,onChange:e=>eG(e.target.value),onKeyDown:e6,placeholder:es("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("button",{onClick:()=>eZ(!eI),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eI?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:es("codeViewer.caseSensitive"),children:"Aa"}),(0,n.jsx)("button",{onClick:()=>e0(!eD),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eD?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:es("codeViewer.wholeWordMatch"),children:"[ab]"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:eU.length>0?`${eF+1}/${eU.length}`:es("common.noMatch")}),(0,n.jsx)("button",{onClick:e3,disabled:0===eU.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:es("common.previous"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,n.jsx)("button",{onClick:e4,disabled:0===eU.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:es("common.next"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,n.jsx)("button",{onClick:()=>{eQ(!1),eG("")},className:"p-1 rounded hover:bg-accent",title:es("common.close"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),_?(0,n.jsx)("div",{ref:eg,className:"flex-1 overflow-auto bg-secondary",children:(0,n.jsxs)("div",{className:"flex",style:{minHeight:"100%"},children:[(0,n.jsx)("div",{className:"flex-shrink-0 font-mono text-sm select-none sticky left-0 z-[2] bg-secondary",style:{width:tz},children:Array.from({length:eu},(e,t)=>(0,n.jsx)("div",{className:"text-right text-muted-foreground/50 pr-3",style:{height:20,lineHeight:"20px"},children:t+1},t))}),(0,n.jsx)("div",{ref:ep,contentEditable:!0,suppressContentEditableWarning:!0,onInput:tw,onKeyDown:tk,onPaste:tN,onCompositionStart:()=>{ey.current=!0},onCompositionEnd:()=>{ey.current=!1,tw()},spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",className:"flex-1 font-mono text-sm outline-none",style:{caretColor:"var(--foreground)",tabSize:2}})]})}):(0,n.jsx)("div",{ref:ew,className:`flex-1 overflow-auto font-mono text-sm bg-secondary${e$?" cmd-held-container":""}`,children:(0,n.jsx)("div",{style:{height:`${eJ.getTotalSize()}px`,minWidth:"100%",width:tR?`calc(${tg+tb+10}ch + 13rem)`:`${tg+tb+10}ch`,position:"relative"},children:eJ.getVirtualItems().map(e=>{let t=eK[e.index];if("code"!==t.type)return null;let s=t.lineIndex,o=s+1,l=eE[s]||(0,d.ZD)(eV[s]||""),a=tn(s,l,B),i=eY.has(o),c=eX.get(o),u=c?.[0],h=!!(eO&&o>=eO.range.start&&o<=eO.range.end),m=tl>=0?to.current:null,x=!_&&z&&m===o?z[s]??null:null,f=tR?W[s]:void 0,p=tR&&s>0?W[s-1]:void 0,g=!!f&&(!p||p.hash!==f.hash),v=f?tP.get(f.author):void 0;return(0,n.jsx)(b,{virtualKey:e.key,lineNum:o,highlightedHtml:a,hasComments:i,firstComment:u,lineCommentsCount:c?.length,isInRange:h,showLineNumbers:r,lineNumChars:tg,commentsEnabled:eH,virtualItemSize:e.size,virtualItemStart:e.start,onCommentBubbleClick:e8,onCmdClick:tp,onTokenHover:tf,onTokenHoverLeave:A,flashLine:eR,blameLine:f,showBlameInfo:g,blameAuthorColor:v,isBlameHovered:!!(f&&tB===f.author),onBlameClick:tW,onBlameMouseEnter:tA,onBlameMouseLeave:tO,inlineBlameData:x,onInlineBlameClick:tW,isCursorLine:J&&!_&&tu.state.cursorLine===s,cursorCol:J&&!_&&tu.state.cursorLine===s?tu.state.cursorCol:void 0},e.key)})})}),J&&(0,n.jsxs)("div",{className:"vi-status-bar flex-shrink-0 h-6 bg-card border-t border-border flex items-center px-3 text-xs font-mono select-none",children:["normal"===tu.state.mode&&(0,n.jsx)("span",{className:"text-green-11 font-medium",children:"NORMAL"}),"insert"===tu.state.mode&&(0,n.jsx)("span",{className:"text-blue-11 font-medium",children:"INSERT"}),"command"===tu.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:":"}),(0,n.jsx)("input",{ref:ti,value:tu.state.commandInput,onChange:e=>tu.setCommandInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tu.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),"search"===tu.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:"/"}),(0,n.jsx)("input",{ref:tc,value:tu.state.searchInput,onChange:e=>tu.setSearchInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tu.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),tu.state.keyBuffer&&"normal"===tu.state.mode&&(0,n.jsx)("span",{className:"ml-2 text-muted-foreground",children:tu.state.keyBuffer}),tu.state.isDirty&&("normal"===tu.state.mode||"command"===tu.state.mode)&&(0,n.jsx)("span",{className:"ml-2 text-amber-11",children:"[+]"}),(0,n.jsxs)("span",{className:"ml-auto text-muted-foreground",children:[tu.state.cursorLine+1,":",tu.state.cursorCol+1]})]}),eT&&ta&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[!_&&(0,n.jsx)(u.f,{floatingToolbarRef:eC,bumpRef:eL,container:ta,onAddComment:e9,onSendToAI:e7,onSearch:er?te:void 0,isChatLoading:ez?.isLoading}),!_&&eO&&(0,n.jsx)(i.t,{x:eO.x,y:eO.y,range:eO.range,codeContent:eO.codeContent,container:ta,onSubmit:tt,onClose:()=>e2(null)}),!_&&eW&&(0,n.jsx)(i.G,{x:eW.x,y:eW.y,range:eW.range,filePath:t,codeContent:eW.codeContent,container:ta,onSubmit:tr,onClose:()=>e5(null),isChatLoading:ez?.isLoading}),!_&&eA&&(0,n.jsx)(h.t,{x:eA.x,y:eA.y,comment:eA.comment,container:ta,onClose:()=>e1(null),onUpdateComment:e_,onDeleteComment:eq}),tD&&(0,n.jsxs)("div",{className:"fixed z-50 bg-card border border-border rounded-lg shadow-lg p-3 max-w-lg",style:{left:Math.min(tD.x,window.innerWidth-450),top:Math.max(8,Math.min(tD.y,window.innerHeight-200))},children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 rounded text-xs font-mono font-medium text-white flex-shrink-0",style:{backgroundColor:tP.get(tD.line.author)?.border||"#666"},children:tD.line.hash}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground",children:tD.line.author}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:tD.line.authorEmail})]})]}),(0,n.jsx)("div",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:tD.line.message}),(0,n.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground border-t border-border pt-2",children:[(0,C.fw)(tD.line.time)," \xb7 ",new Date(1e3*tD.line.time).toLocaleString(),(0,n.jsx)("span",{className:"ml-2 text-brand",children:es("codeViewer.clickToViewDetails")})]})]})]}),ta)]})});function R({content:e,filePath:t,className:r=""}){let o=(0,s.useMemo)(()=>e.split("\n"),[e]),l=(0,c.C)(o,t),a=Math.max(4,String(o.length).length);return(0,n.jsx)("pre",{className:`overflow-auto text-sm font-mono bg-secondary p-2 ${r}`,children:o.map((e,t)=>(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsx)("span",{className:"text-slate-9 select-none pr-4 text-right",style:{minWidth:`${a+2}ch`},children:t+1}),(0,n.jsx)("span",{className:"flex-1",dangerouslySetInnerHTML:{__html:l[t]||(0,d.ZD)(e||" ")}})]},t))})}},41474:(e,t,r)=>{r.d(t,{F:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)(()=>"u"<typeof document||"visible"===document.visibilityState);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}},43430:(e,t,r)=>{r.d(t,{Workspace:()=>D});var n=r(95155),s=r(12115),o=r(79114),l=r(69958),a=r(76288),i=r(83678),c=r(21484);let d={"claude-opus-4-6":{label:"Opus 4.6",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"},"claude-opus-4-5-20251101":{label:"Opus 4.5",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#fb923c"},"claude-sonnet-4-6":{label:"Sonnet 4.6",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#3b82f6"},"claude-sonnet-4-5-20250929":{label:"Sonnet 4.5",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#60a5fa"},"claude-haiku-4-5-20251001":{label:"Haiku 4.5",input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}},u={label:"",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#94a3b8"};function h(e){if(d[e])return d[e];let t=e.toLowerCase();return t.includes("opus")?{...u,input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"}:t.includes("haiku")?{...u,input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}:u}function m(e){let t=d[e];return t?t.label:e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function x(e){return(d[e]??h(e)).color}function f(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function p(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function g({data:e,height:t=200,formatValue:r=f}){let o=(0,s.useRef)(null),l=(0,s.useRef)(null),[a,i]=(0,s.useState)(null),c=(0,s.useRef)([]),d=(0,s.useCallback)(()=>{let n=o.current,s=l.current;if(!n||!s)return;let a=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*a,n.height=t*a,n.style.width=`${i}px`,n.style.height=`${t}px`;let d=n.getContext("2d");d.scale(a,a),d.clearRect(0,0,i,t);let{labels:u,datasets:h}=e;if(0===u.length)return;let m=i-50-12,x=t-8-28,f=function(e){if(e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),r=e/t;return r<=1?t:r<=2?2*t:r<=5?5*t:10*t}(Math.max(1,...u.map((e,t)=>h.reduce((e,r)=>e+r.data[t],0))));d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="10px ui-monospace, monospace",d.textAlign="right",d.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+x-t/f*x;d.fillText(r(t),44,s),d.strokeStyle=(p="--border",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),d.lineWidth=.5,d.beginPath(),d.moveTo(50,s),d.lineTo(50+m,s),d.stroke()}let g=m/u.length,b=Math.max(4,Math.min(.6*g,32)),v=[];u.forEach((e,t)=>{let r=50+t*g+(g-b)/2,s=0;h.forEach(n=>{var o,l,a,i,c,u;let h=n.data[t];if(h<=0)return;let m=h/f*x,p=8+x-s-m;d.fillStyle=n.color,o=d,l=r,a=p,i=b,u=2,(c=m)<1||(u=Math.min(u,c/2,i/2),o.beginPath(),o.moveTo(l+u,a),o.lineTo(l+i-u,a),o.quadraticCurveTo(l+i,a,l+i,a+u),o.lineTo(l+i,a+c-u),o.quadraticCurveTo(l+i,a+c,l+i-u,a+c),o.lineTo(l+u,a+c),o.quadraticCurveTo(l,a+c,l,a+c-u),o.lineTo(l,a+u),o.quadraticCurveTo(l,a,l+u,a),o.fill()),v.push({x:r,y:p,w:b,h:m,label:e,value:h,dataset:n.label,color:n.color}),s+=m}),d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="9px ui-monospace, monospace",d.textAlign="center",d.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&d.fillText(e,r+b/2,8+x+6)}),c.current=v},[e,t,r]);(0,s.useEffect)(()=>{d();let e=new ResizeObserver(()=>d());return l.current&&e.observe(l.current),()=>e.disconnect()},[d]);let u=(0,s.useCallback)(e=>{let t=o.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,s=e.clientY-t.top,l=c.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);l?i({x:e.clientX-t.left,y:l.y-4,content:`${l.dataset}: ${r(l.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:l,className:"relative w-full text-muted-foreground",children:[(0,n.jsx)("canvas",{ref:o,className:"w-full",style:{height:t},onMouseMove:u,onMouseLeave:()=>i(null)}),a&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lg border border-border whitespace-nowrap z-10",style:{left:a.x,top:a.y,transform:"translate(-50%, -100%)"},children:a.content})]})}function b({hourCounts:e}){let{t}=(0,o.Bd)(),r=Math.max(1,...Object.values(e)),s=Array.from({length:24},(e,t)=>t);return(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:t("tokenStats.activeHours")}),(0,n.jsx)("div",{className:"flex gap-[2px] items-end h-16",children:s.map(s=>{let o=e[String(s)]||0,l=o/r;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:s,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*l)}px`,backgroundColor:l>0?`rgba(59, 130, 246, ${.2+.8*l})`:"var(--muted)"}}),s%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:s})]},s)})})]})}function v({isOpen:e,onClose:t}){var r;let l,a,{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(null),[u,y]=(0,s.useState)(!0),[w,k]=(0,s.useState)("day"),[N,C]=(0,s.useState)("tokens"),[S,L]=(0,s.useState)("claude");(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>y(!0)),fetch(`/api/claude-stats?engine=${S}`).then(e=>e.json()).then(e=>{e.error||queueMicrotask(()=>d(e))}).catch(()=>{}).finally(()=>queueMicrotask(()=>y(!1))))},[e,S]);let M=(0,s.useMemo)(()=>c?.modelUsage?Object.entries(c.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:m(e),color:x(e),usage:t,cost:(r=h(e),t.inputTokens/1e6*r.input+t.outputTokens/1e6*r.output+t.cacheReadInputTokens/1e6*r.cacheRead+t.cacheCreationInputTokens/1e6*r.cacheWrite),totalTokens:t.inputTokens+t.outputTokens+t.cacheReadInputTokens+t.cacheCreationInputTokens}}).sort((e,t)=>t.cost-e.cost):[],[c]),E=(0,s.useMemo)(()=>M.reduce((e,t)=>e+t.cost,0),[M]),T=(0,s.useMemo)(()=>M.map(e=>e.id),[M]),$=(0,s.useMemo)(()=>{let e={};for(let t of M)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[M]),{activityChart:R,tokenChart:P,costChart:B}=(0,s.useMemo)(()=>{let e=c?.dailyActivity||[],t=c?.dailyModelTokens||[];if("day"===w){let r=e.slice(-60),n=t.slice(-60),s={labels:r.map(e=>e.date.slice(5)),datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messageCount),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:"#22c55e"}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:T.map(e=>({label:m(e),data:n.map(t=>t.tokensByModel[e]||0),color:x(e)}))},costChart:{labels:o,datasets:T.map(e=>({label:m(e),data:n.map(t=>(t.tokensByModel[e]||0)*($[e]||0)),color:x(e)}))}}}if("week"===w){let r=function(e,t){let r=new Map;for(let t of e){let e=new Date(t.date),n=new Date(e);n.setDate(e.getDate()-e.getDay());let s=n.toISOString().slice(0,10),o=s.slice(5);r.has(s)||r.set(s,{label:o,messages:0,sessions:0,tools:0,tokensByModel:{}});let l=r.get(s);l.messages+=t.messageCount,l.sessions+=t.sessionCount,l.tools+=t.toolCallCount}for(let e of t){let t=new Date(e.date),n=new Date(t);n.setDate(t.getDate()-t.getDay());let s=n.toISOString().slice(0,10);r.has(s)||r.set(s,{label:s.slice(5),messages:0,sessions:0,tools:0,tokensByModel:{}});let o=r.get(s);for(let[t,r]of Object.entries(e.tokensByModel))o.tokensByModel[t]=(o.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:T.map(e=>({label:m(e),data:r.map(t=>t.tokensByModel[e]||0),color:x(e)}))},costChart:{labels:n,datasets:T.map(e=>({label:m(e),data:r.map(t=>(t.tokensByModel[e]||0)*($[e]||0)),color:x(e)}))}}}let r=function(e,t){let r=new Map;for(let t of e){let e=t.date.slice(0,7);r.has(e)||r.set(e,{label:e,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(e);n.messages+=t.messageCount,n.sessions+=t.sessionCount,n.tools+=t.toolCallCount}for(let e of t){let t=e.date.slice(0,7);r.has(t)||r.set(t,{label:t,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(t);for(let[t,r]of Object.entries(e.tokensByModel))n.tokensByModel[t]=(n.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:T.map(e=>({label:m(e),data:r.map(t=>t.tokensByModel[e]||0),color:x(e)}))},costChart:{labels:n,datasets:T.map(e=>({label:m(e),data:r.map(t=>(t.tokensByModel[e]||0)*($[e]||0)),color:x(e)}))}}},[c,w,T,$,i]);if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]),!e)return null;let I=[{key:"day",label:i("tokenStats.day")},{key:"week",label:i("tokenStats.week")},{key:"month",label:i("tokenStats.month")}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-xl w-full max-w-4xl mx-4 max-h-[90vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("tokenStats.title")}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:["claude","claude2"].map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${S===e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{d(null),L(e)},children:"claude"===e?"Claude":"Claude 2"},e))}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:I.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${w===e.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>k(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:u?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(j,{label:i("tokenStats.totalSessions"),value:String(c.totalSessions??0)}),(0,n.jsx)(j,{label:i("tokenStats.totalMessages"),value:f(c.totalMessages??0)}),(0,n.jsx)(j,{label:i("tokenStats.equivalentApiCost"),value:p(E),highlight:!0}),(0,n.jsx)(j,{label:i("tokenStats.longestSession"),value:c.longestSession?(l=Math.floor((r=c.longestSession.duration)/36e5),a=Math.floor(r%36e5/6e4),l>0?`${l}h ${a}m`:`${a}m`):"-"}),(0,n.jsx)(j,{label:i("tokenStats.firstUse"),value:c.firstSessionDate?c.firstSessionDate.slice(0,10):"-"})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.activityTrend")}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-[10px]",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#3b82f6"}}),i("tokenStats.messages")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#22c55e"}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(g,{data:R,height:180})})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.byModel")}),(0,n.jsxs)("div",{className:"flex bg-muted rounded-md p-0.5",children:[(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"tokens"===N?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===N?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:M.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:e.color}}),e.label]},e.id))})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(g,{data:"tokens"===N?P:B,height:180,formatValue:"tokens"===N?f:p})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("tokenStats.modelCostDetail")}),(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"bg-muted/50 text-muted-foreground",children:[(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium",children:i("tokenStats.model")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Input"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Output"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Read"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Write"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.share")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.equivalentCost")})]})}),(0,n.jsxs)("tbody",{children:[M.map(e=>(0,n.jsxs)("tr",{className:"border-t border-border",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.label]})}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:E>0?`${(e.cost/E*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:p(e.cost)})]},e.id)),(0,n.jsxs)("tr",{className:"border-t-2 border-border bg-muted/30",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-medium text-foreground",children:i("tokenStats.total")}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(M.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(M.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(M.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:f(M.reduce((e,t)=>e+t.usage.cacheCreationInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:"100%"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-bold text-foreground",children:p(E)})]})]})]})})]}),c.hourCounts&&Object.keys(c.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(b,{hourCounts:c.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function j({label:e,value:t,highlight:r}){return(0,n.jsxs)("div",{className:"bg-muted/30 rounded-lg px-3 py-2.5",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground",children:e}),(0,n.jsx)("div",{className:`text-sm font-semibold mt-0.5 ${r?"text-brand":"text-foreground"}`,children:t})]})}var y=r(8648),w=r(34075),k=r(45048),N=r(38408);function C({skillId:e,onClose:t}){let[r,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(!0),[i,c]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return a(!0),fetch(`/api/skills/content?id=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{t||o(e)}).catch(e=>console.error("Failed to load skill content",e)).finally(()=>{t||a(!1)}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let d=(0,s.useCallback)(async()=>{if(r?.path)try{await navigator.clipboard.writeText(r.path),(0,w.oR)("Path copied","success")}catch{(0,w.oR)("Failed to copy","error")}},[r]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-4xl h-[85vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:r?.name?`/${r.name}`:"Skill Preview"}),(0,n.jsx)("button",{onClick:d,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),r?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:r.path})]}),(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>c("preview"),className:`px-3 py-1 transition-colors ${"preview"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Preview"}),(0,n.jsx)("button",{onClick:()=>c("source"),className:`px-3 py-1 transition-colors ${"source"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Source"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors flex-shrink-0",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:l?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"Loading..."}):r&&r.valid?"preview"===i?(0,n.jsx)("div",{className:"px-6 py-4",children:(0,n.jsx)(k.T,{content:r.content})}):(0,n.jsx)(N.XO,{content:r.content,filePath:r.path,className:"min-h-full"}):(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"File cannot be read."})})]})]})}var S=r(88371);function L({isOpen:e,onClose:t}){let[r,o]=(0,s.useState)([]),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(!1),[h,m]=(0,s.useState)(""),[x,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(null),b=(0,s.useCallback)(async()=>{a(!0);try{let e=await fetch("/api/skills");if(e.ok){let t=await e.json();o(t)}}catch(e){console.error("Failed to load skills",e)}finally{a(!1)}},[]);(0,s.useEffect)(()=>{e&&b()},[e,b]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!p){if(d){u(!1),m("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,d,p]);let v=(0,s.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):r},[r,i]),j=(0,s.useCallback)(async()=>{let e=h.trim();if(e){f(!0);try{let t=await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})});if(!t.ok){let e=await t.json().catch(()=>({}));(0,w.oR)(e.error||"Failed to add skill","error");return}(0,w.oR)("Skill added","success"),m(""),u(!1),await b(),(0,S.k)()}catch(e){console.error(e),(0,w.oR)("Failed to add skill","error")}finally{f(!1)}}},[h,b]),y=(0,s.useCallback)(async e=>{try{if(!(await fetch(`/api/skills/${encodeURIComponent(e)}`,{method:"DELETE"})).ok)return void(0,w.oR)("Failed to delete","error");o(t=>t.filter(t=>t.id!==e)),(0,S.k)()}catch(e){console.error(e),(0,w.oR)("Failed to delete","error")}},[]),k=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,w.oR)("Path copied","success")}catch{(0,w.oR)("Failed to copy","error")}},[]);return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-3xl h-[80vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:"Skills"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsxs)("svg",{className:"w-4 h-4 absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-4.35-4.35"})]}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Search skills...",className:"w-full pl-8 pr-3 py-1.5 text-sm border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"})]}),(0,n.jsx)("button",{onClick:()=>u(!0),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 active:scale-95 transition-all",children:"+ Add Skill"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:l?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:"Loading..."}):0===v.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:0===r.length?'No skills yet. Click "Add Skill" to add one.':"No skills match your search."}):v.map(e=>(0,n.jsx)(M,{skill:e,onPreview:()=>g(e.id),onDelete:()=>y(e.id),onCopyPath:()=>k(e.path)},e.id))})]})]}),d&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:()=>{x||(u(!1),m(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:"Add Skill"}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:"Absolute path to SKILL.md"}),(0,n.jsx)("input",{type:"text",value:h,onChange:e=>m(e.target.value),onKeyDown:e=>{"Enter"!==e.key||x||j()},placeholder:"/Users/you/.../skills/foo/SKILL.md",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{u(!1),m("")},disabled:x,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",children:"Cancel"}),(0,n.jsx)("button",{onClick:j,disabled:x||!h.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:x?"Adding...":"Add"})]})]})]}),p&&(0,n.jsx)(C,{skillId:p,onClose:()=>g(null)})]}):null}function M({skill:e,onPreview:t,onDelete:r,onCopyPath:o}){let[l,a]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:`border border-border rounded-lg p-3 bg-card hover:bg-accent/30 transition-colors ${e.valid?"":"opacity-60"}`,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"w-9 h-9 flex-shrink-0 flex items-center justify-center rounded-md bg-brand/10 text-brand text-lg",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground",children:["/",e.name]}),e.description&&(0,n.jsx)("span",{className:"text-sm text-muted-foreground line-clamp-2",children:e.description}),!e.valid&&(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:"Invalid"})]}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 truncate",children:e.argumentHint}),(0,n.jsx)("div",{className:"flex items-center gap-1 mt-1",children:(0,n.jsx)("button",{onClick:o,className:"text-xs text-muted-foreground hover:text-foreground font-mono truncate text-left",title:"Copy path",children:e.path})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Preview",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})}),l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{a(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:"Confirm"}),(0,n.jsx)("button",{onClick:()=>a(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:"Cancel"})]}):(0,n.jsx)("button",{onClick:()=>a(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:"Delete",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M1 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})]})]})})}var E=r(47650);let T=[],$=[];function R(){$.forEach(e=>e())}function P(e){T=T.filter(t=>t.id!==e),R()}function B({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return $.push(t),()=>{$=$.filter(e=>e!==t)}},[]),T}();return 0===t.length?null:(0,E.createPortal)((0,n.jsx)("div",{className:"fixed bottom-4 left-4 z-[100] flex flex-col gap-2 pointer-events-none",children:t.map(t=>(0,n.jsx)(I,{item:t,onNavigate:e,onRemove:P},t.id))}),document.body)}function I({item:e,onNavigate:t,onRemove:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),c=(0,s.useRef)(void 0),d=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(c.current=setTimeout(d,5e3),()=>clearTimeout(c.current)),[d]);let u=(0,s.useCallback)(()=>{clearTimeout(c.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),h=(0,s.useCallback)(()=>{clearTimeout(c.current)},[]),m=(0,s.useCallback)(()=>{c.current=setTimeout(d,2e3)},[d]);return(0,n.jsxs)("div",{className:`pointer-events-auto bg-card border border-border rounded-lg shadow-lg px-3 py-2.5 min-w-[260px] max-w-[340px] cursor-pointer hover:bg-accent transition-all ${a?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:a?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:h,onMouseLeave:m,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-green-9 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:e.projectName}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:l("common.done")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"ml-auto p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.message&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-1 ml-6",children:e.message})]})}function D({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[d,u]=(0,s.useState)([]),[h,m]=(0,s.useState)(0),[x,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[b,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(null),[E,$]=(0,s.useState)(!1),[P,I]=(0,s.useState)(!1),[F,A]=(0,s.useState)(new Set),O=(0,s.useRef)(new Map),W=(0,s.useRef)(new Map),z=(0,s.useRef)(new Map),H=(0,s.useRef)(null),_=(0,s.useCallback)(async()=>{try{let e=await fetch("/api/projects");if(e.ok){let t=await e.json();u(t.projects||[]),m(t.activeIndex||0),f(t.collapsed||!1)}}catch(e){console.error("Failed to load projects:",e)}finally{I(!0)}},[]),q=(0,s.useCallback)(async(e,t,r)=>{try{await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projects:e,activeIndex:t,collapsed:r})})}catch(e){console.error("Failed to save projects:",e)}},[]);(0,s.useEffect)(()=>{let e=d[h]?.cwd;e&&A(t=>t.has(e)?t:new Set(t).add(e))},[h,d]),(0,s.useEffect)(()=>{for(let[e,t]of O.current.entries()){let r=d[h]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r},"*")}},[h,d]),(0,s.useEffect)(()=>{_()},[_]);let V=(0,s.useCallback)((e,t)=>{let r=new URL(window.location.href);r.searchParams.set("cwd",e),t?r.searchParams.set("sessionId",t):r.searchParams.delete("sessionId"),window.history.replaceState({},"",r.toString());let n=e.split("/").filter(Boolean).pop();document.title=n?`Cockpit - ${n}`:"Cockpit"},[]),U=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!P||U.current||!e)return;U.current=!0,t&&(W.current.set(e,{sessionId:t}),z.current.set(e,t));let r=d.findIndex(t=>t.cwd===e);if(r>=0)r!==h&&(m(r),q(d,r,x));else{let t=[...d,{cwd:e}],r=t.length-1;u(t),m(r),q(t,r,x)}V(e,t)},[P,e,t,d,h,x,q,V]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r}=e.data;z.current.set(t,r);let n=d[h];n?.cwd===t&&V(t,r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:r,sessionId:n,lastUserMessage:s}=e.data,o=d[h];if(o?.cwd!==r){var t;let e;t={projectName:r.split("/").pop()||r,message:s,cwd:r,sessionId:n},e=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,T=[...T,{...t,id:e}],R()}}if(e.data?.type==="OPEN_TOKEN_STATS"&&k(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&(M(e.data.cwd),C(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){H.current=h;let t=e.data.cwd,r=d.findIndex(e=>e.cwd===t);r>=0&&r!==h&&m(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==H.current&&H.current!==h&&m(H.current),H.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r}=e.data,n=r||"";z.current.set(t,n);let s=d.findIndex(e=>e.cwd===t);if(s>=0){if(n){let e=O.current.get(t);e?.contentWindow&&e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:n},"*")}s!==h&&(m(s),q(d,s,x))}else{let e=[...d,{cwd:t}],r=e.length-1;u(e),m(r),q(e,r,x),n&&W.current.set(t,{sessionId:n})}V(t,n)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[d,h,x,V,q]);let K=(0,s.useCallback)(e=>{m(e),q(d,e,x);let t=d[e];if(t?.cwd){let e=z.current.get(t.cwd);V(t.cwd,e)}},[d,x,q,V]),J=(0,s.useCallback)(e=>{let t=d.filter((t,r)=>r!==e),r=h;e<h?r=h-1:e===h&&r>=t.length&&(r=Math.max(0,t.length-1)),u(t),m(r),q(t,r,x)},[d,h,x,q]),X=(0,s.useCallback)(e=>{let t=d[h],r=e.findIndex(e=>e.cwd===t?.cwd);u(e),m(r>=0?r:0),q(e,r>=0?r:0,x)},[d,h,x,q]),Y=(0,s.useCallback)(()=>{let e=!x;f(e),q(d,h,e)},[d,h,x,q]),Q=(0,s.useCallback)((e,t)=>{z.current.set(e,t);let r=d.findIndex(t=>t.cwd===e);if(r>=0){let n=O.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),m(r),q(d,r,x)}else{let r=[...d,{cwd:e}],n=r.length-1;u(r),m(n),q(r,n,x),W.current.set(e,{sessionId:t,switchToAgent:!0})}V(e,t),g(!1)},[d,x,q,V]),G=(0,s.useCallback)((e,t)=>{z.current.set(e,t);let r=d.findIndex(t=>t.cwd===e);if(r>=0){let n=O.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),r!==h&&(m(r),q(d,r,x))}else{let r=[...d,{cwd:e}],n=r.length-1;u(r),m(n),q(r,n,x),W.current.set(e,{sessionId:t,switchToAgent:!0})}V(e,t)},[d,h,x,q,V]),Z=(0,s.useCallback)(e=>{let t=W.current.get(e);if(t){let r=O.current.get(e);r?.contentWindow&&r.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t.sessionId,switchToAgent:t.switchToAgent},"*"),W.current.delete(e)}},[]);return P?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(l.ProjectSidebar,{projects:d,activeIndex:h,collapsed:x,currentCwd:d[h]?.cwd,onSelectProject:K,onRemoveProject:J,onReorderProjects:X,onToggleCollapse:Y,onOpenSessionBrowser:()=>g(!0),onOpenSettings:()=>j(!0),onOpenNote:e=>{M(e??null),C(!0)},onOpenSkills:()=>$(!0),onSwitchProject:G,onAddProject:e=>{let t=d.findIndex(t=>t.cwd===e);if(t>=0)m(t),q(d,t,x);else{let t=[...d,{cwd:e}],r=t.length-1;u(t),m(r),q(t,r,x)}}}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===d.length?(0,n.jsx)(a.EmptyState,{onSelectSession:Q}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:d.map((e,t)=>F.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?O.current.set(e.cwd,t):O.current.delete(e.cwd)},src:`/project?cwd=${encodeURIComponent(e.cwd)}`,onLoad:()=>Z(e.cwd),className:`absolute inset-0 w-full h-full border-0 ${t===h?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd))})}),(0,n.jsx)(i.SessionBrowser,{isOpen:p,onClose:()=>g(!1),onSelectSession:Q,onAddProject:e=>{let t=d.findIndex(t=>t.cwd===e);if(t>=0)m(t),q(d,t,x);else{let t=[...d,{cwd:e}],r=t.length-1;u(t),m(r),q(t,r,x)}g(!1)}}),(0,n.jsx)(c.SettingsModal,{isOpen:b,onClose:()=>j(!1)}),(0,n.jsx)(v,{isOpen:w,onClose:()=>k(!1)}),(0,n.jsx)(y.NoteModal,{isOpen:N,onClose:()=>{C(!1),M(null)},projectCwd:S,projectName:S?S.split("/").pop():null}),(0,n.jsx)(L,{isOpen:E,onClose:()=>$(!1)}),(0,n.jsx)(B,{onNavigate:G})]}):(0,n.jsx)("div",{className:"h-screen flex items-center justify-center bg-card",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:r("workspace.loadingText")})]})})}},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>i});var n=r(95155),s=r(12115),o=r(79114),l=r(69809);function a(e){return"auto"!==e&&e?e:navigator.language.startsWith("zh")?"zh":"en"}function i({children:e}){return(0,s.useEffect)(()=>{fetch("/api/settings").then(e=>e.json()).then(e=>{let t=a(e.language||"auto");l.A.language!==t&&l.A.changeLanguage(t)}).catch(()=>{let e=a("auto");l.A.language!==e&&l.A.changeLanguage(e)})},[]),(0,s.useEffect)(()=>{let e=e=>(function(e){for(let t of document.querySelectorAll("iframe"))try{t.contentWindow?.postMessage({type:"cockpit:language-change",lang:e},"*")}catch{}})(e);return l.A.on("languageChanged",e),()=>{l.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&l.A.language!==e.data.lang&&l.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:l.A,children:e})}},48347:(e,t,r)=>{r.d(t,{H:()=>l,r:()=>a});var n=r(95155),s=r(12115);let o=(0,s.createContext)(null);function l({value:e,children:t}){return(0,n.jsx)(o.Provider,{value:e,children:t})}function a(){return(0,s.useContext)(o)}},53853:(e,t,r)=>{r.d(t,{G:()=>u,f:()=>h});var n=r(12115);function s(){if("u"<typeof document)return null;let e=document.querySelector('meta[name="cockpit-bridge"]');if(!e)return null;let t=e.dataset.id,r=e.dataset.version;return t?{id:t,version:r||"unknown"}:null}let o=null,l=new Set;function a(){l.forEach(e=>e())}function i(e){l.add(e);let t=s();return t&&!o&&(o=t,Promise.resolve().then(a)),()=>{l.delete(e)}}function c(){return o}function d(){return null}if("u">typeof document&&(o=s()),"u">typeof MutationObserver&&"u">typeof document){let e=new MutationObserver(()=>{let e=s();e&&(!o||e.id!==o.id||e.version!==o.version)&&(o=e,a())}),t=document.head||document.documentElement;t&&e.observe(t,{childList:!0})}function u(){return(0,n.useSyncExternalStore)(i,c,d)}function h(){return o??s()}},56978:(e,t,r)=>{r.d(t,{C:()=>o});var n=r(12115),s=r(17196);function o(e,t){let[r,o]=(0,n.useState)([]),[l,a]=(0,n.useState)(!1),i=(0,n.useRef)("");(0,n.useEffect)(()=>{let e=()=>{a(document.documentElement.classList.contains("dark"))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let c=e.join("\n");return(0,n.useEffect)(()=>{if(0===e.length)return;let r=`${c}:${t}:${l}`;if(r===i.current)return;i.current=r,o(e.map(e=>(0,s.ZD)(e||" ")));let n=!1;return(async()=>{try{let r=await (0,s.kS)();if(n)return;let a=(0,s.sQ)(t),i=e.join("\n"),c=r.codeToTokens(i,{lang:a,theme:l?"github-dark":"github-light"}),d=[];for(let e=0;e<c.tokens.length;e++)if(d[e]=(0,s.b8)(c.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),n))return;o(d)}catch(e){console.error("Line highlight error:",e)}})(),()=>{n=!0}},[c,t,l]),r}},58490:(e,t,r)=>{r.d(t,{TabManager:()=>nQ});var n=r(95155),s=r(12115),o=r(79114);function l({isOpen:e,onClose:t,cwd:r,onSelectSession:a}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,h]=(0,s.useState)(!1),[m,x]=(0,s.useState)(null),[f,p]=(0,s.useState)(""),g=(0,s.useRef)(null),b=(0,s.useCallback)(async()=>{if(r){h(!0),x(null);try{let e=r.replace(/\//g,"-"),t=await fetch(`/api/sessions/projects/${encodeURIComponent(e)}`);if(!t.ok)throw Error("Failed to load sessions");let n=await t.json();d(n)}catch(e){x(e instanceof Error?e.message:"Unknown error")}finally{h(!1)}}},[r]);(0,s.useEffect)(()=>{e&&(b(),setTimeout(()=>{g.current?.focus()},100))},[e,b]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let v=c.filter(e=>{if(!f)return!0;let t=f.toLowerCase();return e.title.toLowerCase().includes(t)||e.firstMessages.some(e=>e.toLowerCase().includes(t))||e.lastMessages.some(e=>e.toLowerCase().includes(t))});return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-6xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("sessions.sessionList")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:r,children:r})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsx)("input",{ref:g,type:"text",placeholder:i("sessions.searchSessions"),value:f,onChange:e=>p(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[u&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:i("sessions.loadingSessions")})]})}),m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:m})}),!u&&!m&&0===v.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:i(f?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!u&&!m&&v.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:v.map(e=>(0,n.jsxs)("div",{onClick:()=>{let n;return n=(e.path.split("/").pop()||"").replace(".jsonl",""),void(a?(a(n,e.title),t()):window.parent.postMessage({type:"OPEN_PROJECT",cwd:r,sessionId:n},"*"))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:e.title,children:e.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[e.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),e.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},e.path))})]})]})]}):null}var a=r(47650),i=r(64428),c=r(64702),d=r(1058),u=r(90717),h=r(70188),m=r(48347),x=r(7320);function f(e,t){let r=e.split("\n"),n=t.split("\n"),s=[],o=r.length,l=n.length,a=Array(o+1).fill(null).map(()=>Array(l+1).fill(0));for(let e=1;e<=o;e++)for(let t=1;t<=l;t++)r[e-1]===n[t-1]?a[e][t]=a[e-1][t-1]+1:a[e][t]=Math.max(a[e-1][t],a[e][t-1]);let i=o,c=l,d=[];for(;i>0||c>0;)i>0&&c>0&&r[i-1]===n[c-1]?(d.push({type:"unchanged",content:r[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||a[i][c-1]>=a[i-1][c])?(d.push({type:"added",content:n[c-1],newLineNum:c}),c--):(d.push({type:"removed",content:r[i-1],oldLineNum:i}),i--);for(;d.length>0;)s.push(d.pop());return s}var p=r(34075),g=r(56978),b=r(17196);function v({lines:e,containerRef:t}){let r=(0,s.useRef)(null),[o,l]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:s}=e,o=r.current?.clientHeight||0;if(n<=s)l({top:0,height:o});else{let e=o/n;l({top:t*e,height:s*e})}};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),()=>{e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}},[t]),0===e.length)return null;let a=100/e.length;return(0,n.jsxs)("div",{ref:r,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let n=t.current,s=r.current;if(!n||!s)return;let o=s.getBoundingClientRect(),l=(e.clientY-o.top)/o.height*n.scrollHeight-n.clientHeight/2;n.scrollTo({top:Math.max(0,l),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,n.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*a}%`,height:`${Math.max(a,.5)}%`,minHeight:"2px"}},t)),(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${o.top}px`,height:`${Math.max(o.height,10)}px`}})]})}var j=r(89109),y=r(37614);function w(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}let k=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:l,onSearch:a,isChatLoading:i}){let[c,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let u=(0,s.useMemo)(()=>e.current,[c]);return(0,n.jsx)(j.w,{x:u?.x??0,y:u?.y??0,visible:!!u,container:r,onAddComment:o,onSendToAI:l,onSearch:a,isChatLoading:i})});function N({oldContent:e,newContent:t,filePath:r,isNew:l=!1,isDeleted:i=!1,cwd:j,enableComments:C=!1,onPreview:S,previewLabel:L,onContentSearch:M,targetLine:E,compact:T=!1,symbols:$}){let{t:R}=(0,o.Bd)(),P=L??R("common.preview"),B=(0,s.useMemo)(()=>f(e,t),[e,t]),I=(0,s.useRef)(null),D=(0,s.useRef)(null),F=(0,s.useRef)(null),A=(0,s.useRef)(!1),[O,W]=(0,s.useState)(!1),z=(0,h.iN)(),H=(0,m.r)(),_=C&&!!j,{comments:q,addComment:V,updateComment:U,deleteComment:K,refresh:J}=(0,d._)({cwd:j||"",filePath:r}),[X,Y]=(0,s.useState)(null),Q=(0,s.useRef)(null),G=(0,s.useRef)(()=>{}),[Z,ee]=(0,s.useState)(null),[et,er]=(0,s.useState)(null);(0,s.useEffect)(()=>{W(!0)},[]);let en=(0,s.useMemo)(()=>{let e=new Set;for(let t of q)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[q]),es=(0,s.useMemo)(()=>{let e=new Map;for(let t of q){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[q]);(0,s.useEffect)(()=>{if(!_)return;let e=F.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,Q.current&&(Q.current=null,G.current())},o=e=>{t=!1;let s=e.target;if(s.closest?.(".floating-toolbar"))return;let o=Math.abs(e.clientX-r)>5||Math.abs(e.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed||!l.toString().trim()||!o){Q.current&&(Q.current=null,G.current());return}let a=l.getRangeAt(0),i=F.current;if(!i||!i.contains(a.commonAncestorContainer))return;let c=e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;for(;t&&t!==i;){let e=t.closest("[data-new-line]");if(e)return parseInt(e.getAttribute("data-new-line")||"0",10);t=t.parentElement}return null},d=c(a.startContainer),u=c(a.endContainer);if(d&&u){let t=Math.min(d,u),r=Math.max(d,u),n=[],s=0;for(let e of B)("unchanged"===e.type||"added"===e.type)&&++s>=t&&s<=r&&n.push(e.content);let o=n.join("\n");Q.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},codeContent:o},G.current()}},l=()=>{if(t||!Q.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(Q.current=null,G.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[_,B]);let eo=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),Q.current=null,G.current(),ee(null),er(null)},[]),el=(0,s.useCallback)(()=>{let e=Q.current;e&&(ee({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),Q.current=null,G.current())},[]),ea=(0,s.useCallback)(()=>{let e=Q.current;e&&(er({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),Q.current=null,G.current())},[]),ei=(0,s.useCallback)(()=>{let e=Q.current;if(!e||!M)return;let t=e.codeContent.trim();Q.current=null,G.current(),t&&M(t)},[M]),ec=(0,s.useCallback)(async e=>{if(et&&H&&j)try{let t=await (0,u.$3)(j),n=[];for(let e of t)n.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});n.push({filePath:r,startLine:et.range.start,endLine:et.range.end,codeContent:et.codeContent});let s=(0,u.Gw)(n,e);H.sendMessage(s),await (0,u.RP)(j),J(),er(null)}catch(e){console.error("Failed to send to AI:",e)}},[et,H,r,j,J]),ed=(0,s.useCallback)(async e=>{Z&&(await V(Z.range.start,Z.range.end,e),ee(null))},[Z,V]);(0,s.useEffect)(()=>{let e=D.current,t=F.current;if(!e||!t)return;let r=(e,t)=>{A.current||(A.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{A.current=!1}))},n=()=>r(e,t),s=()=>r(t,e);return e.addEventListener("scroll",n),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",n),t.removeEventListener("scroll",s)}},[]);let{leftLines:eu,rightLines:eh}=(0,s.useMemo)(()=>{let e=[],t=[],r=0,n=0;for(let s=0;s<B.length;s++){let o=B[s];if("unchanged"===o.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});r++,n++,e.push({lineNum:r,content:o.content,type:"unchanged",originalIdx:s}),t.push({lineNum:n,content:o.content,type:"unchanged",originalIdx:s})}else"removed"===o.type?(r++,e.push({lineNum:r,content:o.content,type:"removed",originalIdx:s})):"added"===o.type&&(n++,t.push({lineNum:n,content:o.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[B]),em=(0,s.useMemo)(()=>B.map(e=>e.content),[B]),ex=(0,g.C)(em,r),[ef,ep]=(0,s.useState)(()=>new Map);(0,s.useEffect)(()=>{ep(new Map),ek.measure()},[eu,eh]);let eg=(0,s.useMemo)(()=>$??[],[$]),{rows:eb,gaps:ev}=(0,s.useMemo)(()=>T?function(e,t,r,n=[]){let s=e.length,o=r=>"unchanged"!==e[r].type||"unchanged"!==t[r].type,l=new Set;for(let e=0;e<s;e++){if(!o(e))continue;let t=Math.max(0,e-3),r=Math.min(s-1,e+3);for(let e=t;e<=r;e++)l.add(e)}let a=[];for(let e=0;e<s;e++){if(l.has(e))continue;let t=e;for(;e<s&&!l.has(e);)e++;a.push({id:a.length,startIdx:t,endIdx:e-1}),e--}for(let e of a){let t=r.get(e.id)??{topRevealed:0,bottomRevealed:0},n=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,n)),o=Math.max(0,Math.min(t.bottomRevealed,n-s));for(let t=e.startIdx;t<e.startIdx+s;t++)l.add(t);for(let t=e.endIdx-o+1;t<=e.endIdx;t++)l.add(t)}let i=[];for(let e=0;e<s;e++){let r;if(l.has(e)){i.push({kind:"diff",idx:e});continue}let o=e;for(;e<s&&!l.has(e);)e++;let c=e-1;e--;let d=a.find(e=>e.startIdx<=o&&c<=e.endIdx);if(!d)continue;let u=c-o+1,h=Math.min(20,u);if(n.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){r=function(e,t){let r=null;for(let n of e)n.startLine<=t&&t<=n.endLine&&(!r||n.endLine-n.startLine<r.endLine-r.startLine)&&(r=n);return r}(n,s)??void 0;break}}i.push({kind:"gap-expand",gapId:d.id,direction:"up",revealCount:h}),i.push({kind:"gap-label",gapId:d.id,hiddenCount:u,enclosingFn:r}),i.push({kind:"gap-expand",gapId:d.id,direction:"down",revealCount:h})}return{rows:i,gaps:a}}(eu,eh,ef,eg):{rows:eu.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[T,eu,eu,eh,ef,eg]),ej=(0,s.useCallback)((e,t)=>{let r=ev.find(t=>t.id===e);r&&ep(n=>{let s=n.get(e)??{topRevealed:0,bottomRevealed:0},o=r.endIdx-r.startIdx+1-s.topRevealed-s.bottomRevealed;if(o<=0)return n;let l=Math.min(20,o),a="up"===t?{...s,topRevealed:s.topRevealed+l}:{...s,bottomRevealed:s.bottomRevealed+l};return new Map(n).set(e,a)})},[ev]),ey=(0,s.useCallback)(e=>{for(let t of ev)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ev]),ew=(0,s.useCallback)(e=>eb[e]?.kind==="gap-label"?28:20,[eb]),ek=(0,c.Te)({count:eb.length,getScrollElement:()=>I.current,estimateSize:ew,overscan:20}),eN=l?"w-1/4":i?"w-3/4":"w-1/2",eC=l?"w-3/4":i?"w-1/4":"w-1/2",eS=(0,s.useMemo)(()=>eb.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=eu[e.idx],r=eh[e.idx];return"removed"===t.type?{type:"removed"}:r?.type==="added"?{type:"added"}:{type:"unchanged"}}),[eb,eu,eh]),eL=ek.getTotalSize(),eM=ek.getVirtualItems();return(0,s.useEffect)(()=>{if(!E)return;let e=("after"===E.side?eh:eu).findIndex(e=>e.lineNum===E.line);if(-1===e)return;let t=eb.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=ey(e);if(null!==t){let e=ev.find(e=>e.id===t);if(!e)return;let r=e.endIdx-e.startIdx+1;ep(e=>{let n=e.get(t)??{topRevealed:0,bottomRevealed:0};if(n.topRevealed+n.bottomRevealed>=r)return e;let s=new Map(e);return s.set(t,{topRevealed:r,bottomRevealed:0}),s})}return}let r=requestAnimationFrame(()=>{ek.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(r)},[E,eu,eh,eb]),(0,n.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,n.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,n.jsx)("div",{className:`${eN} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:l?"(New File)":i?"Deleted":"Old"}),(0,n.jsxs)("div",{className:`${eC} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,n.jsx)("span",{className:"block text-center",children:i?"(Deleted)":"New"}),(0,n.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[S&&(0,n.jsx)("button",{onClick:S,className:"text-muted-foreground hover:text-foreground transition-colors",children:P}),!i&&t&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,p.oR)(R("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:R("common.copy")})]})]}),(0,n.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:I,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,n.jsxs)("div",{className:"flex",style:{height:`${eL}px`},children:[(0,n.jsx)("div",{ref:D,className:`${eN} overflow-x-auto border-r border-border`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eM.map(e=>{let t=eb[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let r="gap-label"===t.kind;return(0,n.jsx)("div",{ref:ek.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:r?"bg-accent border-y border-border":""},e.key)}let r=eu[t.idx];return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===r.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:r.lineNum||""}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r.originalIdx>=0&&ex[r.originalIdx]||(0,b.ZD)(r.content||" ")}})]},e.key)})})}),(0,n.jsx)("div",{ref:F,className:`${eC} overflow-x-auto`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eM.map(e=>{let t=eb[e.index];if("gap-expand"===t.kind)return(0,n.jsx)("button",{ref:ek.measureElement,"data-index":e.index,type:"button",onClick:()=>ej(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,n.jsx)("span",{className:"select-none",children:R("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:R("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,n.jsx)("span",{className:"truncate min-w-0 font-medium",title:w(t.enclosingFn),children:w(t.enclosingFn)})]})]},e.key);let r=eh[t.idx],s=r?.lineNum||0,o=s>0&&en.has(s),l=es.get(s),a=l?.[0],i=Z&&s>=Z.range.start&&s<=Z.range.end,c=et&&s>=et.range.start&&s<=et.range.end,d=i||c;return(0,n.jsxs)("div",{ref:ek.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${d?"bg-blue-9/20":o?"bg-amber-9/10":r?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${d?"bg-blue-9/30":""}`,style:{width:_?"52px":"40px"},children:[_&&s>0&&o&&a&&(0,n.jsx)("button",{onClick:e=>eo(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:R("codeViewer.nComments",{count:l?.length}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),_&&s>0&&!o&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r?.originalIdx>=0&&ex[r.originalIdx]||(0,b.ZD)(r?.content||" ")}})]},e.key)})})})]})}),(0,n.jsx)(v,{lines:eS,containerRef:I})]}),O&&z&&(0,a.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(k,{floatingToolbarRef:Q,bumpRef:G,container:z,onAddComment:el,onSendToAI:ea,onSearch:M?ei:void 0,isChatLoading:H?.isLoading??!1}),Z&&(0,n.jsx)(x.t,{x:Z.x,y:Z.y,range:Z.range,codeContent:Z.codeContent,container:z,onSubmit:ed,onClose:()=>ee(null)}),et&&(0,n.jsx)(x.G,{x:et.x,y:et.y,range:et.range,container:z,onSubmit:ec,onClose:()=>er(null)}),X&&(0,n.jsx)(y.t,{x:X.x,y:X.y,comment:X.comment,container:z,onClose:()=>Y(null),onUpdateComment:U,onDeleteComment:K})]}),z)]})}function C({oldContent:e,newContent:t,filePath:r}){let o=(0,s.useMemo)(()=>f(e,t),[e,t]),l=(0,s.useRef)(null),a=(0,s.useMemo)(()=>o.map(e=>e.content),[o]),i=(0,g.C)(a,r),d=(0,c.Te)({count:o.length,getScrollElement:()=>l.current,estimateSize:()=>20,overscan:20});return(0,n.jsx)("div",{ref:l,className:"font-mono text-sm overflow-auto h-full",children:(0,n.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=o[e.index];return(0,n.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,n.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,n.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:i[e.index]||(0,b.ZD)(t.content||" ")}})]},e.key)})})})}let S={ts:"#3178c6",tsx:"#3178c6",js:"#f1e05a",jsx:"#61dafb",mjs:"#f1e05a",cjs:"#f1e05a",html:"#e44d26",css:"#563d7c",scss:"#cd6799",sass:"#cd6799",less:"#1d365d",vue:"#41b883",svelte:"#ff3e00",json:"#cbcb41",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4121",xml:"#e37933",env:"#ecd53f",md:"#519aba",mdx:"#519aba",txt:"#89898a",py:"#3572a5",go:"#00add8",rs:"#dea584",java:"#b07219",kt:"#a97bff",kts:"#a97bff",c:"#555555",h:"#555555",cpp:"#f34b7d",hpp:"#f34b7d",rb:"#701516",php:"#4f5d95",sh:"#89e051",bash:"#89e051",zsh:"#89e051",png:"#a074c4",jpg:"#a074c4",jpeg:"#a074c4",gif:"#a074c4",svg:"#ffb13b",webp:"#a074c4",ico:"#a074c4",lock:"#89898a",gitignore:"#f14e32",dockerfile:"#2496ed",sql:"#e38c00",graphql:"#e535ab",gql:"#e535ab",default:"#8a8a8a"},L={"package.json":"#cb3837","package-lock.json":"#cb3837","tsconfig.json":"#3178c6","jsconfig.json":"#f1e05a",".gitignore":"#f14e32",".eslintrc":"#4b32c3",".eslintrc.js":"#4b32c3",".eslintrc.json":"#4b32c3",".prettierrc":"#56b3b4",dockerfile:"#2496ed",".env":"#ecd53f",".env.local":"#ecd53f",".env.development":"#ecd53f",".env.production":"#ecd53f","readme.md":"#519aba",license:"#d4af37",makefile:"#6d8086","cargo.toml":"#dea584","go.mod":"#00add8","go.sum":"#00add8","requirements.txt":"#3572a5","yarn.lock":"#2c8ebb","pnpm-lock.yaml":"#f9ad00","vite.config.ts":"#646cff","vite.config.js":"#646cff","next.config.js":"#000000","next.config.mjs":"#000000","tailwind.config.js":"#38bdf8","tailwind.config.ts":"#38bdf8"};function M({name:e,className:t="",size:r=16}){let s,o=L[s=e.toLowerCase()]?L[s]:S[e.split(".").pop()?.toLowerCase()||""]||S.default,l=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===l||"tsx"===l&&e.includes("component")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:o})]}):["md","mdx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,n.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:o}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:o,strokeWidth:"2",fill:"none"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:o}),(0,n.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:o}),(0,n.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"html"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,n.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===l||".gitignore"===e.toLowerCase()?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:o}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,n.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===l||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:o}),(0,n.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"env"===l||e.startsWith(".env")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:o}),(0,n.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"vue"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:o}),(0,n.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.5",fill:"none"})]})}function E({status:e}){let{label:t,className:r}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,n.jsx)("span",{className:`text-xs font-bold ${r}`,children:t})}let T=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let h=o===t.path,m=l.has(t.path),x=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):a(t)},[t,a,i]),f=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(e,t.path,t.isDirectory)},[t.path,t.isDirectory,c]);return t.isDirectory?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*r+8}px`},onClick:x,onContextMenu:f,children:[(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:m?"▼":"▶"}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),u&&u(t)]}),m&&t.children.map(t=>(0,n.jsx)(e,{node:t,level:r+1,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d,renderActions:u},t.path))]}):(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${h?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:x,onContextMenu:f,children:[(0,n.jsx)(M,{name:t.name,size:16,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:`text-sm flex-1 truncate ${h?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,n.jsx)(E,{status:t.status}),d&&void 0!==t.additions&&void 0!==t.deletions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,n.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),u&&u(t)]})});function $({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,cwd:a,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:m}=(0,o.Bd)(),x=d??m("gitFileTree.noFiles"),{contextMenu:f,showContextMenu:p,hideContextMenu:g}=(0,h.Ee)();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:x}):(0,n.jsxs)("div",{className:u||"py-1",children:[e.map(e=>(0,n.jsx)(T,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,onContextMenu:p,showChanges:i,renderActions:c},e.path)),f&&(0,n.jsx)(h.ft,{x:f.x,y:f.y,path:f.path,cwd:a,isDirectory:f.isDirectory,onClose:g})]})}function R(e){let t=[];for(let r of e){let e=r.path.split("/"),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,l=e.slice(0,t+1).join("/"),a=n.find(e=>e.name===s);a||(a={name:s,path:l,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(a)),o||(n=a.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t}function P(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function B(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}var I=r(69809);function D(e){try{let t=JSON.parse(e);return _(t,0)}catch{return e}}let F="#79c0ff",A="#a5d6ff",O="#ff7b72",W="#8b949e",z=(e,t)=>s.createElement("span",{style:{color:e}},t);function H({label:e,labelColor:t,value:r,indent:n}){let[o,l]=s.useState(!1),[a,i]=s.useState({x:0,y:0}),c="string"==typeof r&&r.replace(/\\n/g,"\n").split("\n").length>3,d={onMouseDown:e=>{i({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-a.x,r=e.clientY-a.y;t*t+r*r>25||(e.stopPropagation(),l(e=>!e))},style:{cursor:"pointer"}};if(c&&o&&"string"==typeof r){let n=r.replace(/\\n/g,"\n").split("\n")[0],o=r.replace(/\\n/g,"\n").split("\n").length;return s.createElement("span",d,z(t,e),z(W,": "),z(A,n),z("#6e7681",` ${I.A.t("toolCall.foldedLines",{count:o})}`))}let u=s.createElement(s.Fragment,null,z(t,e),z(W,": "),_(r,n));return c?s.createElement("span",d,u):u}function _(e,t){let r=" ".repeat(t);if(null===e)return z(O,"null");if(void 0===e)return z(O,"undefined");if("string"==typeof e)return z(A,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+r));if("number"==typeof e)return z("#79c0ff",String(e));if("boolean"==typeof e)return z(O,String(e));if(Array.isArray(e))return 0===e.length?z(W,"[]"):s.createElement(s.Fragment,null,z(W,"["),"\n",...e.map((n,o)=>s.createElement("span",{key:o},r+" ",s.createElement(H,{label:`[${o}]`,labelColor:F,value:n,indent:t+1}),o<e.length-1?s.createElement(s.Fragment,null,z(W,","),"\n"):"\n")),r,z(W,"]"));if("object"==typeof e){let n=Object.entries(e);return 0===n.length?z(W,"{}"):s.createElement(s.Fragment,null,z(W,"{"),"\n",...n.map(([e,o],l)=>s.createElement("span",{key:e},r+" ",s.createElement(H,{label:e,labelColor:F,value:o,indent:t+1}),l<n.length-1?s.createElement(s.Fragment,null,z(W,","),"\n"):"\n")),r,z(W,"}"))}return String(e)}let q=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function V(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return q.has(t)}function U(e){return e.toLowerCase().endsWith(".md")}let K="json-search-highlight-style";function J(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(0),h=(0,s.useRef)(null),m=(0,s.useRef)([]),x=(0,s.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),m.current=[];let r=e.current;if(!r||!n){c(0),u(0);return}!function(){if(document.getElementById(K))return;let e=document.createElement("style");e.id=K,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let s=r.textContent||"",o=l?n:n.toLowerCase(),a=l?s:s.toLowerCase(),i=[],d=0;for(;d<a.length;){let e=a.indexOf(o,d);if(-1===e)break;i.push([e,e+o.length]),d=e+1}if(0===i.length){c(0),u(0);return}let h=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),x=0,f=0,p=[],g=null,b=0;for(;(t=h.nextNode())&&f<i.length;){let e=t.textContent?.length||0,r=x,n=x+e;for(;f<i.length;){let[e,s]=i[f];if(e>=n)break;if(!g)if(e>=r)(g=document.createRange()).setStart(t,e-r),b=s;else break;if(b<=n)g.setEnd(t,b-r),p.push(g),g=null,f++;else break}x=n}m.current=p,c(p.length),u(e=>p.length>0?Math.min(e,p.length-1):0),CSS.highlights&&p.length>0&&CSS.highlights.set("json-search",new Highlight(...p))},[e,n,l]),f=(0,s.useCallback)((e,t)=>{let r=e.getBoundingClientRect();(t.top<r.top||t.bottom>r.bottom)&&(e.scrollTop+=t.top-r.top-r.height/2+t.height/2)},[]),p=(0,s.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let r=m.current[t];if(!r||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(r));let n=r.getBoundingClientRect(),s=e.current?.parentElement;s&&f(s,n)},[e,f]);(0,s.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,s.useEffect)(()=>{p(d)},[d,i,p]),(0,s.useEffect)(()=>{let t=e.current;if(!t||!n)return;let r=new MutationObserver(()=>x());return r.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>r.disconnect()},[e,n,x]),(0,s.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),m.current=[])},[t]),(0,s.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let g=(0,s.useCallback)(()=>{0!==i&&u(e=>(e+1)%i)},[i]),b=(0,s.useCallback)(()=>{0!==i&&u(e=>(e-1+i)%i)},[i]),v=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>h.current?.focus(),0)},[]),j=(0,s.useCallback)(()=>{r(!1),o(""),u(0)},[]),y=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?b():g()),"Escape"===e.key&&(e.preventDefault(),j())},[g,b,j]);return{isVisible:t,query:n,setQuery:o,caseSensitive:l,setCaseSensitive:a,matchCount:i,currentIndex:d,searchInputRef:h,open:v,close:j,goToNext:g,goToPrev:b,handleKeyDown:y}}function X({search:e}){return e.isVisible?s.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},s.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:I.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),s.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:I.A.t("codeViewer.caseSensitive")},"Aa"),s.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:I.A.t("common.noMatch")),s.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:I.A.t("common.previous")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),s.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:I.A.t("common.next")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),s.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:I.A.t("common.close")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}function Y({isOpen:e,onClose:t,commit:r,cwd:l,embedded:a=!1,initialFilePath:i,onContentSearch:c}){let{t:d}=(0,o.Bd)(),[u,h]=(0,s.useState)([]),[m,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),M=(0,s.useRef)(null),E=J(M);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&S){e.preventDefault(),E.open();return}if("Escape"===e.key){if(E.isVisible)return void E.close();if(S)return void L(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,S,E]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{h([]),x([]),b(null),j(null),w(!0)}),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];h(t);let n=R(t);if(x(n),p(new Set(P(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{b(e),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error)},0)}}).catch(console.error).finally(()=>w(!1)))},[e,r,l,i]);let T=(0,s.useCallback)(e=>{r&&(b(e),C(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>C(!1)))},[l,r]),B=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),I=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,l,a;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),l=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${l}:${a}`:`${e.getFullYear()}-${s}-${o} ${l}:${a}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]);if(!e||!r)return null;let F=(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border bg-secondary flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-2",children:r.subject}),r.body&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground whitespace-pre-wrap mb-3 max-h-32 overflow-y-auto border-l-2 border-border pl-3",children:r.body}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.hash")}),(0,n.jsx)("span",{className:"font-mono bg-accent px-1.5 py-0.5 rounded",children:r.hash})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-slate-9",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.date")}),(0,n.jsx)("span",{children:I}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-slate-9",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:d("commitDetail.files")}),(0,n.jsx)("span",{children:d("commitDetail.nChanges",{count:u.length})})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto overflow-x-hidden",children:y?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:d("commitDetail.loadingFiles")}):(0,n.jsx)($,{files:m,selectedPath:g?.path||null,expandedPaths:f,onSelect:e=>e.file&&T(e.file),onToggle:B,cwd:l,showChanges:!0,emptyMessage:d("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:k?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:d("commitDetail.loadingDiff")}):v?(0,n.jsx)(N,{oldContent:v.oldContent,newContent:v.newContent,filePath:v.filePath,isNew:v.isNew,isDeleted:v.isDeleted,cwd:l,enableComments:!0,onPreview:!v.isDeleted&&v.filePath.endsWith(".json")?()=>L({content:v.newContent,filePath:v.filePath}):void 0,previewLabel:d("common.readable"),onContentSearch:c}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:d("commitDetail.selectFileToView")})})]})]}),A=S&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>L(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:S.filePath}),(0,n.jsx)("button",{onClick:()=>L(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(X,{search:E}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:M,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:D(S.content)})})]})});return a?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title:d("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),F,A]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("commitDetail.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),F,A]})})}let Q={M:{text:"text-amber-11",bg:"bg-amber-9/20"},A:{text:"text-green-11",bg:"bg-green-9/20"},D:{text:"text-red-11",bg:"bg-red-9/20"},"?":{text:"text-slate-9",bg:"bg-slate-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},G=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:l,onToggle:a,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:h,hasChangedChildren:m}=e,x=h?Q[h]:null,f=(0,s.useCallback)(()=>{d.isDirectory?a(d.path):l(d.path)},[d.isDirectory,d.path,l,a]),p=(0,s.useCallback)(e=>{i(e,d.path,d.isDirectory)},[d.path,d.isDirectory,i]),g=!d.isDirectory&&(".env"===d.name||d.name.startsWith(".env.")),b=h?x.text:m?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!d.isDirectory?"text-brand":"text-foreground";return(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 cursor-pointer hover:bg-accent ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[d.isDirectory?o?(0,n.jsxs)("svg",{className:"w-4 h-4 flex-shrink-0 text-muted-foreground animate-spin",viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):(0,n.jsx)("svg",{className:`w-4 h-4 flex-shrink-0 text-muted-foreground transition-transform ${r?"rotate-90":""}`,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M6 4 L10 8 L6 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)(M,{name:d.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":d.isSymlink&&d.symlinkTarget?`${d.path} → ${d.symlinkTarget}`:d.path,children:d.name}),d.isSymlink&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:"→"}),h&&(0,n.jsx)("span",{className:`text-xs font-mono px-1 rounded ${x.text} ${x.bg} flex-shrink-0`,children:h}),d.isDirectory&&m&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),c?.(d)]})});function Z({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:l=null,loadingDirs:a,onSelect:i,onToggle:d,cwd:u,shouldScrollToSelected:m=!1,onScrolledToSelected:x,className:f,renderActions:p,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y}){let w=(0,s.useRef)(null),{contextMenu:k,showContextMenu:N,hideContextMenu:C}=(0,h.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let l=[];for(let a of t){if(null!==n&&!n.has(a.path))continue;let t=s?.get(a.path),i=a.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(a.path,s):void 0;l.push({node:a,level:o,gitStatus:t,hasChangedChildren:i}),a.isDirectory&&a.children&&r.has(a.path)&&l.push(...e(a.children,r,n,s,o+1))}return l})(e,r,o,l),[e,r,o,l]),L=(0,c.Te)({count:S.length,getScrollElement:()=>w.current,estimateSize:()=>26,overscan:10}),M=(0,s.useRef)(x);return(M.current=x,(0,s.useEffect)(()=>{if(m&&t&&S.length>0){let e=S.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{L.scrollToIndex(e,{align:"center"}),M.current?.()},150);return()=>clearTimeout(t)}}},[m,t,S,L]),0===S.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:w,className:f||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${L.getTotalSize()}px`,width:"100%",position:"relative"},children:L.getVirtualItems().map(e=>{let s=S[e.index];return(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},children:(0,n.jsx)(G,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:a?.has(s.node.path),onSelect:i,onToggle:d,onContextMenu:N,renderActions:p})},s.node.path)})}),k&&(0,n.jsx)(h.ft,{x:k.x,y:k.y,path:k.path,cwd:u,isDirectory:k.isDirectory,onClose:C,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y})]})}var ee=r(38408),et=r(82292),er=r(45048),en=r(97251),es=r(47176),eo=r(79968);function el(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let r=t.closest("[data-source-start]");if(!r)return null;let n=r.getAttribute("data-source-start"),s=r.getAttribute("data-source-end");return n&&s?{start:parseInt(n,10),end:parseInt(s,10)}:null}let ea=[en.W];function ei({content:e,filePath:t,cwd:r,onClose:l,sourceFile:i}){let c=i||(r&&t.startsWith(r)?t.slice(r.endsWith("/")?r.length:r.length+1):t),{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(()=>{}),v=(0,h.iN)(),w=(0,m.r)(),{comments:k,addComment:N,updateComment:C,deleteComment:S,refresh:L}=(0,d._)({cwd:r,filePath:t}),[M,E]=(0,s.useState)(!1),[T,$]=(0,s.useState)(null),[R,P]=(0,s.useState)(null),[B,I]=(0,s.useState)(null),D=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>E(!0))},[]),(0,s.useEffect)(()=>{let e=p.current;if(!e)return;let t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,g.current&&(g.current=null,b.current())},o=s=>{t=!1;let o=s.target;if(o.closest?.(".floating-toolbar")||o.closest?.("[data-comment-card]"))return;let l=Math.abs(s.clientX-r)>5||Math.abs(s.clientY-n)>5,a=window.getSelection();if(!a||a.isCollapsed){g.current=null,b.current();return}let i=a.toString();if(!i.trim()||!l){g.current=null,b.current();return}let c=a.getRangeAt(0);if(!e.contains(c.commonAncestorContainer))return;let d=el(c.startContainer),u=el(c.endContainer);if(d&&u){let e=Math.min(d.start,u.start),t=Math.max(d.end,u.end);g.current={x:s.clientX,y:s.clientY,range:{start:e,end:t},selectedText:i},b.current()}},l=()=>{if(t||!g.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(g.current=null,b.current())};return e.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[]);let F=(0,s.useCallback)(()=>{let e=g.current;e&&($({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),A=(0,s.useCallback)(()=>{let e=g.current;e&&(P({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),O=(0,s.useCallback)(async e=>{T&&(await N(T.range.start,T.range.end,e),$(null))},[T,N]),W=(0,s.useCallback)(async e=>{if(R&&w)try{let n=await (0,u.$3)(r),s=[];for(let e of n)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});let o=Math.max(0,R.range.start-1),l=Math.min(D.length,R.range.end),a=D.slice(o,l).join("\n");s.push({filePath:t,startLine:R.range.start,endLine:R.range.end,codeContent:a});let i=(0,u.Gw)(s,e);w.sendMessage(i),await (0,u.RP)(r),L(),P(null)}catch(e){console.error("Failed to send to AI:",e)}},[R,w,t,r,D,L]),z=(0,s.useMemo)(()=>{if(0===k.length)return[];let e=new Map;for(let t of k){let r=`${t.startLine}-${t.endLine}`;e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[k]),[H,_]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===z.length||!p.current)return void queueMicrotask(()=>_([]));let e=setTimeout(()=>{let e=p.current;if(!e)return;let t=[],r=e.querySelectorAll("[data-source-start]");for(let n of z){let s=null,o=1/0;for(let e of r){let t=parseInt(e.getAttribute("data-source-start"),10),r=parseInt(e.getAttribute("data-source-end"),10);if(t<=n.startLine&&r>=n.endLine){let n=r-t;n<o&&(o=n,s=e)}}if(s){let r=e.getBoundingClientRect(),o=s.getBoundingClientRect();t.push({key:n.key,top:o.top-r.top+e.scrollTop,comments:n.comments})}}_(t)},100);return()=>clearTimeout(e)},[z,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(R){P(null),e.stopPropagation();return}if(T){$(null),e.stopPropagation();return}if(g.current){g.current=null,b.current(),e.stopPropagation();return}if(B){I(null),e.stopPropagation();return}l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[R,T,B,l]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:t}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(eo.ShareReviewToggle,{content:e,sourceFile:c}),(0,n.jsx)("button",{onClick:l,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(es.l,{content:e,containerRef:p}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:p,children:[(0,n.jsx)("div",{className:"p-6",children:(0,n.jsx)(er.T,{content:e,rehypePlugins:ea})}),H.map(({key:e,top:t,comments:r})=>(0,n.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),I({comment:r[0],x:e.clientX,y:e.clientY})},children:(0,n.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:r.length})},e))]})]}),M&&v&&(0,a.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:g,bumpRef:b,container:v,onAddComment:F,onSendToAI:A,isChatLoading:w?.isLoading}),T&&(0,n.jsx)(x.t,{x:T.x,y:T.y,range:T.range,codeContent:T.codeContent,container:v,onSubmit:O,onClose:()=>$(null)}),R&&(0,n.jsx)(x.G,{x:R.x,y:R.y,range:R.range,filePath:t,codeContent:R.codeContent,container:v,onSubmit:W,onClose:()=>P(null),isChatLoading:w?.isLoading}),B&&(0,n.jsx)(y.t,{x:B.x,y:B.y,comment:B.comment,container:v,onClose:()=>I(null),onUpdateComment:C,onDeleteComment:S})]}),v)]})}function ec({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),l=o>=0?e.slice(0,o+1):"",a=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],l="",a=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==a&&l&&(o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-${s}`):(0,n.jsx)("span",{children:l},`${t}-${s}`)),l=""),a=c,l+=e[s]}return l&&o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-end`):(0,n.jsx)("span",{children:l},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[l&&i(l,0,"text-muted-foreground"),i(a,l.length,"text-foreground")]})}function ed({files:e,fileIndex:t,recentFiles:r,onSelectFile:l,onClose:a}){let{t:c}=(0,o.Bd)(),[d,u]=(0,s.useState)(""),[h,m]=(0,s.useState)(0),x=(0,s.useRef)(null),f=(0,s.useRef)(null),p=(0,s.useMemo)(()=>{let r,n;return t??(r=[],(n=e=>{for(let t of e)t.isDirectory&&t.children?n(t.children):t.isDirectory||r.push(t.path)})(e),r)},[t,e]),g=(0,s.useMemo)(()=>{if(!d.trim()){let e=new Set(r);return[...r.map(e=>({path:e,score:0,matchedIndices:[]})),...p.filter(t=>!e.has(t)).slice(0,50).map(e=>({path:e,score:0,matchedIndices:[]}))]}let e=[];for(let t of p){let n=function(e,t){let r=e.toLowerCase(),n=t.toLowerCase(),s=[],o=0,l=0,a=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),a===i-1&&(l+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(l+=10),i>e.lastIndexOf("/")&&(l+=3),e[i]===t[o]&&(l+=1),a=i,o++);return o<n.length?null:(l-=.1*e.length,{path:e,score:l,matchedIndices:s})}(t,d.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[d,p,r]),b=(0,s.useCallback)(e=>{u(e),m(0)},[]);(0,s.useEffect)(()=>{x.current?.focus()},[]),(0,s.useEffect)(()=>{if(f.current){let e=f.current.children[h];e?.scrollIntoView({block:"nearest"})}},[h]);let v=(0,s.useCallback)(e=>{l(e),a()},[l,a]),j=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing)switch(e.key){case"ArrowDown":e.preventDefault(),m(e=>Math.min(e+1,g.length-1));break;case"ArrowUp":e.preventDefault(),m(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),g[h]&&v(g[h].path);break;case"Escape":e.preventDefault(),a()}},[g,h,v,a]);return(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:a,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-2xl overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref:x,value:d,onChange:e=>b(e.target.value),onKeyDown:j,placeholder:c("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",autoCorrect:"off",spellCheck:"false"}),(0,n.jsx)("kbd",{className:"text-[10px] text-muted-foreground px-1.5 py-0.5 rounded border border-border bg-secondary",children:"ESC"})]}),(0,n.jsx)("div",{ref:f,className:"flex-1 overflow-y-auto py-1",children:0===g.length?(0,n.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:c("quickFileOpen.noMatch")}):g.map((e,t)=>(0,n.jsxs)("div",{className:`px-3 py-1.5 flex items-center gap-2 cursor-pointer transition-colors ${t===h?"bg-brand/15 text-foreground":"hover:bg-accent text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(M,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(ec,{path:e.path,matchedIndices:e.matchedIndices}),!d.trim()&&r.includes(e.path)&&(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground px-1.5 py-0.5 rounded bg-secondary flex-shrink-0",children:c("quickFileOpen.recent")})]},e.path))}),(0,n.jsxs)("div",{className:"px-3 py-1.5 border-t border-border flex items-center gap-3 text-[10px] text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"↑↓"})," ",c("quickFileOpen.selectHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Enter"})," ",c("quickFileOpen.openHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Esc"})," ",c("quickFileOpen.closeHint")]})]})]})})})}var eu=r(84626),eh=r(41474),em=r(61878),ex=r(33210),ef=r(48368),ep=r(91958),eg=r(45916),eb=r(31794),ev=r(69048),ej=r(97567),ey=r(68806),ew=r(52475);function ek({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(ef.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(eg.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(eb.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(ev.A,{className:s});case"class":return(0,n.jsx)(ej.A,{className:s});case"interface":return(0,n.jsx)(ey.A,{className:s});default:return(0,n.jsx)(ew.A,{className:s})}}let eN=new Map,eC=new Map;async function eS(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){eN.clear(),eC.clear();return}let t=`${e}::`;for(let e of eN.keys())e.startsWith(t)&&eN.delete(e);for(let e of eC.keys())e.startsWith(t)&&eC.delete(e)}(e);else{let e=eN.get(n);if(e)return e;let t=eC.get(n);if(t)return t}let s=(async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);let l=await o.json();return eN.set(n,l),l})().finally(()=>eC.delete(n));return eC.set(n,s),s}function eL(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let l=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),eS(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?l(e,t,!1):n({state:"idle"})},[e,t,l]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&l(e,t,!0)},[e,t,l])}}var eM=r(3238),eE=r(50538),eT=r(94287);function e$({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-l border-border flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground font-mono min-w-0",children:[(0,n.jsx)(eE.A,{className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:0===e.length?s("blockViewer.history.title"):`${s("blockViewer.history.title")} \xb7 ${e.length}/15`})]}),e.length>0&&(0,n.jsx)(eT.m,{content:s("blockViewer.history.clear"),children:(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",children:(0,n.jsx)(ex.A,{className:"w-3 h-3"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:s("blockViewer.history.empty")}):e.map((e,r)=>{var s;let o;return(0,n.jsx)(eT.m,{content:`${e.qname} \xb7 ${e.filePath}`,children:(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:bg-secondary/60 transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(ek,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]})},`${e.filePath}::${e.qname}::${r}`)})})]})}function eR(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}let eP=new Set(["function","class","method"]);function eB(e){return eP.has(e.kind)}function eI({functions:e,currentQname:t,onSelect:r}){let{t:l}=(0,o.Bd)(),a=(0,s.useMemo)(()=>e.filter(eB),[e]);return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-r border-border flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground font-mono truncate",children:0===a.length?l("blockViewer.toc.title"):`${l("blockViewer.toc.title")} \xb7 ${a.length}`}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:l("blockViewer.toc.empty")}):a.map(e=>{let s=t===e.qualifiedName;return(0,n.jsx)(eT.m,{content:`${e.qualifiedName} \xb7 L${e.startLine}`,children:(0,n.jsxs)("button",{onClick:()=>r(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-center gap-1.5 min-w-0 ${s?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(ek,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs font-mono truncate ${s?"font-semibold text-brand":""}`,children:e.name})]})},e.qualifiedName)})})]})}function eD(e,t,r){if(!document.contains(e))return null;let n=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!n)return null;let s=n.closest("[data-line]");if(!s||!t.contains(s)||r&&!s.closest(r))return null;let o=s.getAttribute("data-line");if(!o)return null;let l=parseInt(o,10);return Number.isFinite(l)?l:null}var eF=r(96035);function eA({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,onCommentClick:l}){let a=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=a.get(n.endLine);e?e.push(n):a.set(n.endLine,[n])}return 0===a.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(a.entries()).map(([e,r])=>{let a=o+(e-t)*s,i=r[0],c=r.length-1;return(0,n.jsx)(eT.m,{content:1===r.length?i.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>l(i,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-sm transition-colors",style:{top:`${a+s/2-8}px`},children:[(0,n.jsx)(eF.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]})},e)})})}function eO(e,t){for(let r=0;r<e.blocks.length;r++){let n=e.blocks[r];if(t>=n.startLine&&t<=n.endLine)return e.prefix[r]+(t-n.startLine)}return null}function eW({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let l,a=(0,s.useRef)(null),i=(0,s.useMemo)(()=>(function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[0];for(let e of t){let t=Math.max(0,e.endLine-e.startLine+1);r.push(r[r.length-1]+t)}return{blocks:t,prefix:r,total:r[r.length-1]}})(t),[t]),c=(0,s.useMemo)(()=>{if(i.total<=0||0===e.size)return[];let t=[];for(let r of e){let e=i.blocks.find(e=>r>=e.startLine&&r<=e.endLine);e&&t.push({line:r,qname:e.qname})}t.sort((e,t)=>e.line-t.line);let r=[],n=null;for(let e of t)n&&e.line===n.end+1&&e.qname===n.qname?n.end=e.line:(n&&r.push(n),n={start:e.line,end:e.line,qname:e.qname});return n&&r.push(n),r},[e,i]);if(i.total<=0)return null;let d=(e,t)=>{let r=eO(i,e),n=eO(i,t);return null===r||null===n?null:{top:r/i.total*100,heightPct:(n-r+1)/i.total*100}};return(0,n.jsxs)("div",{ref:a,onClick:e=>{let t=a.current;if(!t)return;let r=t.getBoundingClientRect();if(r.height<=0)return;let n=function(e,t){if(e.total<=0)return null;let r=Math.max(0,Math.min(e.total-1,t));for(let t=0;t<e.blocks.length;t++){let n=e.prefix[t],s=e.prefix[t+1];if(r>=n&&r<s){let s=e.blocks[t];return{qname:s.qname,line:s.startLine+Math.round(r-n)}}}return null}(i,(e.clientY-r.top)/r.height*i.total);if(!n)return;let s=n.line,l=c.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(l)return void o(l.qname,s);if(c.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=eO(i,s);if(null!==t){let r=null,n=1/0;for(let e of c){let s=eO(i,e.start),o=eO(i,e.end);if(null===s||null===o)continue;let l=t<s?s-t:t>o?t-o:0;l<n&&(r=e,n=l)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let d=i.blocks.find(e=>e.qname===n.qname);d&&o(d.qname,d.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[c.map(e=>{let t=d(e.start,e.end);return t?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${t.top}%`,height:`${t.heightPct}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`):null}),r&&r.end>=r.start&&((l=d(r.start,r.end))?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${l.top}%`,height:`${Math.max(1.2,l.heightPct)}%`}}):null)]})}function ez(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eH({symbol:e,fileSource:t,hasChange:r,onHighlighted:o,comments:l,onCommentClick:a,addedLines:i}){let{resolvedTheme:c}=(0,eM.D)(),d=(0,s.useMemo)(()=>(0,b.sQ)(e.filePath),[e.filePath]),[u,h]=(0,s.useState)(null),[m,x]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!t)return void h(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,b.kS)()).codeToTokens(n,{lang:d,theme:"dark"===c?"github-dark":"github-light"}).tokens.map((t,r)=>{let n=e.startLine+r,s=i?.has(n)??!1;return`<div class="flex${s?" bg-green-9/15":""}" style="min-width:max-content" data-line="${n}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${n}</span><span class="whitespace-pre">${(0,b.b8)(t)}</span></div>`}).join("");r||(h(s),x(null))}catch(e){r||x(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,d,c,e.filePath,i]),(0,s.useEffect)(()=>{(null!==u||null!==m)&&o(e.qualifiedName)},[u,m,e.qualifiedName,o]),(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-secondary/40 text-xs",children:[(0,n.jsx)(ek,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:[e.kind," \xb7 L",e.startLine,"-",e.endLine]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${eq}px`},children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),m&&(0,n.jsx)("span",{className:"text-red-11",children:m}),u&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:u}})]}),l&&l.length>0&&a&&(0,n.jsx)(eA,{comments:l,startLine:e.startLine,endLine:e.endLine,lineHeight:eq,bodyTopOffset:eV+eU,onCommentClick:a})]})}function e_({side:e,pin:t,accent:r,onClick:s}){let o,l,a,i,c,d,u,h=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="ext",a="text-muted-foreground/60",i=t.name,c=t.packageSpec,d="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="method",a="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,c=null,d="method (unresolved)",u=h>0?`at line${h>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",l="self",a="text-muted-foreground/70",i=t.external.name,c=null,d="same-file",u=h>0?`at line${h>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",l=e,a="in"===e?"text-amber-11":"text-green-11",i=t.external.name,c=ez(t.external.filePath),d="in"===e?"caller":"callee",u=t.external.filePath);let m=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${m} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors flex items-center gap-1.5`,"data-tooltip":`${d}${u?" \xb7 "+u:""}`,children:[(0,n.jsx)("span",{className:`${a} text-[9px] uppercase tracking-wider font-semibold flex-shrink-0`,children:l}),(0,n.jsxs)("span",{className:"truncate flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:i}),c&&(0,n.jsx)("span",{className:"text-muted-foreground/70 ml-1",children:c}),h>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60 ml-1",children:["\xb7",h,"\xd7"]})]})]})}let eq=18,eV=29,eU=8;function eK(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function eJ(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function eX(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function eY({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:l,onHighlighted:a,comments:i,onCommentClick:c,accentQnames:d,addedLines:u}){let h=function(e,t){if(0===e.length)return[];let r=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});r.sort((e,t)=>e.line-t.line||e.i-t.i);let n=Array(e.length).fill(0),s=-1/0;for(let{i:e,line:o}of r){let r=Math.max(eV+eU+(o-t.startLine)*eq,s);n[e]=r,s=r+22}return n}(o,e);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:"w-44 flex-shrink-0 flex flex-col gap-1 pt-1",children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(e_,{side:"in",pin:t,accent:eJ(t,d),onClick:()=>l(t,e)},eK("in",t)))}),(0,n.jsx)(eH,{symbol:e,fileSource:t,hasChange:r,onHighlighted:a,comments:i,onCommentClick:c,addedLines:u}),(0,n.jsx)("div",{className:"w-44 flex-shrink-0 relative",children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${h[r]}px`},children:(0,n.jsx)(e_,{side:"out",pin:t,accent:eJ(t,d),onClick:()=>l(t,e)})},eK("out",t)))})]})}function eQ({cwd:e,onSelect:t,onClose:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(""),[c,d]=(0,s.useState)({files:[],symbols:[]}),[u,h]=(0,s.useState)(0),[m,x]=(0,s.useState)(!1),f=(0,s.useMemo)(()=>[...c.files,...c.symbols],[c]);(0,s.useEffect)(()=>{let t=a.trim();if(!t)return void d({files:[],symbols:[]});x(!0);let r=setTimeout(async()=>{try{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await fetch(`/api/projectGraph/search?${r}`);if(n.ok){let e=await n.json();d(e),h(0)}}finally{x(!1)}},120);return()=>clearTimeout(r)},[a,e]);let p=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==f.length){if("ArrowDown"===e.key)e.preventDefault(),h(e=>Math.min(e+1,f.length-1));else if("ArrowUp"===e.key)e.preventDefault(),h(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=f[u];r&&t(r)}}},[f,u,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-2xl overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(em.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:a,onChange:e=>i(e.target.value),onKeyDown:p,placeholder:l("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),m&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===f.length&&a&&!m&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:l("blockViewer.search.noResults","No matches")}),(0,n.jsx)(eG,{label:l("blockViewer.search.files","Files"),hits:c.files,startIdx:0,activeIdx:u,onSelect:t,setActive:h}),(0,n.jsx)(eG,{label:l("blockViewer.search.symbols","Symbols"),hits:c.symbols,startIdx:c.files.length,activeIdx:u,onSelect:t,setActive:h})]})]})})}function eG({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:l}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let a=r+t,i=a===s;return(0,n.jsxs)("button",{onMouseEnter:()=>l(a),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.target.kind?(0,n.jsx)(ef.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(ek,{kind:e.target.symbolKind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function eZ({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:l,enableComments:a=!1,onContentSearch:i,onFocalChange:c,qnameFilter:h,qnameFilterFile:f,accentQnames:p,accentFile:g,addedLines:b,addedLinesFile:v,headerExtraLeft:w,headerExtraRight:k}){let{t:N}=(0,o.Bd)(),[C,S]=(0,s.useState)(null),L=C??t??null;(0,s.useEffect)(()=>{S(null)},[t]),(0,s.useEffect)(()=>{c?.(L)},[L,c]);let{state:M,refresh:E}=eL(e,L),[T,$]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!L)return void $(null);let t=!1;return $(null),(async()=>{try{let r=new URLSearchParams({cwd:e,path:L}),n=await fetch(`/api/files/text?${r}`);if(!n.ok)return;let s=await n.json();t||$({content:s.content,mtimeMs:s.mtimeMs})}catch(e){console.error("[BlockViewer] failed to load file source for",L,e)}})(),()=>{t=!0}},[e,L]);let R=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!T||"ready"!==M.state)return;let e=M.data.mtimeMs;!e||T.mtimeMs<=e||R.current!==T.mtimeMs&&(R.current=T.mtimeMs,E())},[T,M,E]);let[P,B]=(0,s.useState)([]),[I,D]=(0,s.useState)(!1),[F,A]=(0,s.useState)(null),O=(0,s.useRef)(0),W=(0,s.useRef)(0),[z,H]=(0,s.useState)(()=>new Set),_="ready"===M.state?M.data.filePath:null;(0,s.useEffect)(()=>{H(new Set)},[_]);let q=(0,s.useCallback)(e=>{H(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),D(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let V=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;O.current+=1,A({filePath:e,qname:"__imports__",nonce:O.current});return}let r=eX(t),n=eX(e.external);B(e=>eR(eR(e,r),n)),S(n.filePath),O.current+=1,A({filePath:n.filePath,qname:n.qname,nonce:O.current})},[]),U=(0,s.useCallback)(e=>{S(e.filePath),O.current+=1,A({filePath:e.filePath,qname:e.qname,nonce:O.current})},[]),K=(0,s.useCallback)(e=>{D(!1),S(e.target.filePath),"symbol"===e.target.kind&&(O.current+=1,A({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.line,nonce:O.current}))},[]),J=(0,s.useCallback)((e,t)=>{L&&(O.current+=1,A({filePath:L,qname:e,line:t,nonce:O.current}))},[L]),[X,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!X)return;let e=null,t=()=>{e=null;let t=X.getBoundingClientRect();if(t.height<=0)return;let r=X.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let l=Number(r),a=Number(o);if(!Number.isFinite(l)||!Number.isFinite(a))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let c=Math.max(0,t.top-i.top),d=Math.min(i.height,t.bottom-i.top),u=a-l+1,h=Math.floor(c/i.height*u),m=Math.ceil(d/i.height*u)-1,x=l+Math.max(0,h),f=l+Math.min(u-1,Math.max(0,m));x<n&&(n=x),f>s&&(s=f)}),n===1/0||s===-1/0?G(null):G(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),X.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(X);let s=new MutationObserver(r);return s.observe(X,{childList:!0,subtree:!0}),()=>{X.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[X]);let Z=(0,s.useMemo)(()=>{if("ready"!==M.state||!Q)return null;let e=M.data.functions;if(0===e.length)return null;let t=(Q.start+Q.end)/2;for(let r of e)if(r.startLine<=t&&t<=r.endLine)return r.qualifiedName;let r=null;for(let t of e)t.startLine<=Q.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[M,Q]),ee=a&&!!e&&!!L,et=(0,m.r)(),{comments:er,addComment:en,updateComment:es,deleteComment:eo,refresh:el}=(0,d._)({cwd:e,filePath:L??""}),[ea,ei]=(0,s.useState)(null),{toolbar:ec,clearToolbar:ed}=function({enabled:e,container:t,bodyScope:r}){let[n,o]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!e||!t)return;let n=!1,s=0,l=0,a=e=>{n=!0,s=e.clientX,l=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||o(e=>e?null:e)},i=e=>{n=!1;let a=e.target;if(a?.closest?.(".floating-toolbar"))return;let i=Math.abs(e.clientX-s)>5||Math.abs(e.clientY-l)>5,c=window.getSelection();if(!c||c.isCollapsed||!c.toString().trim()||!i)return void o(e=>e?null:e);let d=c.getRangeAt(0);if(!t.contains(d.commonAncestorContainer))return void o(e=>e?null:e);let u=eD(d.startContainer,t,r),h=eD(d.endContainer,t,r);if(null==u||null==h)return void o(e=>e?null:e);let m=Math.min(u,h),x=Math.max(u,h);o({x:e.clientX,y:e.clientY,range:{start:m,end:x},selectedText:c.toString()})},c=()=>{if(n)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||o(e=>e?null:e)};return t.addEventListener("mousedown",a),document.addEventListener("mouseup",i),document.addEventListener("selectionchange",c),()=>{t.removeEventListener("mousedown",a),document.removeEventListener("mouseup",i),document.removeEventListener("selectionchange",c)}},[e,t,r]),{toolbar:n,clearToolbar:()=>o(null)}}({enabled:ee,container:ea}),[eu,eh]=(0,s.useState)(null),[em,ex]=(0,s.useState)(null),[ef,ep]=(0,s.useState)(null),eg=(0,s.useCallback)(()=>{ec&&(eh({x:ec.x,y:ec.y,range:ec.range,codeContent:ec.selectedText}),ed())},[ec,ed]),eb=(0,s.useCallback)(()=>{ec&&(ex({x:ec.x,y:ec.y,range:ec.range,codeContent:ec.selectedText}),ed())},[ec,ed]),ev=(0,s.useCallback)(()=>{if(!ec||!i)return;let e=ec.selectedText.trim();ed(),e&&i(e)},[ec,i,ed]),ej=(0,s.useCallback)(async e=>{eu&&(await en(eu.range.start,eu.range.end,e,eu.codeContent),eh(null))},[eu,en]),ey=(0,s.useCallback)(async t=>{if(em&&et&&e&&L)try{let r=(await (0,u.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:L,startLine:em.range.start,endLine:em.range.end,codeContent:em.codeContent});let n=(0,u.Gw)(r,t);et.sendMessage(n),await (0,u.RP)(e),el(),ex(null)}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[em,et,e,L,el]),ew=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ep({comment:e,x:t.clientX,y:t.clientY}),ed(),eh(null),ex(null)},[ed]);if((0,s.useEffect)(()=>{let e;if(!F||W.current>=F.nonce||"ready"!==M.state||!T||M.data.filePath!==F.filePath)return;if(f&&f===M.data.filePath&&h){let t=0;for(let e of M.data.functions)h.has(e.qualifiedName)&&t++;e=Math.max(1,t)}else e=Math.max(1,M.data.functions.length);if(z.size<e)return;W.current=F.nonce;let t=null,r=requestAnimationFrame(()=>{let e=F.qname.indexOf(">"),r=e>=0?F.qname.slice(0,e):F.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof F.line){let e=n.querySelector(`[data-line="${F.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"instant",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"instant",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[F,M,T,z,h,f]),!L)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:null,fileCount:null,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:N("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:N("blockViewer.empty.hint","or press ⌘K to search.")})]}),I&&(0,n.jsx)(eQ,{cwd:e,onSelect:K,onClose:()=>D(!1)})]});if("idle"===M.state||"loading"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N("blockViewer.fileMode.loading","Loading…")})]});if("notFound"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:N("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),I&&(0,n.jsx)(eQ,{cwd:e,onSelect:K,onClose:()=>D(!1)})]});if("error"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:null,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:M.message}),(0,n.jsx)("button",{onClick:E,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:N("blockViewer.retry","Retry")})]})]});let ek=M.data,eN=ek.functions;if(0===eN.length&&T){let e=Math.max(1,T.content.split("\n").length);eN=[{filePath:ek.filePath,qualifiedName:"__file__",name:ez(ek.filePath),kind:"unknown",startLine:1,endLine:e}]}let eC=f&&f===ek.filePath,eS=g&&g===ek.filePath,eM=v&&v===ek.filePath;eC&&h&&(eN=eN.filter(e=>h.has(e.qualifiedName)));let eE=eS?p:void 0,eT=eM?b:void 0,eP=e0(ek.upstreamCalls),eB=e0(ek.downstreamCalls),eF=new Map(eN.map(e=>[e.qualifiedName,e])),eA=new Map,eO=new Map;for(let e of ek.intraCalls){let t=eF.get(e.to),r=eF.get(e.from);if(t){let r=eA.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eA.set(e.from,[n])}if(r){let t=eO.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):eO.set(e.to,[n])}}let eH=new Map;for(let e of ek.externalCalls??[]){let t=eH.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):eH.set(e.focalQname,[r])}let e_=new Map;for(let e of ek.methodCalls??[]){let t=e_.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):e_.set(e.focalQname,[r])}let eq=r.has(ek.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(e1,{focalFile:L,fileCount:ek.fileCount,functionCount:ek.functions.length,upstreamCount:ek.upstreamCalls.length,downstreamCount:ek.downstreamCalls.length,onSwitchToCode:l,onSearch:()=>D(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{ref:ei,className:"flex-1 relative min-h-0 flex",children:[(0,n.jsx)(eI,{functions:eN,currentQname:Z,onSelect:J}),(0,n.jsx)("div",{ref:Y,className:"flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eN.map(e=>{let t,r,s,o,l,a;return(0,n.jsx)(eY,{symbol:e,fileSource:T?.content??null,hasChange:eq,upstream:(t=eP.get(e.qualifiedName),r=eO.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eB.get(e.qualifiedName),o=eA.get(e.qualifiedName),l=e_.get(e.qualifiedName),a=eH.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...l??[],...a??[]]),onPinClick:V,onHighlighted:q,comments:ee?er:void 0,onCommentClick:ee?ew:void 0,accentQnames:eE,addedLines:eT},e.qualifiedName)})})}),ee&&ec&&ea&&(0,n.jsx)(j.w,{x:ec.x,y:ec.y,visible:!0,container:ea,onAddComment:eg,onSendToAI:eb,onSearch:i?ev:void 0,isChatLoading:et?.isLoading}),ee&&eu&&(0,n.jsx)(x.t,{x:eu.x,y:eu.y,range:eu.range,codeContent:eu.codeContent,container:ea,onSubmit:ej,onClose:()=>eh(null)}),ee&&em&&L&&(0,n.jsx)(x.G,{x:em.x,y:em.y,range:em.range,filePath:L,codeContent:em.codeContent,container:ea,onSubmit:ey,onClose:()=>ex(null),isChatLoading:et?.isLoading}),ee&&ef&&(0,n.jsx)(y.t,{x:ef.x,y:ef.y,comment:ef.comment,container:ea,onClose:()=>ep(null),onUpdateComment:es,onDeleteComment:eo}),eT&&eT.size>0&&eN.length>0&&(0,n.jsx)(eW,{addedLines:eT,blockRanges:eN.map(e=>({qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine})),viewportRange:Q,onJumpToLine:J}),(0,n.jsx)(e$,{entries:P,onSelect:U,onClear:()=>B([])}),I&&(0,n.jsx)(eQ,{cwd:e,onSelect:K,onClose:()=>D(!1)})]})]})}function e0(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function e1({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:l,onSwitchToCode:a,onSearch:i,onRefresh:c,refreshDisabled:d,extraLeft:u,extraRight:h}){let{t:m}=(0,o.Bd)(),x={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:l??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between bg-secondary/30 gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof l&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",l," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(x)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[h&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:h(x)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":m("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(em.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:c,disabled:d,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":m("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(ep.A,{className:"w-3 h-3"})}),a&&(0,n.jsx)("button",{onClick:a,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:"Code"})]})]})}function e2(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function e5(e){return e.replace(/\s+/g," ").trim()}function e4(e,t){return e?`${e}>${t}`:t}function e3(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function e6(e,t,r,n,s=[],o){return{qualifiedName:e4(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e2(e5(e.text)),children:s,params:o}}function e8(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}function e9(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";default:return null}}var e7=r(14066);let te="/tree-sitter",tt=null,tr=new Map;async function tn(e){let t,r=await (!(t=tr.get(e))&&(t=(async()=>(await (!tt&&(tt=e7.iX.init({locateFile:e=>`${te}/${e}`})),tt),e7.TM.load(`${te}/tree-sitter-${e}.wasm`)))(),tr.set(e,t)),t),n=new e7.iX;return n.setLanguage(r),n}function ts(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function to(e){return!ts(e)&&"__file__"!==e.qualifiedName}async function tl(e,t){if(!e)return[];let r=e9(t);if(!r)return null;let n=(await tn(r)).parse(e);if(!n)return null;try{return function(e){let t=[],r=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,contentHash:e2(e5(t.map(e=>e.text).join("\n"))),children:[]}}(e);r&&t.push(r);for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);n&&t.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[e6(t,e3(t),"function",r,[],e8(t))];case"class_declaration":case"abstract_class_declaration":{let e=e3(t),n=e4(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(e6(s,e3(s),"method",t,[],e8(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(e6(s,e3(s),"method",t,[],e8(e)))}}}return r}(t.childForFieldName("body"),n);return[e6(t,e,"class",r,s)]}case"interface_declaration":return[e6(t,e3(t),"interface",r)];case"type_alias_declaration":return[e6(t,e3(t),"type",r)];case"enum_declaration":return[e6(t,e3(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),l=s.childForFieldName("value");if(!o)continue;let a=o.text,i=l&&("arrow_function"===l.type||"function_expression"===l.type),c=i&&l?e8(l):void 0;if(r.push(e6(e,a,i?"function":"const",t,[],c)),l&&"object"===l.type&&!i){let e=t?`${t}>${a}`:a;for(let t=0;t<l.namedChildCount;t++){let n=l.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(e6(n,t.text,"method",e,[],e8(s)))}else if("method_definition"===n.type){let t=e3(n);t&&r.push(e6(n,t,"method",e,[],e8(n)))}}}}}return r}(t,r);case"class_definition":{let e=e3(t),n=e4(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(e6(o,e3(o),"method",r,[],e8(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...e6(t,e3(t),"method",r,[],e8(t)),startLine:o.startPosition.row+1,contentHash:e2(e5(o.text))});else if(t?.type==="class_definition"){let s=e3(t),l=e4(r,s),a=e(t.childForFieldName("body"),l);n.push({...e6(t,s,"class",r,a),startLine:o.startPosition.row+1,contentHash:e2(e5(o.text))})}}else if("class_definition"===o.type){let t=e3(o),s=e4(r,t),l=e(o.childForFieldName("body"),s);n.push(e6(o,t,"class",r,l))}}}return n}(t.childForFieldName("body"),n);return[e6(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:e2(e5(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:e4(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e2(e5(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,l=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&l.push(t)}}if(0===l.length||!o)return[];let a=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=a?`${a} ${o}`:o;return l.map((e,r)=>e6(e,l.length>1?`${i} #${r+1}`:i,"function",t,[],e8(e)))}(t,r)),e}default:return[]}}(n,void 0,!1))}return t.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],l=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,contentHash:e2(e5(s)),children:[]})},a=-1;for(let e=1;e<=n;e++)s[e]?a>=0&&(l(a,e-1),a=-1):a<0&&(a=e);return a>=0&&l(a,n),o}(e,t)),t}(n.rootNode)}finally{n.delete()}}async function ta(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of f(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!e9(r))return{addedLines:o};let[l,a]=await Promise.all([tl(n?"":e,r),tl(s?"":t,r)]),i=a??[],c=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}((l??[]).filter(to),i.filter(to)),d=new Set;for(let e of c)"deleted"!==e.changeKind&&d.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(ts(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(i,o))d.add(e);return{changedQnames:d,addedLines:o}}function ti({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:l=!1,isDeleted:a=!1,changedFiles:i,fileGitStatusMap:c,enableComments:d=!1,onContentSearch:u,headerExtraLeft:h,headerExtraRight:m}){let[x,f]=(0,s.useState)(t);(0,s.useEffect)(()=>{f(t)},[t]);let[p,g]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return g(null),(async()=>{try{let s=await tc(x,t,r,o,l,a,i,c,e);if(n||!s)return;let d=await ta(s.oldContent,s.newContent,x,s.isNew,s.isDeleted);if(n)return;g(d)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[x,t,r,o,l,a,i,c,e]),(0,n.jsx)(eZ,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:d,qnameFilter:p?.changedQnames,qnameFilterFile:x,accentQnames:p?.changedQnames,accentFile:x,addedLines:p?.addedLines,addedLinesFile:x,onFocalChange:e=>e&&f(e),onContentSearch:u,headerExtraLeft:h,headerExtraRight:m})}async function tc(e,t,r,n,s,o,l,a,i){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!l.has(e))return null;let c=a?.get(e);if(!c)return null;let d=new URLSearchParams({cwd:i,file:e,type:c}),u=await fetch(`/api/git/diff?${d}`);if(!u.ok)return null;let h=await u.json();return{oldContent:h.oldContent,newContent:h.newContent,isNew:h.isNew??!1,isDeleted:h.isDeleted??!1}}function td(e){let{refreshKey:t,className:r="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:l}=e,a="absPath"in e&&"string"==typeof e.absPath,i=a?void 0:e.cwd,c=a?void 0:e.path,d=a?e.absPath:void 0,[u,h]=(0,s.useState)({kind:"loading"}),m=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++m.current;return h({kind:"loading"}),(async()=>{if(a){if(e!==m.current)return;h({kind:"ready",etag:null,size:0});return}try{let t=`/api/files/stat?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}`,r=await fetch(t,{cache:"no-store"});if(e!==m.current)return;if(!r.ok)return void h({kind:"error",message:`stat failed (${r.status})`});let n=await r.json();if(e!==m.current)return;if(!n.exists)return void h({kind:"missing"});if("too-large"===n.category)return void h({kind:"too-large",size:n.size??0});if("image"!==n.category)return void h({kind:"error",message:`Not an image (${n.category})`});let s=n.etag||`t-${n.mtimeMs??Date.now()}`;h({kind:"ready",etag:s,size:n.size??0})}catch(t){if(e!==m.current)return;h({kind:"error",message:t instanceof Error?t.message:"Unknown error"})}})(),()=>{m.current++}},[a,i,c,d,t]),"loading"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(u.size/1024/1024)," MB)"]})});if("error"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:u.message})});let x=a?`/api/file?path=${encodeURIComponent(d)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}&v=${encodeURIComponent(u.etag)}`;return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("img",{src:x,alt:l??(c||d),className:o})})}function tu({cwd:e,selected:t,diff:r,showMarkdownPreview:l,setShowMarkdownPreview:a,changedFiles:i,fileGitStatusMap:c,onContentSearch:d,locateInTree:u,jsonPreview:h,setJsonPreview:m,jsonPreviewSearch:x,jsonPreviewPreRef:f}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)("file"),[j,y]=(0,s.useState)("compact"),w=t.file.path,k=(0,et.u)(w),{state:C}=eL(e,w),S=(0,s.useMemo)(()=>{if("ready"===C.state)return C.data.functions.filter(eB).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[C]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[k||"map"!==b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:w}),(0,n.jsx)(eT.m,{content:g("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${w}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(eT.m,{content:g("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(w)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${"staged"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?g("fileBrowser.staged"):g("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!k&&"file"===b&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["compact","full"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e)},className:`px-2 py-0.5 text-xs transition-colors ${j===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("compact"===e?"diffViewer.compact":"diffViewer.full")},e))}),!k&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-xs transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:k?(0,n.jsx)(td,{cwd:e,path:w,className:"p-4 flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:w}):(0,n.jsx)(N,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===j,symbols:S,onPreview:!r.isDeleted&&U(w)?()=>a(!0):!r.isDeleted&&w.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:w.endsWith(".json")?g("common.readable"):g("common.preview"),onContentSearch:d})})]}):(0,n.jsx)(ti,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:c,enableComments:!0,onContentSearch:d,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=c.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eT.m,{content:g("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(eT.m,{content:g("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?g("fileBrowser.staged"):g("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})}),l&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>a(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ei,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>a(!1)})})}),h&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>m(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:h.filePath}),(0,n.jsx)("button",{onClick:()=>m(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(X,{search:x}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:f,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:D(h.content)})})]})})]})}function th({branches:e,selectedBranch:t,onSelect:r,isLoading:l,pinnedBranches:a=[]}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1),[u,h]=(0,s.useState)(""),m=(0,s.useRef)(null),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{m.current&&!m.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{c&&x.current&&x.current.focus()},[c]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=a.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],y=e=>{r(e),d(!1),h("")};return(0,n.jsxs)("div",{className:"relative",ref:m,children:[(0,n.jsxs)("button",{onClick:()=>d(!c),disabled:l,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-slate-9 transition-transform ${c?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lg max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:x,type:"text",value:u,onChange:e=>h(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground placeholder-slate-9"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>y(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}function tm(e){let t=e.split(".").pop()?.toLowerCase();return t?["ts","tsx","js","jsx","mjs","cjs"].includes(t)?"typescript":["py","pyi"].includes(t)?"python":null:null}function tx(e){return e.replace(/^\([^)]+\)\s*/,"")}let tf=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:l,container:a,onMouseEnter:i,onMouseLeave:c,onFindReferences:d,onSearch:u},h){let{t:m}=(0,o.Bd)(),x=(0,s.useRef)(null);(0,s.useImperativeHandle)(h,()=>x.current,[]);let f=a.getBoundingClientRect(),p=r-f.left,g=l-f.top,b=(0,s.useMemo)(()=>tx(e),[e]),v=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,l=0,a=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=a.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},l++));let a=t[0];/^["']/.test(a)?s.push((0,n.jsx)("span",{className:"text-green-400",children:a},l++)):/^\d+$/.test(a)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:a},l++)):r.test(a)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:a},l++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:a},l++)),o=t.index+a.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},l++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!x.current)return;let e=x.current,t=a.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=l-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,l,a]),(0,n.jsxs)("div",{ref:x,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-xl px-3 py-2 pointer-events-none",style:{left:p,top:g},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:v}),t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap",children:t})]}),(d||u)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1.5"}),(0,n.jsxs)("div",{className:"flex items-center gap-3 pointer-events-auto",onMouseEnter:i,onMouseLeave:c,children:[d&&(0,n.jsx)("button",{onClick:d,className:"text-[11px] text-brand hover:underline cursor-pointer",children:m("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(function(e){let t=tx(e),r=t.match(/^(?:function|const|let|var|class|interface|type|enum|async function)\s+([a-zA-Z_$][\w$]*)/);if(r)return r[1];let n=e.match(/\([^)]+\)\s+(?:[\w$]+\.)*([a-zA-Z_$][\w$]*)/);if(n)return n[1];let s=t.match(/([a-zA-Z_$][\w$]*)/);return s?s[1]:t.split(/[(\s:]/)[0]}(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:m("hoverTooltip.search")})]})]})]})});function tp({references:e,loading:t,onSelect:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)();if(t!==l.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let l=(0,b.sQ)(r.file);if("text"!==l)try{let e=n.codeToTokens(r.lineText,{lang:l,theme:s}),a=(0,b.b8)(e.tokens[0]||[]);a&&o.set(t,a)}catch{}}t===l.current&&r(o)})()},[e,n]),t}(e),c=[],d=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=d.get(r.file);void 0===n&&(n=c.length,d.set(r.file,n),c.push({file:r.file,items:[]})),c[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[a("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("references.notFound")}):c.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function tg({results:e,loading:t,totalMatches:r,onSelect:l,onClose:a}){let{t:i}=(0,o.Bd)(),c=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)(),o=new Map;for(let t of e){let e=(0,b.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let l=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),a=(0,b.b8)(t.tokens[0]||[]);a&&o.set(l,a)}catch{}}}t===l.current&&r(o)})()},[e,n]),t}(e);return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[i("searchResults.title")," ",!t&&i("searchResults.nMatches",{count:r})]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.noResults")}):e.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=c.get(s);return(0,n.jsxs)("button",{onClick:()=>l(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}var tb=r(63728);function tv({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:l,initialSearchQuery:c,searchQueryTrigger:d}){var u;let m,x,f,g,b,v,{t:j}=(0,o.Bd)(),{activeView:y}=(0,tb.R8)(),[w,k]=(0,s.useState)(r),[C,S]=(0,s.useState)("code"),L=(0,s.useRef)(null),M=(0,s.useRef)(!1),[E,T]=(0,s.useState)(null),[F,A]=(0,s.useState)(null),[O,W]=(0,s.useState)(!1),z=(0,s.useRef)(1),H=(0,s.useRef)(null),[_,q]=(0,s.useState)(null),V=(0,s.useRef)(null),[K,Q]=(0,s.useState)({isDirty:!1,isSaving:!1}),[G,er]=(0,s.useState)(!1),[en,es]=(0,s.useState)(!1),[eo,el]=(0,s.useState)(null),ea=(0,s.useRef)(null),ec=J(ea),em=(0,s.useRef)(null),ex=J(em),ef=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);try{let r=await fetch("/api/lsp/definition",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:n,column:s})});return(await r.json()).definitions||[]}catch(e){return console.error("[useLSP] definition error:",e),[]}finally{r(!1)}},[e]),loading:t}}(t),ep=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),l=(0,s.useRef)(0),a=(0,s.useRef)(!1),i=(0,s.useRef)(null),c=(0,s.useRef)({x:0,y:0}),d=(0,s.useCallback)(e=>{i.current=e},[]);(0,s.useEffect)(()=>{let e=e=>{c.current.x=e.clientX,c.current.y=e.clientY};return document.addEventListener("mousemove",e),()=>document.removeEventListener("mousemove",e)},[]);let u=(0,s.useRef)(!1),h=(0,s.useRef)(null),m=(0,s.useCallback)(()=>{let e=i.current;e&&u.current&&(e.style.pointerEvents="none"),u.current=!1,h.current&&(i.current?.removeEventListener("mouseleave",h.current),h.current=null)},[]),x=(0,s.useCallback)(()=>{let e=i.current;if(!e||u.current)return;u.current=!0,a.current=!0,e.style.pointerEvents="auto";let t=()=>{a.current=!1,m(),l.current++,r(null)};h.current=t,e.addEventListener("mouseleave",t)},[m]),f=(0,s.useCallback)((t,s,a,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let c=++l.current;n.current=setTimeout(async()=>{try{let n=await fetch("/api/lsp/hover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:s,column:a})}),o=await n.json();if(c!==l.current)return;o.hover&&o.hover.displayString&&r({...o.hover,x:i.x,y:i.y,filePath:t,line:s,column:a})}catch{}},300)},[e]),p=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),l.current++,o.current=setTimeout(function(){if(a.current)return;let e=i.current;if(e){let t=e.getBoundingClientRect(),{x:r,y:n}=c.current;if(r>=t.left&&r<=t.right&&n>=t.top&&n<=t.bottom)return void x()}r(null)},150)},[x]),g=(0,s.useCallback)(()=>{a.current=!0,o.current&&clearTimeout(o.current)},[]),b=(0,s.useCallback)(()=>{a.current=!1,l.current++,r(null)},[]),v=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),a.current=!1,m(),l.current++,r(null)},[m]);return(0,s.useEffect)(()=>{t||m()},[t,m]),{hoverInfo:t,onTokenMouseEnter:f,onTokenMouseLeave:p,onCardMouseEnter:g,onCardMouseLeave:b,clearHover:v,setTooltipEl:d}}(t),eg=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(!1);return{references:t,loading:n,visible:l,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),a(!0);try{let o=await fetch("/api/lsp/references",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:n,column:s})}),l=await o.json();r(l.references||[])}catch(e){console.error("[useLSP] references error:",e),r([])}finally{o(!1)}},[e]),closeReferences:(0,s.useCallback)(()=>{a(!1),r([])},[])}}(t),eb=(m=(0,s.useRef)([]),x=(0,s.useRef)([]),f=(0,s.useCallback)(e=>{m.current.push(e),m.current.length>50&&(m.current=m.current.slice(-50)),x.current=[]},[]),g=(0,s.useCallback)(e=>{if(0===m.current.length)return null;let t=m.current.pop();return x.current.push(e),x.current.length>50&&(x.current=x.current.slice(-50)),t},[]),b=(0,s.useCallback)(e=>{if(0===x.current.length)return null;let t=x.current.pop();return m.current.push(e),m.current.length>50&&(m.current=m.current.slice(-50)),t},[]),{push:f,goBack:g,goForward:b,canGoBack:(0,s.useCallback)(()=>m.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>x.current.length>0,[])}),ev=(0,eh.F)(),ej=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(new Set),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[h,m]=(0,s.useState)(null),[x,f]=(0,s.useState)(new Set),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(""),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(!1),[M,E]=(0,s.useState)(null),T=(0,s.useRef)(null),[$,R]=(0,s.useState)(!1),[P,B]=(0,s.useState)(null),[I,D]=(0,s.useState)("center"),[F,A]=(0,s.useState)(null),[O,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(!1),[_,q]=(0,s.useState)([]),[V,U]=(0,s.useState)(!1),[K,J]=(0,s.useState)(null),[X,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(!1),[Z,ee]=(0,s.useState)(!1),er=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),en=(0,s.useMemo)(()=>(0,et.v3)(er),[er]),es=(0,s.useMemo)(()=>new Set((0,et.tW)(en)),[en]),eo=(0,s.useMemo)(()=>b?n?(0,et.KH)(n,b,j):(0,et.q3)(t,b,j):null,[t,n,b,j]);(0,s.useEffect)(()=>{if(!eo||0===eo.size)return void g(null);let e=new Set;if(n){let t=new Set(n);for(let r of eo)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&eo.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}g(e)},[eo,t,n]);let el=p??x,ea=(0,s.useRef)(null),ei=(0,s.useCallback)(t=>{ea.current&&clearTimeout(ea.current),ea.current=setTimeout(async()=>{try{await fetch("/api/files/expanded",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,paths:Array.from(t)})})}catch(e){console.error("Error saving expanded paths:",e)}},500)},[e]),ec=(0,s.useCallback)(async()=>{C(!0),E(null);try{let t=await fetch(`/api/files/init?cwd=${encodeURIComponent(e)}`),n=await t.json();n.error?E(n.error):(r(n.files||[]),n.expandedPaths&&Array.isArray(n.expandedPaths)&&f(new Set(n.expandedPaths)))}catch(e){console.error("Error loading files:",e),E("Failed to load files")}finally{C(!1)}},[e]),ed=(0,s.useCallback)(async()=>{try{let t=await fetch(`/api/files/index?cwd=${encodeURIComponent(e)}`),r=await t.json();r.paths&&o(r.paths)}catch(e){console.error("Error loading file index:",e)}},[e]),eu=(0,s.useCallback)(async t=>{a(e=>new Set([...e,t]));try{let n=await fetch(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),s=await n.json();s.children&&r(e=>{if(!t){let t=new Map(e.map(e=>[e.path,e]));return s.children.map(e=>{let r=t.get(e.path);return r?.children&&e.isDirectory?{...e,children:r.children}:e})}let r=structuredClone(e),n=(0,et.MB)(r,t);return n&&(n.children=s.children),r})}catch(e){console.error("Error loading directory:",e)}finally{a(e=>{let r=new Set(e);return r.delete(t),r})}},[e]),eh=(0,s.useRef)(l);eh.current=l,(0,s.useEffect)(()=>{for(let e of p??x){let r=(0,et.MB)(t,e);r&&r.isDirectory&&!r.children&&!eh.current.has(e)&&eu(e)}},[t,x,p,eu]);let em=(0,s.useCallback)(async()=>{try{let t=await fetch(`/api/files/recent?cwd=${encodeURIComponent(e)}`),r=await t.json();c(r.files||[])}catch(e){console.error("Error loading recent files:",e)}},[e]),ex=(0,s.useCallback)(async t=>{c(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)});try{await fetch("/api/files/recent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,file:t})})}catch(e){console.error("Error adding to recent files:",e)}},[e]),ef=(0,s.useCallback)((t,r,n,s)=>{c(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),fetch("/api/files/recent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,file:t,scrollLine:r,cursorLine:n,cursorCol:s})}).catch(()=>{})},[e]),ep=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),eg=(0,s.useCallback)(async t=>{let r=t||d;if(r){U(!0),J(null);try{let t=await fetch(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(r)}`),n=await t.json();n.error?J(n.error):q(n.blame||[])}catch(e){console.error("Error loading blame:",e),J("Failed to load blame info")}finally{U(!1)}}},[e,d]),eb=(0,s.useCallback)(async t=>{L(!0),m(null),H(!1),q([]),J(null),Y(null);try{let r=await fetch(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),n=await r.json();if(!r.ok)return void m({type:"error",message:n?.error||"Failed to stat file"});if(!n.exists)return void m({type:"error",message:"File not found"});if("dir"===n.kind)return void m({type:"error",message:"Path is a directory"});switch(n.category){case"image":m({type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}});break;case"binary":m({type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break;case"too-large":m({type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs});break;default:{let r=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"});if(409===r.status){let e=await r.json().catch(()=>({}));m({type:"binary",message:e?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break}if(!r.ok){let e=await r.json().catch(()=>({}));m({type:"error",message:e?.error||"Failed to load file"});break}let s=await r.json();m({type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}})}}ex(t),eg(t)}catch(e){console.error("Error loading file content:",e),m({type:"error",message:"Failed to load file"})}finally{L(!1)}},[e,ex,eg]),ev=(0,s.useCallback)(()=>{z?H(!1):(H(!0),0===_.length&&eg())},[z,_.length,eg]),ej=(0,s.useCallback)((e,t)=>{if(!e)return;if(u(e),B(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(B(t.scrollLine),D("start"),A(t.cursorLine??null),W(t.cursorCol??null)):(D("center"),A(null),W(null))}else D("center"),A(null),W(null);eb(e);let r=e.split("/");if(r.length>1){let e=[];for(let t=1;t<r.length;t++)e.push(r.slice(0,t).join("/"));f(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ei(r),n?r:t})}},[eb,ei,i]),ey=(0,s.useCallback)(e=>{if(p)g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!x.has(e);if(f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ei(r),r}),r){let r=(0,et.MB)(t,e);r&&r.isDirectory&&!r.children&&eu(e)}}},[p,ei,x,t,eu]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:l,expandedPaths:x,setExpandedPaths:f,searchTreeExpandedPaths:p,setSearchTreeExpandedPaths:g,effectiveExpandedPaths:el,searchQuery:b,setSearchQuery:v,searchExactMatch:j,setSearchDirExact:y,matchedPaths:eo,creatingItem:w,setCreatingItem:k,isLoadingFiles:N,fileError:M,searchInputRef:T,shouldScrollToSelected:$,setShouldScrollToSelected:R,targetLineNumber:P,setTargetLineNumber:B,targetScrollAlign:I,setTargetScrollAlign:D,initialCursorLine:F,initialCursorCol:O,setInitialCursorLine:A,setInitialCursorCol:W,selectedPath:d,setSelectedPath:u,fileContent:h,setFileContent:m,isLoadingContent:S,recentFiles:i,recentFilePaths:er,setRecentFiles:c,recentFilesTree:en,recentTreeDirPaths:es,showBlame:z,setShowBlame:H,blameLines:_,isLoadingBlame:V,blameError:K,blameSelectedCommit:X,setBlameSelectedCommit:Y,showMarkdownPreview:Q,setShowMarkdownPreview:G,showEditor:Z,setShowEditor:ee,saveExpandedPaths:ei,loadFiles:ec,loadFileIndex:ed,loadDirectory:eu,loadRecentFiles:em,addToRecentFiles:ex,updateRecentFilePosition:ef,getRecentFilePosition:ep,loadFileContent:eb,loadBlame:eg,handleToggleBlame:ev,handleSelectFile:ej,handleToggle:ey}}({cwd:t});u=ej.selectedPath,v=(0,s.useRef)(null),(0,s.useEffect)(()=>{!u||u===v.current||tm(u)&&(v.current=u,fetch("/api/lsp/warmup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,filePath:u})}).catch(()=>{}))},[t,u]);let ey=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,l]=(0,s.useState)([]),[a,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(new Set),[m,x]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){l([]),p(null);return}if(n.length<2)return void d(I.A.t("fileBrowser.searchMinChars"));i(!0),d(null);try{let n=new URLSearchParams({cwd:e,q:r,caseSensitive:String(m.caseSensitive),wholeWord:String(m.wholeWord),regex:String(m.regex),fileType:m.fileType}),s=await fetch(`/api/files/search?${n}`),o=await s.json();if(o.error)throw Error(o.error);l(o.results),p({totalFiles:o.totalFiles,totalMatches:o.totalMatches,truncated:o.truncated});let a=new Set(o.results.map(e=>e.path));h(a),o.results.length>0&&t?.()}catch(e){d(e instanceof Error?e.message:"Search failed"),l([])}finally{i(!1)}},[e,m,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:a,searchError:c,searchExpandedPaths:u,searchOptions:m,setSearchOptions:x,searchStats:f,contentSearchInputRef:g,performContentSearch:b,handleSearchToggle:(0,s.useCallback)(e=>{h(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>er(!0)}),ew=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(!1),[a,i]=(0,s.useState)(null),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(null),[m,x]=(0,s.useState)(!1),[f,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)([]),[j,y]=(0,s.useState)([]),w=(0,s.useMemo)(()=>{let e=new Set([...P(b),...P(j)]);for(let t of f)e.delete(t);return e},[b,j,f]),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(0),L=(0,s.useCallback)(async()=>{l(!0),i(null);try{let t=`/api/git/status?cwd=${encodeURIComponent(e)}`,r=await fetch(t);if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to fetch git status")}let s=await r.json();n(s);let o=R(s.staged),l=R(s.unstaged);v(o),y(l)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{l(!1)}},[e]),M=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),E=(0,s.useCallback)((e,r)=>{d({file:e,type:r}),t(e.path)},[t]),T=(0,s.useCallback)(async t=>{try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t]})})).ok)throw Error("Failed to stage file");await L(),(0,p.oR)(I.A.t("toast.staged"),"success")}catch(e){console.error("Error staging file:",e),(0,p.oR)(I.A.t("toast.stageFailed"),"error")}},[e,L]),$=(0,s.useCallback)(async t=>{try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t]})})).ok)throw Error("Failed to unstage file");await L(),(0,p.oR)(I.A.t("toast.unstaged"),"success")}catch(e){console.error("Error unstaging file:",e),(0,p.oR)(I.A.t("toast.unstageFailed"),"error")}},[e,L]),B=(0,s.useCallback)(async t=>{if(0!==t.length)try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t})})).ok)throw Error("Failed to stage files");await L(),(0,p.oR)(I.A.t("toast.stagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error staging files:",e),(0,p.oR)(I.A.t("toast.stageFailed"),"error")}},[e,L]),D=(0,s.useCallback)(async t=>{if(0!==t.length)try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t})})).ok)throw Error("Failed to unstage files");await L(),(0,p.oR)(I.A.t("toast.unstagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error unstaging files:",e),(0,p.oR)(I.A.t("toast.unstageFailed"),"error")}},[e,L]),F=(0,s.useCallback)(async t=>{if(0!==t.length)try{let r=t.filter(e=>"untracked"===e.status).map(e=>e.path),n=t.filter(e=>"untracked"!==e.status).map(e=>e.path);if(r.length>0&&!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r,isUntracked:!0})})).ok)throw Error("Failed to discard untracked files");if(n.length>0&&!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:n,isUntracked:!1})})).ok)throw Error("Failed to discard tracked files");await L(),(0,p.oR)(I.A.t("toast.discardedNFiles",{count:t.length}),"success")}catch(e){console.error("Error discarding files:",e),(0,p.oR)(I.A.t("toast.discardFailed"),"error")}},[e,L]),A=(0,s.useCallback)(async()=>{if(r?.unstaged.length)try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r.unstaged.map(e=>e.path)})})).ok)throw Error("Failed to stage all files");await L(),(0,p.oR)(I.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error staging all files:",e),(0,p.oR)(I.A.t("toast.stageFailed"),"error")}},[e,r,L]),O=(0,s.useCallback)(async()=>{if(r?.staged.length)try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r.staged.map(e=>e.path)})})).ok)throw Error("Failed to unstage all files");await L(),(0,p.oR)(I.A.t("toast.unstagedNFiles",{count:r.staged.length}),"success")}catch(e){console.error("Error unstaging all files:",e),(0,p.oR)(I.A.t("toast.unstageFailed"),"error")}},[e,r,L]),W=(0,s.useCallback)(async t=>{try{let r="untracked"===t.status;if(!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t.path],isUntracked:r})})).ok)throw Error("Failed to discard file");await L(),(0,p.oR)(r?I.A.t("toast.deletedFile"):I.A.t("toast.discardedChanges"),"success")}catch(e){console.error("Error discarding file:",e),(0,p.oR)(I.A.t("toast.discardFailed"),"error")}},[e,L]),z=(0,s.useCallback)(async()=>{if(r?.unstaged.length&&await (0,p.lJ)(I.A.t("git.discardAllConfirm",{count:r.unstaged.length}),{danger:!0}))try{let t=r.unstaged.filter(e=>"untracked"===e.status).map(e=>e.path),n=r.unstaged.filter(e=>"untracked"!==e.status).map(e=>e.path);n.length>0&&await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:n,isUntracked:!1})}),t.length>0&&await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t,isUntracked:!0})}),await L(),(0,p.oR)(I.A.t("toast.discardedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error discarding all:",e),(0,p.oR)(I.A.t("toast.discardFailed"),"error")}},[e,r,L]);return(0,s.useEffect)(()=>{c?(async()=>{x(!0);try{let t=new URLSearchParams({file:c.file.path,type:c.type});t.set("cwd",e);let r=await fetch(`/api/git/diff?${t}`);if(!r.ok)throw Error("Failed to fetch diff");let n=await r.json();h(n)}catch(e){console.error("Error fetching diff:",e)}finally{x(!1)}})():h(null)},[c,e,C]),{status:r,setStatus:n,statusLoading:o,statusError:a,statusSelectedFile:c,statusDiff:u,statusDiffLoading:m,statusExpandedPaths:w,stagedTree:b,setStagedTree:v,unstagedTree:j,setUnstagedTree:y,showStatusDiffPreview:k,setShowStatusDiffPreview:N,fetchStatus:L,handleStatusToggle:M,handleStatusFileSelect:E,handleStage:T,handleUnstage:$,handleStageFiles:B,handleUnstageFiles:D,handleDiscardFiles:F,handleStageAll:A,handleUnstageAll:O,handleDiscardFile:W,handleDiscardAll:z,refreshDiff:(0,s.useCallback)(()=>S(e=>e+1),[])}}({cwd:t,addToRecentFiles:ej.addToRecentFiles}),ek=(0,s.useMemo)(()=>{let e=new Set;if(ew.status){for(let t of ew.status.staged)e.add(t.path);for(let t of ew.status.unstaged)e.add(t.path)}return e},[ew.status]),eN=(0,s.useMemo)(()=>{let e=new Map;if(ew.status){for(let t of ew.status.staged)e.set(t.path,"staged");for(let t of ew.status.unstaged)e.set(t.path,"unstaged")}return e},[ew.status]),eC=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(""),[a,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)([]),[m,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!0),[E,T]=(0,s.useState)(!1),[$,B]=(0,s.useState)(!1),[D,F]=(0,s.useState)(null),A=(0,s.useRef)(null),[O,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(!1),[_,q]=(0,s.useState)(""),[V,U]=(0,s.useState)(""),[K,J]=(0,s.useState)([]),[X,Y]=(0,s.useState)([]),[Q,G]=(0,s.useState)(new Set),[Z,ee]=(0,s.useState)(null),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(!1),[el,ea]=(0,s.useState)(!1),ei=(0,s.useCallback)(()=>{w(!0),F(null),fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{e.error?(F("Failed to get branches"===e.error?I.A.t("git.notGitRepo"):e.error),n(null)):e.local&&e.current?(n(e),l(e.current),e.upstream&&q(e.upstream)):(F(I.A.t("git.cannotGetBranches")),n(null))}).catch(e=>{console.error(e),F(I.A.t("git.getBranchesFailed")),n(null)}).finally(()=>w(!1))},[e]),ec=(0,s.useCallback)(t=>{N(!0),d(null),h([]),x([]),b(null),j(null),M(!0),fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${et.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];i(t),M(t.length>=et.B_)}).catch(console.error).finally(()=>N(!1))},[e]),ed=(0,s.useCallback)(()=>{if(C||!L||!o)return;S(!0);let t=a.length;fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(o)}&limit=${et.B_}&offset=${t}`).then(e=>e.json()).then(e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),M(t.length>=et.B_)}).catch(console.error).finally(()=>S(!1))},[e,o,a.length,C,L]),eu=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ed()},[ed]),eh=(0,s.useCallback)(t=>{d(t),b(null),j(null),T(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${t.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];h(t);let r=R(t);x(r),p(new Set(P(r)))}).catch(console.error).finally(()=>T(!1))},[e]),em=(0,s.useCallback)(r=>{c&&(b(r),t(r.path),B(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${c.hash}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>B(!1)))},[e,c,t]),ex=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ef=(0,s.useCallback)(t=>{eo(!0),ee(null),en(null),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{let t=e.files||[];J(t);let r=R(t);Y(r),G(new Set(P(r)))}).catch(console.error).finally(()=>eo(!1))},[e]),ep=(0,s.useCallback)(r=>{ee(r),t(r.path),ea(!0),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(V)}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>en(e)).catch(console.error).finally(()=>ea(!1))},[e,V,t]),eg=(0,s.useCallback)(e=>{G(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eb=(0,s.useCallback)(e=>{if(H(e),e){let e="origin/main";U(e),ef(e)}else J([]),Y([]),ee(null),en(null),U("")},[_,ef]);return{branches:r,selectedBranch:o,setSelectedBranch:l,commits:a,setCommits:i,selectedCommit:c,setSelectedCommit:d,historyFiles:u,historyFileTree:m,historyExpandedPaths:f,historySelectedFile:g,historyFileDiff:v,isLoadingBranches:y,isLoadingCommits:k,isLoadingMore:C,hasMoreCommits:L,setHasMoreCommits:M,isLoadingHistoryFiles:E,isLoadingHistoryDiff:$,historyError:D,commitListRef:A,tooltipPos:O,loadBranches:ei,loadCommits:ec,loadMoreCommits:ed,handleCommitListScroll:eu,handleSelectCommit:eh,handleSelectHistoryFile:em,handleHistoryToggle:ex,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{W({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{W(null)},[]),compareMode:z,toggleCompareMode:eb,compareBaseBranch:V,setCompareBaseBranch:U,upstreamBranch:_,compareFiles:K,compareFileTree:X,compareExpandedPaths:Q,compareSelectedFile:Z,compareFileDiff:er,isLoadingCompareFiles:es,isLoadingCompareDiff:el,handleSelectCompareFile:ep,handleCompareToggle:eg,loadCompareFiles:ef}}({cwd:t,addToRecentFiles:ej.addToRecentFiles}),eS=(0,s.useCallback)(e=>{ej.setFileContent(t=>t?.type==="text"?{...t,content:e}:t)},[ej]),eL=(0,s.useCallback)(e=>{ej.setShowEditor(!0)},[ej]),eM=(0,s.useCallback)(async()=>{if(ej.fileContent&&"text"===ej.fileContent.type&&ej.fileContent.content)try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:ej.selectedPath,content:ej.fileContent.content})});if(!e.ok)throw Error("Failed to save file");let r=await e.json();r.mtime&&ej.setFileContent(e=>e?.type==="text"?{...e,mtime:r.mtime}:e),(0,p.oR)(j("toast.savedSuccess"),"success")}catch{(0,p.oR)(j("toast.saveFailed"),"error")}},[t,ej]),eE=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e=z.current,t=H.current;e>0&&ej.updateRecentFilePosition(ej.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[ej]),eT=(0,s.useCallback)((e,t)=>{e!==ej.selectedPath&&eE(),ej.handleSelectFile(e,t)},[ej,eE]),e$=(0,s.useMemo)(()=>{let e=ey.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,et.v3)(r),s=new Set((0,et.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[ey.contentSearchResults]),[eR,eP]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{eP(e$.expandDirs)},[e$.expandDirs]);let eB=(0,s.useCallback)(e=>{eP(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eI=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=e$.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[e$.matchMap]),eD=G&&ey.contentSearchResults.length>0,eF=!!ej.selectedPath&&null!==tm(ej.selectedPath),eA=(0,s.useCallback)(async(e,r)=>{if(!ej.selectedPath||!eF)return;let n=await ef.goToDefinition(ej.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",l=s.file.startsWith(o)?s.file.slice(o.length):s.file;eb.push({filePath:ej.selectedPath,lineNumber:z.current}),l===ej.selectedPath?ej.setTargetLineNumber(s.line):eT(l,s.line)},[ej,t,eF,ef,eb]),eO=(0,s.useCallback)((e,t,r)=>{ej.selectedPath&&eF&&ep.onTokenMouseEnter(ej.selectedPath,e,t,r)},[ej.selectedPath,eF,ep]),eW=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;ej.selectedPath&&eb.push({filePath:ej.selectedPath,lineNumber:z.current}),n===ej.selectedPath?ej.setTargetLineNumber(e.line):eT(n,e.line)},[ej,t,eb]),ez=(0,s.useMemo)(()=>{if(!ew.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":return"A";case"deleted":return"D";case"renamed":return"R";case"untracked":return"?"}};for(let r of ew.status.staged)e.set(r.path,t(r.status));for(let r of ew.status.unstaged)e.set(r.path,t(r.status));return e},[ew.status]);(0,s.useEffect)(()=>{T(L.current)},[]),(0,s.useEffect)(()=>{k(r)},[r,l]),(0,s.useEffect)(()=>{c&&(k("search"),ey.setContentSearchQuery(c),ey.performContentSearch(c))},[d]);let eH=(0,s.useCallback)(e=>{k(e),ej.setBlameSelectedCommit(null),"history"===e&&eC.selectedBranch&&eC.loadCommits(eC.selectedBranch)},[ej,eC.selectedBranch,eC.loadCommits]),e_=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e={filePath:ej.selectedPath,lineNumber:z.current},t=eb.goBack(e);t&&(t.filePath===ej.selectedPath?ej.setTargetLineNumber(t.lineNumber):eT(t.filePath,t.lineNumber))},[ej,eb]),eq=(0,s.useCallback)(()=>{if(!ej.selectedPath)return;let e={filePath:ej.selectedPath,lineNumber:z.current},t=eb.goForward(e);t&&(t.filePath===ej.selectedPath?ej.setTargetLineNumber(t.lineNumber):eT(t.filePath,t.lineNumber))},[ej,eb]),eV=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;try{await fetch("/api/files/clipboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:e})}),(0,p.oR)(j("toast.copiedName",{name:r}),"success")}catch{(0,p.oR)(j("toast.copyFailed"),"error")}},[t]),eU=(0,s.useCallback)(async e=>{try{let r=await fetch("/api/files/clipboard"),n=await r.json();if(!n.path)return void(0,p.oR)(j("toast.noFileToPaste"),"info");let s=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,targetDir:e,sourceAbsPath:n.path})}),o=await s.json();s.ok?((0,p.oR)(j("toast.pastedFile",{name:o.newName}),"success"),ej.loadDirectory(e),ej.loadFileIndex()):(0,p.oR)(o.error||j("toast.pasteFailed"),"error")}catch{(0,p.oR)(j("toast.pasteFailed"),"error")}},[t,ej]),eK=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===y;if(r&&t.ctrlKey&&!t.metaKey&&"Minus"===t.code){t.preventDefault(),t.shiftKey?eq():e_();return}if(r&&(t.metaKey||t.ctrlKey)&&"p"===t.key){t.preventDefault(),W(e=>!e);return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===w||"recent"===w)&&ej.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),eV(ej.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===w||"recent"===w)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),eU((0,et.S7)(ej.selectedPath,ej.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(eo){t.preventDefault(),ex.open();return}if(en&&ej.selectedPath?.endsWith(".json")){t.preventDefault(),ec.open();return}}if(r&&"Escape"===t.key){if(O)return void W(!1);if(ex.isVisible)return void ex.close();if(ec.isVisible)return void ec.close();if(eo)return void el(null);let t=Date.now();if(t-eK.current<3e3)return;eK.current=t,eg.visible?eg.closeReferences():G?er(!1):ej.blameSelectedCommit?ej.setBlameSelectedCommit(null):ej.showBlame?ej.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,ej.showBlame,ej.blameSelectedCommit,ej,O,eg.visible,eg.closeReferences,G,e_,eq,en,ec,eo,ex,w,eV,eU,y]),(0,s.useEffect)(()=>{ej.loadFiles(),ej.loadFileIndex(),ej.loadRecentFiles(),ew.fetchStatus(),eC.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{ew.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[ew.fetchStatus]);let eJ=(0,s.useRef)(ev);(0,s.useEffect)(()=>{ev&&!eJ.current&&(ej.loadFiles(),ej.loadFileIndex(),ej.loadRecentFiles(),ew.fetchStatus(),eC.loadBranches()),eJ.current=ev},[ev]),(0,s.useEffect)(()=>{eC.selectedBranch&&eC.loadCommits(eC.selectedBranch)},[eC.selectedBranch,eC.loadCommits]);let eX=(0,s.useRef)(w);(0,s.useEffect)(()=>{let e=eX.current;if(eX.current=w,("tree"===w||"recent"===w)&&ej.recentFiles.length>0){let t=ej.recentFiles[0].path;ej.selectedPath&&("status"!==e&&"history"!==e||ej.selectedPath===t)||(ej.setShouldScrollToSelected(!0),eT(t))}},[w,ej.recentFiles,ej.selectedPath,eT,ej]);let eY=(0,s.useRef)(eC.selectedBranch);eY.current=eC.selectedBranch;let eQ=(0,s.useRef)(ej.selectedPath);eQ.current=ej.selectedPath;let eG=(0,s.useRef)(ej.fileContent?.type);eG.current=ej.fileContent?.type;let e0=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!r)return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(fetch(`/api/files/init?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.error||ej.setFiles(e.files||[])})),o.push(fetch(`/api/files/index?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.paths&&ej.setFileIndex(e.paths)})),o.push(fetch(`/api/files/recent?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{ej.setRecentFiles(e.files||[])}))),n||s){o.push(fetch(`/api/git/status?cwd=${encodeURIComponent(t)}`).then(e=>{if(e.ok)return e.json().then(e=>{ew.setStatus(e);let t=R(e.staged),r=R(e.unstaged);ew.setStagedTree(t),ew.setUnstagedTree(r)})})),ew.refreshDiff(),n&&eC.loadBranches();let e=eY.current;e&&o.push(fetch(`/api/git/commits?cwd=${encodeURIComponent(t)}&branch=${encodeURIComponent(e)}&limit=${et.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];eC.setCommits(t),eC.setHasMoreCommits(t.length>=et.B_)}))}let l=eQ.current,a=eG.current;l&&"text"===a&&o.push(fetch(`/api/files/text?cwd=${encodeURIComponent(t)}&path=${encodeURIComponent(l)}`).then(e=>e.ok?e.json():null).then(e=>{e&&"string"==typeof e.content&&ej.setFileContent({type:"text",content:e.content,size:e.size,mtime:e.mtimeMs,...e.isSymlink?{isSymlink:!0,symlinkTarget:e.symlinkTarget}:{}})})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,eu.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:e0,enabled:ev});let e1=(0,s.useCallback)(e=>{let t=e.split("/");if(t.length>1){let e=[];for(let r=1;r<t.length;r++)e.push(t.slice(0,r).join("/"));ej.setExpandedPaths(t=>{let r=new Set(t);for(let t of e)r.add(t);return ej.saveExpandedPaths(r),r})}ej.setSelectedPath(e),ej.setShouldScrollToSelected(!0),k("tree")},[ej]);return(0,n.jsxs)(h.SU,{container:E,children:[(0,n.jsxs)("div",{ref:L,className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsxs)("div",{className:"w-80 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>eH("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eH("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eH("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eH("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eH("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===w?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:j("fileBrowser.historyTab")})]}),"tree"===w&&(0,n.jsxs)("div",{className:"p-2 border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:ej.searchInputRef,type:"text",value:ej.searchQuery,onChange:e=>ej.setSearchQuery(e.target.value),placeholder:j("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),ej.searchQuery&&(0,n.jsx)("button",{onClick:()=>ej.setSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:j("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>ej.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${ej.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:ej.searchExactMatch?j("fileBrowser.exactMatchOn"):j("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>ej.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.refreshTree"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>ej.searchTreeExpandedPaths?ej.setSearchTreeExpandedPaths(new Set):ej.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.collapseAll"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})]})]}),"search"===w&&(0,n.jsxs)("div",{className:"p-2 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:ey.contentSearchInputRef,type:"text",value:ey.contentSearchQuery,onChange:e=>ey.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ey.performContentSearch(ey.contentSearchQuery)},placeholder:j("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),ey.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>ey.setContentSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:j("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>ey.performContentSearch(ey.contentSearchQuery),disabled:ey.isSearching||!ey.contentSearchQuery.trim(),className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",children:ey.isSearching?"...":j("common.search")})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-xs",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.caseSensitive,onChange:e=>ey.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.wholeWord,onChange:e=>ey.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ey.searchOptions.regex,onChange:e=>ey.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:j("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:ey.searchOptions.fileType,onChange:e=>ey.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:j("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===w&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:eC.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),(0,n.jsx)("span",{className:"truncate",children:eC.branches?.current||"HEAD"}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:"HEAD"})]}),(0,n.jsx)("button",{onClick:()=>eC.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:j("fileBrowser.compareModeOff"),children:j("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(th,{branches:eC.branches,selectedBranch:eC.compareBaseBranch,onSelect:e=>{eC.setCompareBaseBranch(e),eC.loadCompareFiles(e)},isLoading:eC.isLoadingBranches,pinnedBranches:["origin/main",...eC.upstreamBranch&&"origin/main"!==eC.upstreamBranch?[eC.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(th,{branches:eC.branches,selectedBranch:eC.selectedBranch,onSelect:e=>{eC.setSelectedBranch(e)},isLoading:eC.isLoadingBranches,pinnedBranches:["origin/main",...eC.upstreamBranch&&"origin/main"!==eC.upstreamBranch?[eC.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>eC.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-accent border border-border",title:j("fileBrowser.compareModeOn"),children:j("fileBrowser.compareMode")})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,n.jsxs)("div",{className:`flex-1 flex flex-col min-h-0 ${"tree"===w?"":"hidden"}`,children:[ej.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border bg-secondary flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:ej.creatingItem.parentPath?j("fileBrowser.createFileIn",{path:ej.creatingItem.parentPath}):j("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:j("fileBrowser.fileName"),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring",onCompositionStart:()=>{M.current=!0},onCompositionEnd:()=>{M.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(M.current)return;let r=e.target.value.trim();if(!r)return;let n=ej.creatingItem.parentPath,s=n?`${n}/${r}`:r;try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:s,content:""})});if(e.ok)(0,p.oR)(j("toast.createdFile",{name:r}),"success"),ej.setCreatingItem(null),ej.loadDirectory(n),ej.loadFileIndex(),n&&ej.setExpandedPaths(e=>new Set([...e,n])),eT(s);else{let t=await e.json();(0,p.oR)(t.error||j("toast.createFailed"),"error")}}catch(e){(0,p.oR)(j("toast.createFailed"),"error")}}else"Escape"===e.key&&ej.setCreatingItem(null)},onBlur:()=>ej.setCreatingItem(null)})]}),ej.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("common.loading")}):ej.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ej.fileError}):(0,n.jsx)(Z,{files:ej.files,selectedPath:ej.selectedPath,expandedPaths:ej.effectiveExpandedPaths,matchedPaths:ej.matchedPaths,gitStatusMap:ez,loadingDirs:ej.loadingDirs,onSelect:e=>{ej.setShouldScrollToSelected(!1),eT(e)},onToggle:ej.handleToggle,cwd:t,shouldScrollToSelected:ej.shouldScrollToSelected,onScrolledToSelected:()=>ej.setShouldScrollToSelected(!1),onCreateFile:e=>ej.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>A({path:e,isDirectory:t,name:r}),onRefresh:()=>ej.loadFiles(),onCopyFile:eV,onPaste:eU})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===w?"":"hidden"}`,children:ey.isSearching?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ey.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ey.searchError}):0===ey.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ey.contentSearchQuery?j("fileBrowser.noContentSearchResults"):j("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[ey.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-secondary border-b border-border flex-shrink-0",children:[j("fileBrowser.nFilesNMatches",{files:ey.searchStats.totalFiles,matches:ey.searchStats.totalMatches}),ey.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",j("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(Z,{files:e$.files,selectedPath:ej.selectedPath,expandedPaths:eR,onSelect:e=>{let t=e$.matchMap.get(e);eT(e,t?.matches[0]?.lineNumber),G||er(!0)},onToggle:eB,cwd:t,renderActions:eI,className:"flex-1 overflow-y-auto py-1 min-w-max"})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"recent"===w?"":"hidden"}`,children:0===ej.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noRecentFiles")}):(0,n.jsx)(Z,{files:ej.recentFilesTree,selectedPath:ej.selectedPath,expandedPaths:ej.recentTreeDirPaths,onSelect:eT,onToggle:et.tE,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===w?"":"hidden"}`,children:ew.statusLoading?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ew.statusError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center p-4",children:(0,n.jsx)("span",{className:"text-red-11 text-sm",children:ew.statusError})}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:j("fileBrowser.stagingArea",{count:ew.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>ew.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("fileBrowser.refreshChanges"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),(ew.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:ew.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:j("fileBrowser.unstageAll")})]}),(0,n.jsx)($,{files:ew.stagedTree,selectedPath:ew.statusSelectedFile?.type==="staged"?ew.statusSelectedFile.file.path:null,expandedPaths:ew.statusExpandedPaths,onSelect:e=>e.file&&ew.handleStatusFileSelect(e.file,"staged"),onToggle:ew.handleStatusToggle,cwd:t,emptyMessage:j("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=B(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleUnstageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:j("fileBrowser.unstageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}return(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleUnstage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:j("fileBrowser.unstageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:j("fileBrowser.workspace",{count:ew.status?.unstaged.length||0})}),(ew.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:ew.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:j("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:ew.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:j("fileBrowser.stageAll")})]})]}),(0,n.jsx)($,{files:ew.unstagedTree,selectedPath:ew.statusSelectedFile?.type==="unstaged"?ew.statusSelectedFile.file.path:null,expandedPaths:ew.statusExpandedPaths,onSelect:e=>e.file&&ew.handleStatusFileSelect(e.file,"unstaged"),onToggle:ew.handleStatusToggle,cwd:t,emptyMessage:j("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=B(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleDiscardFiles(r)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:j("fileBrowser.discardNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ew.handleStageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:j("fileBrowser.stageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]})}return e.file?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleDiscardFile(e.file)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:j("fileBrowser.discardChanges"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ew.handleStage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:j("fileBrowser.stageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]}):null}})]})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"history"===w?"":"hidden"}`,children:eC.historyError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-muted-foreground",children:eC.historyError})]})}):eC.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:eC.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.loadingDiff")}):0===eC.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noDiffFiles")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:j("fileBrowser.nFilesChanged",{count:eC.compareFiles.length,branch:eC.compareBaseBranch})})}),(0,n.jsx)($,{files:eC.compareFileTree,expandedPaths:eC.compareExpandedPaths,onToggle:eC.handleCompareToggle,selectedPath:eC.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eC.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eC.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eC.handleCommitListScroll,children:eC.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.loadingCommits")}):0===eC.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:j("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eC.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>eC.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eC.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-slate-9",title:e.date,children:[e.relativeDate," \xb7 ",(0,et.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),eC.isLoadingMore&&(0,n.jsx)("div",{className:"p-3 text-center",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),!eC.hasMoreCommits&&eC.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:j("fileBrowser.allLoaded",{count:eC.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===w||"search"===w||"recent"===w)&&(ej.blameSelectedCommit?(0,n.jsx)(Y,{isOpen:!0,onClose:()=>ej.setBlameSelectedCommit(null),commit:ej.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:ej.selectedPath||void 0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):"map"===C?(0,n.jsx)(eZ,{cwd:t,highlightedFilePath:ej.selectedPath,changedFiles:ek,onSwitchToCode:()=>S("code"),enableComments:!0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)},headerExtraLeft:({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,p.oR)(j("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),e1(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]})}):ej.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex-shrink-0 flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:ej.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${ej.selectedPath}`),(0,p.oR)(j("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),e1(ej.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:j("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:ej.showEditor?(0,n.jsxs)(n.Fragment,{children:[K.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:j("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>V.current?.save(),disabled:!K.isDirty||K.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${K.isDirty&&!K.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:K.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):j("common.save")}),(0,n.jsx)("button",{onClick:()=>V.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.closeEdit"),children:j("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[ej.fileContent?.type==="text"&&ej.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(ej.fileContent.content),(0,p.oR)(j("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.copyFileContent"),children:j("common.copy")}),ej.selectedPath?.endsWith(".json")&&ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>es(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${en?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:j("fileBrowser.toggleJsonReadable"),children:j("common.readable")}),ej.fileContent?.type==="text"&&U(ej.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ej.setShowMarkdownPreview(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.previewMarkdown"),children:j("common.preview")}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:ej.handleToggleBlame,disabled:ej.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ej.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:j("fileBrowser.viewBlame"),children:ej.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>S("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("blockViewer.viewerToggle.toBlock"),children:j("common.codeMap")}),ej.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>ej.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:j("fileBrowser.editFile"),children:j("common.edit")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:ej.isLoadingContent?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ej.fileContent?"text"===ej.fileContent.type&&"string"==typeof ej.fileContent.content?ej.showBlame&&ej.blameError?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-red-11",children:ej.blameError}),(0,n.jsx)("button",{onClick:()=>ej.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:j("fileBrowser.backToPreview")})]})}):ej.showBlame&&0===ej.blameLines.length&&ej.isLoadingBlame?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):en&&ej.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(X,{search:ec}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:ea,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:D(ej.fileContent.content)})})]}):(0,n.jsx)(ee.Cv,{ref:V,content:ej.fileContent.content,filePath:ej.selectedPath,cwd:t,enableComments:!0,scrollToLine:_??ej.targetLineNumber,scrollToLineAlign:null!=_?"start":ej.targetScrollAlign,onScrollToLineComplete:()=>{q(null),ej.setTargetLineNumber(null)},highlightKeyword:"search"===w?ey.contentSearchQuery:null,visibleLineRef:z,viStateRef:H,initialCursorLine:ej.initialCursorLine,initialCursorCol:ej.initialCursorCol,onInitialCursorSet:()=>{ej.setInitialCursorLine(null),ej.setInitialCursorCol(null)},onCmdClick:eF?eA:void 0,onTokenHover:eF?eO:void 0,onTokenHoverLeave:eF?ep.onTokenMouseLeave:void 0,onTokenHoverCancel:eF?ep.clearHover:void 0,blameLines:ej.showBlame&&ej.blameLines.length>0?ej.blameLines:void 0,inlineBlameLines:ej.blameLines.length>0?ej.blameLines:void 0,onSelectCommit:ej.setBlameSelectedCommit,editable:ej.showEditor,initialMtime:ej.fileContent.mtime,onEditorClose:e=>{ej.setShowEditor(!1),q(e)},onSaved:()=>{let e=z.current??1;ej.loadFileContent(ej.selectedPath),ej.setShowEditor(!1),q(e)},onEditorStateChange:Q,viMode:!0,onContentMutate:eS,onEnterInsertMode:eL,onViSave:eM,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):"image"===ej.fileContent.type&&ej.selectedPath?(0,n.jsx)(td,{cwd:t,path:ej.selectedPath,refreshKey:ej.fileContent.mtime,alt:ej.selectedPath}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("p",{children:ej.fileContent.message||j("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:j("fileBrowser.selectFileToPreview")})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("p",{children:j("fileBrowser.selectFileToPreview")})]})})),"status"===w&&(ew.statusSelectedFile&&ew.statusDiff?(0,n.jsx)(tu,{cwd:t,selected:ew.statusSelectedFile,diff:ew.statusDiff,showMarkdownPreview:ew.showStatusDiffPreview,setShowMarkdownPreview:ew.setShowStatusDiffPreview,changedFiles:ek,fileGitStatusMap:eN,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)},locateInTree:e1,jsonPreview:eo,setJsonPreview:el,jsonPreviewSearch:ex,jsonPreviewPreRef:em}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:j("fileBrowser.selectFileToViewDiff")})})),"history"===w&&!eC.historyError&&(eC.compareMode?eC.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:j("fileBrowser.loadingDiffContent")}):eC.compareFileDiff?(0,n.jsx)(N,{oldContent:eC.compareFileDiff.oldContent,newContent:eC.compareFileDiff.newContent,filePath:eC.compareFileDiff.filePath,isNew:eC.compareFileDiff.isNew,isDeleted:eC.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eC.compareFileDiff.isDeleted&&eC.compareFileDiff.filePath.endsWith(".json")?()=>el({content:eC.compareFileDiff.newContent,filePath:eC.compareFileDiff.filePath}):void 0,previewLabel:j("common.readable"),onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eC.compareFiles.length>0?j("fileBrowser.selectFileToViewDiff"):j("fileBrowser.clickCompareToLoad")})}):eC.selectedCommit?(0,n.jsx)(Y,{isOpen:!0,onClose:()=>eC.setSelectedCommit(null),commit:eC.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:j("fileBrowser.selectCommitToView")})}))]})]}),ej.showMarkdownPreview&&ej.fileContent?.type==="text"&&ej.selectedPath&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>ej.setShowMarkdownPreview(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ei,{content:ej.fileContent.content||"",filePath:ej.selectedPath,cwd:t,onClose:()=>ej.setShowMarkdownPreview(!1)})})}),O&&(0,n.jsx)(ed,{files:ej.files,fileIndex:ej.fileIndex,recentFiles:ej.recentFilePaths,onSelectFile:e=>{eT(e),ej.setShouldScrollToSelected(!0),k("tree")},onClose:()=>W(!1)}),(eD||eg.visible)&&(0,n.jsxs)("div",{className:`flex ${eg.visible&&eD?"":"flex-col"}`,children:[eD&&(0,n.jsx)("div",{className:eg.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tg,{results:ey.contentSearchResults,loading:ey.isSearching,totalMatches:ey.searchStats?.totalMatches??0,onSelect:(e,t)=>{ej.selectedPath&&eb.push({filePath:ej.selectedPath,lineNumber:z.current}),eT(e,t)},onClose:()=>er(!1)})}),eg.visible&&(0,n.jsx)("div",{className:eD?"flex-1 min-w-0":"",children:(0,n.jsx)(tp,{references:eg.references,loading:eg.loading,onSelect:eW,onClose:eg.closeReferences})})]})]}),F&&(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>A(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl p-4 max-w-sm w-full mx-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-2",children:j("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:j("fileBrowser.confirmDeleteMessage",{name:F.name}).split(/<\/?file>/g).map((e,t)=>1===t?(0,n.jsx)("span",{className:"font-mono text-foreground",children:e},t):e)}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>A(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:j("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=F;A(null);try{let n=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:e})});if(n.ok){(0,p.oR)(j("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";ej.loadDirectory(t),ej.loadFileIndex(),ej.selectedPath===e&&eT("")}else{let e=await n.json();(0,p.oR)(e.error||j("toast.deleteFailed"),"error")}}catch{(0,p.oR)(j("toast.deleteFailed"),"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:j("common.delete")})]})]})})}),ep.hoverInfo&&E&&(0,a.createPortal)((0,n.jsx)(tf,{ref:ep.setTooltipEl,displayString:ep.hoverInfo.displayString,documentation:ep.hoverInfo.documentation,x:ep.hoverInfo.x,y:ep.hoverInfo.y,container:E,onMouseEnter:ep.onCardMouseEnter,onMouseLeave:ep.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=ep.hoverInfo;ep.clearHover(),eg.findReferences(e,t,r)},onSearch:e=>{ep.clearHover(),k("search"),ey.setContentSearchQuery(e),ey.performContentSearch(e)}}),E)]})}function tj({isOpen:e,onClose:t,cwd:r}){let l,{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[h,m]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,N]=(0,s.useState)(""),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)([]),[E,T]=(0,s.useState)(""),[$,R]=(0,s.useState)(!1),P=(0,s.useCallback)(async()=>{f(!0);try{let e=await fetch(`/api/git/worktree?cwd=${encodeURIComponent(r)}`);if(e.ok){let t=await e.json();c(t.worktrees),u(t.nextPath),m(t.nextRandomWord),t.gitUserName&&N(t.gitUserName)}}catch(e){console.error("Failed to load worktrees:",e),(0,p.oR)(a("toast.worktreeLoadFailed"),"error")}finally{f(!1)}},[r]),B=(0,s.useCallback)(e=>{let{local:t,remote:r}=e;return r.includes("origin/main")?"origin/main":r.includes("origin/master")?"origin/master":t.includes("main")?"main":t.includes("master")?"master":r.length>0?r[0]:t.length>0?t[0]:"main"},[]);(0,s.useEffect)(()=>{e&&(P(),j(null))},[e,P]);let I=async()=>{if(!d)return;let e="origin/main";try{let t=await fetch(`/api/git/branches?cwd=${encodeURIComponent(r)}`);if(t.ok){let r=await t.json();e=B(r)}}catch{}let t=h||function(){let e="bcdfghjklmnprstvwz",t=["a","e","i","o","u","ai","au","ea","ee","ia","io","oa","oo","ou","ui"],r="";for(let n=0;n<2;n++)r+=e[Math.floor(Math.random()*e.length)],r+=t[Math.floor(Math.random()*t.length)];return r}(),n=k?`${k}/${t}`:t;b(!0);try{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",cwd:r,path:d,newBranch:n,baseBranch:e})});if(t.ok)(0,p.oR)(a("toast.worktreeCreateSuccess",{name:n}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||a("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(a("toast.worktreeCreateFailed"),"error")}finally{b(!1)}},D=async()=>{R(!0),T(""),S(!0);try{let e=await fetch(`/api/git/branches?cwd=${encodeURIComponent(r)}`);if(e.ok){let t=await e.json(),r=new Set(i.map(e=>e.branch).filter(Boolean)),n=[...t.local.filter(e=>!r.has(e)),...t.remote.filter(e=>!r.has(e)&&!t.local.includes(e.replace(/^origin\//,"")))];M(n)}}catch{(0,p.oR)(a("toast.loadBranchFailed"),"error")}finally{R(!1)}},F=async e=>{if(d){S(!1),b(!0);try{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",cwd:r,path:d,branch:e})});if(t.ok)(0,p.oR)(a("toast.worktreeCreateSuccess",{name:e}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||a("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(a("toast.worktreeCreateFailed"),"error")}finally{b(!1)}}},A=async()=>{if(v){w(!0);try{let e=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"remove",cwd:r,path:v.path})});if(e.ok)(0,p.oR)(a("toast.worktreeDeleted"),"success"),j(null),P();else{let t=await e.json();(0,p.oR)(t.error||a("toast.worktreeDeleteFailed"),"error")}}catch(e){console.error("Failed to delete worktree:",e),(0,p.oR)(a("toast.worktreeDeleteFailed"),"error")}finally{w(!1)}}},O=async e=>{let t=e.isLocked?"unlock":"lock";try{let n=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,cwd:r,path:e.path})});if(n.ok)(0,p.oR)(e.isLocked?a("toast.worktreeUnlocked"):a("toast.worktreeLocked"),"success"),P();else{let e=await n.json();(0,p.oR)(e.error||a("toast.operationFailed"),"error")}}catch(e){console.error("Failed to toggle lock:",e),(0,p.oR)(a("toast.operationFailed"),"error")}};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[480px] max-h-[80vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:"Git Worktrees"}),(0,n.jsx)("button",{onClick:t,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:a("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:x?(0,n.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):(0,n.jsx)("div",{className:"space-y-2",children:i.map(e=>{let s=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${s?"border-brand bg-brand/5":"border-border hover:bg-accent cursor-pointer"}`,onClick:()=>{e.path!==r&&(window.parent.postMessage({type:"OPEN_PROJECT",cwd:e.path},"*"),t())},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${s?"bg-brand":"bg-muted-foreground/30"}`}),(0,n.jsx)("span",{className:"font-medium text-foreground truncate",children:e.branch||(e.isDetached?"detached":"unknown")}),e.isLocked&&(0,n.jsx)("span",{className:"text-amber-11",title:a("git.worktree.locked"),children:"\uD83D\uDD12"}),s&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",a("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),O(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?a("git.worktree.unlock"):a("git.worktree.lock"),children:e.isLocked?(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"})}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:a("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate pl-4",children:e.path}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),C&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-3 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("input",{value:E,onChange:e=>T(e.target.value),placeholder:a("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none placeholder:text-muted-foreground",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>S(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:a("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:$?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("common.loading")}):0===(l=L.filter(e=>e.toLowerCase().includes(E.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("git.worktree.noBranches")}):l.map(e=>(0,n.jsx)("button",{onClick:()=>F(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate",children:(0,n.jsx)("span",{className:`${e.startsWith("origin/")?"text-muted-foreground":"text-foreground"}`,children:e})},e))})]}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:a("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:D,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:a("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:I,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:g?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):a("git.worktree.addWorktree")})]})]}),v&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-black/50 rounded-lg",onClick:()=>j(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:a("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:a("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:a("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:v.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:a("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:v.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>j(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:a("common.cancel")}),(0,n.jsx)("button",{onClick:A,disabled:y,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:y?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):a("common.delete")})]})]})})]})}):null}var ty=r(67635),tw=r(73300),tk=r(20986),tN=r(9921),tC=r(66088),tS=r(42790);function tL(e){let t=function(e){let t=0xffffffff;for(let r=0;r<e.length;r++){t^=e.charCodeAt(r);for(let e=0;e<8;e++)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}(e),r="",n=t;for(let e=0;e<4;e++)r+=String.fromCharCode(97+n%26),n=Math.floor(n/26);return r}let tM=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)(async n=>{if(n.stopPropagation(),i)await l(),c(!1),(0,p.oR)(a("toast.disconnected",{id:e}));else{await r(),c(!0);let n=`${"3456"===window.location.port?"cock-dev":"cock"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,p.oR)(a("toast.copiedCommand",{command:n}))}},[i,e,t,r,l,a]);return(0,n.jsxs)("button",{onClick:d,className:"inline-flex items-center gap-1 text-[10px] font-mono leading-none px-1.5 py-0.5 rounded flex-shrink-0 transition-colors bg-muted/60 hover:bg-muted text-muted-foreground",title:i?a("shortIdBadge.clickToDisconnect"):a("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${i?"bg-green-500":"bg-muted-foreground/40"}`}),e]})});var tE=r(12786);let tT=(0,s.lazy)(()=>Promise.all([r.e(3888),r.e(1959)]).then(r.bind(r,71959)).then(e=>({default:e.XtermRenderer}))),t$={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},tR=/\x1b\[[0-9;]*m/g;function tP({output:e,query:t,mode:r,currentIdx:o,matchListRef:l}){let a=(0,s.useRef)(null);a.current||(a.current=new tS.v,a.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return l.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(tR,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=a.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],h=0,m=s.toLowerCase(),x=0;for(;x<m.length;){let e=m.indexOf(c,x);if(-1===e)break;e>h&&u.push((0,n.jsx)("span",{children:s.slice(h,e)},`t${h}`));let t=d++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{l.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+c.length)},`m${e}`)),x=h=e+c.length}return h<s.length&&u.push((0,n.jsx)("span",{children:s.slice(h)},`t${h}`)),(0,n.jsx)("div",{children:u},t)})})}let tB=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:l,output:a,exitCode:i,isRunning:c,selected:d,onSelect:u,onInterrupt:h,onStdin:m,onDelete:x,onRerun:f,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,onPtyResize:y,onToggleMaximize:w,maximized:k,expandedHeight:N,bubbleContentHeight:C,onTitleMouseDown:S}){let{t:L}=(0,o.Bd)(),M=(0,s.useRef)(null),E=(0,s.useRef)(null),T=(0,s.useRef)(!0),$=(0,s.useRef)(null),R=(0,s.useRef)(null),P=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(g),B=e&&t?tL(t+e):void 0,[I,D]=(0,s.useState)(!1),[F,A]=(0,s.useState)(""),O=(0,s.useRef)(null),W=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>O.current?v(e,O.current.write):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[v,e]),(0,s.useEffect)(()=>{if(!j||!e)return;let t=()=>O.current?j(e,O.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]);let[z,H]=(0,s.useState)(!1),[_,q]=(0,s.useState)(""),[V,U]=(0,s.useState)("search"),[K,J]=(0,s.useState)(0),X=(0,s.useRef)([]),Y=(0,s.useRef)(null),Q=(0,s.useRef)(0);(0,s.useEffect)(()=>{Y.current||(Y.current=new tS.v,Y.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=E.current;if(e&&Y.current){if(a.length<Q.current&&(Y.current=new tS.v,Y.current.use_classes=!0,Q.current=0,e.innerHTML=""),a.length>Q.current){let t=a.slice(Q.current),r=Y.current.ansi_to_html(t);Q.current=a.length,e.insertAdjacentHTML("beforeend",r)}if(M.current){let e=M.current.scrollHeight>M.current.clientHeight;D(e),e&&(M.current.scrollTop=M.current.scrollHeight)}}},[a]),(0,s.useEffect)(()=>(c&&T.current&&M.current&&(null!==$.current&&cancelAnimationFrame($.current),$.current=requestAnimationFrame(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight),$.current=null})),()=>{null!==$.current&&cancelAnimationFrame($.current)}),[a,c]),(0,s.useEffect)(()=>{if(!k)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),w?.())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[k,w]);let G=a?a.split("\n").length:0,Z=(0,s.useCallback)(()=>{H(!0),requestAnimationFrame(()=>W.current?.focus())},[]),ee=(0,s.useCallback)(()=>{H(!1),q(""),J(0),O.current?.clearSearch()},[]),et=(0,s.useCallback)(e=>{e.trim()&&(b?O.current?.findNext(e):J(e=>{let t=e+1,r=X.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(X.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),er=(0,s.useCallback)(e=>{e.trim()&&(b?O.current?.findPrevious(e):J(e=>{let t=e-1;if(t>=0)return X.current[t]?.scrollIntoView({block:"nearest"}),t;let r=X.current.length-1;return r>=0&&X.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[b]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),Z();return}if("Escape"===e.key&&z){e.preventDefault(),e.stopPropagation(),ee();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,z,Z,ee]);let en=k&&N?N-41:C??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground dark:text-slate-11 relative overflow-hidden border transition-colors cursor-pointer ${k?"rounded-none border-0":"rounded-2xl rounded-bl-md rounded-br-md"} ${k?"":d?"border-brand":"border-brand/30"}`,onClick:u,children:[k?(0,n.jsxs)("div",{onDoubleClick:()=>w?.(),className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41,flexShrink:0},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded bg-muted text-muted-foreground",children:">_"}),(0,n.jsx)("span",{className:"flex-1 text-xs text-muted-foreground truncate font-mono",children:l}),c&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse"}),L("console.runningText")]}),c&&h&&(0,n.jsx)("button",{onClick:h,className:"text-xs px-3 py-1 rounded-md font-medium bg-destructive text-destructive-foreground transition-all duration-150 hover:bg-destructive/80 hover:shadow-md active:scale-95 active:bg-destructive/70 cursor-pointer select-none",children:"Ctrl+C"}),(0,n.jsx)("button",{onClick:()=>w?.(),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.restoreTooltip",{modKey:(0,tE.Mu)()}),children:(0,n.jsx)(ex.A,{className:"w-4 h-4"})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>S?.(),onDoubleClick:e=>{e.stopPropagation(),w?.()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing ${d?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:">_"}),B&&e&&t&&(0,n.jsx)(tM,{shortId:B,type:"terminal",onRegister:()=>{fetch("/api/terminal/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tabId:t,commandId:e,command:l,projectCwd:r})}).catch(()=>{})},onUnregister:()=>{fetch("/api/terminal/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandId:e})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:l}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(l),(0,p.oR)(L("toast.copiedCmd"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyCommand"),children:(0,n.jsx)(ty.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),I&&!c&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:L("console.totalLines",{count:G})}),a&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=a.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,p.oR)(L("toast.copiedOutput"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyOutput"),children:(0,n.jsx)(tw.A,{className:"w-3.5 h-3.5"})}),f&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),f()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.rerun"),children:(0,n.jsx)(tk.A,{className:"w-3.5 h-3.5"})}),x&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:L("console.deleteRecord"),children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),z&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card",style:{flexShrink:0},children:[(0,n.jsx)(em.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:W,value:_,onChange:e=>{let t=e.target.value;q(t),J(0),b&&(t.trim()?O.current?.findNext(t):O.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?er(_):et(_))},placeholder:L("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}),!b&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>U("search"),className:`px-1.5 py-0.5 rounded transition-colors ${"search"===V?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:L("console.searchMode")}),(0,n.jsx)("button",{onClick:()=>U("filter"),className:`px-1.5 py-0.5 rounded transition-colors ${"filter"===V?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:L("console.filterMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>er(_),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.prevShiftEnter"),children:(0,n.jsx)(tN.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>et(_),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.nextEnter"),children:(0,n.jsx)(tC.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:ee,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsx)("div",{style:{height:en,overflow:"hidden"},children:(0,n.jsx)(s.Suspense,{fallback:(0,n.jsx)("div",{className:"px-4 py-2 text-xs text-muted-foreground",style:{height:en},children:L("console.loadingTerminal")}),children:(0,n.jsx)(tT,{ref:O,output:a,isRunning:c,onInput:m,onResize:y,maximized:k,height:en,directWrite:!!v})})}):(0,n.jsx)("div",{ref:M,className:"overflow-auto px-4 py-2",style:{height:en},onScroll:()=>{if(M.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=M.current;T.current=t-e-r<50}},children:z&&_.trim()?(0,n.jsx)(tP,{output:a,query:_,mode:V,currentIdx:K,matchListRef:X}):(0,n.jsx)("pre",{ref:E,className:"text-sm font-mono whitespace-pre-wrap break-words select-text"})}),c&&!k&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse flex-shrink-0"}),b?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-1",children:L("console.clickToInput")}):m?(0,n.jsx)("input",{ref:R,value:F,onChange:e=>A(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=t$[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),m(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),m(F+"\n"),A("")),"Tab"===e.key&&(e.preventDefault(),m(" "))},placeholder:L("console.stdinPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs font-mono text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:L("console.runningText")}),h&&(0,n.jsx)("button",{onClick:h,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),P&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:P})]}),!c&&void 0!==i&&!k&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${0===i?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:L("console.exitCode",{code:i})}),(0,n.jsx)("span",{className:"flex-1"}),P&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:P})]})]})})});var tI=r(68459),tD=r(51914);function tF({cwd:e,tabId:t,onClose:r,onSave:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)(""),[h,m]=(0,s.useState)(""),[x,f]=(0,s.useState)(!0),p=(0,s.useCallback)(async()=>{f(!0);try{let r=new URLSearchParams({cwd:e});t&&r.set("tabId",t);let n=await fetch(`/api/terminal/env?${r}`);if(n.ok){let e=await n.json();c(e.env||{})}}catch(e){console.error("Failed to load env:",e)}finally{f(!1)}},[e,t]);(0,s.useEffect)(()=>{p()},[p]);let g=()=>{d.trim()&&(c(e=>({...e,[d.trim()]:h})),u(""),m(""))},b=async()=>{try{(await fetch("/api/terminal/env",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:t,env:i})})).ok&&(l(i),r())}catch(e){console.error("Failed to save env:",e)}};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-lg font-semibold",children:a("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?a("envManager.tabScope"):a("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:x?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:a("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(i).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"flex-1 px-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void c(t=>({...t,[e]:r}))},placeholder:a("envManager.valuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>{c(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors",children:(0,n.jsx)(tI.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:a("envManager.varNamePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("input",{type:"text",value:h,onChange:e=>m(e.target.value),placeholder:a("envManager.varValuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("button",{onClick:g,disabled:!d.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(tD.A,{className:"w-4 h-4"})})]}),0===Object.keys(i).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:a("envManager.noVars")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:a("common.cancel")}),(0,n.jsx)("button",{onClick:b,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:a("common.save")})]})]})})}var tA=r(10762);function tO({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[h,m]=(0,s.useState)(!0),x=(0,s.useCallback)(async()=>{m(!0);try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();a(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}finally{m(!1)}},[]);(0,s.useEffect)(()=>{x()},[x]);let f=()=>{i.trim()&&d.trim()&&(a(e=>({...e,[i.trim()]:d.trim()})),c(""),u(""))},p=async()=>{try{(await fetch("/api/terminal/aliases",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({aliases:l})})).ok&&(t(l),e())}catch(e){console.error("Failed to save aliases:",e)}};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[(0,n.jsx)(tA.A,{className:"w-5 h-5"}),r("aliasManager.title")]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:r("aliasManager.description")})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(ex.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:h?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:r("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(l).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2 group",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"})]}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void a(t=>({...t,[e]:r}))},placeholder:r("aliasManager.fullCommandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"})]}),(0,n.jsx)("button",{onClick:()=>{a(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100",children:(0,n.jsx)(tI.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:r("aliasManager.aliasPlaceholder"),className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),f())}})]}),(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:r("aliasManager.commandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),f())}})]}),(0,n.jsx)("button",{onClick:f,disabled:!i.trim()||!d.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(tD.A,{className:"w-4 h-4"})})]}),(0,n.jsxs)("div",{className:"mt-4 p-3 bg-accent rounded-lg",children:[(0,n.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,n.jsx)("strong",{children:r("aliasManager.usage")}),r("aliasManager.usageDesc")]}),(0,n.jsxs)("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ ll"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"ls -la"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ gs"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"git status"})]})]})]}),0===Object.keys(l).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:r("aliasManager.noAliases")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:e,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:p,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:r("common.save")})]})]})})}var tW=r(53961),tz=r(15813),tH=r(37595),t_=r(49698),tq=r(20232);let tV=new Map;function tU(e){tV.set(e.type,e)}function tK(e){return tV.get(e)}function tJ(e){for(let t of tV.values())if(t.match(e))return t;return null}var tX=r(53853);function tY(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.set("_cockpit","1"),t.toString()}catch{let t=e.includes("?")?"&":"?";return`${e}${t}_cockpit=1`}}function tQ(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.delete("_cockpit"),t.toString()}catch{return e.replace(/[?&]_cockpit=1/,"")}}async function tG(e){let t=(0,tX.f)()?.id??null;return!!t&&new Promise(r=>{try{let n=globalThis.chrome?.runtime;if(!n?.sendMessage)return void r(!1);let s=setTimeout(()=>r(!1),2e3);n.sendMessage(t,{type:"prepare-iframe",url:e},e=>{clearTimeout(s),r(e?.ok??!1)})}catch{r(!1)}})}function tZ(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function t0({url:e,id:t,selected:r,maximized:l,expandedHeight:a,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,onNewTab:h,timestamp:m,onTitleMouseDown:x,initialSleeping:f,onSleep:g,onWake:b}){let{t:v}=(0,o.Bd)(),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(e),[S,L]=(0,s.useState)(null),[M,E]=(0,s.useState)(f??!1),T=(0,s.useRef)(null),$=(0,s.useRef)(null),R=(0,s.useRef)(null);(0,s.useEffect)(()=>{C(e)},[e]);let P=(0,s.useRef)(!0),B=(0,s.useCallback)(()=>{M||(E(!0),L(null),g?.(t))},[M,t,g]),I=(0,s.useCallback)(()=>{T.current&&(clearTimeout(T.current),T.current=null)},[]),{shortId:D,connected:F,connect:A,disconnect:O}=function(e,t,r){let n=(0,s.useMemo)(()=>tL(e),[e]),[o,l]=(0,s.useState)(!1),a=(0,s.useRef)(null),i=(0,s.useRef)([]),c=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,s.useRef)(r);(0,s.useEffect)(()=>{u.current=r});let h=(0,s.useRef)([]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="cockpit:cmd-result"){let{reqId:t,ok:r,data:n,error:s}=e.data,o=a.current;o&&o.readyState===WebSocket.OPEN&&o.send(JSON.stringify({type:"browser:cmd-result",reqId:t,ok:r,data:n,error:s}));return}if(e.data?.type==="cockpit:prepare-screenshot"){let r=t.current;if(!r?.contentWindow)return;let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),window.parent.postMessage({type:"SCREENSHOT_PREPARE",cwd:n},"*"),requestAnimationFrame(()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(()=>{let t=r.getBoundingClientRect(),n=window.devicePixelRatio||1,s=t.x,o=t.y;try{let e=window;for(;e!==e.top;){let t=e.frameElement;if(t){let e=t.getBoundingClientRect();s+=e.x,o+=e.y}e=e.parent}}catch{}r.contentWindow?.postMessage({type:"cockpit:screenshot-bounds",reqId:e.data.reqId,bounds:{x:Math.round(s*n),y:Math.round(o*n),width:Math.round(t.width*n),height:Math.round(t.height*n),dpr:n}},"*")},150)})));return}if(e.data?.type==="cockpit:screenshot-done"){window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),window.parent.postMessage({type:"SCREENSHOT_DONE"},"*");return}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let m=(0,s.useCallback)(e=>{let r=t.current;if(!r?.contentWindow){let t=a.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"browser:cmd-result",reqId:e.reqId,ok:!1,error:"iframe not available (page may be sleeping)"}));return}r.contentWindow.postMessage({type:"cockpit:cmd",reqId:e.reqId,action:e.action,params:e.params},"*")},[t]);(0,s.useEffect)(()=>{if(!o)return;let r=!1;return d.current=!0,!function n(){if(r||!d.current)return;let s="https:"===window.location.protocol?"wss:":"ws:",o=new WebSocket(`${s}//${window.location.host}/ws/browser?fullId=${encodeURIComponent(e)}`);a.current=o,o.onopen=()=>{for(let e of h.current)e();if(h.current=[],i.current.length>0){for(let e of i.current)m(e);i.current=[]}},o.onmessage=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("browser:cmd"===r.type){let e=r;t.current?.contentWindow&&u.current?m(e):i.current.push(e)}},o.onclose=()=>{a.current=null,!r&&d.current&&(c.current=setTimeout(n,3e3))},o.onerror=()=>o.close()}(),()=>{r=!0,d.current=!1,c.current&&clearTimeout(c.current),a.current&&(a.current.close(),a.current=null),h.current=[]}},[o,e,t,m]),(0,s.useEffect)(()=>{if(r&&i.current.length>0){for(let e of i.current)m(e);i.current=[]}},[r,m]);let x=(0,s.useCallback)(()=>o&&a.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{h.current.push(e),o||l(!0)}),[o]);return{shortId:n,connected:o,connect:x,disconnect:(0,s.useCallback)(()=>{l(!1)},[])}}(t,R,!!S&&!M&&!j),W=(0,s.useRef)(F);W.current=F,(0,s.useEffect)(()=>{let e=$.current;if(!e||M)return;let t=new IntersectionObserver(([e])=>{P.current=e.isIntersecting,e.isIntersecting||W.current?I():(T.current&&clearTimeout(T.current),T.current=setTimeout(B,3e5))});return t.observe(e),()=>t.disconnect()},[M,B,I]),(0,s.useEffect)(()=>{M?O():F?I():P.current||(T.current&&clearTimeout(T.current),T.current=setTimeout(B,3e5))},[F,M,O,I,B]),(0,s.useEffect)(()=>{f&&L(null)},[]);let z=(0,s.useCallback)(()=>{E(!1),b?.(t);let r=tY(e);tZ(e)?L(r):tG(e).then(()=>L(r))},[e,t,b]);(0,s.useEffect)(()=>{if(!e||M){e||L(null);return}let t=tY(e);if(tZ(e))return void L(t);let r=!1;return tG(e).then(()=>{r||L(t)}),()=>{r=!0}},[e,M]);let H=(0,s.useCallback)(()=>y(!1),[]);(0,s.useEffect)(()=>{let e=$.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,l=()=>{o&&t&&(t.scrollTop=s)},a=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",l)},i=()=>{o=!1,t.removeEventListener("scroll",l),t.style.overflow=n};return e.addEventListener("mouseenter",a),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",a),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",l),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=$.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?h?.(tQ(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&C(tQ(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,h]);let _=(0,s.useCallback)(()=>{y(!1),k(v("browser.pageLoadFailed"))},[]),q=(0,s.useCallback)(()=>{if(M)return void z();let e=$.current?.querySelector("iframe");if(e&&S){y(!0),k(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[M,z,S]);(0,s.useEffect)(()=>{e&&!M&&(y(!0),k(null))},[e,M]);let V=(0,s.useCallback)(()=>{N&&window.open(N,"_blank")},[N]);(0,s.useEffect)(()=>{if(!r&&!l)return;let e=e=>{"Escape"===e.key&&l&&(e.stopPropagation(),u()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),u())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[l,r,u]);let U=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e}}(N),K=l&&a?a-41:i??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
|
|
2
2
|
relative transition-colors cursor-pointer
|
|
3
3
|
${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
|
|
4
4
|
${l?"":r?"border-brand":"border-brand/30"}`,onClick:l?void 0:c,children:[l?(0,n.jsxs)("div",{onDoubleClick:u,className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),D&&(0,n.jsx)(tM,{shortId:D,type:"browser",onRegister:()=>A(),onUnregister:async()=>{O(),await fetch("/api/browser/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:D})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate font-mono",children:N||v("browser.blankPage")}),N&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(N),(0,p.oR)(v("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),j&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:q,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:V,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:u,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.exitMaximize",{modKey:(0,tE.Mu)()}),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>x?.(),onDoubleClick:e=>{e.stopPropagation(),u()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing
|