9remote 3.0.24 → 3.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/dist/cli.cjs +50 -48
  2. package/dist/server.cjs +24 -24
  3. package/dist/ui/assets/index-BOOiLX1B.js +8 -0
  4. package/dist/ui/index.html +1 -1
  5. package/dist/web/404.html +1 -1
  6. package/dist/web/__next.__PAGE__.txt +2 -2
  7. package/dist/web/__next._full.txt +2 -2
  8. package/dist/web/__next._head.txt +1 -1
  9. package/dist/web/__next._index.txt +1 -1
  10. package/dist/web/__next._tree.txt +1 -1
  11. package/dist/web/_next/static/chunks/app/login/{page-2a2743b7f8cb2435.js → page-5a8b059b59f831f9.js} +1 -1
  12. package/dist/web/_next/static/chunks/app/{page-590ad581a1270380.js → page-bd6ebc0a436fea70.js} +2 -2
  13. package/dist/web/_next/static/chunks/app/workspace/{layout-d6c53117c6436790.js → layout-4b7802a47d5a41d9.js} +1 -1
  14. package/dist/web/_not-found/__next._full.txt +1 -1
  15. package/dist/web/_not-found/__next._head.txt +1 -1
  16. package/dist/web/_not-found/__next._index.txt +1 -1
  17. package/dist/web/_not-found/__next._not-found.__PAGE__.txt +1 -1
  18. package/dist/web/_not-found/__next._not-found.txt +1 -1
  19. package/dist/web/_not-found/__next._tree.txt +1 -1
  20. package/dist/web/_not-found.html +1 -1
  21. package/dist/web/_not-found.txt +1 -1
  22. package/dist/web/admin/__next._full.txt +1 -1
  23. package/dist/web/admin/__next._head.txt +1 -1
  24. package/dist/web/admin/__next._index.txt +1 -1
  25. package/dist/web/admin/__next._tree.txt +1 -1
  26. package/dist/web/admin/__next.admin.__PAGE__.txt +1 -1
  27. package/dist/web/admin/__next.admin.txt +1 -1
  28. package/dist/web/admin/admins/__next._full.txt +1 -1
  29. package/dist/web/admin/admins/__next._head.txt +1 -1
  30. package/dist/web/admin/admins/__next._index.txt +1 -1
  31. package/dist/web/admin/admins/__next._tree.txt +1 -1
  32. package/dist/web/admin/admins/__next.admin.admins.__PAGE__.txt +1 -1
  33. package/dist/web/admin/admins/__next.admin.admins.txt +1 -1
  34. package/dist/web/admin/admins/__next.admin.txt +1 -1
  35. package/dist/web/admin/admins.html +1 -1
  36. package/dist/web/admin/admins.txt +1 -1
  37. package/dist/web/admin/login/__next._full.txt +1 -1
  38. package/dist/web/admin/login/__next._head.txt +1 -1
  39. package/dist/web/admin/login/__next._index.txt +1 -1
  40. package/dist/web/admin/login/__next._tree.txt +1 -1
  41. package/dist/web/admin/login/__next.admin.login.__PAGE__.txt +1 -1
  42. package/dist/web/admin/login/__next.admin.login.txt +1 -1
  43. package/dist/web/admin/login/__next.admin.txt +1 -1
  44. package/dist/web/admin/login.html +1 -1
  45. package/dist/web/admin/login.txt +1 -1
  46. package/dist/web/admin/modes/__next._full.txt +1 -1
  47. package/dist/web/admin/modes/__next._head.txt +1 -1
  48. package/dist/web/admin/modes/__next._index.txt +1 -1
  49. package/dist/web/admin/modes/__next._tree.txt +1 -1
  50. package/dist/web/admin/modes/__next.admin.modes.__PAGE__.txt +1 -1
  51. package/dist/web/admin/modes/__next.admin.modes.txt +1 -1
  52. package/dist/web/admin/modes/__next.admin.txt +1 -1
  53. package/dist/web/admin/modes.html +1 -1
  54. package/dist/web/admin/modes.txt +1 -1
  55. package/dist/web/admin/ota/__next._full.txt +1 -1
  56. package/dist/web/admin/ota/__next._head.txt +1 -1
  57. package/dist/web/admin/ota/__next._index.txt +1 -1
  58. package/dist/web/admin/ota/__next._tree.txt +1 -1
  59. package/dist/web/admin/ota/__next.admin.ota.__PAGE__.txt +1 -1
  60. package/dist/web/admin/ota/__next.admin.ota.txt +1 -1
  61. package/dist/web/admin/ota/__next.admin.txt +1 -1
  62. package/dist/web/admin/ota.html +1 -1
  63. package/dist/web/admin/ota.txt +1 -1
  64. package/dist/web/admin/turn/__next._full.txt +1 -1
  65. package/dist/web/admin/turn/__next._head.txt +1 -1
  66. package/dist/web/admin/turn/__next._index.txt +1 -1
  67. package/dist/web/admin/turn/__next._tree.txt +1 -1
  68. package/dist/web/admin/turn/__next.admin.turn.__PAGE__.txt +1 -1
  69. package/dist/web/admin/turn/__next.admin.turn.txt +1 -1
  70. package/dist/web/admin/turn/__next.admin.txt +1 -1
  71. package/dist/web/admin/turn.html +1 -1
  72. package/dist/web/admin/turn.txt +1 -1
  73. package/dist/web/admin.html +1 -1
  74. package/dist/web/admin.txt +1 -1
  75. package/dist/web/dev/question/__next._full.txt +1 -1
  76. package/dist/web/dev/question/__next._head.txt +1 -1
  77. package/dist/web/dev/question/__next._index.txt +1 -1
  78. package/dist/web/dev/question/__next._tree.txt +1 -1
  79. package/dist/web/dev/question/__next.dev.question.__PAGE__.txt +1 -1
  80. package/dist/web/dev/question/__next.dev.question.txt +1 -1
  81. package/dist/web/dev/question/__next.dev.txt +1 -1
  82. package/dist/web/dev/question.html +1 -1
  83. package/dist/web/dev/question.txt +1 -1
  84. package/dist/web/index.html +1 -1
  85. package/dist/web/index.txt +2 -2
  86. package/dist/web/login/__next._full.txt +2 -2
  87. package/dist/web/login/__next._head.txt +1 -1
  88. package/dist/web/login/__next._index.txt +1 -1
  89. package/dist/web/login/__next._tree.txt +1 -1
  90. package/dist/web/login/__next.login.__PAGE__.txt +2 -2
  91. package/dist/web/login/__next.login.txt +1 -1
  92. package/dist/web/login.html +1 -1
  93. package/dist/web/login.txt +2 -2
  94. package/dist/web/workspace/__next._full.txt +2 -2
  95. package/dist/web/workspace/__next._head.txt +1 -1
  96. package/dist/web/workspace/__next._index.txt +1 -1
  97. package/dist/web/workspace/__next._tree.txt +1 -1
  98. package/dist/web/workspace/__next.workspace.__PAGE__.txt +1 -1
  99. package/dist/web/workspace/__next.workspace.txt +2 -2
  100. package/dist/web/workspace/browse/__next._full.txt +2 -2
  101. package/dist/web/workspace/browse/__next._head.txt +1 -1
  102. package/dist/web/workspace/browse/__next._index.txt +1 -1
  103. package/dist/web/workspace/browse/__next._tree.txt +1 -1
  104. package/dist/web/workspace/browse/__next.workspace.browse.__PAGE__.txt +1 -1
  105. package/dist/web/workspace/browse/__next.workspace.browse.txt +1 -1
  106. package/dist/web/workspace/browse/__next.workspace.txt +2 -2
  107. package/dist/web/workspace/browse.html +1 -1
  108. package/dist/web/workspace/browse.txt +2 -2
  109. package/dist/web/workspace/editor/__next._full.txt +2 -2
  110. package/dist/web/workspace/editor/__next._head.txt +1 -1
  111. package/dist/web/workspace/editor/__next._index.txt +1 -1
  112. package/dist/web/workspace/editor/__next._tree.txt +1 -1
  113. package/dist/web/workspace/editor/__next.workspace.editor.__PAGE__.txt +1 -1
  114. package/dist/web/workspace/editor/__next.workspace.editor.txt +1 -1
  115. package/dist/web/workspace/editor/__next.workspace.txt +2 -2
  116. package/dist/web/workspace/editor.html +1 -1
  117. package/dist/web/workspace/editor.txt +2 -2
  118. package/dist/web/workspace/files/__next._full.txt +2 -2
  119. package/dist/web/workspace/files/__next._head.txt +1 -1
  120. package/dist/web/workspace/files/__next._index.txt +1 -1
  121. package/dist/web/workspace/files/__next._tree.txt +1 -1
  122. package/dist/web/workspace/files/__next.workspace.files.__PAGE__.txt +1 -1
  123. package/dist/web/workspace/files/__next.workspace.files.txt +1 -1
  124. package/dist/web/workspace/files/__next.workspace.txt +2 -2
  125. package/dist/web/workspace/files.html +1 -1
  126. package/dist/web/workspace/files.txt +2 -2
  127. package/dist/web/workspace/git/__next._full.txt +2 -2
  128. package/dist/web/workspace/git/__next._head.txt +1 -1
  129. package/dist/web/workspace/git/__next._index.txt +1 -1
  130. package/dist/web/workspace/git/__next._tree.txt +1 -1
  131. package/dist/web/workspace/git/__next.workspace.git.__PAGE__.txt +1 -1
  132. package/dist/web/workspace/git/__next.workspace.git.txt +1 -1
  133. package/dist/web/workspace/git/__next.workspace.txt +2 -2
  134. package/dist/web/workspace/git.html +1 -1
  135. package/dist/web/workspace/git.txt +2 -2
  136. package/dist/web/workspace/mobile/__next._full.txt +2 -2
  137. package/dist/web/workspace/mobile/__next._head.txt +1 -1
  138. package/dist/web/workspace/mobile/__next._index.txt +1 -1
  139. package/dist/web/workspace/mobile/__next._tree.txt +1 -1
  140. package/dist/web/workspace/mobile/__next.workspace.mobile.__PAGE__.txt +1 -1
  141. package/dist/web/workspace/mobile/__next.workspace.mobile.txt +1 -1
  142. package/dist/web/workspace/mobile/__next.workspace.txt +2 -2
  143. package/dist/web/workspace/mobile.html +1 -1
  144. package/dist/web/workspace/mobile.txt +2 -2
  145. package/dist/web/workspace/remote/__next._full.txt +2 -2
  146. package/dist/web/workspace/remote/__next._head.txt +1 -1
  147. package/dist/web/workspace/remote/__next._index.txt +1 -1
  148. package/dist/web/workspace/remote/__next._tree.txt +1 -1
  149. package/dist/web/workspace/remote/__next.workspace.remote.__PAGE__.txt +1 -1
  150. package/dist/web/workspace/remote/__next.workspace.remote.txt +1 -1
  151. package/dist/web/workspace/remote/__next.workspace.txt +2 -2
  152. package/dist/web/workspace/remote.html +1 -1
  153. package/dist/web/workspace/remote.txt +2 -2
  154. package/dist/web/workspace/terminal/default/__next._full.txt +2 -2
  155. package/dist/web/workspace/terminal/default/__next._head.txt +1 -1
  156. package/dist/web/workspace/terminal/default/__next._index.txt +1 -1
  157. package/dist/web/workspace/terminal/default/__next._tree.txt +1 -1
  158. package/dist/web/workspace/terminal/default/__next.workspace.terminal.$d$sessionId.__PAGE__.txt +1 -1
  159. package/dist/web/workspace/terminal/default/__next.workspace.terminal.$d$sessionId.txt +1 -1
  160. package/dist/web/workspace/terminal/default/__next.workspace.terminal.txt +1 -1
  161. package/dist/web/workspace/terminal/default/__next.workspace.txt +2 -2
  162. package/dist/web/workspace/terminal/default.html +1 -1
  163. package/dist/web/workspace/terminal/default.txt +2 -2
  164. package/dist/web/workspace/workspaces/__next._full.txt +2 -2
  165. package/dist/web/workspace/workspaces/__next._head.txt +1 -1
  166. package/dist/web/workspace/workspaces/__next._index.txt +1 -1
  167. package/dist/web/workspace/workspaces/__next._tree.txt +1 -1
  168. package/dist/web/workspace/workspaces/__next.workspace.txt +2 -2
  169. package/dist/web/workspace/workspaces/__next.workspace.workspaces.__PAGE__.txt +1 -1
  170. package/dist/web/workspace/workspaces/__next.workspace.workspaces.txt +1 -1
  171. package/dist/web/workspace/workspaces.html +1 -1
  172. package/dist/web/workspace/workspaces.txt +2 -2
  173. package/dist/web/workspace.html +1 -1
  174. package/dist/web/workspace.txt +2 -2
  175. package/package.json +1 -1
  176. package/dist/ui/assets/index-DcykK_na.js +0 -8
  177. /package/dist/web/_next/static/{xSpq32VEKUqU6vBkX2q0J → doBLJdxjaGN7ToTue-RM0}/_buildManifest.js +0 -0
  178. /package/dist/web/_next/static/{xSpq32VEKUqU6vBkX2q0J → doBLJdxjaGN7ToTue-RM0}/_ssgManifest.js +0 -0
@@ -11,4 +11,4 @@ ${nB(p||[])}`}),setTimeout(()=>e?.emit("input",{sessionId:t,data:"\r"}),eV.YS),l
11
11
  `:`${i}
12
12
  ${l}
13
13
  `:`${l}
14
- `;return await e.writeFile(r,d)}let lp="application/x-file-paths",lf=()=>"u">typeof document&&"webkitdirectory"in document.createElement("input"),lh=e=>{let t=e.dataTransfer.getData(lp);if(!t)return null;try{return JSON.parse(t)}catch{return null}},lb=e=>[...e.dataTransfer?.types||[]].includes("Files");function lg({workspace:e,fileBus:t,onOpenFile:s,activeFile:l,onSwitchWorkspace:a,onNewTerminal:i,onSearchFolder:o,compact:c=!1,onlyChanged:d=!1,onActions:u}){let{t:x}=(0,ec.s)(),[m,p]=(0,r.useState)(null),f=(0,r.useRef)(null),h=sq(f,m?.x??0,m?.y??0),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(""),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(""),[C,S]=(0,r.useState)(null),[E,R]=(0,r.useState)(null),[T,$]=(0,r.useState)(()=>new Set),M=(0,r.useRef)(T);(0,r.useEffect)(()=>{M.current=T},[T]);let z=(0,r.useRef)(v);(0,r.useEffect)(()=>{z.current=v},[v]);let P=(0,r.useRef)(b);(0,r.useEffect)(()=>{P.current=b},[b]);let[I,A]=(0,r.useState)(null),[L,D]=(0,r.useState)(!1),[B,K]=(0,r.useState)(null),[O,W]=(0,r.useState)(null),[_,H]=(0,r.useState)(null),[q,U]=(0,r.useState)(null),V=(0,r.useRef)(null),X=(0,r.useRef)(null),G=(0,r.useRef)(null),J=(0,r.useRef)(null),[Y]=(0,r.useState)(lf),Z=(0,r.useRef)(null),Q=(0,r.useRef)(null),ee=(0,r.useRef)(null),et=(0,r.useCallback)(t=>t&&e?t.replace(`${e}/`,""):t,[e]),{tree:es,expanded:er,loading:el,truncatedDirs:ea,gitStatusMap:ed,showHidden:eu,setShowHidden:ex,loadDir:em,loadGitStatus:ep,toggleFolder:ef,expandDir:eh,collapseAll:eb,refreshAll:eg}=function({workspace:e,fileBus:t}){let[s,n]=(0,r.useState)(()=>new Map),[l,a]=(0,r.useState)(()=>new Set),[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(()=>new Set),[u,x]=(0,r.useState)(()=>new Set),[m,p]=(0,r.useState)({}),[f,h]=(0,r.useState)(rX),b=(0,r.useCallback)(async e=>{d(t=>{let s=new Set(t);return s.add(e),s});let s=await t.getFiles(e,f);return(d(t=>{let s=new Set(t);return s.delete(e),s}),s?.success)?(n(t=>{let n=new Map(t);return n.set(e,s.files||[]),n}),x(t=>{let n=!!s.truncated;if(n===t.has(e))return t;let r=new Set(t);return n?r.add(e):r.delete(e),r}),s.files||[]):[]},[t,f]),g=(0,r.useRef)(0),v=(0,r.useCallback)(async()=>{if(!e)return;let s=++g.current,{map:n}=await rU(t,e);s===g.current&&p(n)},[t,e]);(0,r.useEffect)(()=>{if(!e)return;let t=!0;return(async()=>{let s,n,r=Array.isArray(n=(s=rV())[e])?n:Array.isArray(s.legacy)?s.legacy:[],l=new Set([e]),i=r.filter(t=>"string"==typeof t&&t.startsWith(e));for(let e of i)l.add(e);await Promise.all([b(e),...i.map(e=>b(e))]),t&&(a(l),o(e),v())})(),()=>{t=!1}},[e]),(0,r.useEffect)(()=>{let e=null,t=()=>{clearTimeout(e),e=setTimeout(v,300)},s=["fileExplorer:fileSaved","fileExplorer:fileCreated","fileExplorer:fileDeleted","fileExplorer:fileRenamed",F.GW];return s.forEach(e=>window.addEventListener(e,t)),()=>{clearTimeout(e),s.forEach(e=>window.removeEventListener(e,t))}},[v]),(0,r.useEffect)(()=>{if(i===e&&e)try{let t=rV();delete t.legacy,t[e]=[...l],window.localStorage.setItem(F.d5.expandedFolders,JSON.stringify(t))}catch{}},[e,i,l]),(0,r.useEffect)(()=>{window.localStorage.setItem(F.d5.showHidden,JSON.stringify(f)),s.size>0&&Promise.all([...s.keys()].map(e=>b(e))).catch(()=>{})},[f]);let y=(0,r.useCallback)(async e=>{(0,eo.e)();let t=e.path;l.has(t)?a(e=>{let s=new Set(e);return s.delete(t),s}):(s.has(t)||await b(t),a(e=>{let s=new Set(e);return s.add(t),s}))},[l,s,b]),w=(0,r.useCallback)(e=>{a(t=>{let s=new Set(t);return s.add(e),s})},[]),j=(0,r.useCallback)(()=>{(0,eo.e)(),a(new Set)},[]),k=rH(),N=(0,r.useMemo)(()=>[...s.keys()].filter(t=>t===e||l.has(t)),[s,l,e]),C=(0,r.useCallback)(e=>{Promise.all(e.map(e=>b(e))).catch(()=>{}),v()},[b,v]);r_({dirs:N,fileBus:t,onDirsChanged:C,enabled:k});let S=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=k&&!S.current;S.current=k,e&&s.size&&C([...s.keys()])},[k]);let E=(0,r.useCallback)(async()=>{(0,eo.e)();let e=[...s.keys()];await Promise.all(e.map(e=>b(e))),v()},[s,b,v]);return{tree:s,expanded:l,loading:c,truncatedDirs:u,gitStatusMap:m,showHidden:f,setShowHidden:h,loadDir:b,loadGitStatus:v,toggleFolder:y,expandDir:w,collapseAll:j,refreshAll:E}}({workspace:e,fileBus:t}),{createItem:ev,renameItem:ey,deleteItem:ew,deleteMany:ej,duplicateItem:ek,moveTo:eN,pasteInto:eC}=function({fileBus:e,loadDir:t,loadGitStatus:s,expandDir:n,onOpenFile:l,onMoved:a}){let i=(0,r.useCallback)(async(s,r,a)=>{let i=rK(s,r),o=await e.createItem(i,a);o?.success&&(rJ("created"),await t(s),"folder"===a?n(s):l?.(i))},[e,t,n,l]),o=(0,r.useCallback)(async(s,n)=>{let r=rO(s.path),l=rK(r,n),a=await e.renameItem(s.path,l);a?.success&&(rJ("renamed"),await t(r))},[e,t]),c=(0,r.useCallback)(async s=>{let n=rO(s.path),r=await e.deleteItem(s.path);r?.success&&(rJ("deleted"),await t(n))},[e,t]),d=(0,r.useCallback)(async n=>{if(!n?.length)return;let r=new Set;for(let t of n){let s=await e.deleteItem(t.path);s?.success&&r.add(rO(t.path))}if(r.size){for(let e of(rJ("deleted"),r))await t(e);s(),a?.()}},[e,t,s,a]),u=(0,r.useCallback)(async(t,s)=>{let n=rW(t),r=new Set(((await e.getFiles(s,!0))?.files||[]).map(e=>e.name)),l=n;if(r.has(l)){let e=n.lastIndexOf("."),t=e>0?n.slice(0,e):n,s=e>0?n.slice(e):"";l=`${t} copy${s}`;for(let e=2;r.has(l);e++)l=`${t} copy ${e}${s}`}return e.copyItem(t,rK(s,l))},[e]),x=(0,r.useCallback)(async e=>{let n=rO(e.path),r=await u(e.path,n);r?.success&&(rJ("created"),await t(n),s())},[u,t,s]),m=(0,r.useCallback)(async(n,r)=>{if(n?.length&&r){for(let t of n){let s=rK(r,t.split("/").pop());t===s||s.startsWith(t+"/")||await e.renameItem(t,s)}for(let e of new Set([r,...n.map(e=>rO(e))]))await t(e);rJ("renamed"),s(),a?.()}},[e,t,s,a]),p=(0,r.useCallback)(async(e,r,l)=>{if(!e?.length||!r)return;if("cut"===l)return m(e,r);let a=0;for(let t of e){if(r===t||r.startsWith(t+"/"))continue;let e=await u(t,r);e?.success&&a++}a&&(rJ("created"),await t(r),n(r),s())},[u,m,t,n,s]);return{createItem:i,renameItem:o,deleteItem:c,deleteMany:d,duplicateItem:x,moveTo:m,pasteInto:p}}({fileBus:t,loadDir:em,loadGitStatus:ep,expandDir:eh,onOpenFile:s,onMoved:()=>$(new Set)});(0,r.useEffect)(()=>{if(!m)return;let e=()=>p(null);return window.addEventListener("click",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("click",e),window.removeEventListener("scroll",e,!0)}},[m]),(0,r.useEffect)(()=>{if(b&&Q.current){Q.current.focus();let e=Q.current.value.length;Q.current.setSelectionRange(e,e)}},[b]),(0,r.useEffect)(()=>{w&&ee.current&&ee.current.focus()},[w]);let eS=(0,r.useCallback)(()=>E&&es.has(E)?E:e,[E,es,e]),eE=(0,r.useCallback)(async e=>{let t=k.trim();if(!t)return;let s=w?.dir||eS();await ev(s,t,e),j(null),N("")},[k,w,eS,ev]),eR=(0,r.useCallback)(async()=>{let e=P.current;if(!e)return;let t=z.current.trim();t&&t!==e.name&&await ey(e,t),g(null)},[ey]),eT=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),e$=(0,r.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),(0,eo.e)(),$(e=>e.has(t.path)?e:new Set([t.path])),U(t.path),p({file:t,x:e.clientX,y:e.clientY})},[]),eM=(0,r.useCallback)((e,t)=>{let s=e.touches?.[0];if(!s)return;let n=s.clientX,r=s.clientY;Z.current=setTimeout(()=>{(0,eo.e)(),p({file:t,x:n,y:r})},500)},[]),ez=(0,r.useCallback)(()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)},[]),eP=(0,r.useMemo)(()=>{if(!l)return null;if(!(0,F.pA)(l))return l;let{repoPath:t,filePath:s}=(0,F.qu)(l);return s?`${t||e}/${s}`:null},[l,e]),eI=e=>!d||!!ed[et(e.path)],eA=(0,r.useMemo)(()=>{let t=[],s=(e,n)=>{for(let r of es.get(e)||[])(!d||ed[et(r.path)])&&(t.push({file:r,depth:n}),"folder"===r.type&&er.has(r.path)&&s(r.path,n+1))};return s(e,0),t},[es,er,ed,d,e,et]),eL=(0,r.useCallback)(e=>eA.find(t=>t.file.path===e)?.file||null,[eA]),eD=(0,r.useCallback)(e=>{let t=eA.filter(e=>T.has(e.file.path)).map(e=>e.file);return t.length?t:e?[e]:[]},[eA,T]),eB=(0,r.useCallback)((e,t)=>{let s=eA.findIndex(t=>t.file.path===e),n=eA.findIndex(e=>e.file.path===t);if(-1===s||-1===n)return new Set([t]);let[r,l]=s<=n?[s,n]:[n,s];return new Set(eA.slice(r,l+1).map(e=>e.file.path))},[eA]),eF=(0,r.useCallback)((e,t)=>{if((0,eo.e)(),V.current?.focus({preventScroll:!0}),t?.metaKey||t?.ctrlKey){$(t=>{let s=new Set(t);return s.has(e.path)?s.delete(e.path):s.add(e.path),s}),U(e.path),X.current=e.path;return}if(t?.shiftKey&&X.current){$(eB(X.current,e.path)),U(e.path);return}$(new Set([e.path])),U(e.path),X.current=e.path,"folder"===e.type?(R(e.path),ef(e)):s?.(e.path)},[ef,s,eB]),eK=(0,r.useCallback)(t=>t?"folder"===t.type?t.path:rO(t.path):e,[e]),eO=(0,r.useCallback)(e=>{let t=eD(e);t.length&&S({files:t})},[eD]),eW=(0,r.useCallback)(async()=>{let e=C?.files||[];S(null),1===e.length?await ew(e[0]):await ej(e),$(new Set)},[C,ew,ej]),e_=(0,r.useCallback)((e,t)=>{let s=eD(e).map(e=>e.path);s.length&&K({paths:s,mode:t})},[eD]),eH=(0,r.useCallback)(async e=>{B?.paths?.length&&(await eC(B.paths,eK(e),B.mode),"cut"===B.mode&&K(null))},[B,eC,eK]),eq=(0,r.useCallback)(async(e,s)=>{if(!e.length)return;let n=0;W({total:e.length,done:0,failed:0}),await t.uploadFiles(s,e,{onConflict:(e,t)=>new Promise(s=>H({name:t||e?.name,resolve:s})),onFileDone:()=>W(e=>e?{...e,done:e.done+1}:e),onError:()=>{n+=1,W(e=>e?{...e,done:e.done+1,failed:n}:e)}}),W(e=>e&&n?e:null),H(null),await em(s),eh(s),ep()},[t,em,eh,ep]),eU=(0,r.useCallback)(async(e,t)=>{eq(await ln(e),t)},[eq]),eV=(0,r.useCallback)(()=>g(null),[]),eX=(0,r.useCallback)((e,t)=>{let s=M.current,n=s.has(t.path)?[...s]:[t.path];e.dataTransfer.setData(lp,JSON.stringify(n)),e.dataTransfer.effectAllowed="move"},[]),eG=(0,r.useCallback)((e,t)=>{let s=lb(e);("folder"===t.type||s)&&(e.preventDefault(),e.dataTransfer.dropEffect=s?"copy":"move","folder"===t.type&&A(t.path))},[]),eJ=(0,r.useCallback)(e=>{A(t=>t===e.path?null:t)},[]),eY=(0,r.useCallback)((e,t)=>{let s=lb(e);if("folder"!==t.type&&!s)return;if(e.preventDefault(),e.stopPropagation(),A(null),D(!1),s)return void eU(e.dataTransfer,eK(t));let n=lh(e);n&&eN(n,t.path)},[eU,eK,eN]),eZ=(0,r.useCallback)(e=>{let t=w?.dir||eS(),s=[...e.target.files].map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}));e.target.value="",j(null),eq(s,t)},[w,eS,eq]),eQ=(0,r.useCallback)((e,t)=>{if(!eA.length)return;let s=eA.findIndex(e=>e.file.path===q),n=eA[Math.min(eA.length-1,Math.max(0,-1===s?0:s+e))];if(!n)return;let r=n.file.path;t&&X.current?$(eB(X.current,r)):($(new Set([r])),X.current=r),U(r),V.current?.querySelector(`[data-path="${CSS.escape(r)}"]`)?.scrollIntoView({block:"nearest"})},[eA,q,eB]),e0=(0,r.useCallback)(e=>{if(b||w||C)return;let t=eL(q),n=e.metaKey||e.ctrlKey;if(n&&"a"===e.key.toLowerCase()){e.preventDefault(),$(new Set(eA.map(e=>e.file.path))),X.current=eA[0]?.file.path||null;return}if(n&&"c"===e.key.toLowerCase()){e.preventDefault(),e_(t,"copy");return}if(n&&"x"===e.key.toLowerCase()){e.preventDefault(),e_(t,"cut");return}if(n&&"v"===e.key.toLowerCase()){e.preventDefault(),eH(t);return}switch(e.key){case"ArrowDown":e.preventDefault(),eQ(1,e.shiftKey);return;case"ArrowUp":e.preventDefault(),eQ(-1,e.shiftKey);return;case"ArrowRight":if(!t)return;e.preventDefault(),"folder"!==t.type||er.has(t.path)?eQ(1,!1):ef(t);return;case"ArrowLeft":if(!t)return;e.preventDefault(),"folder"===t.type&&er.has(t.path)?ef(t):eQ(-1,!1);return;case"Enter":if(!t)return;e.preventDefault(),ti()?(g(t),y(t.name)):"folder"===t.type?ef(t):s?.(t.path);return;case"F2":if(!t)return;e.preventDefault(),g(t),y(t.name);return;case"Delete":case"Backspace":if(!t)return;e.preventDefault(),eO(t);return;case"Escape":$(new Set),K(null);return}},[b,w,C,q,eL,eA,er,ef,s,eQ,e_,eH,eO]),e1=(e,t)=>{if(!eI(e))return null;let s="folder"===e.type,r=s&&er.has(e.path),l=T.has(e.path);return(0,n.jsx)(lt,{file:e,depth:t,isFolder:s,isExpanded:r,isLoading:s&&el.has(e.path),isActive:eP===e.path,isSelected:l,isRenaming:b?.path===e.path,isDragOver:I===e.path&&s,isCut:B?.mode==="cut"&&B.paths.includes(e.path),gitStatus:ed[et(e.path)],renameValue:b?.path===e.path?v:"",renameInputRef:Q,onRenameChange:y,onRenameSubmit:eR,onRenameCancel:eV,onToggleFolder:ef,onClick:eF,onContextMenu:e$,onTouchStart:eM,onTouchEnd:ez,onDragStart:eX,onDragOver:eG,onDragLeave:eJ,onDrop:eY,compact:c,children:s&&r&&(0,n.jsxs)("div",{children:[(es.get(e.path)||[]).map(e=>e1(e,t+1)),ea.has(e.path)&&(0,n.jsx)(le,{depth:t+1,compact:c})]})},e.path)},e2=(0,r.useMemo)(()=>es.get(e)||[],[es,e]);(0,r.useEffect)(()=>{if(!d)return;let t=!0;return(async()=>{for(let s of Object.keys(ed)){if("folder-changed"!==ed[s])continue;let n=`${e}/${s}`;if(!es.has(n)&&(await em(n),!t))return;eh(n)}})(),()=>{t=!1}},[d,ed,e]),(0,r.useEffect)(()=>{if(!eP||!V.current)return;let e=setTimeout(()=>{let e=V.current?.querySelector(`[data-path="${CSS.escape(eP)}"]`);e?.scrollIntoView({block:"nearest"})},0);return()=>clearTimeout(e)},[eP,es]);let e5=(0,r.useMemo)(()=>rW(e),[e]),e3=(e,t)=>{(0,eo.e)(),j({type:e,dir:t}),N("")};(0,r.useEffect)(()=>{if(u)return u({newFile:()=>e3("file",eS()),newFolder:()=>e3("folder",eS()),refresh:eg,collapseAll:eb,hasExpanded:er.size>0,showHidden:eu,toggleHidden:()=>ex(e=>!e)}),()=>u(null)},[u,eu,eg,eb,er.size,e]);let e4=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=et(s.path),r=await lm(t,e,n,"folder"===s.type);r?.success&&(ep(),window.dispatchEvent(new CustomEvent(F.GW)))},[e,t,et,ep]),e6="text-text-muted hover:text-text p-1 rounded hover:bg-surface-2";return(0,n.jsxs)("div",{className:"relative flex flex-col flex-1 min-h-0 text-text overflow-hidden",children:[!c&&(0,n.jsxs)("div",{style:{height:32},className:"bg-surface border-b border-border flex items-center gap-2 sticky top-0 z-10 flex-shrink-0 px-3",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),a?.()},className:"flex items-center gap-1 flex-1 min-w-0 hover:text-text",children:[(0,n.jsx)("span",{className:"text-xs uppercase tracking-wider text-text-muted font-medium truncate",children:e5||"No Workspace"}),(0,n.jsx)(en.Ay,{name:"ChevronDown",size:12,className:"text-text-muted shrink-0"})]}),(0,n.jsx)("button",{onClick:()=>e3("file",eS()),className:e6,title:"New File",children:(0,n.jsx)(en.Ay,{name:"Plus",size:14})}),(0,n.jsx)("button",{onClick:()=>e3("folder",eS()),className:e6,title:"New Folder",children:(0,n.jsx)(en.Ay,{name:"FolderOpen",size:14})}),(0,n.jsx)("button",{onClick:eg,className:e6,title:"Refresh",children:(0,n.jsx)(en.Ay,{name:"RefreshCw",size:14})}),er.size>0&&(0,n.jsx)("button",{onClick:eb,className:e6,title:x("fileExplorer.collapseAll"),children:(0,n.jsx)(en.Ay,{name:"ChevronsDownUp",size:14})}),(0,n.jsx)("button",{onClick:()=>ex(e=>!e),className:`p-1 rounded hover:bg-surface-2 ${eu?"text-text":"text-text-muted hover:text-text"}`,title:eu?"Hide hidden files":"Show hidden files",children:(0,n.jsx)(en.Ay,{name:eu?"Eye":"EyeOff",size:14})})]}),(0,n.jsx)("div",{ref:V,tabIndex:0,onKeyDown:e0,className:`flex-1 overflow-auto py-1 outline-none ${L?"ring-2 ring-inset ring-brand-500/40 bg-brand-500/5":""}`,onDragOver:e=>{e.preventDefault();let t=lb(e);e.dataTransfer.dropEffect=t?"copy":"move",t&&D(!0)},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||D(!1)},onClick:e=>{e.target===e.currentTarget&&($(new Set),R(null))},onDrop:t=>{if(t.preventDefault(),D(!1),lb(t))return void eU(t.dataTransfer,e);let s=lh(t);s&&eN(s,e)},children:d&&!e2.some(eI)?(0,n.jsx)("div",{className:"text-text-subtle text-xs px-3 py-4 text-center",children:x("git.noChanges")}):0!==e2.length||el.has(e)?(0,n.jsxs)(n.Fragment,{children:[e2.map(e=>e1(e,0)),ea.has(e)&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted italic py-0.5 px-3",children:"Showing first 300 entries — use search for the rest."})]}):(0,n.jsx)("div",{className:"text-text-subtle text-xs px-3 py-4 text-center",children:"Empty workspace"})}),m&&(0,n.jsx)("div",{ref:f,className:"fixed z-50 menu-popover p-1 min-w-[150px] animate-in fade-in zoom-in-95 duration-100",style:{left:h.left,top:h.top},onClick:e=>e.stopPropagation(),children:(e=>{if(!e)return[];let n="folder"===e.type,r=eD(e),l=r.length>1,a=[];return!l&&n?(i&&a.push({label:x("workspaces.openHere"),icon:"Terminal",action:()=>i(e.path)}),o&&a.push({label:"Search in Folder",icon:"Search",action:()=>o(e.path)}),a.push({label:"New File",icon:"Plus",action:()=>e3("file",e.path)}),a.push({label:"New Folder",icon:"FolderOpen",action:()=>e3("folder",e.path)})):!l&&(a.push({label:"Open",icon:"File",action:()=>s?.(e.path)}),(0,F.YO)(e.path)&&a.push({label:x("editor.preview"),icon:"Eye",action:()=>s?.(e.path,{preview:!0})})),a.push({label:"Cut",icon:"Scissors",action:()=>e_(e,"cut")}),a.push({label:"Copy",icon:"Copy",action:()=>e_(e,"copy")}),B?.paths?.length&&a.push({label:"Paste",icon:"ClipboardPaste",action:()=>eH(e)}),l||(a.push({label:"Reveal in OS",icon:"FolderOpen",action:()=>t.revealInOS(e.path)}),a.push({label:"Rename",icon:"Pencil",action:()=>{g(e),y(e.name)}}),a.push({label:"Duplicate",icon:"Copy",action:()=>ek(e)}),a.push({label:"Copy Path",icon:"Copy",action:()=>eT(e.path)}),a.push({label:"Copy Relative Path",icon:"Copy",action:()=>eT(et(e.path))}),a.push({label:x("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:"EyeOff",action:()=>e4(e)})),a.push({label:l?`Delete ${r.length} items`:"Delete",icon:"Trash2",danger:!0,action:()=>eO(e)}),a})(m.file).map((e,t)=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),e.action(),p(null)},className:`w-full flex items-center gap-1.5 px-2 py-1.5 text-xs text-left hover:bg-surface-2/80 rounded-[6px] transition-colors ${e.danger?"text-red-400":"text-text"}`,children:[(0,n.jsx)(en.Ay,{name:e.icon,size:13,className:"shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.label})]},t))}),w&&(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[4px] animate-in fade-in duration-150",onClick:()=>j(null)}),(0,n.jsxs)("div",{className:"relative card-elev p-4 w-full max-w-sm animate-in zoom-in-95 duration-150",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text mb-2",children:"folder"===w.type?"New Folder":"New File"}),(0,n.jsxs)("p",{className:"text-xs text-text-muted mb-2 truncate",children:["in ",et(w.dir)||e5||"/"]}),(0,n.jsx)("input",{ref:ee,value:k,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key?eE(w.type):"Escape"===e.key&&j(null)},placeholder:"folder"===w.type?"folder name":"file name",className:"w-full bg-surface-3 text-text text-sm px-2 py-1.5 rounded outline-none border border-border focus:border-brand-500"}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-3",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),("folder"===w.type&&Y?J:G).current?.click()},className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-text-muted hover:text-text rounded-brand hover:bg-surface-3",title:"folder"===w.type&&Y?"Upload a folder from this computer":"Upload files from this computer",children:[(0,n.jsx)(en.Ay,{name:"Upload",size:13}),"Upload"]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),j(null)},className:"px-3 py-1.5 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand",children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),eE(w.type)},className:"px-3 py-1.5 text-sm bg-brand-500 hover:bg-brand-500/80 text-white rounded-brand",children:"Create"})]})]}),(0,n.jsx)("input",{ref:G,type:"file",multiple:!0,className:"hidden",onChange:eZ}),(0,n.jsx)("input",{ref:J,type:"file",webkitdirectory:"",className:"hidden",onChange:eZ})]}),O&&(0,n.jsx)("div",{className:"absolute bottom-0 inset-x-0 bg-surface-2 border-t border-border px-3 py-1.5 pb-safe text-[11px] text-text-muted flex items-center gap-2",children:O.failed?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-danger",children:x("fileExplorer.uploadFailedCount",{n:O.failed,total:O.total})}),(0,n.jsx)("button",{type:"button",onClick:()=>W(null),className:"ml-auto underline hover:text-text",children:x("common.close")})]}):(0,n.jsx)("span",{children:x("fileExplorer.uploadingCount",{n:Math.min(O.done+1,O.total),total:O.total})})}),_&&(0,n.jsx)(lx,{name:_.name,onResolve:e=>{_.resolve(e),H(null)}}),(0,n.jsx)(ei.A,{isOpen:!!C,onClose:()=>S(null),onConfirm:eW,title:"Delete",message:(C?.files?.length||0)>1?`Are you sure you want to delete these ${C.files.length} items?`:`Are you sure you want to delete "${C?.files?.[0]?.name}"?`,confirmText:"Delete",cancelText:"Cancel"})]})}function lv({x:e,y:t,items:s,onClose:l}){let a=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!a.current)return;let s=a.current.getBoundingClientRect(),n=Math.min(e,window.innerWidth-s.width-8),r=Math.min(t,window.innerHeight-s.height-8);a.current.style.left=`${Math.max(8,n)}px`,a.current.style.top=`${Math.max(8,r)}px`},[e,t]),(0,r.useEffect)(()=>{let e=e=>{a.current&&!a.current.contains(e.target)&&l()},t=e=>{"Escape"===e.key&&l()},s=setTimeout(()=>{document.addEventListener("mousedown",e),document.addEventListener("contextmenu",e,!0),document.addEventListener("keydown",t)},0);return()=>{clearTimeout(s),document.removeEventListener("mousedown",e),document.removeEventListener("contextmenu",e,!0),document.removeEventListener("keydown",t)}},[l]),(0,n.jsx)("div",{ref:a,className:"fixed z-50 min-w-[180px] py-1 rounded-lg border border-border bg-surface shadow-elev animate-in fade-in",style:{left:e,top:t},onContextMenu:e=>e.preventDefault(),children:s.filter(Boolean).map((e,t)=>(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:t=>{t.stopPropagation(),e.onClick?.(),l()},className:`w-full flex items-center gap-2.5 px-3 py-1.5 text-sm text-left transition-colors ${e.disabled?"text-text-subtle cursor-not-allowed":e.danger?"text-danger hover:bg-[rgba(var(--danger-rgb),0.12)]":"text-text hover:bg-surface-2"}`,children:[e.icon&&(0,n.jsx)(e.icon,{size:14,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 truncate",children:e.label})]},e.key+t))})}let ly={Copy:en.QR,FileText:en.iU,ExternalLink:en.Gr,Undo2:en.bE,X:en.X,EyeOff:en.X_};function lw(){let[e,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=window.matchMedia("(hover: none), (pointer: coarse)"),s=()=>t(e.matches);return s(),e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[]),e}let lj=(e,t)=>(e||"").split("\n").map(e=>e.trim()).find(t)||"",lk=(e,t)=>{let s=lj(t,e=>/files? changed/.test(e));return e("git.commitSuccess")+(s?` \xb7 ${s}`:"")},lN=(e,t)=>{if(/up.to.date/i.test(t||""))return e("git.upToDate");let s=lj(t,e=>e.includes("->"));return e("git.pushSuccess")+(s?` \xb7 ${s}`:"")},lC="changes",lS="untracked";function lE(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}function lR(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(0,t):""}function lT(e,t){if(!e)return t;let s=e.endsWith("/")||e.endsWith("\\")?"":"/";return`${e}${s}${t}`}let l$=(0,r.memo)(function({file:e,workspace:t,isUntracked:s,t:r,isTouch:l,openDiff:a,onCtxMenu:i,onDiscard:o,onStage:c}){let d=F.vs[e.status]||"text-text-muted";return lT(t,e.path),(0,n.jsxs)("div",{className:"group relative flex items-center gap-1.5 px-2 py-1 hover:bg-surface-2 cursor-pointer",onContextMenu:t=>i(e,t),onClick:()=>{(0,eo.e)(),a(e)},children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:r6({name:lE(e.path),path:e.path,type:"file"},16)}),(0,n.jsx)("span",{className:"truncate text-xs text-text",title:e.path,children:lE(e.path)}),(0,n.jsx)("span",{className:"truncate text-[11px] text-text-muted flex-1",title:lR(e.path),children:lR(e.path)}),(0,n.jsxs)("div",{className:`absolute right-[22px] top-1/2 -translate-y-1/2 flex items-center gap-0.5 pl-2 pr-1 bg-surface-2 transition-opacity ${l?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:[(0,n.jsx)("button",{type:"button",title:r(s?"common.delete":"git.discard"),onClick:t=>{t.stopPropagation(),(0,eo.e)(),o(e)},className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(en.X,{size:12})}),(0,n.jsx)("button",{type:"button",title:r("git.stage"),onClick:t=>{t.stopPropagation(),(0,eo.e)(),c(e)},className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(en.FW,{size:12})})]}),(0,n.jsx)("span",{className:`flex-shrink-0 w-4 h-4 flex items-center justify-center text-[10px] font-mono rounded bg-surface-2 ${d}`,children:e.status})]})});function lM({workspace:e,fileBus:t,onOpenFile:s,tagDiffWithRepo:l=!1}){let{t:a}=(0,ec.s)(),i=lw(),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),[p,f]=(0,r.useState)([]),[h,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(new Set([lC,lS])),[N,C]=(0,r.useState)(!1),[S,E]=(0,r.useState)(!1),[R,T]=(0,r.useState)(null),[$,M]=(0,r.useState)(!1),[z,P]=(0,r.useState)(null),[I,A]=(0,r.useState)(null),L=(0,r.useCallback)(async()=>{if(!e||!t)return;v(!0);let[s,n]=await Promise.all([t.gitStatus?.(e),t.gitBranch?.(e)]);v(!1),s?.success&&f(s.files||[]),n?.success&&(c(n.branch||""),u(n.ahead??null),m(n.behind??null))},[e,t]);(0,r.useEffect)(()=>{L()},[L]),(0,r.useEffect)(()=>{let e=()=>L(),t=["fileExplorer:fileSaved","fileExplorer:fileCreated","fileExplorer:fileDeleted","fileExplorer:fileRenamed",F.GW];return t.forEach(t=>window.addEventListener(t,e)),()=>t.forEach(t=>window.removeEventListener(t,e))},[L]);let{changes:D,untracked:B}=(0,r.useMemo)(()=>{let e=[],t=[];for(let s of p)"?"===s.status?t.push(s):e.push(s);return{changes:e,untracked:t}},[p]),K=(0,r.useCallback)(e=>{k(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),O=(0,r.useCallback)(async s=>{e&&(await t.gitAdd?.(e,[s.path]),L())},[e,t,L]),W=(0,r.useCallback)(async()=>{e&&(await t.gitAdd?.(e,["."]),L())},[e,t,L]),_=(0,r.useCallback)(async s=>{e&&(await t.gitDiscard?.(e,s.path,s.status),L())},[e,t,L]),H=(0,r.useCallback)(e=>{T(e),E(!0)},[]),q=(0,r.useCallback)(t=>{s?.(l?(0,F.n2)(t.status,e,t.path):(0,F.Dk)(t.status,t.path))},[s,l,e]),U=(0,r.useCallback)((e=!1)=>{!h.trim()||p.length&&(M(e),C(!0))},[h,p]),V=(0,r.useCallback)(async()=>{if(!e)return;w(null);let s=await t.gitAdd?.(e,["."]);if(s&&!s.success)return void w({ok:!1,text:s.error||a("git.stageFailed")});let n=await t.gitCommit?.(e,h.trim());if(!n?.success){w({ok:!1,text:n?.output||n?.error||a("git.commitFailed")}),L();return}if(b(""),!$){w({ok:!0,text:lk(a,n.output)}),L();return}let r=await t.gitPush?.(e);w(r?.success?{ok:!0,text:`${lk(a,n.output)} \xb7 ${lN(a,r.output)}`}:{ok:!1,text:r?.output||r?.error||a("git.pushFailed")}),L()},[e,t,h,$,L,a]),X=(0,r.useCallback)(async()=>{if(!e)return;v(!0),w(null);let s=await t.gitPush?.(e);v(!1),w(s?.success?{ok:!0,text:lN(a,s.output)}:{ok:!1,text:s?.output||s?.error||a("git.pushFailed")}),L()},[e,t,L,a]),G=(0,r.useCallback)(async()=>{if(!e)return;v(!0),w(null);let s=await t.gitPull?.(e);v(!1),w(s?.success?{ok:!0,text:((e,t)=>{if(/already up to date|up.to.date/i.test(t||""))return e("git.upToDate");let s=lj(t,e=>/files? changed|fast-forward/i.test(e));return e("git.pullSuccess")+(s?` \xb7 ${s}`:"")})(a,s.output)}:{ok:!1,text:s?.output||s?.error||a("git.pullFailed")}),L()},[e,t,L,a]),J=(0,r.useCallback)((e,t)=>{e.stopPropagation(),(0,eo.e)();let s=e.currentTarget.getBoundingClientRect();t({x:s.right,y:s.bottom+4})},[]),[Y,Z]=(0,r.useState)(null),Q=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),ee=(0,r.useCallback)((e,t)=>{t.preventDefault(),t.stopPropagation(),(0,eo.e)(),Z({file:e,x:t.clientX,y:t.clientY})},[]),et=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=await lm(t,e,s.path);n?.success&&(window.dispatchEvent(new CustomEvent(F.GW)),L())},[e,t,L]),es=(0,r.useCallback)(t=>{let n=lT(e,t.path);return[{key:"open",label:a("git.openFile"),icon:en.Gr,disabled:"D"===t.status,onClick:()=>s?.(n)},{key:"copyPath",label:a("files.copyPath",{defaultValue:"Copy Path"}),icon:en.Gr,onClick:()=>Q(n)},{key:"copyRel",label:a("files.copyRelPath",{defaultValue:"Copy Relative Path"}),icon:en.Gr,onClick:()=>Q(t.path)},{key:"copyName",label:a("files.copyName",{defaultValue:"Copy Filename"}),icon:en.Gr,onClick:()=>Q(lE(t.path))},{key:"addToGitignore",label:a("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:en.X_,onClick:()=>et(t)}]},[e,s,Q,et,a]),er=(t,s,r,l)=>{let o=j.has(t);return(0,n.jsxs)("div",{className:"border-t border-border",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),K(t)},className:"w-full flex items-center gap-1 px-2 py-1 hover:bg-surface-2 text-left",children:[o?(0,n.jsx)(en.yQ,{size:12,className:"text-text-subtle"}):(0,n.jsx)(en.c_,{size:12,className:"text-text-subtle"}),(0,n.jsx)("span",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:s}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 ml-auto rounded-brand bg-surface-3 text-text-muted",children:r.length})]}),o&&r.map(t=>(0,n.jsx)(l$,{file:t,workspace:e,isUntracked:l,t:a,isTouch:i,openDiff:q,onCtxMenu:ee,onDiscard:H,onStage:O},`${t.status}-${t.path}`))]})};return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text",children:[(0,n.jsxs)("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(en.Zr,{size:14,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-xs text-text truncate flex-1",children:o||"—"}),d>0&&(0,n.jsxs)("span",{className:"text-[10px] font-medium px-1.5 rounded-brand bg-brand-500/15 text-brand-500",children:["↑",d]}),x>0&&(0,n.jsxs)("span",{className:"text-[10px] font-medium px-1.5 rounded-brand bg-surface-3 text-text-muted",children:["↓",x]}),(0,n.jsx)("button",{type:"button",title:a("common.refresh"),onClick:()=>{(0,eo.e)(),L()},className:"p-1 text-text-muted hover:text-text",children:(0,n.jsx)(en.e9,{size:12,className:g?"animate-spin":""})}),(0,n.jsx)("button",{type:"button",title:a("git.gitActions"),onClick:e=>J(e,A),className:"p-1 text-text-muted hover:text-text",children:(0,n.jsx)(en.a4,{size:12})})]}),(0,n.jsx)("textarea",{value:h,onChange:e=>b(e.target.value),rows:2,placeholder:a("git.commitPlaceholder"),className:"w-full bg-surface-2 border border-border rounded-brand px-2 py-1 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500 resize-none"}),(0,n.jsxs)("div",{className:`flex items-stretch h-7 rounded-brand overflow-hidden bg-brand-500 text-white transition-opacity ${!h.trim()||!p.length?"opacity-40":""}`,children:[(0,n.jsx)("button",{type:"button",disabled:!h.trim()||!p.length,onClick:()=>{(0,eo.e)(),U(!1)},className:"flex-1 text-xs hover:bg-black/10 disabled:cursor-not-allowed transition-colors",children:a("git.commit")}),(0,n.jsx)("span",{className:"w-px my-1.5 bg-white/25"}),(0,n.jsx)("button",{type:"button",title:a("git.gitActions"),disabled:!h.trim()||!p.length,onClick:e=>J(e,P),className:"px-1.5 flex items-center hover:bg-black/10 disabled:cursor-not-allowed transition-colors",children:(0,n.jsx)(en.yQ,{size:12})})]}),y&&(0,n.jsx)("div",{className:`text-[11px] leading-snug break-words rounded-brand px-2 py-1 ${y.ok?"text-[var(--success)] bg-[rgba(var(--success-rgb),0.1)]":"text-[var(--danger)] bg-[rgba(var(--danger-rgb),0.1)]"}`,children:y.text})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[er(lC,a("git.changes"),D,!1),er(lS,a("git.untracked"),B,!0)]}),(0,n.jsx)(ei.A,{isOpen:N,onClose:()=>C(!1),onConfirm:V,title:a("git.stageAllConfirmTitle"),message:a("git.stageAllConfirmMessage"),confirmText:a("git.stageAndCommit"),cancelText:a("common.cancel")}),(0,n.jsx)(ei.A,{isOpen:S,onClose:()=>{E(!1),T(null)},onConfirm:()=>{R&&_(R),T(null)},title:a("git.discardConfirmTitle"),message:R?"?"===R.status?a("git.discardConfirmDelete",{name:lE(R.path)}):a("git.discardConfirmDiscard",{name:lE(R.path)}):"",confirmText:a("git.discard"),cancelText:a("common.cancel")}),Y&&(0,n.jsx)(lv,{x:Y.x,y:Y.y,items:es(Y.file),onClose:()=>Z(null)}),z&&(0,n.jsx)(lv,{x:z.x,y:z.y,items:[{key:"commitPush",label:a("git.commitAndPush"),icon:en.Do,disabled:!h.trim()||!p.length,onClick:()=>U(!0)}],onClose:()=>P(null)}),I&&(0,n.jsx)(lv,{x:I.x,y:I.y,items:[{key:"push",label:a("git.push"),icon:en.Do,onClick:X},{key:"pull",label:a("git.pull"),icon:en.yd,onClick:G},{key:"stageAll",label:a("git.stageAll"),icon:en.FW,disabled:!p.length,onClick:W}],onClose:()=>A(null)})]})}let lz=[{key:"files",icon:en.sv,labelKey:"workspaces.tabFiles"},{key:"git",icon:en.Zr,labelKey:"workspaces.tabGit"},{key:"trees",icon:en.dx,labelKey:"workspaces.tabTrees"}].filter(e=>"trees"!==e.key);function lP({results:e,loading:t,query:s,searchDir:r,workspace:l,onOpen:a}){let{t:i}=(0,ec.s)();if(!s||s.length<2){let e=r?r.split("/").pop():"";return(0,n.jsxs)("div",{className:"p-6 text-xs text-text-subtle text-center flex flex-col items-center gap-2",children:[(0,n.jsx)(en.vj,{size:20,className:"opacity-40"}),(0,n.jsx)("span",{children:e?`Type at least 2 characters to search in ${e}`:i("files.searchPlaceholder")})]})}return t?(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle text-center",children:i("files.searching")}):e.length?(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:e.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),a(e.path)},className:"w-full px-2 py-1.5 flex items-center gap-2 border-b border-border-subtle hover:bg-surface-2 transition-colors text-left",title:e.path,children:["binary"===e.type?(0,n.jsx)(en.lP,{size:14,className:"text-red-500/70 flex-shrink-0"}):(0,n.jsx)(en.ZH,{size:14,className:"text-text-subtle flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate text-xs text-text flex-1",children:e.name}),(0,n.jsx)("span",{className:"truncate text-[10px] text-text-subtle max-w-[45%]",children:e.path.replace(l,"").replace(/^\//,"")})]},e.path))}):(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle text-center",children:i("files.noFilesFound")})}function lI({root:e,multiple:t,isOpen:s,onToggle:r,onRemove:l=null,removeLabel:a="",children:i}){return t?(0,n.jsxs)("div",{className:`flex flex-col min-h-0 ${s?"flex-1":"flex-shrink-0"}`,children:[(0,n.jsxs)("div",{className:"group px-2 py-1 flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-text-muted bg-surface-2/40 hover:bg-surface-2 border-b border-border-subtle transition-colors",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),r()},className:"flex-1 min-w-0 flex items-center gap-1.5 hover:text-text transition-colors",title:e.path,children:[(0,n.jsx)(en.c_,{size:11,className:`flex-shrink-0 transition-transform duration-150 ${s?"rotate-90":""}`}),(0,n.jsx)("span",{className:"truncate flex-1 text-left",children:e.branch||e.name||e.path.split("/").pop()}),!e.isMain&&(0,n.jsx)(en.dx,{size:10,className:"flex-shrink-0 opacity-60"})]}),l&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),l()},title:a,className:"p-0.5 shrink-0 hover:text-red-500 transition-colors",children:(0,n.jsx)(en.TB,{size:11})})]}),s&&(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:i})]}):(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:i})}function lA({icon:e,label:t,onClick:s,active:r,disabled:l,spinning:a}){return(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),s?.()},disabled:l,title:t,className:`p-2 sm:p-1 rounded-[3px] hover:bg-surface-2 transition-colors disabled:opacity-40 ${r?"text-brand-500":"text-text-muted hover:text-text"}`,children:(0,n.jsx)(e,{size:16,className:`sm:w-[13px] sm:h-[13px] ${a?"animate-spin":""}`})})}function lL({onClick:e,children:t}){return(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),e()},className:"w-full px-3 py-1.5 text-[11px] text-text-subtle hover:text-text hover:bg-surface-2 transition-colors text-left",children:t})}function lD({repo:e,changedCount:t=0,isOpen:s,onToggle:r,onHide:l,children:a}){let{t:i}=(0,ec.s)();return(0,n.jsxs)("div",{className:"border-b border-border-subtle last:border-0",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),r()},className:"group/repo w-full sticky top-0 z-10 px-2 py-1 flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-text-muted hover:text-text bg-surface-3 border-b border-border-subtle transition-colors",children:[(0,n.jsx)(en.c_,{size:11,className:`flex-shrink-0 transition-transform duration-150 ${s?"rotate-90":""}`}),(0,n.jsx)("span",{className:"truncate flex-1 text-left",title:e.relPath||e.name,children:e.relPath||e.name}),e.branch&&(0,n.jsx)("span",{className:"text-text-subtle normal-case tracking-normal truncate max-w-[45%]",title:e.branch,children:e.branch}),t>0&&(0,n.jsx)("span",{className:"px-1 rounded-[2px] bg-brand-500/15 text-brand-500 normal-case tracking-normal flex-shrink-0",children:t}),l&&(0,n.jsx)("span",{role:"button",tabIndex:-1,onClick:e=>{e.stopPropagation(),(0,eo.e)(),l()},className:"p-0.5 text-text-subtle hover:text-text flex-shrink-0 opacity-100 sm:opacity-0 sm:group-hover/repo:opacity-100 transition-opacity",title:i("workspaces.hideRepo"),children:(0,n.jsx)(en.X_,{size:11})})]}),s&&a]})}let lB=(0,r.memo)(function({workspacePath:e,filesRoot:t=null,cwdHint:s=null,fileBus:l,activeFile:a,tab:i,onTabChange:o,width:c,onResize:d,onClose:u,onOpenFile:x,onNewTerminal:m,onAddWorkspace:p,onOpenFiles:f,homeDir:h,changedPerRepo:b={},hiddenRepos:g=[],onHiddenReposChange:v,isDesktop:y=!0}){let{t:w}=(0,ec.s)(),j=l||et.getState(),k="trees"===i?"git":i,{repos:N,refresh:C,scanning:S,deep:E,scanDeeper:R}=function(e,t){let[s,n]=(0,r.useState)([]),[l,a]=(0,r.useState)(!1),i=t||et.getState(),[o,c]=(0,r.useState)(!1),d=(0,r.useCallback)(async(t,s)=>{if(!e||!i?.gitScanRepos)return;a(!0),t&&await i.gitRefreshRepos?.(e);let r=s?eV.Tk.deepMaxDepth:eV.Tk.maxDepth,l=await i.gitScanRepos(e,r);a(!1),n(l?.success&&l.repos||[])},[e,i]);return(0,r.useEffect)(()=>{let e=setTimeout(()=>void d(!1,o),0);return()=>clearTimeout(e)},[d,o]),{repos:s,refresh:(0,r.useCallback)(()=>d(!0,o),[d,o]),scanning:l,deep:o,scanDeeper:(0,r.useCallback)(()=>c(!0),[])}}(e,j),T=t||e,{roots:$,refresh:M}=function(e,t){let[s,n]=(0,r.useState)([]),l=t||et.getState(),a=(0,r.useCallback)(async()=>{if(!e||!l?.gitWorktreeList)return n([]);let t=await l.gitWorktreeList(e);if(!t?.success||!t.worktrees?.length)return n([{path:e,branch:null,name:rF(e)}]);n(t.worktrees.map(e=>({path:e.path,branch:e.branch,name:rF(e.path),isMain:e.isMain})))},[e,l]);return(0,r.useEffect)(()=>{let e=setTimeout(()=>void a(),0);return()=>clearTimeout(e)},[a]),{roots:s,refresh:a}}(T,j),z=()=>{C(),M()},{branch:P}=n8(e,j),I=(0,r.useRef)({path:null,branch:null});(0,r.useEffect)(()=>{let t=I.current;I.current={path:e,branch:P},t.path===e&&null!==t.branch&&t.branch!==P&&(C(),M(),window.dispatchEvent(new Event(F.GW)))},[P,e]);let[A,L]=(0,r.useState)({forWorkspace:e,showClean:!1,openRepo:null}),D=A.forWorkspace===e?A:{showClean:!1,openRepo:null},B=D.showClean,K=D.openRepo,O=new Set(g),W=e=>b[e.path]??e.changedCount??0,_=t=>!t.relPath||t.path===e,H=N.filter(e=>!O.has(e.path)),q=H.filter(e=>W(e)>0).reduce((e,t)=>e+W(t),0),U=B?H:H.filter(e=>W(e)>0||_(e)),V=B?0:H.length-U.length,X=N.length-H.length,G=K??(1===U.length?U[0].path:null),J=!y||c>=eV.Ds.min,[Y,Z]=(0,r.useState)(null),[Q,ee]=(0,r.useState)(null),[es,er]=(0,r.useState)(null),[el,ea]=(0,r.useState)(null),ed=$.find(e=>e.isMain)?.path||e,eu=async e=>{er(null);let t=await j.gitWorktreeRemove(ed,e.path,{probe:!0,deleteBranch:e.branch||void 0});if(!t?.success)return er(t?.error||"Probe failed");ee({root:e,sessions:t.sessions||[],branchMerged:t.branchMerged})},ex=async(e,t=!1)=>{er(null),ea(null);let s=await j.gitWorktreeRemove(ed,e.path,{confirmed:!0,force:t,deleteBranch:e.branch||void 0});return!s?.success&&/use --force/i.test(s?.error||"")?ee({root:e,dirty:!0}):(ee(null),s?.success)?void(s.branchKept&&ea(e.branch),z()):er(s?.error||"Remove failed")},em=s||T,ep=(0,r.useMemo)(()=>{let e=$.filter(e=>em===e.path||em?.startsWith(`${e.path}/`));return e.length?e.sort((e,t)=>t.path.length-e.path.length)[0].path:($.find(e=>e.isMain)||$[0])?.path||T},[$,em,T]),[ef,eh]=(0,r.useState)({forProbe:null,path:null}),eb=ef.forProbe===em?ef.path:ep,[eg,ev]=(0,r.useState)({forRoot:null,searchDir:null,show:!1,query:"",results:[],loading:!1}),ey=eg.forRoot===T?eg:{show:!1,searchDir:null,query:"",results:[],loading:!1},ew=(0,r.useRef)(null),ej=(0,r.useCallback)(()=>{ev({forRoot:null,searchDir:null,show:!1,query:"",results:[],loading:!1})},[]),ek=(0,r.useCallback)(e=>{ev({forRoot:T,searchDir:e,show:!0,query:"",results:[],loading:!1})},[T]),eN=(0,r.useCallback)(()=>{ev(e=>{let t={...e,searchDir:null};return e.query&&e.query.length>=2&&(t.loading=!0,j.searchFiles(T,e.query).then(e=>{ev(t=>t.loading?{...t,results:e.success?e.files:[],loading:!1}:t)})),t})},[j,T]),eC=(0,r.useCallback)(e=>{if(ev(t=>({...t,query:e})),ew.current&&clearTimeout(ew.current),!e||e.length<2)return void ev(e=>({...e,results:[],loading:!1}));ev(e=>({...e,loading:!0}));let t=ey.searchDir||T;ew.current=setTimeout(async()=>{let s=await j.searchFiles(t,e);ev(t=>t.query===e&&t.loading?{...t,results:s.success?s.files:[],loading:!1}:t)},300)},[j,T,ey.searchDir]);return(0,r.useEffect)(()=>()=>{ew.current&&clearTimeout(ew.current)},[]),(0,n.jsxs)("div",{className:`h-full flex flex-col terminal-sidebar-bg border-l border-border-subtle relative shrink ${y?"":"pb-safe"}`,style:y?{width:c,flexBasis:c,minWidth:eV.Ds.min}:void 0,children:[(0,n.jsxs)("div",{className:`h-11 ${s1} pl-1 pr-0.5 flex items-stretch gap-0 border-b border-border-subtle flex-shrink-0`,children:[lz.map(({key:e,icon:t,labelKey:s})=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),o(e)},className:`px-3 sm:px-2 flex items-center justify-center gap-1 text-[11px] border-b-2 -mb-px transition-colors ${k===e?"text-text border-brand-500":"text-text-muted border-transparent hover:text-text"}`,title:w(s),children:[(0,n.jsx)(t,{size:18,className:"sm:w-[15px] sm:h-[15px]"}),J&&(0,n.jsx)("span",{children:w(s)}),"git"===e&&q>0&&(0,n.jsx)("span",{className:"min-w-[14px] h-[14px] px-[4px] rounded-full bg-brand-500 text-white text-[9px] font-semibold flex items-center justify-center leading-none",children:q>99?"99+":q})]},e)),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 sm:gap-0.5",children:[(0,n.jsx)(lA,{icon:en.e9,label:w("workspaces.refreshRepos"),onClick:()=>{z(),Y?.refresh?.()},disabled:S,spinning:S}),u&&(0,n.jsx)(lA,{icon:en.X,label:w("common.close"),onClick:u})]})]}),"files"===k&&e&&(0,n.jsx)("div",{className:`h-11 ${s1} px-2 flex items-center gap-1.5 border-b border-border-subtle flex-shrink-0`,children:ey.show?(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[(0,n.jsx)(en.vj,{size:14,className:"text-text-subtle shrink-0"}),(0,n.jsx)("input",{type:"text",value:ey.query,onChange:e=>eC(e.target.value),onKeyDown:e=>{"Escape"===e.key&&ej()},placeholder:ey.searchDir?`Search in ${ey.searchDir.split("/").pop()}…`:w("files.searchPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs text-text placeholder-text-subtle focus:outline-none",autoFocus:!0}),ey.loading?(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-brand-500 shrink-0"}):ey.query?(0,n.jsx)("button",{type:"button",onClick:()=>eC(""),className:"p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(en.X,{size:12})}):null,(0,n.jsx)(lA,{icon:en.X,label:w("common.close"),onClick:ej})]}):(0,n.jsxs)(n.Fragment,{children:[Y&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(lA,{icon:en.FW,label:w("files.newFile"),onClick:Y.newFile}),(0,n.jsx)(lA,{icon:en.JU,label:w("files.newFolder"),onClick:Y.newFolder})]}),(0,n.jsx)(lA,{icon:en.vj,label:w("files.searchFiles"),onClick:()=>{if(ey.show)return ej();ev({forRoot:T,searchDir:null,show:!0,query:"",results:[],loading:!1})},active:ey.show}),(0,n.jsx)("div",{className:"flex-1"}),Y?.hasExpanded&&(0,n.jsx)(lA,{icon:en.WE,label:w("fileExplorer.collapseAll"),onClick:Y.collapseAll}),Y&&(0,n.jsx)(lA,{icon:Y.showHidden?en.kU:en.X_,label:w("files.toggleHidden"),onClick:Y.toggleHidden,active:Y.showHidden}),f&&(0,n.jsx)(lA,{icon:en.Gr,label:w("workspaces.openFullFiles"),onClick:f})]})}),"files"===k&&e&&ey.show&&ey.searchDir&&(0,n.jsxs)("div",{className:"px-3 py-1 bg-surface-3/40 border-b border-border-subtle flex items-center justify-between text-[11px] text-text-muted flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)(en.vd,{size:12,className:"text-yellow-500/80 shrink-0"}),(0,n.jsx)("span",{className:"text-text-subtle shrink-0",children:"Folder:"}),(0,n.jsx)("span",{className:"font-medium text-text truncate max-w-[150px]",title:ey.searchDir,children:ey.searchDir.split("/").pop()})]}),(0,n.jsx)("button",{type:"button",onClick:eN,className:"text-brand-500 hover:text-brand-400 hover:underline shrink-0 text-[11px] ml-2",children:"Search all"})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:e?"files"===k?ey.show?(0,n.jsx)(lP,{results:ey.results,loading:ey.loading,query:ey.query,searchDir:ey.searchDir,workspace:T,onOpen:e=>{x?.(e),ej()}}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(es||el)&&(0,n.jsxs)("div",{className:"px-3 py-1.5 border-b border-border-subtle text-[11px]",children:[es&&(0,n.jsx)("p",{className:"text-red-500 break-words whitespace-pre-wrap",children:es}),el&&(0,n.jsx)("p",{className:"text-text-muted break-words",children:w("workspaces.worktreeBranchKept",{branch:el})})]}),$.map(e=>(0,n.jsx)(lI,{root:e,multiple:$.length>1,isOpen:1===$.length||eb===e.path,onToggle:()=>eh({forProbe:em,path:eb===e.path?null:e.path}),onRemove:e.isMain?null:()=>{(0,eo.e)(),eu(e)},removeLabel:w("workspaces.removeWorktree"),children:(0,n.jsx)(lg,{workspace:e.path,fileBus:j,activeFile:a,onOpenFile:x,onNewTerminal:m,onSearchFolder:ek,compact:!0,onActions:e.path===eb||1===$.length?Z:void 0})},e.path))]}):"git"===k?(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[U.map(t=>(0,n.jsx)(lD,{repo:t,changedCount:W(t),isOpen:G===t.path,onToggle:()=>{let s;return s=G===t.path?"":t.path,L({...D,forWorkspace:e,openRepo:s})},onHide:v&&!_(t)?()=>{let e;return e=t.path,v?.([...g,e])}:null,children:(0,n.jsx)(lM,{workspace:t.path,fileBus:j,onOpenFile:x,tagDiffWithRepo:!0})},t.path)),!U.length&&!S&&(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle italic",children:B?w("workspaces.emptyWorkspace"):w("git.noChanges")}),(V>0||X>0||!E)&&(0,n.jsxs)("div",{className:"border-t border-border-subtle mt-1",children:[V>0&&(0,n.jsx)(lL,{onClick:()=>L({...D,forWorkspace:e,showClean:!0}),children:w("workspaces.showCleanRepos",{count:V})}),X>0&&(0,n.jsx)(lL,{onClick:()=>v?.([]),children:w("workspaces.showHiddenRepos",{count:X})}),!E&&(0,n.jsx)(lL,{onClick:R,children:w("workspaces.scanDeeper")})]})]}):null:(0,n.jsxs)("div",{className:"p-4 flex flex-col items-center gap-2 text-center",children:[(0,n.jsx)(en.vd,{size:22,className:"text-text-subtle"}),(0,n.jsx)("p",{className:"text-xs text-text-subtle",children:w("workspaces.emptyWorkspace")}),p&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),p()},className:"mt-1 px-2 py-1 text-[11px] text-brand-500 bg-brand-500/10 hover:bg-brand-500/20 rounded-[3px] transition-colors",children:w("workspaces.selectFolder")})]})}),(0,n.jsx)(ei.A,{isOpen:!!Q,onClose:()=>ee(null),onConfirm:()=>{(0,eo.e)(),ex(Q.root,!!Q.dirty)},title:w("workspaces.removeWorktree"),message:Q?Q.dirty?w("workspaces.worktreeDirty"):[w("workspaces.removeWorktreeFolder",{path:Q.root.path}),Q.root.branch&&w(!0===Q.branchMerged?"workspaces.removeWorktreeBranchDelete":!1===Q.branchMerged?"workspaces.removeWorktreeBranchKeep":"workspaces.removeWorktreeBranch",{branch:Q.root.branch}),Q.sessions?.length?w("workspaces.removeWorktreeSessions",{count:Q.sessions.length,names:Q.sessions.map(e=>e.name).join(", ")}):null].filter(Boolean).join("\n"):""}),y&&(0,n.jsx)("div",{onPointerDown:e=>eU(e,{startWidth:c,axis:-1,onWidth:e=>d?.(e)}),className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})]})});function lF(e){return e?e<1024?`${e}B`:e<1048576?`${(e/1024).toFixed(1)}KB`:`${(e/1048576).toFixed(1)}MB`:""}function lK({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!0),[x,m]=(0,r.useState)(1),[p,f]=(0,r.useState)({x:0,y:0}),[h,b]=(0,r.useState)(0),g=(0,r.useRef)(null),v=(0,r.useRef)(null),y=(0,r.useRef)(null),w=(0,r.useRef)(null),j=(0,r.useRef)(null),k=(0,r.useRef)(null),N=(0,r.useRef)(0);(0,r.useEffect)(()=>{let s=!1,n=[],r="";u(!0),c(""),l(""),i(null),m(1),f({x:0,y:0}),b(0),y.current=null,w.current&&(URL.revokeObjectURL(w.current),w.current=null);let a=e.toLowerCase();if(a.endsWith(".tif")||a.endsWith(".tiff"))return t.readMedia(e).then(e=>{s||(e.success?(l(e.dataUrl),i({size:e.originalSize||e.size,width:e.width,height:e.height,scaled:e.scaled,originalWidth:e.originalWidth,originalHeight:e.originalHeight})):c(e.error||"Failed to load image"),u(!1))}),()=>{s=!0};let o=t.streamMedia(e,{onMeta:e=>{s||(r=e.mime||"image/*",i({size:e.size,width:e.width,height:e.height,scaled:e.scaled,originalWidth:e.originalWidth,originalHeight:e.originalHeight}))},onChunk:e=>{s||n.push(e)},onDone:()=>{if(s)return;let e=new Blob(n,{type:r});if(e.size>F.W5){y.current=e,b(e.size),u(!1);return}w.current=URL.createObjectURL(e),l(w.current),u(!1)},onError:e=>{s||(c(e.message||"Failed to load image"),u(!1))}});return()=>{s=!0,o?.()}},[e,t]),(0,r.useEffect)(()=>()=>{w.current&&URL.revokeObjectURL(w.current)},[]);let C=(0,r.useCallback)((e,t,s)=>{let n=v.current,r=g.current;if(!n||!r)return{x:e,y:t};let l=r.clientWidth,a=r.clientHeight,i=n.clientWidth*s,o=n.clientHeight*s,c=Math.max(0,(i-l)/2),d=Math.max(0,(o-a)/2);return{x:Math.max(-c,Math.min(c,e)),y:Math.max(-d,Math.min(d,t))}},[]),S=(0,r.useCallback)(()=>{m(1),f({x:0,y:0})},[]),E=(0,r.useCallback)((e,t,s)=>{m(n=>{let r=Math.max(.2,Math.min(8,n*e));if(r===n)return n;if(null!=t&&null!=s){let e=g.current;if(e){let l=e.clientWidth/2,a=e.clientHeight/2,i=t-l,o=s-a;f(e=>C((e.x-i)*(r/n)+i,(e.y-o)*(r/n)+o,r))}}else f(e=>C(e.x,e.y,r));return r})},[C]),R=(e,t)=>Math.hypot(e.clientX-t.clientX,e.clientY-t.clientY),T=(0,r.useCallback)(e=>{if(2===e.touches.length)k.current=null,j.current={dist:R(e.touches[0],e.touches[1]),scale:x,pos:p};else if(1===e.touches.length){let t=Date.now();if(t-N.current<300){x>1.01?S():(m(2),f({x:0,y:0})),N.current=0,k.current=null;return}N.current=t,x>1.01&&(k.current={x:e.touches[0].clientX,y:e.touches[0].clientY,pos:p})}},[x,p,S]),$=(0,r.useCallback)(e=>{if(2===e.touches.length&&j.current){e.preventDefault();let t=R(e.touches[0],e.touches[1]),s=Math.max(.2,Math.min(8,j.current.scale*(t/j.current.dist)));m(s),f(e=>C(e.x,e.y,s))}else if(1===e.touches.length&&k.current){e.preventDefault();let t=e.touches[0],s=t.clientX-k.current.x,n=t.clientY-k.current.y;f(C(k.current.pos.x+s,k.current.pos.y+n,x))}},[x,C]),M=(0,r.useCallback)(e=>{e.touches.length<2&&(j.current=null),0===e.touches.length&&(k.current=null)},[]),z=(0,r.useCallback)(e=>{e.preventDefault();let t=e.deltaY<0?1.1:1/1.1,s=g.current?.getBoundingClientRect();E(t,s?e.clientX-s.left:null,s?e.clientY-s.top:null)},[E]);if(d)return(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(en.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading image..."})]});if(o)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:o});if(h)return(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-text-muted px-6 text-center",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-text truncate max-w-full",title:e,children:e.split("/").pop()}),(0,n.jsxs)("span",{className:"text-xs",children:[lF(h)," — decoding an image this large can crash mobile Safari."]}),(0,n.jsx)("button",{onClick:()=>{let e=y.current;e&&(w.current=URL.createObjectURL(e),l(w.current),b(0))},className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-surface-3 text-text text-sm",children:"Open anyway"})]});let P=a?.width&&a?.height?`${a.width}\xd7${a.height}`:"",I=a?.scaled&&a?.originalWidth&&a?.originalWidth!==a?.width;return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-3 py-1.5 flex items-center gap-2 text-xs text-text-muted",children:[(0,n.jsx)("span",{className:"truncate flex-1",title:e,children:e.split("/").pop()}),a?.size?(0,n.jsx)("span",{className:"text-text-subtle",children:lF(a.size)}):null,P?(0,n.jsxs)("span",{className:"text-text-subtle",children:[P,I?" ↓":""]}):null,(0,n.jsx)("button",{onClick:()=>E(1/1.2),className:"px-2 hover:bg-surface-2 rounded",children:"−"}),(0,n.jsxs)("span",{className:"w-12 text-center",children:[Math.round(100*x),"%"]}),(0,n.jsx)("button",{onClick:()=>E(1.2),className:"px-2 hover:bg-surface-2 rounded",children:"+"}),(0,n.jsx)("button",{onClick:S,className:"px-2 hover:bg-surface-2 rounded",children:"Reset"})]}),(0,n.jsx)("div",{ref:g,className:"flex-1 min-h-0 overflow-hidden flex items-center justify-center bg-[repeating-conic-gradient(#0001_0%_25%,transparent_0%_50%)] bg-[length:20px_20px] touch-none",onTouchStart:T,onTouchMove:$,onTouchEnd:M,onWheel:z,children:(0,n.jsx)("img",{ref:v,src:s,alt:e,draggable:!1,onLoad:e=>i(t=>({...t,width:e.target.naturalWidth,height:e.target.naturalHeight})),style:{transform:`translate(${p.x}px, ${p.y}px) scale(${x})`,transformOrigin:"center",willChange:"transform"},className:"max-w-full max-h-full object-contain select-none"})})]})}function lO({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(""),[o,c]=(0,r.useState)(0),[d,u]=(0,r.useState)(""),[x,m]=(0,r.useState)(!0);if((0,r.useEffect)(()=>{let s=!1,n=null,r=null,a=null,o=null,d=[],x=!1;m(!0),u(""),l(""),i(""),c(0);let p=!1,f="",h=()=>{if(!s&&!p&&o&&!o.updating){if(d.length)return void o.appendBuffer(d.shift());if(x&&r&&"open"===r.readyState)try{r.endOfStream()}catch{}}};return n=t.streamMedia(e,{onMeta:({mime:e,size:t})=>{if(!s){if(i(e),c(t),!("u">typeof MediaSource&&MediaSource.isTypeSupported(e))){p=!0,f=e;return}r=new MediaSource,l(a=URL.createObjectURL(r)),m(!1),r.addEventListener("sourceopen",()=>{s||((o=r.addSourceBuffer(e)).addEventListener("updateend",h),h())})}},onChunk:e=>{!s&&(d.push(e),p||h())},onDone:()=>{if(!s)if(p){let e=new Blob(d,{type:f||"application/octet-stream"});l(a=URL.createObjectURL(e)),m(!1)}else x=!0,h()},onError:e=>{s||(u(e.message||"Stream error"),m(!1))}}),()=>{s=!0,n?.(),a&&URL.revokeObjectURL(a);try{r&&"open"===r.readyState&&r.endOfStream()}catch{}}},[e,t]),x)return(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(en.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading media..."})]});if(d)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:d});let p=a.startsWith("video/"),f=e.split("/").pop();return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-3 py-1.5 flex items-center gap-2 text-xs text-text-muted",children:[(0,n.jsx)("span",{className:"truncate flex-1",title:e,children:f}),o?(0,n.jsx)("span",{className:"text-text-subtle",children:o?o<1024?`${o}B`:o<1048576?`${(o/1024).toFixed(1)}KB`:`${(o/1048576).toFixed(1)}MB`:""}):null]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto flex items-center justify-center bg-black/30",children:p?(0,n.jsx)("video",{src:s,controls:!0,className:"max-h-full max-w-full"}):(0,n.jsx)("audio",{src:s,controls:!0,className:"w-full max-w-md"})})]})}function lW({filePath:e,fileBus:t}){let[l,a]=(0,r.useState)(!0),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)([]),[u,x]=(0,r.useState)(0),[m,p]=(0,r.useState)([]),f=(0,r.useRef)(null),h=(0,r.useRef)(null),b=(0,r.useRef)(null);if((0,r.useEffect)(()=>{let n=!1,r=null,l=[],i=(0,F.$b)(e);a(!0),o(""),d([]),x(0),p([]),h.current=null,f.current&&(f.current.innerHTML="");let c=async e=>{try{if(i){let{renderAsync:t}=await s.e(910).then(s.bind(s,80910));if(n||!f.current){n||a(!1);return}for(let s of(await t(new Blob([e]),f.current,void 0,{inWrapper:!0,renderAltChunks:!1}),f.current.querySelectorAll("a[href]"))){let e=s.getAttribute("href")||"";/^(https?:|mailto:|#)/i.test(e.trim())||s.removeAttribute("href")}n||a(!1)}else{let t=await Promise.all([s.e(8874),s.e(4930)]).then(s.bind(s,19819));if(n)return;b.current=t,h.current=t.read(e,{type:"array"}),d(h.current.SheetNames),x(0),(()=>{let e=h.current,t=b.current;if(!e||!t)return;let s=e.SheetNames[0];s&&(p(t.utils.sheet_to_json(e.Sheets[s],{header:1,defval:"",raw:!1})),a(!1))})()}}catch(e){n||(o(e.message||"Failed to render"),a(!1))}};return r=t.streamMedia(e,{onChunk:e=>{n||l.push(e)},onDone:()=>{if(n)return;let e=new Uint8Array(l.reduce((e,t)=>e+t.byteLength,0)),t=0;for(let s of l)e.set(s,t),t+=s.byteLength;c(e)},onError:e=>{n||(o(e.message||"Failed to load"),a(!1))}}),()=>{n=!0,r?.()}},[e,t]),(0,r.useEffect)(()=>{let e=h.current,t=b.current;if(!e||!t)return;let s=e.SheetNames[u];s&&p(t.utils.sheet_to_json(e.Sheets[s],{header:1,defval:"",raw:!1}))},[u]),i)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:i});let g=(0,F.$b)(e);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[l&&(0,n.jsxs)("div",{className:"absolute inset-0 z-10 flex items-center justify-center gap-2 bg-surface text-text-muted",children:[(0,n.jsx)(en.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading document..."})]}),!g&&c.length>1&&(0,n.jsx)("div",{className:"flex gap-1 overflow-x-auto bg-surface border-b border-border px-2 py-1 flex-shrink-0",children:c.map((e,t)=>(0,n.jsx)("button",{onClick:()=>x(t),className:`px-2 py-1 text-xs rounded whitespace-nowrap transition-colors ${t===u?"bg-brand-500 text-white":"bg-surface-2 text-text-muted hover:text-text"}`,children:e},t))}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto bg-white text-black",children:g?(0,n.jsx)("div",{ref:f,className:"p-4"}):(0,n.jsx)("div",{className:"p-2",children:(0,n.jsx)("table",{className:"border-collapse",children:(0,n.jsx)("tbody",{children:m.map((e,t)=>(0,n.jsx)("tr",{children:e.map((e,t)=>(0,n.jsx)("td",{className:"border border-gray-300 px-2 py-1 whitespace-pre-wrap align-top",children:e},t))},t))})})})})]})}function l_({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(""),[o,c]=(0,r.useState)(!0);return((0,r.useEffect)(()=>{let s=!1,n=null,r=[],a="application/pdf";c(!0),i(""),l("");let o=t.streamMedia(e,{onMeta:({mime:e})=>{!s&&e&&(a=e)},onChunk:e=>{s||r.push(e)},onDone:()=>{if(s)return;let e=new Blob(r,{type:a}),t=URL.createObjectURL(e);n=t,l(t),c(!1)},onError:e=>{s||(i(e.message||"Failed to load PDF"),c(!1))}});return()=>{s=!0,o(),n&&URL.revokeObjectURL(n)}},[e,t]),o)?(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(en.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading PDF..."})]}):a?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:a}):(0,n.jsx)("iframe",{src:s,title:"PDF preview",className:"h-full w-full bg-bg"})}let lH=e=>(0,F.u)(e)||(0,F.AE)(e)||(0,F.L8)(e)||(0,F.ZH)(e)||(0,F.$b)(e)||(0,F.iB)(e);function lq({filePath:e,fileBus:t}){return(0,F.ZH)(e)?(0,n.jsx)(l_,{filePath:e,fileBus:t},e):(0,F.$b)(e)||(0,F.iB)(e)?(0,n.jsx)(lW,{filePath:e,fileBus:t},e):(0,F.AE)(e)||(0,F.L8)(e)?(0,n.jsx)(lO,{filePath:e,fileBus:t},e):(0,n.jsx)(lK,{filePath:e,fileBus:t},e)}function lU({filePath:e,fileBus:t}){let[s,n]=(0,r.useState)(!0),[l,a]=(0,r.useState)(null),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),f=(0,r.useRef)(""),h=(0,r.useRef)(null),b=(0,r.useRef)(null),[g,v]=(0,r.useState)(!1),y=(0,r.useCallback)(e=>{h.current=e},[]),w=(0,r.useCallback)(async(s=()=>!1)=>{n(!0),o(""),d(!1),v(!1);let r=await t.readFile(e);if(s())return;if(!r?.success){o(r?.error||""),n(!1);return}let l=r.content;if(r.streamInstead)try{let n=[];if(await new Promise((s,r)=>{t.streamMedia(e,{onMeta:()=>{},onChunk:e=>n.push(e),onDone:s,onError:r})}),s())return;l=await new Blob(n).text()}catch(e){if(s())return;o(e?.message||""),n(!1);return}f.current=l,a(l),n(!1)},[e,t]);(0,r.useEffect)(()=>{let t=!1;if(!e){n(!1),a(null),d(!1),o(""),v(!1);return}return w(()=>t),()=>{t=!0}},[e,w]);let j=(0,r.useCallback)(()=>{c?v(!0):w()},[c,w]);(0,r.useEffect)(()=>()=>clearTimeout(b.current),[]);let k=(0,r.useCallback)(e=>{d(e!==f.current)},[]),N=(0,r.useCallback)(async()=>{let s=h.current?.();if(null==s||u||s===f.current)return!0;x(!0);let n=await t.writeFile(e,s);return(x(!1),n?.success)?(f.current=s,d(!1),o(""),p(!0),clearTimeout(b.current),b.current=setTimeout(()=>p(!1),2e3),window.dispatchEvent(new CustomEvent("fileExplorer:fileSaved",{detail:{filePath:e}})),!0):(o(n?.error||""),!1)},[e,t,u]);return{loading:s,content:l,error:i,dirty:c,saving:u,justSaved:m,staleOnDisk:g,register:y,onTextChanged:k,save:N,discard:(0,r.useCallback)(()=>{d(!1),a(f.current)},[]),setError:o,reload:w,onChangedOnDisk:j}}function lV({dirty:e,onSave:t}){let[s,n]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!e)return;let t=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[e]);let l=(0,r.useCallback)(t=>{if(!e)return t();n(()=>t)},[e]),a=(0,r.useCallback)(async()=>{await t()&&(n(null),s?.())},[t,s]),i=(0,r.useCallback)(()=>{n(null),s?.()},[s]);return{guard:l,asking:!!s,saveThenLeave:a,discardAndLeave:i,cancel:(0,r.useCallback)(()=>n(null),[])}}function lX({isOpen:e,fileName:t,onSave:s,onDiscard:l,onCancel:a}){let{t:i}=(0,ec.s)(),o=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{o.current?.focus()});return()=>cancelAnimationFrame(t)},[e]),(0,r.useEffect)(()=>{if(!e)return;let t=e=>{if("Escape"===e.key)e.preventDefault(),e.stopPropagation(),a?.();else if("Enter"===e.key){if(document.activeElement?.tagName==="BUTTON"&&document.activeElement!==o.current)return;e.preventDefault(),e.stopPropagation(),(0,eo.e)(),s?.()}else"d"!==e.key&&"D"!==e.key||e.metaKey||e.ctrlKey||e.altKey||(e.preventDefault(),e.stopPropagation(),(0,eo.e)(),l?.())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e,a,s,l]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[90] flex items-center justify-center px-4",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},onClick:a,children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60"}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:"relative card-elev w-full max-w-sm p-5",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-[15px] font-semibold text-text mb-1.5",children:i("editor.unsavedTitle",{name:t||""})}),(0,n.jsx)("p",{className:"text-[13px] text-text-muted leading-snug mb-5",children:i("editor.unsavedBody")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),l?.()},className:"px-3 py-2 text-[13px] text-text-muted hover:text-red-500 transition-colors flex items-center gap-1",children:[(0,n.jsx)("span",{children:i("editor.discard")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"D"})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{onClick:a,className:"px-4 py-2 text-[13px] text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)("span",{children:i("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{ref:o,onClick:()=>{(0,eo.e)(),s?.()},autoFocus:!0,className:"px-4 py-2 text-[13px] font-semibold text-white bg-brand-500 hover:bg-brand-600 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)("span",{children:i("editor.save")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(en.Lt,{size:10,strokeWidth:2.5})})]})]})]})]}):null}var lG=s(70256),lJ=s(39821),lY=s(48907),lZ=s(74447),lQ=s(15332),l0=s(9722),l1=s(97320),l2=s(99833),l5=s(50807),l3=s(57378),l4=s(41554),l6=s(42760);let l8={javascript:(0,lZ.Q2)(),html:(0,lQ.qy)(),css:(0,l0.AH)(),json:(0,l1.Pq)(),markdown:(0,l2.wD)()};function l9({filePath:e,content:t,onTextChanged:s,onRegisterView:l,onSave:a,onCursorChange:i,line:o,column:c,compact:d=!1,className:u=""}){let x,m,{theme:p}=(0,n_.D)(),f=(0,r.useRef)(null),h=(0,r.useRef)(null),b=(0,r.useRef)(s),g=(0,r.useRef)(i),v=(0,r.useRef)(a);(0,r.useEffect)(()=>{b.current=s},[s]),(0,r.useEffect)(()=>{g.current=i},[i]),(0,r.useEffect)(()=>{v.current=a},[a]);let[y]=tK(F.d5.editorFontSize,F.A0),[w]=tK(F.d5.wordWrap,!0),j=window.innerWidth<eV.jK,k=d?Math.max(F.rL,y-F.xl):y+ +!!j,{extension:N}=(x="."+e.split(".").pop()?.toLowerCase(),{lang:m=F.so[x]||"plaintext",extension:l8[m]||[]});return(0,r.useEffect)(()=>{if(null==t||!f.current)return;let e=lY.$t.create({doc:t,extensions:[lG.oQ,..."dark"===p?[l5.bM]:[],N,...w?[lJ.Lz.lineWrapping]:[],(0,l3.$P)(),(0,l4.yU)(),(0,l4.wm)(),lJ.w4.of([{key:"Mod-s",preventDefault:!0,run:()=>(v.current?.(),!0)},...l4.Bc,...l4.OO,l6.Yc]),lJ.Lz.updateListener.of(e=>{if(e.docChanged&&b.current?.(e.state.doc.toString()),e.selectionSet||e.docChanged){let t=e.state.selection.main.head,s=e.state.doc.lineAt(t);g.current?.({line:s.number,column:t-s.from+1})}}),lJ.Lz.theme({"&":{height:"100%",fontSize:`${k}px`},".cm-scroller":{overflow:"auto",lineHeight:d?"1.35":""},".cm-content":{minHeight:"100%"},".cm-gutters":d?{fontSize:`${Math.max(8,k-1)}px`}:{}})]});return h.current?.destroy(),h.current=new lJ.Lz({state:e,parent:f.current}),l?.(()=>h.current?.state.doc.toString()??null,h.current),()=>{h.current?.destroy(),h.current=null}},[t,e,p,w,k,d]),(0,r.useEffect)(()=>{let e=h.current;if(!e||!o)return;let t=e.state.doc,s=Math.max(1,Math.min(o,t.lines)),n=t.line(s),r=Math.min(n.from+Math.max(0,(c||1)-1),n.to);e.dispatch({selection:{anchor:r},effects:lJ.Lz.scrollIntoView(r,{y:"center"})}),e.focus()},[o,c,t]),(0,n.jsx)("div",{ref:f,className:`h-full w-full overflow-hidden ${u}`})}function l7(e,t){return decodeURIComponent((t&&e.startsWith(t)?e.slice(t.length):e)||"/").replace(/^\//,"")||"/"}function ae({filePath:e,fileBus:t,reloadKey:s=0}){let{t:l}=(0,ec.s)(),{getAuth:i}=(0,a.Fo)(),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(""),[x,m]=(0,r.useState)(0),[p,f]=(0,r.useState)(e),[h,b]=(0,r.useState)({entries:[],index:-1}),g=(0,r.useRef)(null),v=(0,r.useRef)(!1);p!==e&&(f(e),c(null),u(""),b({entries:[],index:-1})),(0,r.useEffect)(()=>{let s=!1;return t.previewStart(e).then(e=>{var n;if(s){e.success&&t.previewEnd(e.sessionId);return}if(!e.success)return void u(e.error||l("editor.previewFailed"));let r=(n=i(),n?.localIp&&"https:"!==window.location.protocol?`http://${n.localIp}`:n?.tunnelUrl||null);if(!r){t.previewEnd(e.sessionId),u(l("editor.previewNoRoute"));return}let a=`/preview/${e.sessionId}`;g.current=e.sessionId,c({origin:r,root:a}),b({entries:[`${a}/${encodeURIComponent(e.entry)}`],index:0})}),()=>{s=!0,g.current&&t.previewEnd(g.current),g.current=null}},[e,t]);let y=o?.root;(0,r.useEffect)(()=>{if(!y)return;let e=e=>{if(e.data?.source!==F.fQ||"string"!=typeof e.data.path)return;let t=e.data.path;if(t.startsWith(y+"/")||t===y){if(v.current){v.current=!1;return}b(e=>{if(e.index>=0&&e.entries[e.index]===t)return e;let s=[...e.entries.slice(0,e.index+1),t];return{entries:s,index:s.length-1}})}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[y]);let w=(0,r.useCallback)(e=>{(0,eo.e)(),v.current=!0,b(t=>{let s=Math.max(0,Math.min(t.entries.length-1,t.index+e));return s===t.index?t:{...t,index:s}})},[]);if(d)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm px-6 text-center",children:d});if(!o)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:l("common.loading")});let j=h.entries[h.index]||o.root,k=`${o.origin}${j}`,N=h.index>0,C=h.index<h.entries.length-1,S="p-1 rounded-[3px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors disabled:opacity-30 disabled:hover:bg-transparent";return(0,n.jsxs)("div",{className:"h-full w-full flex flex-col bg-white",children:[(0,n.jsxs)("div",{className:"h-8 flex items-center gap-0.5 px-1.5 shrink-0 border-b border-border-subtle bg-surface",children:[(0,n.jsx)("button",{onClick:()=>w(-1),disabled:!N,title:l("editor.previewBack"),className:S,children:(0,n.jsx)(en.JG,{size:14})}),(0,n.jsx)("button",{onClick:()=>w(1),disabled:!C,title:l("editor.previewForward"),className:S,children:(0,n.jsx)(en.c_,{size:14})}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),m(e=>e+1)},title:l("editor.reload"),className:S,children:(0,n.jsx)(en.e9,{size:13})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate px-2 py-0.5 mx-1 rounded-[3px] bg-surface-2 text-[11px] text-text-muted",title:l7(j,o.root),children:l7(j,o.root)}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),window.open(k,"_blank","noopener")},title:l("editor.previewOpenTab"),className:S,children:(0,n.jsx)(en.Gr,{size:13})})]}),(0,n.jsx)("iframe",{src:k,sandbox:"allow-scripts allow-forms allow-popups",className:"flex-1 min-h-0 w-full border-0",title:"HTML preview"},`${k}|${h.index}|${s}|${x}`)]})}let at=null,as=0;function an({content:e,reloadKey:t=0}){let l,a,{t:i}=(0,ec.s)(),{theme:o}=(0,n_.D)(),[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(""),m=(0,r.useRef)(null),p=(a=(l=String(e||"").trim()).match(/^```(?:mermaid)?\s*([\s\S]*?)\s*```$/i))?a[1].trim():l,[f,h]=(0,r.useState)(p);return(f!==p&&(h(p),d(""),x("")),(0,r.useEffect)(()=>{let e=!1;if(p)return(!at&&(at=Promise.all([s.e(3755),s.e(7162),s.e(3606)]).then(s.bind(s,86492)).then(e=>e.default)),at).then(async t=>{if(!e){t.initialize({startOnLoad:!1,theme:"dark"===o?"dark":"default",securityLevel:z.Ic});try{let{svg:s}=await t.render(`mmd-${++as}`,p);if(e)return;d(s),x("")}catch(t){if(e)return;d(""),x(t?.message||String(t))}}}).catch(t=>{e||x(t?.message||String(t))}),()=>{e=!0}},[p,o,t]),u)?(0,n.jsxs)("div",{className:"h-full overflow-auto p-3",children:[(0,n.jsx)("p",{className:"text-[11px] text-red-500 mb-2 break-words",children:u}),(0,n.jsx)("pre",{className:"text-[11px] text-text-muted whitespace-pre-wrap break-words",children:p})]}):p?c?(0,n.jsx)("div",{ref:m,className:"h-full overflow-auto p-3 flex items-start justify-center [&_svg]:max-w-full [&_svg]:h-auto",dangerouslySetInnerHTML:{__html:c}}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:i("common.loading")}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:i("editor.mermaidEmpty")})}var ar=s(49430),al=s(93473);let aa=(e,t)=>function({children:s,className:r,node:l,...a}){return(0,n.jsx)(e,{className:r?`${t} ${r}`:t,...a,children:s})},ai={h1:aa("h1","text-xl sm:text-2xl font-bold border-b border-border-subtle pb-2 mt-5 mb-3 text-text first:mt-0"),h2:aa("h2","text-lg sm:text-xl font-bold border-b border-border-subtle pb-1.5 mt-4 mb-2.5 text-text first:mt-0"),h3:aa("h3","text-base sm:text-lg font-semibold mt-3.5 mb-2 text-text"),h4:aa("h4","text-sm sm:text-base font-semibold mt-3 mb-1.5 text-text"),h5:aa("h5","text-xs sm:text-sm font-semibold mt-2.5 mb-1 text-text"),h6:aa("h6","text-xs font-semibold mt-2 mb-1 text-text-muted"),p:aa("p","my-2 leading-relaxed text-text text-sm"),ul:aa("ul","list-disc pl-5 my-2 space-y-1 text-sm text-text"),ol:aa("ol","list-decimal pl-5 my-2 space-y-1 text-sm text-text"),li:aa("li","leading-relaxed"),blockquote:aa("blockquote","border-l-4 border-brand-500/40 pl-3.5 my-2.5 text-text-muted italic text-sm"),th:aa("th","border border-border-subtle bg-surface-2 px-3 py-1.5 font-semibold text-left text-text align-top whitespace-normal break-words"),td:aa("td","border border-border-subtle px-3 py-1.5 text-text align-top whitespace-normal break-words"),hr:aa("hr","border-t border-border-subtle my-4"),img:({alt:e="",node:t,...s})=>(0,n.jsx)("img",{className:"max-w-full h-auto rounded my-2",alt:e,...s}),a:({children:e,className:t,node:s,...r})=>(0,n.jsx)("a",{className:`text-brand-500 hover:underline wrap-anywhere${t?` ${t}`:""}`,target:"_blank",rel:"noopener noreferrer",...r,children:e}),table:({children:e,node:t,...s})=>(0,n.jsx)("table",{className:"w-full table-fixed border-collapse border border-border-subtle text-xs my-3",...s,children:e}),pre:function({children:e,node:t,...s}){let[l,a]=(0,r.useState)(!1),i=(0,r.useRef)(null);return(0,n.jsxs)("div",{className:"relative group/code my-2.5",children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)();let t=i.current?.innerText||"";try{navigator.clipboard.writeText(t)}catch{}a(!0),setTimeout(()=>a(!1),2e3)},className:"absolute top-2 right-2 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-100 sm:opacity-0 sm:group-hover/code:opacity-100 transition-opacity z-10",title:"Copy code",children:l?(0,n.jsx)(en.aJ,{size:13,className:"text-brand-500"}):(0,n.jsx)(en.QR,{size:13})}),(0,n.jsx)("pre",{ref:i,className:"p-3 rounded bg-surface-2 whitespace-pre-wrap break-words text-[12px] font-mono border border-border-subtle text-text [&_code]:bg-transparent [&_code]:p-0 [&_code]:border-0 [&_code]:text-text",...s,children:e})]})},code:({children:e,className:t,node:s,...r})=>{let l=/language-/.test(t||"");return(0,n.jsx)("code",{className:`${l?"font-mono text-[12px] text-text":"font-mono text-[0.9em] text-accent wrap-anywhere"}${t?` ${t}`:""}`,...r,children:e})},input:({type:e,checked:t,node:s,...r})=>"checkbox"===e?(0,n.jsx)("input",{type:"checkbox",checked:t,readOnly:!0,className:"mr-2 rounded accent-brand-500 cursor-default",...r}):(0,n.jsx)("input",{type:e,...r})},ao=(0,r.memo)(function({content:e,components:t}){return(0,n.jsx)(ar.oz,{remarkPlugins:[al.A],components:t?{...ai,...t}:ai,children:e})},(e,t)=>e.content===t.content);function ac({content:e}){let{t}=(0,ec.s)();return e?.trim()?(0,n.jsx)("div",{className:"h-full overflow-auto p-4 sm:p-6 bg-bg select-text",children:(0,n.jsx)("div",{className:"max-w-4xl mx-auto",children:(0,n.jsx)(ao,{content:e})})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:t("common.empty",{defaultValue:"Empty file"})})}function ad({kind:e,filePath:t,fileBus:s,content:r,reloadKey:l=0}){return"html"===e?(0,n.jsx)(ae,{filePath:t,fileBus:s,reloadKey:l}):"mermaid"===e?(0,n.jsx)(an,{content:r,reloadKey:l}):"markdown"===e?(0,n.jsx)(ac,{content:r}):null}var au=s(23910);s(14876);let ax=["diff --git","index ","new file","deleted file","--- ","+++ "];function am({diff:e,compact:t=!1,className:s=""}){let[l,a]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(t)return;let e=window.matchMedia(`(min-width: ${F.gh}px)`),s=()=>a(e.matches);return s(),e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[t]);let i=!t&&l,o=(0,r.useCallback)(t=>{if(t&&e&&i)try{new au.LU(t,e,{drawFileList:!1,matching:"words",outputFormat:"side-by-side",renderNothingWhenEmpty:!1}).draw()}catch{t.replaceChildren(Object.assign(document.createElement("pre"),{className:"text-text-muted p-4",textContent:e}))}},[e,i]),c=(0,r.useMemo)(()=>i||!e?[]:function(e){let t=[],s=0,n=0;for(let r of e.split("\n")){if(ax.some(e=>r.startsWith(e))){r.startsWith("diff --git")&&t.push({type:"file",text:r.replace("diff --git a/","").split(" b/")[0]});continue}if(r.startsWith("@@")){let e=r.match(/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);e&&(s=parseInt(e[1],10),n=parseInt(e[2],10)),t.push({type:"hunk",text:r});continue}r.startsWith("+")?t.push({type:"add",text:r.slice(1),newLn:n++}):r.startsWith("-")?t.push({type:"del",text:r.slice(1),oldLn:s++}):t.push({type:"ctx",text:r.slice(1),oldLn:s++,newLn:n++})}return t}(e),[i,e]);return i?(0,n.jsx)("div",{ref:o,className:`diff-themed ${t?"diff-themed-compact":"bg-surface rounded"} overflow-hidden text-sm ${s}`}):(0,n.jsx)("div",{className:`w-full max-w-full overflow-hidden font-mono leading-[1.6] ${t?"text-[10px] leading-[1.45]":"rounded-lg border border-border bg-surface text-[12.5px]"} ${s}`,children:c.map((e,t)=>{if("file"===e.type)return(0,n.jsx)("div",{className:"px-3 py-2 bg-surface-2 text-text font-semibold break-all",children:e.text},t);if("hunk"===e.type)return(0,n.jsx)("div",{className:"px-3 py-1 bg-surface-2/60 text-text-muted select-none break-all",children:e.text},t);let s="add"===e.type?e.newLn:"del"===e.type?e.oldLn:e.newLn,r="add"===e.type?"bg-[rgba(var(--success-rgb),0.14)]":"del"===e.type?"bg-[rgba(var(--danger-rgb),0.14)]":"",l="add"===e.type?"text-[var(--success)]":"del"===e.type?"text-[var(--danger)]":"text-text-subtle",a="add"===e.type?"+":"del"===e.type?"-":" ";return(0,n.jsxs)("div",{className:`flex ${r}`,children:[(0,n.jsx)("span",{className:"shrink-0 w-9 px-1 text-right text-text-subtle bg-black/5 select-none",children:s}),(0,n.jsx)("span",{className:`shrink-0 w-4 text-center font-bold ${l} select-none`,children:a}),(0,n.jsx)("span",{className:"flex-1 min-w-0 pr-2 whitespace-pre-wrap break-words text-text",children:e.text||"\xa0"})]},t)})})}function ap({title:e,badge:t,badgeColor:s,img:r,loading:l,error:a,t:i}){var o;let c,d,u=[(c=r?.originalWidth||r?.width,d=r?.originalHeight||r?.height,c&&d?`${c} \xd7 ${d}`:""),!(o=r?.size||r?.originalSize)?"":o<1024?`${o} B`:o<1048576?`${(o/1024).toFixed(1)} KB`:`${(o/1048576).toFixed(1)} MB`].filter(Boolean).join(" \xb7 ");return(0,n.jsxs)("div",{className:"flex-1 flex flex-col rounded-brand border border-border-subtle bg-surface overflow-hidden min-h-[220px]",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border-subtle flex items-center justify-between bg-surface-2/60 shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-text",children:e}),t&&(0,n.jsx)("span",{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded-[3px] ${s}`,children:t})]}),u&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted font-mono",children:u})]}),(0,n.jsx)("div",{className:"flex-1 p-3 flex items-center justify-center bg-surface-2/20 min-h-[160px] overflow-hidden relative",children:l?(0,n.jsxs)("div",{className:"flex items-center gap-2 text-text-muted text-xs",children:[(0,n.jsx)(en.kr,{size:16,className:"animate-spin"}),(0,n.jsx)("span",{children:i("common.loading")})]}):a?(0,n.jsx)("div",{className:"text-xs text-text-muted text-center px-4 py-6",children:a}):r?.dataUrl?(0,n.jsx)("img",{src:r.dataUrl,alt:e,className:"max-h-[320px] max-w-full object-contain rounded drop-shadow-sm select-none"}):(0,n.jsx)("div",{className:"text-xs text-text-muted",children:i("git.noChanges")})})]})}function af({filePath:e,status:t,workspace:s,fileBus:l,compact:a=!1}){let{t:i}=(0,ec.s)(),o="A"===t||"?"===t,c="D"===t,d=!o,u=!c,[x,m]=(0,r.useState)(null),[p,f]=(0,r.useState)(d),[h,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)(u),[j,k]=(0,r.useState)(""),[N,C]=(0,r.useState)(e);N!==e&&(C(e),m(null),f(d),b(""),v(null),w(u),k("")),(0,r.useEffect)(()=>{let t=!1;if(!e||!l)return;let n=s&&!e.startsWith("/")?`${s}/${e}`:e,r=s&&e.startsWith(s)?e.slice(s.length).replace(/^\//,""):e,a=setTimeout(()=>{d&&(f(!0),b(""),l.gitShowMedia?.(s,r,"HEAD").then(e=>{t||(f(!1),e?.success?m(e):b(e?.error||i("git.noOldVersion",{defaultValue:"No previous version in HEAD"})))}).catch(e=>{t||(f(!1),b(e?.message||"Failed to load old version"))})),u&&(w(!0),k(""),l.readMedia?.(n).then(e=>{t||(w(!1),e?.success?v(e):k(e?.error||i("git.noNewVersion",{defaultValue:"Failed to load working image"})))}).catch(e=>{t||(w(!1),k(e?.message||"Failed to load new version"))}))},0);return()=>{t=!0,clearTimeout(a)}},[e,s,l,d,u,i]);let S=e?e.split("/").pop():"",E=c||d&&!h&&(p||!!x?.dataUrl),R=E&&u;return(0,n.jsx)("div",{className:"h-full overflow-y-auto p-2 sm:p-3 flex flex-col gap-3",children:(0,n.jsxs)("div",{className:`flex-1 ${!a&&R?"grid grid-cols-1 md:grid-cols-2 gap-3":"flex flex-col gap-3"}`,children:[E&&(0,n.jsx)(ap,{title:c?`${S} (Deleted)`:"Old (HEAD)",badge:c?"DELETED":"ORIGINAL",badgeColor:"bg-red-500/15 text-red-400",img:x,loading:p,error:h,t:i}),u&&(0,n.jsx)(ap,{title:o?`${S} (Added)`:"New (Working Tree)",badge:o?"NEW":"MODIFIED",badgeColor:"bg-green-500/15 text-green-400",img:g,loading:y,error:j,t:i})]})})}function ah({diffPath:e,workspace:t,fileBus:s,compact:l=!1}){let{t:a}=(0,ec.s)(),{status:i,repoPath:o,filePath:c}=(0,F.qu)(e),d=o||t,u=(0,F.u)(c),[x,m]=(0,r.useState)(!u),[p,f]=(0,r.useState)(""),[h,b]=(0,r.useState)("");return((0,r.useEffect)(()=>{if(u)return;let e=!1,t=setTimeout(async()=>{m(!0),b("");let t=await s.gitDiff?.(d,c,i);e||(t?.success?f(t.diff||""):b(t?.error||""),m(!1))},0);return()=>{e=!0,clearTimeout(t)}},[d,c,i,s,u]),u)?(0,n.jsx)(af,{filePath:c,status:i,workspace:d,fileBus:s,compact:l}):(0,n.jsxs)("div",{className:`h-full overflow-auto ${l?"p-0":"p-2 sm:p-3"}`,children:[h&&(0,n.jsx)("div",{className:"bg-red-500/20 border border-red-500/50 rounded px-4 py-2 text-red-400 text-sm mb-3",children:h}),x?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted text-sm",children:a("common.loading")}):p?(0,n.jsx)(am,{diff:p,compact:l}):(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted text-sm",children:a("git.noChanges")})]})}function ab({filePath:e,workspace:t,fileBus:s,width:l,onResize:a,onClose:i,onOpenFull:o,onOpenFile:c,isDesktop:d=!0,previewSeq:u=0,artifactTitle:x=null}){let{t:m}=(0,ec.s)(),p=(0,F.pA)(e),f=p?(0,F.qu)(e):null,h=f?.repoPath||t,b=p?f.filePath:e,g=f?f.repoPath?`${f.repoPath.replace(/\/$/,"")}/${f.filePath}`:f.filePath.startsWith("/")?f.filePath:`${t?.replace(/\/$/,"")||""}/${f.filePath}`:"",v=!!e&&!p&&!lH(e),y=lU({filePath:v?e:"",fileBus:s}),w=(0,r.useRef)(y);(0,r.useEffect)(()=>{w.current=y},[y]);let j=lV({dirty:v&&y.dirty,onSave:y.save}),k=v?(0,F.YO)(e):null,N=u>0,[C,S]=(0,r.useState)(N),[E,R]=(0,r.useState)(0),[T,$]=(0,r.useState)(e),[M,z]=(0,r.useState)(!1),[P,I]=(0,r.useState)(u);(T!==e||P!==u)&&($(e),I(u),S(N)),y.justSaved!==M&&(z(y.justSaved),y.justSaved&&R(e=>e+1)),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&j.guard(i)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[j,i]);let A=e&&!p?e.slice(0,e.lastIndexOf("/")):"",L=(0,r.useMemo)(()=>A?[A]:[],[A]),D=rH(),B=(0,r.useCallback)(()=>{R(e=>e+1),w.current?.onChangedOnDisk()},[]);if(r_({dirs:L,fileBus:s,enabled:!!A&&D,debounceMs:F.Jl.PREVIEW_DEBOUNCE_MS,onDirsChanged:B}),!e)return null;let K=b.split("/").pop(),O=t&&b.startsWith(t)?b.slice(t.length).replace(/^\//,""):b;return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg border-l border-border-subtle relative shrink min-w-0",style:d?{width:l,flexBasis:l,minWidth:eV.Ao.min}:void 0,children:[(0,n.jsxs)("div",{style:{height:32},className:"px-2 flex items-center gap-1.5 border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:r6({name:K,type:"file"},14)}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-[12px] text-text",title:O,children:K}),x&&(0,n.jsx)("span",{className:"flex-shrink-0 px-1.5 py-px rounded-[3px] text-[9px] font-medium uppercase tracking-wide bg-brand-500/15 text-brand-500",children:m("editor.artifact")}),p&&(0,n.jsx)("span",{className:`text-[10px] font-bold flex-shrink-0 ${F.vs[f.status]||"text-text-muted"}`,children:f.status}),k&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),S(e=>!e)},title:m(C?"editor.editCode":"editor.preview"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:C?(0,n.jsx)(en.GD,{size:13}):(0,n.jsx)(en.kU,{size:13})}),v&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),y.save()},disabled:!y.dirty||y.saving,title:m("editor.save"),className:`p-1 rounded-[3px] transition-colors disabled:opacity-30 ${y.dirty?"text-brand-500 hover:bg-surface-2":"text-text-muted"}`,children:(0,n.jsx)(en.eM,{size:13})}),(p?!!c:o&&d)&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),p?c(g):o(e)},title:m(p?"git.openFile":"editor.openFull"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:p?(0,n.jsx)(en.GD,{size:13}):(0,n.jsx)(en.Gr,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),j.guard(i)},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:(0,n.jsx)(en.X,{size:13})})]}),y.error&&v&&(0,n.jsx)("div",{className:"px-3 py-1.5 text-[11px] text-red-500 bg-red-500/10 border-b border-border-subtle break-words",children:y.error}),y.staleOnDisk&&(0,n.jsxs)("div",{className:"px-3 py-1.5 flex items-center gap-2 text-[11px] text-amber-500 bg-amber-500/10 border-b border-border-subtle",children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:m("editor.changedOnDisk")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),y.reload()},className:"shrink-0 px-1.5 py-0.5 rounded-[3px] hover:bg-amber-500/20 font-medium transition-colors",children:m("editor.reloadFromDisk")})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:p?(0,n.jsx)(ah,{diffPath:(0,F.Dk)(f.status,f.filePath),workspace:h,fileBus:s,compact:!0}):lH(e)?(0,n.jsx)(lq,{filePath:e,fileBus:s}):C&&k?(0,n.jsx)(ad,{kind:k,filePath:e,fileBus:s,content:y.content,reloadKey:E}):y.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:m("common.loading")}):(0,n.jsx)(l9,{filePath:e,content:y.content,onTextChanged:y.onTextChanged,onRegisterView:y.register,onSave:y.save,compact:!0})}),(0,n.jsx)(lX,{isOpen:j.asking,fileName:K,onSave:j.saveThenLeave,onDiscard:j.discardAndLeave,onCancel:j.cancel}),d&&(0,n.jsx)("div",{onPointerDown:e=>eU(e,{startWidth:l,axis:-1,onWidth:e=>a?.(e)}),className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})]})}function ag(){let[e,t]=(0,r.useState)(null),s="mouse"!==tF();return((0,r.useEffect)(()=>{if(s)return;let e=null,n=null,r=()=>{clearTimeout(e),n=null,t(null)},l=s=>{let r=s.target?.closest?.("[data-tip]");if(r!==n){if(clearTimeout(e),n=r,!r)return t(null);e=setTimeout(()=>{let e;(e=r.getAttribute("data-tip"))&&function(e){let t=e.getBoundingClientRect();if(e.scrollHeight>e.clientHeight+eV.de.SLACK_PX)return!0;let s=document.createRange();s.selectNodeContents(e);let n=s.getBoundingClientRect().width;s.detach();let r=getComputedStyle(e),l=parseFloat(r.paddingLeft)+parseFloat(r.paddingRight);return n>t.width-l+eV.de.SLACK_PX}(r)&&t({text:e,...function(e){let{GAP_PX:t,EDGE_PX:s,MAX_WIDTH_PX:n,EST_HEIGHT_PX:r}=eV.de,l=e.bottom+t,a=l+r>window.innerHeight-s;return{left:Math.min(Math.max(e.left,s),Math.max(s,window.innerWidth-n-s)),top:a?void 0:l,bottom:a?window.innerHeight-e.top+t:void 0}}(r.getBoundingClientRect())})},"focusin"===s.type?0:eV.de.DELAY_MS)}},a=e=>{"Escape"===e.key&&r()};return document.addEventListener("mouseover",l,!0),document.addEventListener("focusin",l,!0),document.addEventListener("focusout",r,!0),document.documentElement.addEventListener("mouseleave",r),document.addEventListener("mousedown",r,!0),document.addEventListener("keydown",a,!0),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{clearTimeout(e),document.removeEventListener("mouseover",l,!0),document.removeEventListener("focusin",l,!0),document.removeEventListener("focusout",r,!0),document.documentElement.removeEventListener("mouseleave",r),document.removeEventListener("mousedown",r,!0),document.removeEventListener("keydown",a,!0),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[s]),e)?(0,sU.createPortal)((0,n.jsx)("div",{role:"tooltip",className:"fixed z-[90] pointer-events-none px-2 py-1 rounded-[3px] bg-surface-2 border border-border-subtle shadow-lg text-[11px] text-text break-words animate-in fade-in duration-100",style:{left:e.left,top:e.top,bottom:e.bottom,maxWidth:eV.de.MAX_WIDTH_PX},children:e.text}),document.body):null}let av=(0,r.memo)(function({height:e=1,className:t=""}){let s=(0,r.useRef)(null),[l,a]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=s.current;if(!e)return;let t=new ResizeObserver(([t])=>{let s=t?.contentRect?.width||e.offsetWidth;s>0&&a(Math.round(s))});return t.observe(e),()=>t.disconnect()},[]);let i=l||600,o=Math.max(1.8,(i+140)/250);return(0,n.jsx)("div",{ref:s,"aria-hidden":"true",className:`absolute inset-x-0 top-0 overflow-hidden pointer-events-none ${t}`,style:{height:e,"--pane-w":`${i}px`,"--beam-w":"140px","--beam-dur":`${o.toFixed(2)}s`,"--beam-delay":`${(o/2).toFixed(2)}s`},children:(0,n.jsxs)("div",{className:"relative w-full h-full bg-blue-500/10",children:[(0,n.jsx)("div",{className:"pane-light-beam"}),(0,n.jsx)("div",{className:"pane-light-beam pane-light-beam-2"})]})})}),ay=["newTerminal","palette","help"];function aw({onAddWorkspace:e,onOpenRemote:t,recent:s=[],homeDir:r,onOpenRecent:l}){let{t:a}=(0,ec.s)(),i=[...ay.map(e=>ts.find(t=>t.id===e)).filter(Boolean),tn];return(0,n.jsxs)("div",{className:"h-full w-full empty-stage empty-stage-h",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),e?.()},disabled:!e,className:"empty-half text-left transition-all duration-150 enabled:hover:opacity-90 enabled:active:scale-[0.99] disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",a("workspaces.emptyTagWorkspace")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordTerminal")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaWorkspace")}}),(0,n.jsxs)("span",{className:"empty-go",children:[a("workspaces.selectFolder"),(0,n.jsx)(en.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]}),!!s.length&&(0,n.jsx)("span",{className:"flex flex-wrap gap-1.5 mt-4 max-w-full",children:s.slice(0,4).map(e=>(0,n.jsx)("span",{role:"button",title:e.path,onClick:t=>{t.stopPropagation(),(0,eo.e)(),l?.(e.path)},className:"welcome-chip path-tail px-2 py-1 text-[11px] font-mono text-text-muted rounded-full truncate max-w-[180px]",children:sf(e.path,r)},e.path))})]}),!!t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"empty-hairline","aria-hidden":!0}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),t?.()},className:"empty-half text-left transition-all duration-150 enabled:hover:opacity-90 enabled:active:scale-[0.99] disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"02"})," / ",a("workspaces.emptyTagRemote")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordRemote")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaRemote")}}),(0,n.jsxs)("span",{className:"empty-go",children:[a("menu.remoteDesktop"),(0,n.jsx)(en.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]})]})]}),(0,n.jsx)("div",{className:"hidden lg:flex absolute bottom-0 inset-x-0 z-[2] flex-wrap items-center justify-center gap-x-5 gap-y-1.5 px-8 pb-6 font-mono text-[11px] text-text-subtle",children:i.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[a(`shortcuts.${e.id}`),(0,n.jsx)("kbd",{className:"px-1.5 py-0.5 rounded-[4px] bg-surface-2/60 text-text-muted whitespace-nowrap",children:to(e)})]},e.id))})]})}let aj=new Set(["Agent","Task","Workflow","task","browser_subagent","invoke_subagent","spawn_agent"]),ak=e=>e?.input?.subagent_type||e?.input?.agent||e?.input?.description||"agent",aN=e=>e?.input?.description||e?.input?.command||"shell";function aC(e=[],t=""){if(!t)return null;let s=null,n=e=>{for(let r of e||[]){if(r?.id===t)return s=r,!0;if(r?.children?.length&&n(r.children))return!0}return!1};for(let t=e.length-1;t>=0&&!s;t--)n(e[t]?.tools);return s}function aS(e=[],t=""){let s=aC(e,t);if(!s)return null;let n=s;for(;"running"===n.status;){let e=n.children||[],t=e.filter(e=>e?.status==="running").pop()||e[e.length-1];if(!t||t===n)break;n=t}return n}function aE(e){return(e||[]).map(e=>{let t=e.children?aE(e.children):null;return"running"!==e.status||e.async?t?{...e,children:t}:e:{...e,status:"done",...t?{children:t}:null}})}function aR(e,t,s){let n=!1,r=(e||[]).map(e=>{if(t(e))return n=!0,s(e);let r=aR(e.children,t,s);return r?(n=!0,{...e,children:r}):e});return n?r:null}var aT=s(91524);function a$(e,t="claude"){if(!e?.name)return"";let{name:s,input:n={}}=e,r=az(n.file_path||n.path);switch((0,aT.$Z)(t,s)){case"bash":return aI(n.description||n.command||"shell",aM);case"file":return aI(`${/^(list|list_dir|ls)$/i.test(s)?"Listing":"Reading"} ${r}`,aM);case"search":return aI([n.pattern?`"${n.pattern}"`:n.query||n.url||"",r?`in ${r}`:""].filter(Boolean).join(" "),aM);case"diff":return aI(`${/^(Write|write_to_file)$/i.test(s)?"Writing":"Editing"} ${az(n.file_path||n.filePath||n.file||n.path)||aL(n)}`,aM);case"agent":return aI(n.description||aL(n)||"sub-agent",aM);case"plan":return aI(az(n.path)||s,aM);default:return aI([aA(s),aL(n)].filter(Boolean).join(" "),aM)}}let aM=60,az=e=>"string"==typeof e&&e.replace(/\\/g,"/").split("/").filter(Boolean).pop()||"",aP=e=>{if("string"!=typeof e)return"";let t=e.slice(-512).split("\n");for(let e=t.length-1;e>=0;e--){let s=t[e].trim();if(s)return s}return""},aI=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,aA=(e="")=>{let t=/^mcp__[^_]+(?:_[^_]+)*__(.+)$/.exec(e);return t?t[1]:e},aL=(e={})=>e.url||e.query||e.pattern||e.name||az(e.path)||az(e.file_path)||"";function aD(e){let t=Number(e)||0,s=t>=1e6?[1e6,"M"]:t>=1e3?[1e3,"k"]:null;if(!s)return String(t);let n=t/s[0];return`${n>=100?Math.round(n):n.toFixed(1).replace(/\.0$/,"")}${s[1]}`}let aB=new Set(["Edit","Write","MultiEdit","NotebookEdit","edit","write","patch","apply","write_to_file","replace_file_content","multi_replace_file_content","sed_file","file_change"]),aF=e=>"string"==typeof e&&e?e.split("\n").length:0;function aK(e=[]){let t=0,s=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if("user"===r.role)break;let l=r.diffs||[];for(let e of l)for(let n of(e.patch||e.diff||"").split("\n"))n.startsWith("+")&&!n.startsWith("+++")?t++:n.startsWith("-")&&!n.startsWith("---")&&s++;let a=new Set(l.map(e=>e.file).filter(Boolean));for(let e of r.tools||[]){if(!aB.has(e?.name))continue;let n=e.input?.file_path||e.input?.path||e.input?.file||"";if(n&&a.has(n))continue;let r=function(e){let t=e.input;if(!t||"string"==typeof t)return null;let s=t.file_path||t.path||t.file||"",n=Array.isArray(t.edits)?t.edits:Array.isArray(t.replacement_chunks)?t.replacement_chunks:Array.isArray(t.replacements)?t.replacements:null;if(n){let e=0,t=0;for(let s of n)t+=aF(s.old_string??s.oldString??s.old??s.target_content),e+=aF(s.new_string??s.newString??s.new??s.replacement_content);return{file:s,added:e,removed:t}}if("string"==typeof t.content&&t.content)return{file:s,added:aF(t.content),removed:0};let r=t.old_string??t.oldString??t.old_str??t.target_content??t.TargetContent,l=t.new_string??t.newString??t.new_str??t.replacement_content??t.ReplacementContent;return void 0===r&&void 0===l?null:{file:s,added:aF(l),removed:aF(r)}}(e);r&&(t+=r.added,s+=r.removed)}}return{added:t,removed:s}}let aO=/^\s*<(task-notification|environment_context|turn_aborted|persisted-output)>/,aW=e=>aO.test(String(e||""));function a_(e){let t=String(e||"").trim();if(!t)return"";if(!t.startsWith("<persisted-output>"))return t;let s=/saved to: (\S+)/.exec(t);return s?`saved to: ${s[1]}`:""}let aH=new Set(["completed","failed","killed","stopped"]),aq=(e,t=Date.now())=>e?.usage?.duration_ms>0?e.usage.duration_ms:e?.endedAt&&e?.startedAt?Math.max(0,e.endedAt-e.startedAt):e?.startedAt?Math.max(0,t-e.startedAt):0,aU=(e,t)=>t?.startedAt?null:{startedAt:Date.now()-(Number.isFinite(e)?Math.max(0,e):0)},aV=(e=[])=>{for(let t=e.length-1;t>=0;t--)if(e[t]?.compacting)return t;return -1},aX=new Set(["compacting"]);function aG(e,t,s,n,r){if("system"!==t)return e;let l=Number.isFinite(r)?r:n?.ageMs;switch(s){case"task_started":if(!n?.task_id)return e;return aJ(e,n.task_id,{taskId:n.task_id,status:"running",background:!!n.is_backgrounded,...n.tool_use_id?{toolUseId:n.tool_use_id}:null,...n.description?{description:n.description}:null,...n.subagent_type?{subagentType:n.subagent_type}:null,...n.task_type?{taskType:n.task_type}:null,...aU(l,e.find(e=>e.taskId===n.task_id))});case"task_updated":{let t=e.findIndex(e=>e.taskId===n?.task_id);if(-1===t)return e;let s=n.patch||{},r=e.slice(),a=s.status&&!aH.has(s.status),i={...r[t],...s.status?{status:s.status}:null,...s.description?{description:s.description}:null,...s.end_time?{endedAt:s.end_time}:null};return a&&delete i.endedAt,a&&r[t].endedAt&&Object.assign(i,aU(l,null)),r[t]=i,r}case"task_notification":{let t=e.findIndex(e=>e.taskId===n?.task_id);if(-1===t)return e;let s=e.slice();return s[t]={...s[t],status:n.status||"completed",endedAt:s[t].endedAt||Date.now(),...n.output_file?{outputFile:n.output_file}:null,...n.summary?{summary:n.summary}:null,...n.usage?{usage:n.usage}:null},s}case"background_tasks_changed":{let t=new Set((n?.tasks||[]).map(e=>e.task_id)),s=e;for(let e of(s.some(e=>e.background&&!aH.has(e.status)&&!t.has(e.taskId))&&(s=s.map(e=>!e.background||aH.has(e.status)||t.has(e.taskId)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()})),n?.tasks||[]))s=aJ(s,e.task_id,{background:!0,status:"running",...e.description?{description:e.description}:null,...e.task_type?{taskType:e.task_type}:null,...aU(l,s.find(t=>t.taskId===e.task_id))});return s}default:return e}}function aJ(e,t,s){let n=e.findIndex(e=>e.taskId===t);if(-1===n)return[...e,{taskId:t,toolUseId:"",...s}];let r={...e[n],...s};if(aY(r,e[n]))return e;let l=e.slice();return l[n]=r,l}let aY=(e,t)=>{let s=Object.keys(e);return s.length===Object.keys(t).length&&s.every(s=>e[s]===t[s])};function aZ(e,t){let s=[];for(let t of e||[])t&&(s=aG(s,t.type||"system",t.subtype||"",t.record||null,t.ageMs));let n=new Map(s.map(e=>[e.taskId,e]));for(let e of t||[])e?.taskId&&n.set(e.taskId,{...n.get(e.taskId),...e});return[...n.values()]}function aQ(e,t){if(!t)return null;if(e.startsWith("session.next."))return"session.next.retried"===e?{subtype:e,level:"warning",content:`Retrying (attempt ${t.attempt??"?"}): ${t.error?.message||""}`.trim()}:"session.next.compaction.started"===e?{subtype:e,level:"info",content:"Compacting…",compacting:!0}:"session.next.compaction.ended"===e?{subtype:e,level:"info",content:"Compacted",compactSettled:!0}:"session.next.revert.staged"===e?{subtype:e,level:"info",content:"Rewind staged"}:"session.next.revert.committed"===e?{subtype:e,level:"info",content:"Rewound the conversation"}:"session.next.agent.switched"===e?{subtype:e,level:"info",content:`Agent: ${t.agent||""}`}:null;if("warning"===e||"guardianWarning"===e||"configWarning"===e||"deprecationNotice"===e)return null;let s="error"===e?String(t.error?.message||"").trim():"warning"===e||"guardianWarning"===e?String(t.message||"").trim():"configWarning"===e||"deprecationNotice"===e?[t.summary,t.details].filter(Boolean).join(" — ").trim():"model/rerouted"===e?`Model rerouted: ${t.fromModel} → ${t.toModel}`:"";if(s){let n="error"!==e||t.willRetry?"warning":"error";return{subtype:e,level:n,content:s}}if("thread/compacted"===e)return{subtype:e,level:"info",content:"Compacted",compactSettled:!0};if("system"===e&&"compact_boundary"===t.subtype){let e=function(e){let t=e.compact_metadata||e.compactMetadata;if(!t||"object"!=typeof t)return null;let s=e=>Number.isFinite(e)?e:null,n=s(t.pre_tokens??t.preTokens),r=s(t.post_tokens??t.postTokens),l=null!=n&&null!=r?`${aD(n)} → ${aD(r)} tokens`:"";return{trigger:t.trigger||"auto",preTokens:n,postTokens:r,durationMs:s(t.duration_ms??t.durationMs),...l?{detail:l}:null}}(t),s="string"==typeof t.content?t.content.trim():"";return e||s?{subtype:"compact_boundary",level:t.level||"info",content:s||"Compacted",compactSettled:!0,...e?{compact:e}:null}:null}if("system"===e&&"status"===t.subtype){if(aX.has(t.status))return{subtype:"status",level:"info",content:"Compacting…",compacting:!0};if(null!=t.status&&!t.compact_result)return null;let e="failed"===t.compact_result;return{subtype:"status",level:e?"error":"info",content:e?String(t.compact_error||"").trim()||"Compaction failed":"",compactSettled:!0}}if("attachment"===e){let e=t.attachment||t,s=e.type||"";if("edited_text_file"===s)return null;if("hook_success"===s){if("SessionStart"!==e.hookEvent)return null;let t=a_(e.content);return t?{subtype:s,level:"info",content:t}:null}let n="queued_command"===s?e.prompt:"";if("string"!=typeof n||!n.trim()||aW(n))return null;let r=a_(n);return r?{subtype:s,level:"info",content:r}:null}if("system"!==e||aW(t.content))return null;let n="string"==typeof t.content&&t.content.trim()?t.content.trim():"string"==typeof t.error?.formatted&&t.error.formatted.trim()?t.error.formatted.trim():"string"==typeof t.error?.message&&t.error.message.trim()?t.error.message.trim():"";return n?{subtype:t.subtype||"",level:t.level||"info",content:n}:null}function a0(e=[],t){if(!t)return e||[];if(t.replaceAll)return t.todos||[];let s=e||[],n=t.taskId?String(t.taskId):"",r=t.id?String(t.id):"",l=s.findIndex(e=>n&&String(e.taskId)===n||r&&e.id&&String(e.id)===r);if("deleted"===t.status)return -1===l?s:[...s.slice(0,l),...s.slice(l+1)];if(-1===l)return t.subject?[...s,t]:s;let a=s.slice();return a[l]={...a[l],...t},a}let a1=(0,tg.KU)(()=>window.localStorage),a2=null,a5=a1&&{...a1,setItem:(e,t)=>{t!==a2&&(a2=t,a1.setItem(e,t))}},a3=0,a4=e=>`${e}-${Date.now()}-${++a3}`,a6={messages:[],isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null,gateError:!1,activeBlocked:null,permissionMode:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0},metadata:{model:"",skills:[],mcpServers:[]},tasks:[],harnessTasks:[],queue:[]},a8=(e,t)=>({...a6,...e.bySession[t]});function a9(e,t){if(!t?.length)return null;let s=e.filter(e=>e.toolUseId&&aH.has(e.status));if(!s.length)return null;let n=t;for(let e of s){let t="failed"===e.status?"error":"done",s=n.map(s=>{if(!s.tools)return s;let n=aR(s.tools,t=>t.id===e.toolUseId&&"running"===t.status,e=>({...e,status:t}));return n?{...s,tools:n}:s});s.some((e,t)=>e!==n[t])&&(n=s)}return n===t?null:n}let a7=(0,b.v)((0,tg.Zr)((e,t)=>({bySession:{},initSession:s=>{s&&!t().bySession[s]&&e(e=>({bySession:{...e.bySession,[s]:{...a6}}}))},setTaskRecords:(t,s)=>{t&&Array.isArray(s)&&e(e=>{let n=a8(e,t),r=aZ(s,[]),l=a9(r,n.messages);return r!==n.harnessTasks||l?{bySession:{...e.bySession,[t]:{...n,harnessTasks:r,...l?{messages:l}:null}}}:e})},applyTaskRecords:(t,s)=>{t&&s?.length&&e(e=>{let n=a8(e,t),r=n.harnessTasks||[],l=r;for(let[e,t,n,r]of s)l=aG(l,e,t,n,r);let a=a9(l,n.messages);return l!==r||a?{bySession:{...e.bySession,[t]:{...n,harnessTasks:l,...a?{messages:a}:null}}}:e})},addNotice:(t,s)=>{let n="string"==typeof s?.content?s.content.trim():"";!t||(n||s?.compactSettled)&&e(e=>{let r=a8(e,t);if(s?.compacting&&-1!==aV(r.messages))return e;if(-1!==(s?.compactSettled?aV(r.messages):-1)){let l=r.messages.findIndex(e=>e?.compacting),a=r.messages.filter(e=>!e?.compacting);return n&&a.splice(l,0,{id:a4("n"),role:"notice",subtype:s.subtype||"",level:s.level||"info",content:n,...s.compact?{compact:s.compact}:null}),{bySession:{...e.bySession,[t]:{...r,messages:a}}}}if(!n)return e;let l={id:a4("n"),role:"notice",subtype:s.subtype||"",level:s.level||"info",content:n,...s.file?{file:s.file}:null,...s.compact?{compact:s.compact}:null,...s.compacting?{compacting:!0}:null},a=r.messages[r.messages.length-1],i=!a||"assistant"!==a.role||a.content||a.thinking||(a.tools||[]).length?[...r.messages,l]:[...r.messages.slice(0,-1),l];return{bySession:{...e.bySession,[t]:{...r,messages:i}}}})},setPermissionMode:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,permissionMode:s}}}})},setTurnRunning:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,isTurnRunning:s}}}})},setQueue:(t,s)=>{t&&e(e=>{let n=a8(e,t),r=Array.isArray(s)?s:[];return{bySession:{...e.bySession,[t]:{...n,queue:r}}}})},setMetadata:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,metadata:{...n.metadata,...s}}}}})},setStats:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,stats:{...n.stats,...s}}}}})},addUserMessage:(t,s,n=null,r=!1)=>{e(e=>{let l=a8(e,t),a={id:a4("u"),role:"user",content:s,attachments:n||[]},i={id:a4("a"),role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0};return{bySession:{...e.bySession,[t]:{...l,...r?null:{isTurnRunning:!0,turnStartedAt:Date.now(),lastTurnMs:0,turnBaseline:{inputTokens:l.stats.inputTokens||0,outputTokens:l.stats.outputTokens||0},activeBlocked:null},messages:[...l.messages,a,i]}}}})},appendDelta:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages],l=r[r.length-1];return l&&"assistant"===l.role&&l.isLive?r[r.length-1]={...l,content:(l.content||"")+(s||"")}:r.push({id:a4("msg"),role:"assistant",content:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendThinking:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages],l=r[r.length-1];return l&&"assistant"===l.role&&l.isLive?r[r.length-1]={...l,thinking:(l.thinking||"")+(s||"")}:r.push({id:a4("msg"),role:"assistant",content:"",thinking:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendStream:(t,s,n)=>{e(e=>{let r=a8(e,t),l=[...r.messages],a=l[l.length-1];return a&&"assistant"===a.role&&a.isLive?l[l.length-1]={...a,...s?{content:(a.content||"")+s}:null,...n?{thinking:(a.thinking||"")+n}:null}:l.push({id:a4("msg"),role:"assistant",content:s||"",thinking:n||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...r,messages:l}}}})},appendDiff:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages],l=r[r.length-1];l&&"assistant"===l.role?(l={...l},r[r.length-1]=l):(l={id:a4("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},r.push(l));let a=[...l.diffs||[]],i=a.findIndex(e=>e.file===s.file);return -1!==i?a[i]=s:a.push(s),l.diffs=a,{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendTool:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages],l=r[r.length-1];if(l&&"assistant"===l.role&&l.isLive&&(l.content||l.thinking||"").length>0)r[r.length-1]={...l,isLive:!1},r.push({id:a4("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...s,status:s.status||"running"}]});else if(l&&"assistant"===l.role){let e=[...l.tools||[]],t=e.findIndex(e=>e.id===s.id);-1!==t?e[t]={...e[t],...s}:e.push({...s,status:s.status||"running"}),r[r.length-1]={...l,tools:e}}else r.push({id:a4("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...s,status:s.status||"running"}]});return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},updateToolResult:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e];if(!t?.tools)continue;let n=t.tools.findIndex(e=>e.id===s.id);if(-1!==n){let l=[...t.tools];l[n]={...l[n],...s,status:s.status||"done"},r[e]={...t,tools:l};break}}return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},nestTool:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e],n=aR(t?.tools,e=>e.id===s.parentToolUseId,e=>{let t=[...e.children||[]],n=t.findIndex(e=>e.id===s.id);return -1!==n?t[n]={...t[n],...s}:t.push({...s,status:s.status||"running"}),{...e,children:t}});if(n){r[e]={...t,tools:n};break}}return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},nestToolResult:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e],n=aR(t?.tools,e=>(e.children||[]).some(e=>e.id===s.id),e=>({...e,children:e.children.map(e=>e.id===s.id?{...e,...s,status:s.status||"done"}:e)}));if(n){r[e]={...t,tools:n};break}}return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},setPermission:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,activePermission:s,gateError:!1}}}})},clearPermission:t=>{e(e=>{let s=a8(e,t);return{bySession:{...e.bySession,[t]:{...s,activePermission:null}}}})},setBlocked:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,activeBlocked:s}}}})},clearBlocked:t=>{e(e=>{let s=a8(e,t);return{bySession:{...e.bySession,[t]:{...s,activeBlocked:null}}}})},setGateError:(t,s,n=!0)=>{e(e=>{let r=a8(e,t);return r.activePermission?.requestId!==s?e:{bySession:{...e.bySession,[t]:{...r,gateError:n}}}})},finishTurn:(t,s,n=0,r=!1)=>{e(e=>{let l=a8(e,t),a=l.messages.map((e,t)=>({...e,...t===l.messages.length-1?{isLive:!1}:null,...e.tools?{tools:aE(e.tools)}:null}));return{bySession:{...e.bySession,[t]:{...l,...r?{activePermission:null}:{isTurnRunning:!1,lastTurnMs:n||(l.turnStartedAt?Date.now()-l.turnStartedAt:l.lastTurnMs),activePermission:null,stats:s?{...l.stats,...s}:l.stats},messages:a}}}})},clearMessages:t=>{e(e=>{let s=a8(e,t);return{bySession:{...e.bySession,[t]:{...s,messages:[],tasks:[],turnStartedAt:0,lastTurnMs:0,activePermission:null,activeBlocked:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0}}}}})},rewindToMessage:(t,s,n)=>{e(e=>{let r=a8(e,t),l=r.messages.findIndex(e=>e.id===s);if(-1===l)return e;let a=r.messages.slice(0,l+1);return n&&(a[l]={...a[l],content:n}),{bySession:{...e.bySession,[t]:{...r,messages:a,isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null}}}})},upsertTask:(t,s)=>{e(e=>{let n=a8(e,t),r=a0(n.tasks,s);return r===n.tasks?e:{bySession:{...e.bySession,[t]:{...n,tasks:r}}}})},hydrateSession:(t,{messages:s=[],tasks:n=[],isTurnRunning:r=!1,metadata:l={},stats:a=null,permissionMode:i=null,activeBlocked:o=null,elapsedMs:c=0,lastTurnMs:d=0,harnessTasks:u=null,queue:x=null})=>{e(e=>{let m=a8(e,t),p=u?a9(u,s):null;return{bySession:{...e.bySession,[t]:{...m,activePermission:null,messages:p||s,tasks:n,isTurnRunning:r,...Array.isArray(x)?{queue:x}:{},turnStartedAt:r?Date.now()-(c||0):0,lastTurnMs:r?0:d||0,turnBaseline:r?{inputTokens:0,outputTokens:0}:{inputTokens:a?.inputTokens||0,outputTokens:a?.outputTokens||0},metadata:{...m.metadata,...l},stats:a?{...m.stats,...a}:m.stats,activeBlocked:o,...i?{permissionMode:i}:{},...u?{harnessTasks:u}:{}}}}})},prependMessages:(t,s)=>{s?.length&&e(e=>{let n=a8(e,t),r=a9(n.harnessTasks||[],s)||s,l=new Set(n.messages.map(e=>e.id)),a=r.map(e=>l.has(e.id)?{...e,id:a4(e.id.split("-")[0])}:(l.add(e.id),e));return{bySession:{...e.bySession,[t]:{...n,messages:[...a,...n.messages]}}}})},restoreTurnState:(t,s={})=>{if(void 0===s.isTurnRunning)return;let{isTurnRunning:n,lastTurnMs:r=0,elapsedMs:l=0}=s;(n||r)&&e(e=>{let s=a8(e,t);return{bySession:{...e.bySession,[t]:{...s,isTurnRunning:n,lastTurnMs:r,turnStartedAt:n?Date.now()-(l||0):0}}}})},removeSession:t=>{e(e=>{let{[t]:s,...n}=e.bySession;return{bySession:n}})}}),{name:"9remote-ai-store",storage:a5,partialize:e=>({bySession:Object.fromEntries(Object.entries(e?.bySession||{}).map(([e,t])=>[e,{permissionMode:t?.permissionMode??null,metadata:{model:t?.metadata?.model||"",effort:t?.metadata?.effort||""}}]))})}));function ie(e){if(!e)return 0;let t=(e.content?.length||0)+(e.thinking?.length||0);if(Array.isArray(e.tools))for(let s of e.tools)t+=(s.command?.length||0)+(s.output?.length||0)+120;if(Array.isArray(e.diffs))for(let s of e.diffs)t+=(s.diff?.length||0)+(s.file?.length||0)+80;return Math.max(t,100)}function it(e,t,s,n=2){if(!Array.isArray(e)||0===e.length)return 0;let r=Math.min(s??e.length,e.length),l=0,a=0;for(let s=r-1;s>=0&&(l+=ie(e[s]),a++,!(l>=t)||!(a>=n));s--);return r-a}async function is({startSeq:e,fetchChunk:t,reduceChunk:s,maxChunks:n=8,pageBudget:r=131072,estimateBytes:l=()=>0}){let a=e,i=[],o=0,c=!0,d=0,u=!1;for(;d<n;){let e=await t(a);if(d++,null==e)break;if(!e.success||!e.events?.length){c=!1;break}u=!0;let n=s(e.events,i.length);if(i=[...n,...i],o+=n.reduce((e,t)=>e+l(t),0),a=e.events[0].seq,!(c=!!e.hasMore)||o>=r)break}return{messages:i,before:a,hasMore:c,answered:u,chunks:d}}let ir=[1200,3e3,6e3],il=e=>Array.isArray(e)?e.map(e=>"string"==typeof e?{id:e,name:e,description:""}:e):[];function ia(e,t){let s=String(t||"").trim();if(!s)return!1;let n=e[e.length-1];return!!(n&&"assistant"===n.role&&String(n.content||"").trim().endsWith(s))}let ii=e=>e?.text?`Not sent — ${e.reason||"the turn is still running"}: ${e.text}`:e?.reason||"Not sent";function io(e=[],t="claude",s=0){let n=[],r=[],l=[],a={model:"",skills:[],mcpServers:[]},i={inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},o=!1,c=null,d=null,u=null,x=!1,m=s;for(let s of e){let e=s?.event,p=s?.data;if(e)switch(e){case"user_message":o=!0,d=null,n.push({id:`u-${++m}`,role:"user",content:p?.text||"",attachments:p?.attachments||[]}),n.push({id:`a-${++m}`,role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0});break;case"init":{let e=il(p?.skills),t=e.length>0?e:a.skills,{model:s,...n}=p||{};a={...a,...n,skills:t,...s?{model:s}:{}};break}case"goal":a={...a,goal:p?.goal||null};break;case"delta":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++m}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.content=(e.content||"")+(p?.text||"");break}case"thinking":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++m}`,role:"assistant",content:"",thinking:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.thinking=(e.thinking||"")+(p?.text||"");break}case"diff":{if(!p)break;let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++m}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e));let t=e.diffs||(e.diffs=[]),s=t.findIndex(e=>e.file===p.file);-1!==s?t[s]=p:t.push(p);break}case"tool_child":if(!p)break;for(let e=n.length-1;e>=0;e--){let t=aR(n[e]?.tools,e=>e.id===p.parentToolUseId,e=>{let t=[...e.children||[]],s=t.findIndex(e=>e.id===p.id);return -1!==s?t[s]={...t[s],...p}:t.push({...p,status:p.status||"running"}),{...e,children:t}});if(t){n[e].tools=t;break}}break;case"tool_result_child":if(!p?.id)break;for(let e=n.length-1;e>=0;e--){let t=aR(n[e]?.tools,e=>(e.children||[]).some(e=>e.id===p.id),e=>({...e,children:e.children.map(e=>e.id===p.id?{...e,...p,status:p.status||"done"}:e)}));if(t){n[e].tools=t;break}}break;case"tool_start":{if(!p)break;let e=n[n.length-1];if(e&&"assistant"===e.role&&e.isLive&&(e.content||e.thinking||"").length>0)e.isLive=!1,e={id:`msg-${++m}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...p,status:p.status||"running"}]},n.push(e);else if(e&&"assistant"===e.role){let t=e.tools||(e.tools=[]),s=t.findIndex(e=>e.id===p.id);-1!==s?t[s]={...t[s],...p}:t.push({...p,status:p.status||"running"})}else e={id:`msg-${++m}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...p,status:p.status||"running"}]},n.push(e);if(p.name){let e=(0,aT.Zm)(t,p.name,p.input,p.id,r);e&&(r=a0(r,e))}break}case"tool_result":{if(!p?.id)break;for(let e=n.length-1;e>=0;e--){let t=n[e],s=t?.tools?.find(e=>e.id===p.id);if(s){Object.assign(s,p,{status:p.status||"done"});break}}let e=(0,aT.in)(t,p.name||"",p.output||"",p.id);e&&(r=a0(r,e));break}case"permission_request":c=p;break;case"permission_resolved":c=null;break;case"blocked":d=p;break;case"options_changed":p?.permissionMode&&(u=p.permissionMode),p?.model&&(a.model=p.model),p?.effort&&(a.effort=p.effort);break;case"turn_complete":x=!0,o=!1,c=null,p?.stats&&(i={...i,...p.stats}),n.length>0&&(n[n.length-1].isLive=!1),p?.isError&&!ia(n,p.result)&&n.push({id:`n-${++m}`,role:"notice",subtype:p.subtype||"",level:"error",content:p.result||"The turn ended in an error."});break;case"stats":p?.stats&&(i={...i,...p.stats});break;case"stopped":x=!0,o=!1,c=null;break;case"stall":for(let e of(x=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);break;case"exit":for(let e of(x=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);(p?.error||p?.code!=null&&0!==p.code)&&n.push({id:`n-${++m}`,role:"notice",subtype:"exit",level:"error",content:p.error||`The AI process exited (code ${p.code}).`});break;case"error":for(let e of(x=!0,o=!1,n))e.isLive&&(e.isLive=!1);n.push({id:`n-${++m}`,role:"notice",subtype:"error",level:"error",content:p?.message||"AI process failed"});break;case"prompt_refused":n.push({id:`n-${++m}`,role:"notice",subtype:"prompt_refused",level:"error",content:ii(p)});break;case"conversation_reset":n.length=0,r.length=0,l.length=0,o=!1,c=null,d=null;break;case"cli_event":{let e=p?.type||"",t=p?.record||null;l.push([e,p?.subtype||"",t,p?.ageMs]);let s=aQ(e,t);if(!s)break;let{compactSettled:r,...a}=s,i=r?aV(n):-1;if(-1!==i){a.content?.trim()?n[i]={id:`n-${++m}`,role:"notice",...a}:n.splice(i,1);break}if(!a.content?.trim())break;let o=n[n.length-1];!o||"assistant"!==o.role||o.content||o.thinking||(o.tools||[]).length||n.pop(),n.push({id:`n-${++m}`,role:"notice",...a})}}}if(x)for(let e of n)e.tools&&(e.tools=aE(e.tools));let p=[];for(let[e,t,s]of l)p=aG(p,e,t,s);return{messages:n,tasks:r,metadata:a,stats:i,isTurnRunning:o,activePermission:c,activeBlocked:d,permissionMode:u,harnessRecords:l,harnessTasks:p}}let ic=(0,r.memo)(function({message:e,engine:t="claude",workspacePath:s="",onResolvePermission:l,onRewind:a,onPreviewRewind:i,onCutLocal:o,rewindIndex:c=null,canRewind:d=!1}){let[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),[f,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(null);(0,h.B)(e=>e.openEditorFile);let{id:N,role:C,content:S,thinking:E,diffs:R=[],tools:T=[],permission:$=null,isLive:M=!1,attachments:z=[]}=e;if("user"===C){let e=async e=>{w(!0),k("preview");let t=await i?.(null,{index:c});(w(!1),k(null),t?.ok)?v({files:t.files||[],text:e}):v({error:t?.error||"The host could not preview this rewind.",text:e})},t=async()=>{let e=g?.text;v(null),w(!0),k("apply"),o?.(N,e);let t=await a?.(null,e,{index:c});(w(!1),k(null),t&&!t.ok)?v({error:t.error||"The rewind did not go through.",text:e}):p(!1)},s=(0,n.jsx)(ei.A,{isOpen:!!g,onClose:()=>v(null),onConfirm:g?.error?()=>v(null):t,title:g?.error?"Cannot rewind":"Rewind to this prompt?",message:g?.error?g.error:["This discards every turn after this prompt and re-sends your edited text.",g?.files?.length?`These ${g.files.length} file${1===g.files.length?"":"s"} go back to how they were:`:"No file changes to restore — this rewinds the conversation only.",...g?.files?.slice(0,8).map(e=>`\xb7 ${e.file}${e.status?` (${e.status})`:""}`)||[],g?.files?.length>8?`… and ${g.files.length-8} more`:"","Edits made by hand, or by shell commands, are NOT restored."].filter(Boolean).join("\n"),confirmText:g?.error?"OK":"Rewind"});if(m)return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex justify-end my-3",children:(0,n.jsxs)("div",{className:"max-w-[85%] sm:max-w-[75%] w-full",children:[(0,n.jsx)("textarea",{value:f,onChange:e=>b(e.target.value),onBlur:()=>{y||g||p(!1)},onKeyDown:t=>{if("Enter"===t.key&&!t.shiftKey){if(t.nativeEvent.isComposing||229===t.keyCode||(t.preventDefault(),y||g))return;f.trim()&&e(f.trim())}"Escape"===t.key&&p(!1)},rows:Math.min(10,f.split("\n").length+1),className:"w-full resize-none overflow-hidden rounded-brand-lg bg-surface-2 px-4 py-2.5 text-sm text-text focus:outline-none focus:ring-1 focus:ring-brand-500 leading-relaxed",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex justify-end items-center gap-1.5 mt-1.5 text-[11px] text-text-muted",children:[y&&(0,n.jsx)(en.kr,{size:11,className:"animate-spin"}),(0,n.jsx)("span",{children:"apply"===j?"Rewinding...":"preview"===j?"Checking what this would change...":"Enter to rewind, Esc to cancel"})]})]})}),s]});let r=d&&!!a,l=()=>{(0,eo.e)(),b(S||""),p(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"group/msg flex flex-col items-end my-3",children:[(0,n.jsxs)("div",{className:"max-w-[85%] sm:max-w-[75%] flex flex-col items-end gap-1.5",children:[z.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap justify-end gap-1.5",children:z.map((e,t)=>(0,n.jsxs)("span",{className:`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] ${e.isImage?"border-brand-500/40 bg-brand-500/10 text-brand-500":"border-border-subtle bg-surface-2 text-text-muted"}`,children:[e.isImage?(0,n.jsx)(en._V,{size:10}):(0,n.jsx)(en.xv,{size:10}),(0,n.jsx)("span",{className:"max-w-[160px] truncate",children:e.filename})]},`${e.filename}-${t}`))}),S&&(0,n.jsx)("div",{onClick:r?e=>{let t=window.getSelection();t&&!t.isCollapsed&&t.containsNode(e.currentTarget,!0)||l()}:void 0,className:`px-4 py-2.5 rounded-brand-lg bg-brand-500/15 border border-brand-500/25 text-text text-sm whitespace-pre-wrap wrap-anywhere ${r?"cursor-pointer":""}`,children:S})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),S&&(navigator.clipboard.writeText(S),x(!0),setTimeout(()=>x(!1),2e3))},className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors",title:"Copy this prompt",children:u?(0,n.jsx)(en.aJ,{size:11,className:"text-success"}):(0,n.jsx)(en.QR,{size:11})}),r&&(0,n.jsx)("button",{type:"button",disabled:y,onClick:l,className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors disabled:opacity-40",title:"Edit & rewind to here",children:y&&"preview"===j?(0,n.jsx)(en.kr,{size:11,className:"animate-spin"}):(0,n.jsx)(en.gH,{size:11})})]})]}),s]})}return null},(e,t)=>e.message===t.message&&e.onResolvePermission===t.onResolvePermission&&e.rewindIndex===t.rewindIndex||!e.message.isLive&&!t.message.isLive&&e.message.id===t.message.id&&e.message.content===t.message.content&&e.message.thinking===t.message.thinking&&e.message.permission===t.message.permission&&e.message.tools===t.message.tools&&e.message.diffs===t.message.diffs&&e.canRewind===t.canRewind&&e.rewindIndex===t.rewindIndex&&e.onResolvePermission===t.onResolvePermission);function id(e,t){if("string"!=typeof e||!e)return{dir:"",name:""};let s=e.replace(/\\/g,"/"),n=t?t.replace(/\\/g,"/").replace(/\/+$/,""):"",r=!!n&&s.startsWith(`${n}/`),l=r?5:4,a=(r?s.slice(n.length+1):s).split("/").filter(Boolean);a.length>l&&(a=["…",...a.slice(-l)]);let i=a.pop()||"";return{dir:a.join("/"),name:i}}let iu={file:en.kU},ix=(0,r.memo)(function e({id:t="",name:s="tool",command:l="",input:a=null,output:i="",error:o="",status:c="done",children:d=[],engine:u="claude",workspacePath:x="",deferred:m=!1}){let p=!!(o||"error"===c),[f,b]=(0,r.useState)(p&&!m),[g,v]=(0,r.useState)(!1),y=(0,h.B)(e=>e.openEditorFile);(0,r.useEffect)(()=>{p&&!m&&b(!0)},[p,m]);let w=!!l||"string"!=typeof a&&!!a?.command,j="string"==typeof a?"":a?.file_path||a?.notebook_path||a?.path||a?.file||"",k=l||j||("string"==typeof a?a:a?.command||a?.pattern||a?.query||""),N=!w&&j&&k===j?function(e,t){let{dir:s,name:n}=id(e,t);return s?`${s}/${n}`:n}(k,x):k,C=a?.file_path||a?.path||a?.file||"",S=iu[(0,aT.$Z)(u,s)]||en.Jl;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>b(!f),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:"running"===c?(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-accent"}):p?(0,n.jsx)(en.RI,{size:13,className:"text-danger"}):(0,n.jsx)(S,{size:13,className:"text-success"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1 font-mono text-[11px] leading-relaxed line-clamp-2",children:[(0,n.jsx)("span",{className:"text-[10px] font-semibold text-text uppercase tracking-wider break-all px-1 py-0.5 rounded bg-surface-2/80 [box-decoration-break:clone]",title:s,children:s}),N&&(0,n.jsxs)(n.Fragment,{children:[" ",(0,n.jsx)("span",{className:"text-text-muted break-all",title:N,children:N})]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 self-center",children:f?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0 ml-2 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:[C&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)(),C&&y(C)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1",title:"Open file in editor",children:(0,n.jsx)(en.Gr,{size:11})}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)();let t=i||o||N;t&&(navigator.clipboard.writeText("string"==typeof t?t:JSON.stringify(t,null,2)),v(!0),setTimeout(()=>v(!1),2e3))},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors",title:"Copy output",children:g?(0,n.jsx)(en.aJ,{size:11,className:"text-success"}):(0,n.jsx)(en.QR,{size:11})})]})]}),f&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text",children:[o&&(0,n.jsx)("div",{className:"text-danger mb-1.5 whitespace-pre-wrap",children:o}),i?(0,n.jsx)("div",{className:"text-text whitespace-pre-wrap leading-relaxed",children:"string"==typeof i?i:JSON.stringify(i,null,2)}):o?null:(0,n.jsx)("div",{className:"text-text-muted italic",children:"Running or no output returned..."})]}),f&&d.length>0&&(0,n.jsx)("div",{className:"ml-3.5 pl-3 border-l-2 border-border-subtle/80",children:d.map(t=>(0,n.jsx)(e,{...t,engine:u,workspacePath:x},t.id))})]})}),im=new Set(["TaskCreate","TaskUpdate","TodoWrite","todowrite"]),ip=new Set(["claude","omp","devin","opencode"]),ih=new Set(["Edit","Write","MultiEdit","NotebookEdit","file_change","edit","write","write_to_file","replace_file_content"]),ib=e=>"thought"===e.kind||"tool"===e.kind||"diff"===e.kind;function ig({total:e,windowSize:t=3,children:s}){let[l,a]=(0,r.useState)(0),i=function(e,t,s=0){let n=e-Math.max(0,s);return n>t+1?n-t:0}(e,t,l);return(0,n.jsxs)(n.Fragment,{children:[l>0?(0,n.jsx)("button",{type:"button",onClick:()=>a(e=>e-Math.min(12,Math.max(0,e))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:"▼ show less"}):i>0?(0,n.jsxs)("button",{type:"button",onClick:()=>a(e=>e+Math.min(12,Math.max(0,i))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:["▲ ",i," more ",1===i?"step":"steps"]}):null,s(i)]})}let iv=(0,r.memo)(function({file:e="",patch:t="",diff:s="",content:l="",workspacePath:a=""}){let[i,o]=(0,r.useState)(!1),c=(0,h.B)(e=>e.openEditorFile),d=lw(),u=t||s||(t||s||!l?"":String(l).split("\n").map(e=>`+${e}`).join("\n")),x=u?u.split("\n"):[],m=id(e,a),p=x.filter(e=>e.startsWith("+")&&!e.startsWith("+++")).length,f=x.filter(e=>e.startsWith("-")&&!e.startsWith("---")).length;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>o(!i),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(en.GD,{size:13,className:"text-success shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 font-mono font-medium text-text text-[11px] break-all",title:e,children:m.dir?`${m.dir}/${m.name}`:m.name||"diff"}),(p>0||f>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 font-mono text-[10px] shrink-0 text-text-muted",children:[p>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",p]}),f>0&&(0,n.jsxs)("span",{className:"text-danger",children:["-",f]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:i?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]}),(0,n.jsx)("div",{className:`flex items-center gap-1 shrink-0 ml-2 transition-opacity ${d?"opacity-100":"opacity-0 group-hover/tool:opacity-100"}`,children:e&&(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),(0,eo.e)(),e&&c(e)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1 text-[10px]",title:"Open file in editor",children:(0,n.jsx)(en.Gr,{size:11})})})]}),i&&(0,n.jsx)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[300px] overflow-y-auto font-mono text-[11px] leading-relaxed select-text",children:0===x.length?(0,n.jsx)("div",{className:"text-text-muted italic py-1 px-2",children:"No changes"}):x.map((e,t)=>{let s=e.startsWith("+")&&!e.startsWith("+++"),r=e.startsWith("-")&&!e.startsWith("---"),l=e.startsWith("@@"),a="text-text",i="";return s?(a="text-success",i="bg-success/10"):r?(a="text-danger",i="bg-danger/10"):l&&(a="text-text-muted",i="bg-surface-2/40"),(0,n.jsx)("div",{className:`px-2 py-0.5 rounded-sm whitespace-pre ${a} ${i}`,children:e},t)})})]})});var iy=s(6552);let iw=(0,r.memo)(function({text:e="",isLive:t=!1,defaultOpen:s=!1}){let[l,a]=(0,r.useState)(s);return e?.trim()?(0,n.jsxs)("div",{className:"my-1.5 text-xs select-none",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>a(e=>!e),className:"inline-flex items-center gap-1.5 text-[11px] text-text-muted hover:text-text py-0.5 transition-colors cursor-pointer group",children:[(0,n.jsx)(en.sU,{size:12,className:t?"animate-pulse text-success":"text-success"}),(0,n.jsx)("span",{className:"italic",children:t?"Thinking...":"Thought process"}),(0,n.jsx)("span",{className:"text-text-muted/50 group-hover:text-text-muted",children:l?(0,n.jsx)(en.yQ,{size:12}):(0,n.jsx)(en.c_,{size:12})})]}),l&&(0,n.jsx)("div",{className:"mt-1 pl-3.5 border-l-2 border-border-subtle/80 font-mono text-[11px] text-text-muted leading-relaxed whitespace-pre-wrap max-h-[260px] overflow-y-auto custom-scrollbar select-text py-1",children:e})]}):null}),ij=/Command running in background with ID:\s*([^\s.]+)/;var ik=s(14890);let iN=(0,r.memo)(function({id:e="",name:t="Bash",input:s=null,output:l="",error:a="",status:i="done",deferred:o=!1}){let c,{sessionId:d}=(0,ik.OO)(),u=!!(a||"error"===i),[x,m]=(0,r.useState)(u&&!o),[p,f]=(0,r.useState)(!1),[h,b]=(0,r.useState)(!1);(0,r.useEffect)(()=>{u&&!o&&m(!0)},[u,o]);let g=s?.command||"",v=s?.description||"",y=a||l||"",w="string"==typeof y?y:y?JSON.stringify(y,null,2):"",j=(c=ij.exec("string"==typeof l?l:""))?c[1]:"",k=!!(s?.run_in_background||j);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:(0,ik.xo)(d,"shell",e),children:[(0,n.jsxs)("div",{onClick:()=>m(!x),className:"flex items-start justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:"running"===i?(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-accent"}):u?(0,n.jsx)(en.RI,{size:13,className:"text-danger"}):(0,n.jsx)(en.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:"text-text-muted select-none shrink-0 font-mono text-[11px] leading-relaxed",children:"$"}),(0,n.jsx)("span",{className:"font-mono text-[11px] leading-relaxed text-text line-clamp-2 min-w-0",title:g,children:g||t}),k&&(0,n.jsxs)("span",{className:"font-mono text-[10px] font-semibold text-warning shrink-0 px-1 py-0.5 rounded bg-warning/10",title:j?`Background shell ${j}`:"Running in the background",children:["BG",j?` ${j}`:""]}),w&&(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:x?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 shrink-0 ml-2 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:g&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)(),navigator.clipboard.writeText(g),f(!0),setTimeout(()=>f(!1),2e3)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors text-[10px] flex items-center gap-0.5",title:"Copy command",children:p?(0,n.jsx)(en.aJ,{size:11,className:"text-success"}):(0,n.jsx)(en.QR,{size:11})})})]}),v&&!x&&(0,n.jsxs)("div",{className:"ml-7 text-[10px] text-text-muted/70 italic truncate",children:["# ",v]}),x&&w&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text relative group/out",children:[v&&(0,n.jsxs)("div",{className:"px-2 pt-1.5 text-[10px] text-text-muted/70 italic",children:["# ",v]}),(0,n.jsx)("pre",{className:`p-2 whitespace-pre-wrap leading-relaxed ${u?"text-danger":"text-text"}`,children:w}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)(),navigator.clipboard.writeText(w),b(!0),setTimeout(()=>b(!1),2e3)},className:"absolute top-1.5 right-1.5 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-0 group-hover/out:opacity-100 transition-opacity text-[10px]",title:"Copy output",children:h?(0,n.jsx)(en.aJ,{size:10,className:"text-success"}):(0,n.jsx)(en.QR,{size:10})})]})]})});function iC(e){let t=String(e||"").split("\n")[0].trim();return t.length>140?`${t.slice(0,140)}…`:t}let iS=(0,r.memo)(function({id:e="",name:t="Agent",input:s=null,output:l="",error:a="",status:i="done",children:o=[],engine:c="claude",workspacePath:d=""}){let{sessionId:u}=(0,ik.OO)(),x="running"===i,m=!!(a||"error"===i),p=o.filter(e=>"running"===e.status).length,[f,h]=(0,r.useState)(m);(0,r.useEffect)(()=>{m&&h(!0)},[m]);let b=aj.has(t),g=b?ak({input:s}):t||"agent",v=b?iC(s?.prompt??s?.description??s?.message):iC(s?.message??s?.prompt??s?.query);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:(0,ik.xo)(u,"agent",e),children:[(0,n.jsxs)("div",{onClick:()=>h(!f),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0",children:x?(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-accent"}):m?(0,n.jsx)(en.RI,{size:13,className:"text-danger"}):(0,n.jsx)(en.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:"AGENT"}),(0,n.jsx)("span",{className:"font-mono text-[11px] font-semibold text-brand-500 shrink-0",children:g}),v&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",title:v,children:v})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 shrink-0 ml-2",children:[o.length>0&&(0,n.jsxs)("span",{className:"font-mono text-[10px] text-text-subtle",title:`${o.length} sub-agent tool calls`,children:[x&&p>0?`${p}/${o.length}`:o.length," tools"]}),(0,n.jsx)("span",{className:"text-text-muted/50",children:f?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]})]}),f&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 py-1 space-y-0.5",children:[o.length>0?(0,n.jsx)(ig,{total:o.length,children:e=>(e>0?o.slice(e):o).map(e=>iM(c,e,{workspacePath:d})||(0,n.jsx)(ix,{...e,engine:c,workspacePath:d},e.id))}):(0,n.jsx)("div",{className:"text-text-muted italic py-0.5",children:x?"Sub-agent started…":"No tool calls reported."}),!x&&(l||a)&&(0,n.jsx)("div",{className:"mt-1 pl-3 border-l-2 border-border-subtle/60 font-mono text-[11px] max-h-[240px] overflow-y-auto select-text",children:(0,n.jsx)("div",{className:`whitespace-pre-wrap leading-relaxed ${m?"text-danger":"text-text-muted"}`,children:"string"==typeof(a||l)?a||l:JSON.stringify(a||l,null,2)})})]})]})}),iE=(0,r.memo)(function({toolName:e="EnterPlanMode",input:t={}}){let s="string"==typeof t?.plan?t.plan.trim():"";if(s)return(0,n.jsx)(iR,{plan:s,explanation:t?.explanation||""});let r="EnterPlanMode"===e,l=t?.reason||(r?"Exploring codebase and designing implementation approach":"Implementation plan finalized");return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${r?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between font-semibold",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[r?(0,n.jsx)(en.y8,{size:16,className:"text-brand-500"}):(0,n.jsx)(en.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:r?"Plan Mode Activated":"Plan Mode Completed"})]}),(0,n.jsx)("span",{className:"font-mono text-[10px] px-2 py-0.5 rounded bg-surface-2 text-text-muted",children:e})]}),(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reason: "}),l]}),r&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted/80 italic pl-6 select-none",children:"Plan mode reads files and drafts an approach — nothing is applied without your review, in whichever CLI this chat is running."})]})}),iR=(0,r.memo)(function({plan:e,explanation:t=""}){return(0,n.jsxs)("div",{className:"p-3.5 rounded-brand-lg border border-brand-500/30 bg-brand-500/10 text-text my-2 text-xs flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[(0,n.jsx)(en.y8,{size:16,className:"text-brand-500"}),(0,n.jsx)("span",{children:"Plan"})]}),(0,n.jsx)("pre",{className:"font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-words pl-6 max-h-[320px] overflow-y-auto",children:e}),t&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted pl-6 italic",children:t})]})}),iT=(0,r.memo)(function({toolName:e="enteredReviewMode",input:t={}}){let s="enteredReviewMode"===e,r=String(t?.review||"").trim();return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${s?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[s?(0,n.jsx)(en.kU,{size:16,className:"text-brand-500"}):(0,n.jsx)(en.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:s?"Code review started":"Code review finished"})]}),r&&(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reviewing: "}),r]})]})}),i$={bash:(e,t)=>(0,n.jsx)(iN,{...e,deferred:t},e.id),agent:(e,t,{engine:s,workspacePath:r})=>(0,n.jsx)(iS,{...e,engine:s,workspacePath:r},e.id),plan:e=>(0,n.jsx)(iE,{toolName:e.name,input:e.input},e.id),review:e=>(0,n.jsx)(iT,{toolName:e.name,input:e.input},e.id),question:(e,t,s)=>{if("running"===e.status||!e.output&&!e.error)return null;let r=s?.engine==="antigravity"&&/user skipped/i.test(String(e.output||""));return(0,n.jsx)(iy.J,{engine:s?.engine,questions:e.input?.questions||[],answers:r||e.error?null:e.output||"",declined:r||!!e.error||"error"===e.status},e.id)}};function iM(e,t,s={}){let n=i$[(0,aT.$Z)(e,t.name)];return n?n(t,s.deferred,{...s,engine:e}):null}function iz({row:e,engine:t,workspacePath:s,deferred:r}){if("thought"===e.kind)return(0,n.jsx)(iw,{text:e.text,isLive:e.isLive});if("diff"===e.kind){let t=e.diff;return(0,n.jsx)(iv,{file:t.file,patch:t.patch,diff:t.diff,content:t.content,workspacePath:s})}let l=e.tool;return iM(t,l,{workspacePath:s,deferred:r})||(0,n.jsx)(ix,{...l,engine:t,workspacePath:s,deferred:r})}let iP={info:"text-text-muted",suggestion:"text-text-muted",warning:"text-warning",error:"text-danger"};function iI({notice:e}){if(!e?.content)return null;let t=`text-xs leading-relaxed py-1 px-2 my-0.5 rounded border-l-2 border-current/30 bg-surface-2/40 wrap-anywhere ${iP[e.level]||iP.info}`;return e.compacting?(0,n.jsxs)("div",{className:`${t} flex items-center gap-2`,children:[(0,n.jsx)(en.kr,{size:12,className:"animate-spin text-brand-500 shrink-0"}),(0,n.jsx)("span",{children:e.content}),(0,n.jsx)(iL,{})]}):(0,n.jsxs)("div",{className:t,children:[e.content,e.compact?.detail&&(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",e.compact.detail]}),e.compact?.durationMs?(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",iA(e.compact.durationMs)]}):null]})}function iA(e){let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`}function iL(){let[e]=(0,r.useState)(()=>Date.now()),[t,s]=(0,r.useState)(e);return(0,r.useEffect)(()=>{let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[]),(0,n.jsx)("span",{className:"text-text-muted/70 tabular-nums",children:iA(t-e)})}function iD({content:e,isLive:t}){let s=function(e,t){let[s,n]=(0,r.useState)(e),l=(0,r.useRef)(e);return(0,r.useEffect)(()=>{l.current=e},[e]),(0,r.useEffect)(()=>{if(!t)return;let e=setInterval(()=>{n(e=>e===l.current?e:l.current)},80);return()=>clearInterval(e)},[t]),t?s:e}(e,t);return(0,n.jsxs)("div",{className:"text-sm leading-relaxed text-text py-1.5 wrap-anywhere",children:[(0,n.jsx)(ao,{content:s}),t&&(0,n.jsx)("span",{className:"inline-block w-1.5 h-3.5 bg-brand-500 animate-pulse ml-1 align-middle"})]})}let iB=(0,r.memo)(function({messages:e=[],engine:t="claude",workspacePath:s="",onResolvePermission:l,isLive:a=!0}){let i=(0,r.useMemo)(()=>(function(e=[],t="claude"){let s=[],n=new Set;for(let r of e){if("notice"===r.role){s.push({kind:"notice",id:r.id,notice:{subtype:r.subtype,level:r.level,content:r.content,...r.compact?{compact:r.compact}:null,...r.compacting?{compacting:!0}:null}});continue}if("assistant"!==r.role)continue;r.thinking?.trim()&&s.push({kind:"thought",id:`${r.id}-th`,text:r.thinking});let e=function(e,t,s){return(t||[]).filter(t=>!(!t||!t.name||(s||[]).some(e=>{let s;return e.file&&(s=e.file,ih.has(t?.name)&&s&&((t.input?.paths||[]).includes(s)||((e={})=>e.file_path||e.notebook_path||e.path||e.filePath||e.file||"")(t.input)===s))})||"task"===(0,aT.$Z)(e,t.name)&&im.has(t.name)))}(t,r.tools,r.diffs);for(let l=0;l<e.length;l++){let a=e[l];if("question"===(0,aT.$Z)(t,a.name)&&"running"===a.status&&ip.has(t))continue;let i=a.id||`${r.id}-t${l}`;n.has(i)||(n.add(i),s.push({kind:"tool",id:i,tool:a,engine:t}))}for(let e=0;e<(r.diffs?.length||0);e++){let t=r.diffs[e];s.push({kind:"diff",id:`${r.id}-d${e}`,diff:t})}r.content&&s.push({kind:"prose",id:`${r.id}-p`,content:r.content,isLive:r.isLive}),r.permission&&s.push({kind:"permission",id:`${r.id}-perm`,permission:r.permission})}return s})(e,t),[e,t]),o=(0,r.useMemo)(()=>(function(e=[],t=6,{deferred:s=!1}={}){let n=[];for(let t of e)if(ib(t)){let e=n[n.length-1];e?.type==="steps"?e.rows.push(t):n.push({type:"steps",rows:[t]})}else n.push({type:"row",row:t});return n.map((e,n)=>{if("steps"!==e.type)return{...e,key:`r${n}`,deferred:s};let r=e.rows.length>t+1?e.rows.length-t:0;return{type:"steps",key:`s${n}`,rows:e.rows,hidden:r,deferred:s}})})(i,3,{deferred:!a}),[i,a]);return(0,n.jsx)("div",{className:"my-1",children:o.map(e=>{if("steps"!==e.type){if("prose"===e.row.kind)return(0,n.jsx)(iD,{content:e.row.content,isLive:e.row.isLive},e.key);if("notice"===e.row.kind)return(0,n.jsx)(iI,{notice:e.row.notice},e.key);if("permission"===e.row.kind){let t=e.row.permission;return(0,n.jsx)(iy.J,{requestId:t.requestId,questions:t.input?.questions||[],onResolve:l},e.key)}return null}return(0,n.jsx)("div",{className:"relative pl-2.5 border-l-2 border-border-subtle/50 my-1",children:(0,n.jsx)(ig,{total:e.rows.length,children:r=>(r>0?e.rows.slice(r):e.rows).map(e=>(0,n.jsx)(iz,{row:e,engine:t,workspacePath:s,deferred:!a},e.id))})},e.key)})})},(e,t)=>{if(e.messages.length!==t.messages.length)return!1;for(let s=0;s<e.messages.length;s++)if(e.messages[s]!==t.messages[s])return!1;return e.engine===t.engine&&e.workspacePath===t.workspacePath&&e.isLive===t.isLive&&e.onResolvePermission===t.onResolvePermission}),iF=[],iK=(e,t)=>{if(!e||!t)return null;let s=e.getBoundingClientRect();return{scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight,nodeTop:t.getBoundingClientRect().top-s.top+e.scrollTop}},iO=e=>String(e).padStart(2,"0");function iW(e){let t=Math.max(0,Math.floor(e/1e3)),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}h ${n}m ${iO(r)}s`:n>0?`${n}m ${iO(r)}s`:`${r}s`}function i_(e){return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),aD(e)," tokens"]}):null}let iH=(0,r.memo)(function({engine:e="claude",failed:t=!1,onRetry:s}){let r=tb.UB[e]||tb.UB.claude;return t?(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-center p-6 select-none",children:[(0,n.jsx)("span",{className:"font-mono text-[12px] text-danger",children:"Couldn't load this conversation"}),(0,n.jsx)("span",{className:"text-[11px] font-mono text-text-muted/70",children:r.label}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),s?.()},className:"px-3 py-1.5 rounded-brand text-[11px] font-mono text-text bg-surface-2 hover:bg-surface-3 transition-colors",children:"Retry"})]}):(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-center p-6 select-none",children:[(0,n.jsx)(en.kr,{size:20,className:"animate-spin text-brand-500"}),(0,n.jsx)("span",{className:"ai-sheen-text font-mono text-[12px] text-text-muted",children:"Syncing…"}),(0,n.jsx)("span",{className:"text-[11px] font-mono text-text-muted/70",children:r.label})]})}),iq=(0,r.memo)(function({sessionId:e,engine:t="",hydrating:s=!1}){let l=a7(t=>t.bySession[e]?.isTurnRunning),a=a7(t=>t.bySession[e]?.turnStartedAt),i=a7(t=>t.bySession[e]?.lastTurnMs),o=a7(t=>t.bySession[e]?.stats),c=a7(t=>t.bySession[e]?.turnBaseline),d=(0,u.d)(e=>e.connected),x=(0,u.d)(e=>e.retryStatus),m=a7(t=>t.bySession[e]?.messages)||iF,p=m[m.length-1]||null,f=Math.max(0,(o?.outputTokens||0)-(c?.outputTokens||0)),[h,b]=(0,r.useState)(Date.now());(0,r.useEffect)(()=>{if(!l)return;b(Date.now());let e=setInterval(()=>b(Date.now()),1e3);return()=>clearInterval(e)},[l]);let[g,v]=(0,r.useState)(null),y=(0,r.useRef)(l);(0,r.useEffect)(()=>{y.current&&!l&&a&&v({ms:i||Date.now()-a,outputTokens:f,changes:aK(m)}),l&&v(null),y.current=l},[l,a,i,f,m]);let w=(0,r.useMemo)(()=>g||l||!i?null:{ms:i,outputTokens:0,changes:aK(m)},[g,l,i,m]),j=g||w;if(!l&&!j)return null;if(!l)return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 select-none text-xs text-text-muted",children:[(0,n.jsx)(en.aJ,{size:14,className:"text-emerald-400 shrink-0"}),(0,n.jsxs)("span",{className:"flex items-center min-w-0 font-mono text-[11px]",children:[(0,n.jsxs)("span",{className:"truncate",children:["Worked for ",(0,n.jsx)("span",{className:"text-text",children:iW(j.ms)})]}),(0,n.jsxs)("span",{className:"shrink-0",children:[function({added:e,removed:t}){return e||t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),e>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",e]}),e>0&&t>0&&" ",t>0&&(0,n.jsxs)("span",{className:"text-danger",children:["−",t]})]}):null}(j.changes),i_(j.outputTokens)]})]})]});let k=p?.tools?.find(e=>"running"===e.status),N=f+function(e=[]){let t=0;for(let s=e.length-1;s>=0;s--){let n=e[s];if("user"===n.role)break;t+=(n.content?.length||0)+(n.thinking?.length||0)}return Math.round(t/4)}(m),C=function({connected:e=!0,hydrating:t=!1,retryStatus:s=null,activeTool:n=null,engine:r="",lastMsg:l=null}={}){if(!e){let e=s||{};return{verb:"Reconnecting",detail:e.isRetrying?`attempt ${e.attempt}/${e.maxAttempts}${e.failed?" \xb7 gave up":""}`:"",tone:"alert"}}if(t)return{verb:"Syncing",detail:"from host",tone:"wait"};if(n?.name){let{name:e,input:t={}}=n,s=(0,aT.$Z)(r,e),l=az(t.file_path||t.path);switch(s){case"bash":return{verb:"Running",detail:aI(t.command||"",aM),tone:"wait"};case"file":{let s=/^(list|list_dir|ls)$/i.test(e),n=t.offset?`:L${t.offset}`:"";return{verb:s?"Listing":"Reading",detail:aI(`${l}${n}`,aM),tone:"wait"}}case"search":{let e=t.pattern?`"${t.pattern}"`:t.query||t.url||"",s=az(t.path);return{verb:"Searching",detail:aI([e,s?`in ${s}`:""].filter(Boolean).join(" "),aM),tone:"wait"}}case"diff":return{verb:/^(Write|write_to_file)$/i.test(e)?"Writing":"Editing",detail:aI(az(t.file_path||t.filePath||t.file||t.path)||aL(t),aM),tone:"wait"};case"agent":{let e=n.children?.length||0;return{verb:"Delegating",detail:aI([t.description||aL(t),e?`${e} steps`:""].filter(Boolean).join(" \xb7 "),aM),tone:"wait"}}case"task":return{verb:"Updating tasks",detail:aI(t.activeForm||t.subject||"",aM),tone:"wait"};case"plan":return{verb:"Planning",detail:aI(az(t.path)||e,aM),tone:"wait"};default:return{verb:"Calling",detail:aI([aA(e),aL(t)].filter(Boolean).join(" "),aM),tone:"wait"}}}return l?.thinking?{verb:"Thinking",detail:aI(aP(l.thinking),aM),tone:"wait"}:l?.content?{verb:"Writing",detail:aI(aP(l.content),aM),tone:"wait"}:{verb:"Working",detail:"",tone:"wait"}}({connected:d,hydrating:s,retryStatus:x,activeTool:k,engine:t,lastMsg:p});return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 select-none text-xs text-text-muted",children:["alert"===C.tone?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-danger animate-pulse shrink-0"}):(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-brand-500 shrink-0"}),(0,n.jsxs)("span",{className:"flex items-center min-w-0 font-mono text-[11px]",children:[(0,n.jsxs)("span",{className:"truncate",children:[(0,n.jsxs)("span",{className:`ai-sheen-text${"alert"===C.tone?" !text-danger":""}`,children:[C.verb,"…"]}),C.detail&&(0,n.jsxs)("span",{className:"text-text-subtle",children:[" ",C.detail]}),(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),iW(h-(a||h))]}),(0,n.jsx)("span",{className:"shrink-0",children:i_(N)})]})]})}),iU=(0,r.memo)(function({engine:e,engineMeta:t,workspacePath:s,bus:l=null,fileBus:a,onSendPrompt:i,onOpenResume:o}){let{t:c}=(0,ec.s)(),[d,u]=(0,r.useState)([]),[x,m]=(0,r.useState)(null),p=n8(s,a,{enabled:!!s});(0,r.useEffect)(()=>{if(!s)return;let e=!0;return a?.getSystemInfo?.().then(t=>{e&&t?.success&&m(t.homedir||null)}).catch(()=>{}),()=>{e=!1}},[a,s]),(0,r.useEffect)(()=>{if(!s)return;let t=!0;if(l?.emit)return l.emit("getAgentSessions",{cwd:s},s=>{t&&u((Array.isArray(s?.sessions)?s.sessions:[]).filter(t=>!e||t.agent===e).slice(0,8))}),()=>{t=!1}},[s,e]);let f=s?sf(s,x):"";return(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-center p-6 select-none overflow-y-auto custom-scrollbar",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-2xl flex items-center justify-center mb-3 shadow-md border border-border-subtle/40 backdrop-blur-sm shrink-0",style:{backgroundColor:`${t.color}15`},children:(0,n.jsx)("img",{src:e1(`${e}-ui`),alt:t.label,className:`w-7 h-7 object-contain ${e0}`})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-text mb-1",children:t.label}),f&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-3 text-[11px] font-mono text-text-muted",title:s,children:[(0,n.jsx)("span",{className:"truncate max-w-[220px]",children:f}),p.branch&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/50",children:"\xb7"}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:p.branch}),p.dirty&&(0,n.jsxs)("span",{className:"text-amber-400",title:`${p.changedCount} changed`,children:["●",p.changedCount]})]})]}),d.length>0&&(0,n.jsxs)("div",{className:"w-full max-w-md mb-4 text-left",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1.5 px-1 text-[10px] uppercase tracking-wide text-text-muted",children:[(0,n.jsx)(en.BZ,{size:11}),(0,n.jsx)("span",{children:"Recent in this project"})]}),(0,n.jsx)("div",{className:"max-h-[38vh] overflow-y-auto custom-scrollbar rounded-brand border border-border-subtle bg-surface-2/30",children:d.map(e=>{let t=!!e.openSessionId;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),t?window.dispatchEvent(new CustomEvent(eV.vP,{detail:{sessionId:e.openSessionId}})):o?.(e)},className:"w-full flex items-center gap-2 px-2.5 py-1.5 text-left border-b border-border-subtle/50 last:border-b-0 hover:bg-surface-2 transition-colors",title:t?c("agentHistory.openNow"):void 0,children:[(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-[11px] ${t?"text-text font-medium":"text-text-muted"}`,children:e.title||"Untitled conversation"}),(0,n.jsx)("span",{className:"shrink-0 text-[10px] font-mono text-text-muted",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m`;let s=Math.round(t/60);return s<24?`${s}h`:`${Math.round(s/24)}d`}(e.updatedAt)})]},`${e.agent}:${e.sessionId}`)})}),d.length>=8&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),o?.()},className:"mt-1.5 px-1 text-[10px] font-mono text-text-muted hover:text-text transition-colors",children:"All conversations →"})]}),(0,n.jsx)("div",{className:"flex flex-wrap items-center justify-center gap-2 max-w-md shrink-0",children:tb.y2.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>i?.(e),className:"px-2.5 py-1 rounded-full bg-surface-2 hover:bg-surface-3 text-[11px] text-text font-mono border border-border-subtle transition-colors",children:e},e))})]})}),iV=(0,r.memo)(function({sessionId:e,engine:t="claude",workspacePath:s="",bus:l=null,fileBus:a=null,onSendPrompt:i,onResolvePermission:o,hasOlder:c=!1,onLoadOlder:d,onRewind:u,onPreviewRewind:x,onCutLocal:m,onListRewindPoints:p,onOpenResume:f,hydrating:h=!1,synced:b=!0,hydrateFailed:g=!1,onReload:v}){let y=(0,r.useRef)(null),w=(0,r.useRef)(null),j=(0,r.useRef)(!0),k=(0,r.useRef)(null),N=(0,r.useRef)(null),C=(0,r.useRef)(null),S=(0,r.useRef)(null),E=(0,r.useRef)(0),[R,T]=(0,r.useState)(!1),[$,M]=(0,r.useState)(131072),[z,P]=(0,r.useState)(null),I=(0,r.useRef)({sessionId:null,n:0}),L=a7(t=>t.bySession[e]?.messages)||iF,D=tb.UB[t]||tb.UB.claude;(0,r.useEffect)(()=>{M(131072),P(null),S.current=null},[e]);let{id:B,index:F}=(0,r.useMemo)(()=>(function(e,t,s){if(!t?.length)return{id:null,index:0};let n=it(t,s,void 0),r=null!=e?t.findIndex(t=>t.id===e):-1,l=it(t,Math.max(524288,s),void 0),a=r<0?n:Math.max(r,l);return{id:t[a].id,index:a}})(z,L,$),[z,L,$]);(0,r.useEffect)(()=>{P(B)},[B]);let K=F>0?L.slice(F):L,[O,W]=(0,r.useState)(null),_=(0,r.useRef)(0),H=(0,r.useMemo)(()=>L.filter(e=>"user"===e.role).length,[L]);(0,r.useEffect)(()=>{if(O?.ok||O?.supported===!1||_.current>=6)return;_.current+=1;let e=!0;return p?.().then(t=>{e&&W(t)}).catch(()=>{}),()=>{e=!1}},[p,t,e,H,O?.ok,O?.supported]);let q=!!O?.ok,U=(0,r.useMemo)(()=>{let e=new Map,t=0;for(let s=L.length-1;s>=0;s--)"user"===L[s].role&&e.set(L[s].id,t++);return e},[L]),V=(0,r.useMemo)(()=>{let e=[];for(let t of K)"user"===t.role||0===e.length?e.push({key:t.id,messages:[t]}):e[e.length-1].messages.push(t);return e},[K]),X=(0,r.useCallback)(async({auto:e=!1}={})=>{let t=y.current,s=Date.now();if(!e&&s-E.current<300)return;E.current=s;let n=C.current,r=n?function({scrollTop:e=0,scrollHeight:t=0,clientHeight:s=0,nodeTop:n=0}={}){return{nodeTop:n,scrollTop:e,atBottom:t-e-s<8}}(iK(t,n)):null,l=r?{...r,atBottom:e&&j.current,node:n}:null,a={hiddenCount:F,hasOlder:c,scrollTop:t?.scrollTop??0,scrollHeight:t?.scrollHeight??0},i=null;0===F&&c&&(i=await d?.()),(0,A.Lq)("ai-page","loadMore",{...a,fetched:i}),S.current=l,P(null),M(e=>e+131072)},[F,c,d]);(0,r.useLayoutEffect)(()=>{let e=y.current,t=S.current;if(!e||!t)return;S.current=null;let s=function(e,{scrollHeight:t=0,clientHeight:s=0,nodeTop:n=0}={}){return e?e.atBottom?t:n<=e.nodeTop?null:Math.max(0,n-(e.nodeTop-e.scrollTop)):null}(t,iK(e,t.node)||{});null!=s&&(e.scrollTop=s);let n=e.scrollHeight-e.scrollTop-e.clientHeight;j.current=n<8,T(n>140)},[$,z]),(0,r.useEffect)(()=>{let t=I.current;t.sessionId!==e&&(t.sessionId=e,t.n=0),!(t.n>=40)&&!h&&b&&j.current&&c&&L?.length&&L[F]?.role!=="user"&&(t.n+=1,X({auto:!0}))},[e,L,F,c,h,b,X]);let G=(0,r.useCallback)(()=>{k.current||(k.current=requestAnimationFrame(()=>{k.current=null;let e=y.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight,s=t<80;j.current=s,T(!s&&t>140),e.scrollTop<120&&(F>0||c)&&X()}))},[X,F,c]);(0,r.useEffect)(()=>{let e=y.current,t=w.current;if(!e||!t)return;let s=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&!j.current&&X()},{root:e,rootMargin:"120px"});return s.observe(t),()=>s.disconnect()},[X]);let J=(0,r.useMemo)(()=>L.map(e=>`${e.id}:${+!!e.thinking}:${+!!e.content}:${e.tools?.length||0}:${e.diffs?.length||0}:${+!!e.permission}`).join("|"),[L]),Y=(0,r.useCallback)(e=>{C.current=e},[]);(0,r.useEffect)(()=>{let e=y.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},[J]);let Z=(0,r.useMemo)(()=>L.reduce((e,t)=>e+(t.content?.length||0),0),[L]);(0,r.useEffect)(()=>{!j.current||N.current||(N.current=setTimeout(()=>{N.current=null;let e=y.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},150))},[Z]),(0,r.useEffect)(()=>()=>{N.current&&clearTimeout(N.current)},[]),(0,r.useEffect)(()=>{let e=y.current;if(!e)return;let t=new ResizeObserver(()=>{j.current&&(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>t.disconnect()},[]);let Q=(0,r.useCallback)(()=>{(0,eo.e)();let e=y.current;e&&(e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),j.current=!0,T(!1))},[]),ee=(0,r.useCallback)(e=>e.messages.some(e=>e.isLive),[]);return(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{ref:y,onScroll:G,className:"ai-conversation flex-1 min-h-0 overflow-y-auto px-4 sm:px-6 py-4 space-y-4 custom-scrollbar relative",children:[(F>0||c)&&(0,n.jsx)("div",{ref:w,"aria-hidden":"true",className:"h-px"}),0===L.length?b?(0,n.jsx)(iU,{engine:t,engineMeta:D,workspacePath:s,bus:l,fileBus:a,onSendPrompt:i,onOpenResume:f}):(0,n.jsx)(iH,{engine:t,failed:g,onRetry:v}):(0,n.jsxs)(n.Fragment,{children:[(F>0||c)&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),X()},className:"w-full py-1.5 text-[11px] font-mono text-text-muted hover:text-text bg-surface-2/50 hover:bg-surface-2 border border-border-subtle/60 rounded-brand transition-colors",children:F>0?`Load older \xb7 ${F} more`:"Load older turns"}),V.map((e,r)=>{let[l,...a]=e.messages;return"user"!==l.role?(0,n.jsx)("div",{ref:0===r?Y:void 0,children:(0,n.jsx)(iB,{messages:e.messages,engine:t,workspacePath:s,onResolvePermission:o,isLive:ee(e)})},e.key):(0,n.jsxs)("div",{ref:0===r?Y:void 0,children:[(0,n.jsx)(ic,{message:l,engine:t,workspacePath:s,onResolvePermission:o,onRewind:u,onPreviewRewind:x,onCutLocal:m,rewindIndex:U.get(l.id),canRewind:q}),(0,n.jsx)(iB,{messages:a,engine:t,workspacePath:s,onResolvePermission:o,isLive:ee(e)})]},e.key)}),(0,n.jsx)(iq,{sessionId:e,engine:t,hydrating:h})]})]}),R&&(0,n.jsx)("button",{type:"button",onClick:Q,className:"absolute bottom-4 right-6 p-2 rounded-full bg-surface-2 border border-border-subtle shadow-lg hover:bg-surface-3 text-text transition-all duration-150 z-30",title:"Scroll to bottom",children:(0,n.jsx)(en.yd,{size:16})})]})});function iX(e){return e.provider?e.provider:e.id&&e.id.includes("/")?e.id.split("/")[0]:""}function iG(e,t,s,n){let r=n?t:e,l=[],a=r.filter(e=>e.recent||e.id===s).sort((e,t)=>(e.recentRank??999)-(t.recentRank??999));a.length>0&&l.push({key:"recent",title:"Recent",items:a});let i=new Set(a.map(e=>e.id)),o=r.filter(e=>!i.has(e.id)),c=new Map;for(let e of o){let t=iX(e)||"other";c.has(t)||c.set(t,[]),c.get(t).push(e)}for(let e of[...c.keys()].sort((e,t)=>"opencode-go"===e?-1:"opencode-go"===t?1:"opencode"===e?-1:"opencode"===t?1:e.localeCompare(t))){let t=c.get(e)||[];0!==t.length&&(t.sort((e,t)=>(e.label||e.id).localeCompare(t.label||t.id)),l.push({key:e,title:e?"opencode-go"===e?"OpenCode Go":"opencode"===e?"OpenCode Zen":"9router"===e?"9Router":"google-antigravity"===e?"Google Antigravity":"ollama-cloud"===e?"Ollama Cloud":"anthropic"===e?"Anthropic":"openai"===e?"OpenAI":"google"===e?"Google":e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):"Other Models",items:t}))}return l}let iJ=[],iY=(0,r.memo)(function({sessionId:e="",engine:t="claude",bus:s=null,isTurnRunning:l=!1,isFocused:a=!1,onSend:i,onRemoveQueueItem:o,onClearQueue:c,onStop:d,onRunShell:u,onResolvePermission:x,onSelectModel:m,onModeChange:p,onOpenModal:f,onOptionChange:h,onActivate:b,fileBus:g=null,workspacePath:v="",model:y="",modalOpen:w=!1}){let{t:j,locale:k}=(0,ec.s)(),N="mouse"===tF(),C=ti()?"Opt ←/→ \xb7 Opt 1…9 to switch tab":"Ctrl+Shift+←/→ \xb7 1…9 to switch tab",S=(0,aT.Tw)(t),E=S.permissionModes,R=S.slashCommands,T=a7(t=>t.bySession[e]?.isTurnRunning),$=a7(t=>t.bySession[e]?.metadata?.model),M=a7(t=>t.bySession[e]?.metadata?.modelOptions),z=M?.length?M:S.models,P=a7(t=>t.bySession[e]?.metadata?.skills)||iJ,I=a7(t=>t.bySession[e]?.metadata?.commands)||iJ,A=a7(t=>t.bySession[e]?.permissionMode),L=a7(t=>t.bySession[e]?.metadata?.effort||t.bySession[e]?.metadata?.variant),D=A||S.defaultMode,B=void 0!==T?T:l,F=void 0!==$?$:y,[K,O]=(0,r.useState)(""),W=a7(t=>t.bySession[e]?.queue)||iJ,[_,H]=(0,r.useState)(-1),q=(0,r.useRef)(""),[U,V]=(0,r.useState)(!1),[X,G]=(0,r.useState)(null),[J,Y]=(0,r.useState)(""),[Z,Q]=(0,r.useState)([]),[ee,et]=(0,r.useState)(0),[es,er]=(0,r.useState)(null),[el,ea]=(0,r.useState)(-1),ei=tk(e=>e.addCommand),ed=tk(e=>e.resolveAlias),eu=tk(e=>e.history),ex=tk(e=>e.pinned),em=(0,r.useMemo)(()=>U?[]:tT(K,eu,ex,[],!N),[K,eu,ex,N,U]),[ep,ef]=(0,r.useState)(!1),[eh,eb]=(0,r.useState)(""),[eg,ev]=(0,r.useState)(()=>new Set),[ey,ew]=(0,r.useState)(!1),[ej,ek]=(0,r.useState)(!1),eN=(0,r.useRef)(null),{attachments:eC,setAttachments:eS,removeAttachment:eE,handleFileUpload:eR,handleAttachPaste:eT}=tV({bus:s,sessionId:e}),[e$]=tI(k),eM=tD({lang:tz(e$),onText:e=>{O(e),eL.current&&(eL.current.value=e,eL.current.style.height="auto",eL.current.style.height=`${Math.min(eL.current.scrollHeight,120)}px`,eL.current.focus())}}),ez=(0,r.useCallback)(()=>{(0,eo.e)(),eM.stop()},[eM]),eP=(0,r.useCallback)(()=>{eM.cancel()},[eM]),eI=(0,r.useCallback)(()=>{eM.listening?eM.stop():(document.activeElement?.blur(),eM.start(K))},[eM,K]),eA=(0,r.useCallback)(()=>{(0,eo.e)(),O(""),eL.current&&(eL.current.value="",eL.current.style.height="26px");try{localStorage.removeItem(`9remote_draft_${e}`)}catch{}eL.current?.focus()},[e]),eL=(0,r.useRef)(null),eD=(0,r.useRef)(eC);(0,r.useEffect)(()=>{eD.current=eC},[eC]);let eB=(0,r.useRef)(null),eF=(0,r.useRef)(!1),eK=(0,r.useRef)(0),eO=(0,r.useRef)(0),eW=(0,r.useRef)(0);tb.UB[t]||tb.UB.claude,(0,r.useEffect)(()=>{a&&!w&&N&&eL.current?.focus({preventScroll:!0})},[a,w,N]),(0,r.useEffect)(()=>{let e=e=>{eN.current&&!eN.current.contains(e.target)&&(ef(!1),ew(!1))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,r.useEffect)(()=>{B&&(ef(!1),ew(!1))},[B]),(0,r.useEffect)(()=>{let e=eL.current;if(!e)return;e.style.height="auto";let t=Math.min(e.scrollHeight,140);e.style.height=`${Math.max(t,26)}px`},[K]),(0,r.useEffect)(()=>{if(!U||!eB.current)return;let e=eB.current.querySelectorAll("[data-menu-item]")[ee];e&&e.scrollIntoView({block:"nearest"})},[ee,U]),(0,r.useEffect)(()=>{if(e){eS([]);try{O(localStorage.getItem(`9remote_draft_${e}`)||"")}catch{}}},[e,eS]),(0,r.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{try{K?localStorage.setItem(`9remote_draft_${e}`,K):localStorage.removeItem(`9remote_draft_${e}`)}catch{}},300);return()=>clearTimeout(t)},[K,e]),(0,r.useEffect)(()=>{if(es){let e=es.name.replace(/[/@]/g,"\\$&");if(RegExp(`(?:^|\\s)${e}\\s*$`).test(K))return;er(null)}let e=/(?:^|\s)([/@][\w\d_.-]*)$/.exec(K);if(!e){V(!1),G(null),Y("");return}let t=e[1],n=t[0],r=t.slice(1).toLowerCase();if(G(n),Y(r),et(0),"/"===n){let e=function({staticCommands:e=[],liveCommands:t=[],skills:s=[],filter:n=""}={}){let r=(t||[]).map(e=>({name:`/${e.name}`,description:e.description||"",isCommand:!0})),l=(s||[]).map(e=>({name:`/${e.name||e.id}`,description:e.description||`Skill: ${e.name||e.id}`,isSkill:!0})),a=new Set,i=String(n||"").toLowerCase();return[...e||[],...r,...l].filter(e=>!a.has(e.name)&&!!e.name.toLowerCase().includes(i)&&(a.add(e.name),!0))}({staticCommands:R,liveCommands:I,skills:P,filter:r});Q(e),V(e.length>0)}else"@"===n&&(s?.emit?s.emit("ai:files",{workspace:v,query:r},e=>{e?.ok&&Array.isArray(e.files)&&(Q(e.files.map(e=>({name:e.path||e,description:e.isModified?`${e.dir?e.dir+" \xb7 ":""}modified`:e.dir||""}))),V(e.files.length>0))}):g?.searchFiles&&v?g.searchFiles(v,r).then(e=>{e?.success&&Array.isArray(e.files)&&(Q(e.files.slice(0,10).map(e=>({name:e.path||e,description:e.relPath||e}))),V(e.files.length>0))}):(Q([]),V(!1)))},[K,g,v,P,I,R,es]);let e_=(0,r.useCallback)(t=>{let s=ed((("string"==typeof t?t:eL.current?eL.current.value:K)||K).trim()),n=eD.current;if(!s&&0===n.length)return;let r=Date.now();if(r-eO.current<250)return;eO.current=r,eW.current=r,(0,eo.e)(),s&&!s.startsWith("!")&&ei(s),H(-1),O(""),eL.current&&(eL.current.value="",eL.current.style.height="26px");try{localStorage.removeItem(`9remote_draft_${e}`)}catch{}if(s.startsWith("!")){n.length||u?.(s.slice(1).trim());return}let l=a7.getState().bySession[e]?.activePermission;l&&x?.(l.requestId,tb.x6,tb.mX),n.length&&eS([]),i?.(s,{attachments:n.map(({name:e,type:t,content:s})=>({filename:e,type:t,content:s}))})},[K,e,i,u,x,eS,ei,ed]),eH=(0,r.useCallback)(()=>{(0,eo.e)(),d?.()},[d]),eq=(0,r.useCallback)(e=>{let t=e.action||"send",[s,n]=t.split(":");if("modal"===s){eL.current?.blur(),f?.(n);return}if("clear"===s){i?.("/clear",{force:!0}),O("");return}if("setMode"===s){p?.(e.mode),O("");return}if("send"===s||"send"===t){i?.(e.name),O("");return}eL.current?.focus()},[f,i,p]),eU=(0,r.useCallback)(e=>{(0,eo.e)();let t=/(?:^|\s)([/@][\w\d_.-]*)$/.exec(K);if(!t)return;let s=t[1],n=K.slice(0,K.length-s.length),r="/"===X&&e.action?.startsWith("modal:"),l="@"===X?`@${e.name} `:`${e.name} `;(O(r?n:`${n}${l}`),V(!1),"/"!==X)?eL.current?.focus():"submenu"===e.action&&Array.isArray(e.subOptions)&&e.subOptions.length>0?B&&("effort"===e.optionKey||"variant"===e.optionKey)?O(""):(er(e),et(0),V(!0)):eq(e)},[K,X,eq,B]),eV=(0,r.useCallback)(e=>{(0,eo.e)(),es&&(h?.(es.optionKey,e.value),er(null),V(!1),O(""),eL.current?.focus())},[es,h]),eX=(0,r.useCallback)(e=>{(0,eo.e)();let t=/(?:^|\s)(\S*)$/.exec(K),s=t?t[1]:"";O(K.slice(0,K.length-s.length)+e),ea(-1),eL.current?.focus()},[K]),eG=e=>String(e||"").toLowerCase().replace(/\[[^\]]*\]$/,""),eJ=(0,r.useMemo)(()=>{if(!F)return null;let e=z||[],t=eG(F);return e.find(e=>e.id===F)||e.find(e=>eG(e.id)===t)||e.find(e=>eG(e.id).split("/").pop()===t.split("/").pop())||null},[F,z]),eY=eJ?.short||eJ?.label||F||"Model",eZ=L||S.defaultEffort||"",eQ=(0,r.useMemo)(()=>{let e=[...z||[]];return F&&!e.some(e=>e.id===F)&&e.unshift({id:F,label:F,short:F}),e},[z,F]),e2=(0,r.useMemo)(()=>{if(eQ.length<=20)return eQ;let e=eh.trim().toLowerCase();return e?eQ.filter(t=>{let s=(t.id||"").toLowerCase();return(t.label||"").toLowerCase().includes(e)||s.includes(e)||(t.provider||"").toLowerCase().includes(e)}):eQ},[eQ,eh]),e5=(0,r.useMemo)(()=>eQ.length<=20?[{key:"all",title:"",items:eQ}]:iG(eQ,e2,F,eh.trim()),[eQ,e2,F,eh]),e3=(0,r.useMemo)(()=>(R||[]).find(e=>"submenu"===e.action&&("effort"===e.optionKey||"variant"===e.optionKey)),[R]),e4=(0,r.useMemo)(()=>{let e=(eJ?.efforts||[]).map(e=>({value:e,label:e}));return e.length>0?e:e3?.subOptions||[]},[e3,eJ]);return(0,n.jsxs)("div",{className:"relative px-3 py-1.5 bg-transparent border-t border-border-subtle/40 select-none",children:[U&&es&&(0,n.jsxs)("div",{ref:eB,className:"absolute left-3 right-3 bottom-[calc(100%+6px)] max-h-52 bg-surface border border-border-subtle rounded-brand shadow-lg overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsxs)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1 flex items-center justify-between",children:[(0,n.jsxs)("span",{children:[es.name," — ",es.optionKey]}),(0,n.jsx)("button",{type:"button",onClick:()=>{er(null),V(!1),O("")},className:"text-text-muted hover:text-text",children:(0,n.jsx)(en.X,{size:11})})]}),(es.subOptions||[]).map((e,t)=>(0,n.jsxs)("div",{"data-menu-item":"true",onClick:()=>eV(e),onMouseEnter:()=>et(t),className:`px-2 py-1 rounded-brand flex items-center justify-between text-xs cursor-pointer ${t===ee?"bg-surface-2 text-text font-medium":"text-text-muted hover:text-text"}`,children:[(0,n.jsx)("span",{className:"font-mono text-xs text-text",children:e.label}),e.desc&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted truncate ml-2 max-w-[55%]",children:e.desc})]},e.value))]}),U&&!es&&Z.length>0&&(0,n.jsxs)("div",{ref:eB,className:"absolute left-3 right-3 bottom-[calc(100%+6px)] max-h-52 bg-surface border border-border-subtle rounded-brand shadow-lg overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"/"===X?"Slash Commands & Skills":"Files in repo (@)"}),Z.map((e,t)=>{let s=B&&("/model"===e.name||"submenu"===e.action&&("effort"===e.optionKey||"variant"===e.optionKey));return(0,n.jsxs)("div",{"data-menu-item":"true",onClick:s?void 0:()=>eU(e),onMouseEnter:()=>et(t),className:`px-2 py-1 rounded-brand flex items-center justify-between text-xs ${s?"opacity-40 cursor-not-allowed":t===ee?"bg-surface-2 text-text font-medium cursor-pointer":"text-text-muted hover:text-text cursor-pointer"}`,title:s?"Cannot change while turn is running":void 0,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 truncate",children:[e.isSkill?(0,n.jsx)(en.Kq,{size:12,className:"text-warning shrink-0"}):"/"===X?(0,n.jsx)(en.BK,{size:12,className:"text-accent shrink-0"}):(0,n.jsx)(en.GD,{size:12,className:"text-accent shrink-0"}),(0,n.jsx)("span",{className:"font-mono text-xs text-text",children:e.name}),e.isSkill&&(0,n.jsx)("span",{className:"text-[9px] px-1 rounded bg-warning/15 text-warning font-mono",children:"skill"}),"submenu"===e.action&&(0,n.jsx)(en.rX,{size:11,className:"text-text-muted shrink-0 rotate-90"})]}),e.description&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted truncate ml-2 max-w-[50%]",children:e.description})]},e.name)})]}),W.length>0&&(0,n.jsx)("div",{className:"mb-1 space-y-0.5",children:W.map((e,t)=>(0,n.jsxs)("div",{className:"px-2 py-0.5 rounded bg-brand-500/10 border border-brand-500/30 flex items-center justify-between text-xs animate-in fade-in duration-100",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-mono text-[9px] uppercase tracking-wider font-semibold px-1 rounded bg-brand-500/20 text-brand-400 shrink-0",children:0===t?"Next":`Queued ${t+1}`}),(0,n.jsx)("span",{className:"truncate text-text font-mono text-[11px]",children:e.text}),e.attachments?.length>0&&(0,n.jsxs)("span",{className:"shrink-0 text-text-muted flex items-center gap-0.5 font-mono text-[10px]",children:[(0,n.jsx)(en.xv,{size:10}),e.attachments.length]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0 ml-2",children:[0===t&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),eH()},className:"text-text-muted hover:text-brand-400 p-1 rounded hover:bg-surface-2 transition-colors cursor-pointer",title:"Send now (stops the current turn)",children:(0,n.jsx)(en.Vn,{size:13})}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),o?.(e.id)},className:"text-text-muted hover:text-text p-1 rounded hover:bg-surface-2 transition-colors cursor-pointer",title:"Remove from queue",children:(0,n.jsx)(en.X,{size:14})})]})]},e.id))}),(0,n.jsx)(t5,{voice:eM,onDone:ez,onCancel:eP,className:"mb-1.5"}),(0,n.jsxs)("div",{className:"relative rounded-brand border border-border-subtle/80 bg-transparent focus-within:border-brand-500 transition-colors px-2.5 py-1 flex flex-col gap-1",children:[eC.length>0&&(0,n.jsx)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x pt-0.5",children:eC.map(e=>(0,n.jsxs)("div",{className:"relative flex-shrink-0 group",children:[e.isImage?(0,n.jsx)("img",{src:`data:${e.type};base64,${e.content}`,alt:e.name,className:"w-10 h-10 object-cover rounded border border-border-subtle"}):(0,n.jsxs)("div",{className:"w-10 h-10 flex flex-col items-center justify-center rounded border border-border-subtle bg-surface-2 px-1",children:[(0,n.jsx)(en.xv,{size:12,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-[8px] text-text-muted truncate w-full text-center",children:e.name})]}),(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>eE(e.id),className:"absolute -top-1.5 -right-1.5 w-4 h-4 flex items-center justify-center bg-surface-3 rounded-full text-text-muted hover:text-text border border-border-subtle","aria-label":"Remove attachment",children:(0,n.jsx)(en.X,{size:10})})]},e.id))}),(0,n.jsx)(t$,{value:K,store:tk,isMobile:!N,activeIndex:el,onSelect:eX}),(0,n.jsxs)("div",{className:"flex items-start gap-1",children:[(0,n.jsx)("textarea",{ref:eL,value:K,onPaste:eT,onChange:e=>{if(Date.now()-eW.current<200){eL.current&&(eL.current.value="");return}O(e.target.value),ea(-1)},onFocus:()=>b?.(),onKeyDown:t=>{if(w||t.nativeEvent?.isComposing||229===t.keyCode)return;if(t.shiftKey&&"Tab"===t.key){t.preventDefault(),t.stopPropagation(),(0,eo.e)();let e=E||[];if(e.length>0){let t=e.findIndex(e=>e.id===D),s=-1===t?0:(t+1)%e.length,n=e[s]?.id;n&&p?.(n)}return}if("Escape"===t.key){if(es){t.preventDefault(),er(null),V(!1),O("");return}if(U){t.preventDefault(),V(!1);return}if(B){t.preventDefault(),console.log("[TEMP DIAGNOSTIC] Esc → stop",{sessionId:e}),eH();return}if(W.length>0){t.preventDefault(),c?.();return}}if(es){let e=es.subOptions||[];if("ArrowDown"===t.key){t.preventDefault(),et(t=>(t+1)%e.length);return}if("ArrowUp"===t.key){t.preventDefault(),et(t=>(t-1+e.length)%e.length);return}if("Enter"===t.key||"Tab"===t.key){t.preventDefault(),eV(e[ee]);return}}if(U&&Z.length>0){if("ArrowDown"===t.key){t.preventDefault(),et(e=>(e+1)%Z.length);return}if("ArrowUp"===t.key){t.preventDefault(),et(e=>(e-1+Z.length)%Z.length);return}if("Enter"===t.key||"Tab"===t.key){t.preventDefault(),eU(Z[ee]);return}}if(em.length>0){let e=el<0?-1:(el%em.length+em.length)%em.length;if("Tab"===t.key&&!t.shiftKey){t.preventDefault(),ea(-1===e?0:(e+1)%em.length);return}if(("Enter"===t.key||"Tab"===t.key)&&-1!==e){t.preventDefault(),eX(em[e].cmd);return}}let s=eL.current,n=s?.selectionStart??0,r=s?.value??"",l=-1===r.lastIndexOf("\n",n-1),a=-1===r.indexOf("\n",n);if("ArrowUp"===t.key&&!es&&!U&&l&&eu.length>0){t.preventDefault(),-1===_&&(q.current=K);let e=Math.min(_+1,eu.length-1);if(e===_)return;H(e),O(eu[e]);return}if("ArrowDown"===t.key&&!es&&!U&&a&&-1!==_){t.preventDefault();let e=_-1;e<0?(H(-1),O(q.current)):(H(e),O(eu[e]));return}if("Enter"===t.key&&(t.metaKey||t.ctrlKey)){t.preventDefault(),e_();return}"Enter"===t.key&&!t.shiftKey&&N&&(t.preventDefault(),e_())},onCompositionStart:()=>{eF.current=!0},onCompositionEnd:()=>{eF.current=!1,eK.current=Date.now(),Date.now()-eW.current<200&&(eL.current&&(eL.current.value=""),O(""))},placeholder:B?N?"Type command \xb7 Enter to queue \xb7 Esc to stop":"Type command \xb7 Send to queue":N?`Type command \xb7 ${C}`:"Type command",rows:1,className:"ai-conversation ai-composer-input flex-1 min-w-0 bg-transparent resize-none text-xs text-text placeholder-text-muted focus:outline-none custom-scrollbar leading-snug min-h-[24px]"}),K.trim().length>0?(0,n.jsx)("button",{type:"button",onClick:eA,className:"shrink-0 mt-0.5 p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center justify-center",title:"Clear input",children:(0,n.jsx)(en.X,{size:16})}):(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),ek(!0)},className:"shrink-0 mt-0.5 p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center justify-center",title:j("history.title"),children:(0,n.jsx)(en.BZ,{size:16})})]}),(0,n.jsxs)("div",{className:"relative flex items-center justify-between text-xs pt-0.5 border-t border-border-subtle/30",children:[(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:(0,n.jsxs)("div",{ref:eN,className:"relative min-w-0 flex items-center gap-1",children:[(0,n.jsxs)("button",{type:"button",disabled:B,onClick:()=>{ef(!ep),ep||eb(""),ew(!1)},className:"min-w-0 px-1.5 py-0.5 rounded text-[11px] font-medium flex items-center gap-1 font-mono text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",title:B?"Cannot change model while turn is running":"Select model (/model)",children:[(0,n.jsx)("img",{src:e1(`${t}-ui`),alt:"",className:`w-3.5 h-3.5 object-contain shrink-0 ${e0}`}),(0,n.jsx)("span",{dir:"rtl",className:"truncate min-w-0",children:(0,n.jsx)("bdi",{children:eY})}),(0,n.jsx)(en.rX,{size:11,className:`text-text-muted shrink-0 transition-transform ${ep?"":"rotate-180"}`})]}),ep&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[260px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"Select Model"}),eQ.length>20&&(0,n.jsxs)("div",{className:"px-1.5 pb-1.5 mb-1 border-b border-border-subtle flex items-center gap-1.5 text-text-muted",children:[(0,n.jsx)(en.vj,{size:12,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:eh,onChange:e=>eb(e.target.value),placeholder:"Search models...",autoFocus:!0,className:"w-full bg-transparent text-[11px] text-text placeholder-text-muted/70 focus:outline-none py-0.5"})]}),0===e2.length&&(0,n.jsxs)("div",{className:"px-2 py-2 text-[11px] text-text-muted",children:['No models match "',eh,'"']}),e5.map(e=>(0,n.jsxs)("div",{children:[e5.length>1&&(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.key,void ev(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},"aria-expanded":!eg.has(e.key),className:"w-full px-2 py-0.5 text-[10px] font-mono uppercase tracking-wider font-semibold text-text flex items-center justify-between select-none border-b border-border-subtle mb-1 mt-1 first:mt-0",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-[8px]",children:eg.has(e.key)?"▶":"▼"}),e.title]}),(0,n.jsx)("span",{className:"text-[9px] text-text-subtle",children:e.items.length})]}),!eg.has(e.key)&&e.items.map(e=>{let t=F===e.id;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),m?.(e.id),ef(!1)},title:e.id,className:`w-full pl-4 pr-2 py-1.5 rounded text-left text-xs flex flex-col gap-0.5 transition-colors ${t?"bg-surface-2 text-text font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsxs)("span",{className:"w-full flex items-center justify-between",children:[(0,n.jsx)("span",{className:"truncate",children:e.label}),t&&(0,n.jsx)(en.aJ,{size:12,className:"text-text shrink-0 ml-1"})]}),e.label!==e.id&&(0,n.jsx)("span",{className:"truncate font-mono text-[10px] text-text-subtle",children:e.id})]},e.id)})]},e.key))]}),e4.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:B,onClick:()=>{ew(e=>!e),ef(!1)},className:"shrink-0 px-1 py-0.5 rounded text-[10px] uppercase tracking-wide font-mono text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",title:B?`Cannot change ${e3?.optionKey||"effort"} while turn is running`:`Select ${e3?.optionKey||"effort"}`,children:eZ||"—"}),ey&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[220px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:e3?.optionKey==="variant"?"Variant":"Reasoning effort"}),e4.map(e=>{let t=eZ===e.value;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),h?.(e3?.optionKey||"effort",e.value),ew(!1)},className:`w-full px-2 py-1.5 rounded text-left text-xs flex items-center justify-between gap-2 transition-colors ${t?"bg-brand-500/15 text-brand-400 font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),t&&(0,n.jsx)(en.aJ,{size:12,className:"text-brand-400 shrink-0"}),!t&&e.desc&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle truncate max-w-[55%]",children:e.desc})]},e.value)})]})]})]})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 pl-1.5",children:[(0,n.jsxs)("label",{className:"p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer flex items-center justify-center",title:"Attach file or image",children:[(0,n.jsx)(en.xv,{size:15}),(0,n.jsx)("input",{type:"file",multiple:!0,onChange:eR,className:"hidden",accept:"*/*"})]}),eM.active&&(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:eI,title:j("not-allowed"===eM.error||"service-not-allowed"===eM.error?"voice.denied":"voice.dictate"),"aria-label":j("voice.dictate"),className:`p-1.5 rounded flex items-center justify-center transition-colors ${eM.listening?"bg-red-500/90 text-white animate-pulse":eM.error?"text-red-400":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:eM.listening?(0,n.jsx)(en.jj,{size:15}):(0,n.jsx)(en.GO,{size:15})}),B?(0,n.jsxs)(n.Fragment,{children:[(K.trim()||eC.length>0)&&(0,n.jsxs)("button",{type:"button",onClick:e_,className:"px-2 py-0.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 text-[11px] font-medium transition-colors shadow-sm cursor-pointer",title:N?"Queue message (Enter)":"Queue message",children:[(0,n.jsx)(en.Vn,{size:13}),(0,n.jsx)("span",{children:"Queue"})]}),(0,n.jsx)("button",{type:"button",onClick:eH,className:"px-2 py-0.5 rounded bg-danger/20 hover:bg-danger/30 text-danger flex items-center gap-1 text-[11px] font-medium transition-colors cursor-pointer",title:W.length?"Stop & run the next queued message (Esc)":"Stop generation (Esc)",children:(0,n.jsx)(en.M6,{size:13,className:"fill-current"})})]}):(0,n.jsx)("button",{type:"button",onClick:e_,disabled:!K.trim()&&0===eC.length,className:`px-2 py-1 rounded transition-colors flex items-center justify-center ${K.trim()||eC.length>0?"bg-brand-500 hover:bg-brand-600 text-white shadow-sm cursor-pointer":"text-text-muted bg-surface-2 cursor-not-allowed opacity-40"}`,title:"Send (Enter)",children:(0,n.jsx)(en.Vn,{size:14})})]})]})]}),(0,n.jsx)(tC,{isOpen:ej,store:tk,onSelect:eX,onClose:()=>ek(!1)})]})}),iZ={Shield:"text-text-muted",Pencil:"text-accent",Eye:"text-accent",Sparkles:"text-warning"},iQ=(0,r.memo)(function({sessionId:e="",sessionName:t="",engine:s="claude",workspacePath:l="",fileBus:a=null,isTurnRunning:i=!1,isDesktop:o=!0,onModeChange:c,onNewChat:d}){let u=a7(t=>t.bySession[e]?.isTurnRunning),x=a7(t=>t.bySession[e]?.metadata),m=x?.goal,p=(0,aT.Tw)(s).permissionModes||[],f=a7(t=>t.bySession[e]?.permissionMode)||(0,aT.Tw)(s).defaultMode,{branch:h,dirty:b}=n8(l,a,{enabled:!!a&&!!l}),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=e=>{y.current&&!y.current.contains(e.target)&&v(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let w=p.find(e=>e.id===f)||p[0];return(0,n.jsxs)("div",{className:`relative min-h-6 px-3 bg-surface/50 border-t border-border-subtle/50 flex items-center text-[11px] font-mono text-text-muted select-none flex-shrink-0 z-20 gap-3${o?"":" safe-area-bottom"}`,children:[(void 0!==u?u:i)&&(0,n.jsx)(av,{className:"hidden sm:block"}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[w&&p.length>0&&(0,n.jsxs)("div",{ref:y,className:"relative",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),v(e=>!e)},className:"hover:text-text flex items-center gap-1 transition-colors",title:"Change permission mode (Shift+Tab)",children:[(0,n.jsx)(en.Ay,{name:w.icon||"Shield",size:11,className:`${iZ[w.icon]||"text-text-muted"} shrink-0`}),(0,n.jsx)("span",{children:w.label}),(0,n.jsx)(en.rX,{size:11,className:`text-text-muted transition-transform ${g?"":"rotate-180"}`})]}),g&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[220px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"Permission Mode"}),p.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),c?.(e.id),v(!1)},className:`w-full px-2 py-1.5 rounded text-left text-xs flex flex-col gap-0.5 transition-colors cursor-pointer ${f===e.id?"bg-brand-500/15 text-brand-400 font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(en.Ay,{name:e.icon||"Shield",size:12,className:`${iZ[e.icon]||"text-text-muted"} shrink-0`}),(0,n.jsx)("span",{children:e.label})]}),f===e.id&&(0,n.jsx)(en.aJ,{size:12,className:"text-brand-400 shrink-0"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted/70 font-normal font-sans leading-tight",children:e.desc})]},e.id))]})]}),m?.objective&&(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",title:`Goal (${m.status}): ${m.objective}`,children:[(0,n.jsx)(en.We,{size:11,className:`shrink-0 ${"active"===m.status?"text-danger":"text-text-muted"}`}),(0,n.jsx)("span",{className:"truncate max-w-[22ch]",children:m.objective})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 shrink-0",children:[h&&!(0,eV.ok)(h)&&(0,n.jsx)(n9,{branch:h,dirty:b,size:11,className:"text-text font-medium",iconClassName:"text-brand-500 opacity-100"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),d?.()},className:"hover:text-text flex items-center transition-colors p-0.5 rounded hover:bg-surface-2",title:"New chat",children:(0,n.jsx)(en.J4,{size:12})})]})]})}),i0=(0,r.memo)(function({skills:e=[],onClose:t,onSelectSkill:s}){let[l,a]=(0,r.useState)(""),i=e.filter(e=>{let t=l.toLowerCase();return(e.name||e.id||"").toLowerCase().includes(t)||(e.description||"").toLowerCase().includes(t)});return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.Kq,{size:14}),title:`Agent Skills (${e.length})`,subtitle:"Skills loaded from ~/.claude/skills and project directory",onClose:t,children:[(0,n.jsx)("div",{className:"p-3 border-b border-border-subtle bg-bg",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-brand bg-surface border border-border-subtle focus-within:border-brand-500",children:[(0,n.jsx)(en.vj,{size:14,className:"text-text-muted shrink-0"}),(0,n.jsx)("input",{type:"text",value:l,onChange:e=>a(e.target.value),placeholder:"Search skills (e.g. cloudflare, review, deploy)...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted focus:outline-none",autoFocus:!0})]})}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.Kq,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:0===e.length?"No skills discovered on host agent.":`No skills matching "${l}".`})]}):i.map(e=>(0,n.jsxs)("div",{onClick:()=>{(0,eo.e)(),s?.(e.name||e.id),t?.()},className:"modal-row items-start",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1 flex flex-col gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 font-mono text-xs font-semibold text-text",children:[(0,n.jsxs)("span",{children:["/",e.name||e.id]}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-3 text-text-muted font-normal",children:"skill"})]}),e.description&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted leading-relaxed line-clamp-2",children:e.description})]}),(0,n.jsxs)("span",{className:"modal-row-acts text-[11px] text-brand-500 items-center gap-1",children:[(0,n.jsx)("span",{children:"Use"}),(0,n.jsx)(en.Lt,{size:11})]})]},e.id||e.name))})]})}),i1=(0,r.memo)(function({mcpServers:e=[],onClose:t}){return(0,n.jsx)(nl,{icon:(0,n.jsx)(en.lP,{size:14}),iconClass:"bg-sky-500/15 text-sky-400",title:`MCP Servers (${e.length})`,subtitle:"Model Context Protocol tools and integrations",onClose:t,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===e.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.lP,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:"No MCP servers configured yet."})]}):e.map((e,t)=>(0,n.jsxs)("div",{className:"modal-row",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"text-xs font-semibold text-text flex items-center gap-2",children:[(0,n.jsx)(en.Jl,{size:13,className:"text-emerald-400 shrink-0"}),(0,n.jsx)("span",{className:"font-mono",children:e.name||e.id})]}),e.command&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted font-mono break-all mt-1",children:e.command})]}),(0,n.jsx)("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-emerald-500/15 text-emerald-300 border border-emerald-500/30 uppercase shrink-0 ml-2",children:e.status||"active"})]},e.id||t))})})}),i2=(0,r.memo)(function({currentModel:e="",currentEffort:t="",models:s=[],onClose:l,onSelectModel:a,onSelectEffort:i,isTurnRunning:o=!1}){let[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(e),[m,p]=(0,r.useState)(()=>new Set),f=(0,r.useMemo)(()=>{let t=[...s||[]];return e&&!t.some(t=>t.id===e)&&t.unshift({id:e,label:e,desc:"Active CLI model",recent:!0}),t},[s,e]),h=f.find(e=>e.id===u),b=h?.efforts||[],g=(0,r.useMemo)(()=>{let e=c.trim().toLowerCase();return e?f.filter(t=>{let s=(t.label||"").toLowerCase(),n=(t.id||"").toLowerCase(),r=(t.desc||"").toLowerCase(),l=iX(t).toLowerCase();return s.includes(e)||n.includes(e)||r.includes(e)||l.includes(e)}):f},[f,c]),v=(0,r.useMemo)(()=>iG(f,g,e,c.trim()),[f,g,e,c]);return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.cC,{size:14}),title:"Switch AI Model",subtitle:"Select an active model for this session",maxWidth:"max-w-md",onClose:l,children:[(0,n.jsx)("div",{className:"px-4 py-2.5 border-b border-border-subtle shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 focus-within:text-text text-text-muted",children:[(0,n.jsx)(en.vj,{size:14,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Search models...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted/70 focus:outline-none",autoFocus:!0}),c&&(0,n.jsx)("button",{type:"button",onClick:()=>d(""),className:"text-text-muted hover:text-text shrink-0 text-xs px-1","aria-label":"Clear search",children:"✕"})]})}),b.length>0&&(0,n.jsxs)("div",{className:"px-3 pt-3 shrink-0",children:[(0,n.jsx)("div",{className:"text-[10px] font-mono uppercase tracking-wider text-text-muted mb-1.5",children:"Reasoning effort"}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:b.map(e=>(0,n.jsx)("button",{type:"button",disabled:o,onClick:()=>{(0,eo.e)(),i?.(e)},className:`px-2.5 py-1 rounded-brand text-[11px] font-mono border transition-colors ${t===e?"border-brand-500 bg-brand-500/10 text-brand-400":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"} disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent`,title:o?"Cannot change effort while turn is running":void 0,children:e},e))})]}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===g.length?(0,n.jsxs)("div",{className:"py-8 text-center text-xs text-text-muted",children:['No models found matching "',c,'"']}):v.map(e=>(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 mb-2",children:[v.length>1&&(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.key,void p(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},"aria-expanded":!m.has(e.key),className:"w-full text-left text-[10px] font-mono uppercase tracking-wider font-semibold text-text px-2 pt-2 pb-1 select-none flex items-center justify-between border-b border-border-subtle",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-[8px]",children:m.has(e.key)?"▶":"▼"}),e.title]}),(0,n.jsx)("span",{className:"text-text-subtle text-[9px]",children:e.items.length})]}),!m.has(e.key)&&e.items.map(s=>{var r;let l=u===s.id,c=iX(s),d=(r=s.contextWindow)&&!(r<=0)?r>=1e6?`${Math.round(r/1e5)/10}M`:r>=1e3?`${Math.round(r/1e3)}k`:`${r}`:null;return(0,n.jsxs)("div",{onClick:o?void 0:()=>(e=>{(0,eo.e)(),a?.(e),x(e);let s=f.find(t=>t.id===e),n=s?.efforts||[];if(n.length>0&&!n.includes(t)){let e=s?.defaultEffort||n[0];e&&i?.(e)}})(s.id),"data-selected":l,className:`modal-row ml-2 ${o?"opacity-40 cursor-not-allowed pointer-events-none":""}`,title:o?"Cannot change model while turn is running":s.id,children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:`text-xs flex items-center gap-1.5 flex-wrap ${l?"text-text font-semibold":"text-text-muted"}`,children:[(0,n.jsx)("span",{className:"truncate",children:s.label||s.id}),"opencode"===c&&(0,n.jsx)("span",{className:"text-[9px] px-1.5 py-0.2 rounded bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 font-mono shrink-0",children:"Free"}),d&&(0,n.jsx)("span",{className:"text-[9px] px-1 py-0.2 rounded bg-surface-2/60 text-text-subtle font-mono shrink-0",children:d}),s.efforts?.length>0&&(0,n.jsx)("span",{className:"text-[9px] px-1 py-0.2 rounded bg-brand-500/10 text-brand-400 font-mono shrink-0",children:"reasoning"})]}),(s.desc||s.label!==s.id&&s.id)&&(0,n.jsx)("div",{className:"text-[10px] font-mono text-text-subtle truncate mt-0.5",children:s.desc||s.id})]}),l&&(0,n.jsx)(en.aJ,{size:14,className:"text-text shrink-0"})]},`${e.key}-${s.id}`)})]},e.key))})]})}),i5=(0,r.memo)(function({engine:e="claude",workspacePath:t="",bus:s=null,onClose:l,onResume:a}){let[i,o]=(0,r.useState)([]),[c,d]=(0,r.useState)(!0),[u,x]=(0,r.useState)(""),m=(0,r.useCallback)(()=>{if(!s?.emit||!t){o([]),d(!1);return}d(!0),s.emit("getAgentSessions",{cwd:t},e=>{o(Array.isArray(e?.sessions)?e.sessions:[]),d(!1)})},[t]);(0,r.useEffect)(()=>{m()},[m]);let p=(0,r.useMemo)(()=>{let t=u.toLowerCase();return i.filter(t=>!e||t.agent===e).filter(e=>!t||(e.title||"").toLowerCase().includes(t)||(e.sessionId||"").toLowerCase().includes(t))},[i,e,u]);return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.BZ,{size:14}),iconClass:"bg-sky-500/15 text-sky-400",title:"Resume a session",subtitle:`Past ${e} conversations in this project`,maxWidth:"max-w-xl",onClose:l,children:[(0,n.jsx)("div",{className:"px-4 py-2.5 border-b border-border-subtle shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 focus-within:text-text text-text-muted",children:[(0,n.jsx)(en.vj,{size:14,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:u,onChange:e=>x(e.target.value),placeholder:"Search sessions...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted/70 focus:outline-none",autoFocus:!0}),(0,n.jsx)("button",{type:"button",onClick:m,className:"hover:text-text shrink-0",title:"Refresh",children:(0,n.jsx)(en.e9,{size:13,className:c?"animate-spin":""})})]})}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:c?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-text-muted",children:[(0,n.jsx)(en.kr,{size:14,className:"animate-spin"}),(0,n.jsx)("span",{children:"Scanning conversations..."})]}):0===p.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.BZ,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:0===i.length?"No past conversations found for this project.":`No sessions matching "${u}".`})]}):p.map(e=>{let t=!!e.openSessionId;return(0,n.jsxs)("div",{onClick:()=>{if((0,eo.e)(),t){window.dispatchEvent(new CustomEvent(eV.vP,{detail:{sessionId:e.openSessionId}})),l?.();return}(0,eo.e)(),a?.(e),l?.()},className:"modal-row",title:e.sessionId,children:[(0,n.jsx)("img",{src:e1("ui"===e.mode?`${e.agent}-ui`:e.agent),alt:e.agent,className:`shrink-0 ${e0} ${t?"":"opacity-50"}`,style:{width:14,height:14}}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-xs ${t?"text-text font-medium":"text-text-muted"}`,children:e.title||"Untitled conversation"}),e.updatedAt?(0,n.jsx)("span",{className:"shrink-0 text-[10px] font-mono text-text-subtle tabular-nums",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m ago`;let s=Math.round(t/60);return s<24?`${s}h ago`:`${Math.round(s/24)}d ago`}(e.updatedAt)}):null]},`${e.agent}:${e.sessionId}`)})})]})}),i3={claude:{shape:"flat",items:[]},codex:{shape:"flat",items:[{key:"personality",kind:"menu",label:"Personality",desc:"Communication style codex is instructed to use",choices:[{value:"",label:"Default"},...aT.Mm],default:""},{key:"networkAccess",kind:"bool",label:"Network access",desc:"Let sandboxed commands reach the network",default:!1},{key:"planEffort",kind:"menu",label:"Plan mode reasoning",desc:"Reasoning tier used while in plan mode",choices:[{value:"",label:"Default"},{value:"low",label:"low"},{value:"medium",label:"medium"},{value:"high",label:"high"},{value:"xhigh",label:"xhigh"}],default:""},{key:"addDirs",kind:"list",label:"Extra writable directories",desc:"Absolute paths, comma-separated",default:[]},{key:"enable",kind:"list",label:"Enable features",desc:"Feature names, comma-separated (see `codex features list`)",default:[]},{key:"disable",kind:"list",label:"Disable features",desc:"Feature names, comma-separated",default:[]},{key:"skipGitRepoCheck",kind:"bool",label:"Allow outside a git repo",desc:"Run in a directory without a repository",default:!1},{key:"ephemeral",kind:"bool",label:"Ephemeral run",desc:"Do not persist the session to disk",default:!1}]},opencode:{shape:"flags",items:[{key:"pure",kind:"bool",label:"Pure mode",desc:"Run without external plugins",default:!1},{key:"printLogs",kind:"bool",label:"Print logs",desc:"Show CLI logs on stderr",default:!1}]}};function i4(e){return i3[e]||{shape:"flat",items:[]}}let i6=(0,r.memo)(function({engine:e="claude",options:t,onClose:s,onApply:l}){let{shape:a,items:i}=i4(e),[o,c]=(0,r.useState)(()=>{let s,n;return s=i4(e).items,n=t||{},Object.fromEntries(s.map(e=>[e.key,void 0!==n[e.key]?n[e.key]:e.default]))}),d=(e,t)=>c(s=>({...s,[e]:t}));return(0,n.jsx)(nl,{icon:(0,n.jsx)(en.wB,{size:14}),iconClass:"bg-surface-3 text-text-muted",title:"Configuration",subtitle:`Runtime flags for ${e}`,maxWidth:"max-w-md",onClose:s,footer:i.length>0?(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border-subtle flex justify-end gap-2 shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"px-3 py-1.5 rounded-brand text-xs text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)();let e={};for(let t of i){let s=o[t.key];"list"===t.kind?e[t.key]=String(s||"").split(",").map(e=>e.trim()).filter(Boolean):e[t.key]=s}l?.("flags"===a?{flags:e}:e),s?.()},className:"px-3 py-1.5 rounded-brand text-xs bg-brand-500 hover:bg-brand-600 text-white font-medium transition-colors",children:"Apply"})]}):null,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-2 custom-scrollbar",children:0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.wB,{size:32,className:"opacity-50"}),(0,n.jsxs)("span",{className:"text-sm",children:["No runtime flags are configurable for ",e,"."]})]}):i.map(e=>(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-surface-2/50",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text",children:e.label}),(0,n.jsx)("div",{className:"text-[11px] text-text-muted",children:e.desc})]}),"bool"===e.kind&&(0,n.jsx)("input",{type:"checkbox",checked:!!o[e.key],onChange:()=>d(e.key,!o[e.key]),className:"w-4 h-4 accent-brand-500 rounded shrink-0"})]}),"menu"===e.kind&&(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-2",children:e.choices.map(t=>(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),d(e.key,t.value)},className:`px-2.5 py-1 rounded-brand text-[11px] border transition-colors ${o[e.key]===t.value?"border-brand-500 bg-brand-500/10 text-brand-400":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"}`,children:t.label},t.value))}),"list"===e.kind&&(0,n.jsx)("input",{type:"text",value:Array.isArray(o[e.key])?o[e.key].join(", "):o[e.key]||"",onChange:t=>d(e.key,t.target.value),placeholder:"/path/one, /path/two",className:"mt-2 w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs font-mono text-text placeholder-text-muted focus:outline-none focus:border-brand-500"})]},e.key))})})}),i8={Shield:"text-text-muted",Pencil:"text-accent",Eye:"text-accent",Sparkles:"text-warning"},i9=(0,r.memo)(function({modes:e=[],currentMode:t="",onClose:s,onSelectMode:r}){return(0,n.jsx)(nl,{icon:(0,n.jsx)(en.Ay,{name:"Shield",size:14}),title:"Permissions",subtitle:"What the agent may do without asking",maxWidth:"max-w-md",onClose:s,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:e.map(e=>{let l=t===e.id;return(0,n.jsxs)("div",{onClick:()=>{var t;return t=e.id,void((0,eo.e)(),r?.(t),s?.())},"data-selected":l,className:"modal-row",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[(0,n.jsx)(en.Ay,{name:e.icon||"Shield",size:14,className:`${i8[e.icon]||"text-text-muted"} shrink-0`}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text",children:e.label}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle",children:e.desc})]})]}),l&&(0,n.jsx)(en.aJ,{size:14,className:"text-brand-500 shrink-0"})]},e.id)})})})}),i7=(0,r.memo)(function({engine:e="claude",workspacePath:t="",bus:s=null,onClose:l}){let[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!0),d=(0,r.useCallback)(()=>{if(!s?.emit){i({error:"Not connected to the host agent."}),c(!1);return}c(!0),s.emit("ai:doctor",{engine:e,cwd:t},e=>{i(e?.ok?{output:e.output||"",version:e.version||""}:{error:e?.error||"Doctor check failed."}),c(!1)})},[e,t]);return(0,r.useEffect)(()=>{d()},[d]),(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.mN,{size:14}),iconClass:"bg-emerald-500/15 text-emerald-400",title:"Diagnostics",subtitle:`Health check for the ${e} CLI`,onClose:l,children:[(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto custom-scrollbar",children:o?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-8 text-xs text-text-muted",children:[(0,n.jsx)(en.kr,{size:14,className:"animate-spin"}),(0,n.jsxs)("span",{children:["Running ",e," doctor..."]})]}):a?.error?(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-danger/10 border border-danger/30 text-danger text-xs flex items-start gap-2",children:[(0,n.jsx)(en.RI,{size:14,className:"shrink-0 mt-0.5"}),(0,n.jsx)("span",{children:a.error})]}):(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-emerald-500/10 border border-emerald-500/30 text-emerald-300 text-xs flex items-center gap-2",children:[(0,n.jsx)(en.Jl,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"font-medium",children:a?.version?`${e} ${a.version}`:`${e} environment report`})]}),(0,n.jsx)("pre",{className:"p-3 rounded-brand bg-bg border border-border-subtle text-[11px] font-mono text-text-muted whitespace-pre-wrap break-words leading-relaxed",children:a?.output||"No output."})]})}),(0,n.jsx)("div",{className:"px-4 py-3 border-t border-border-subtle flex justify-end shrink-0",children:(0,n.jsxs)("button",{type:"button",onClick:d,disabled:o,className:"px-3 py-1.5 rounded-brand text-xs text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-1.5 disabled:opacity-50",children:[(0,n.jsx)(en.e9,{size:12,className:o?"animate-spin":""}),(0,n.jsx)("span",{children:"Re-run"})]})})]})}),oe={completed:{icon:en.Jl,cls:"text-emerald-400",line:"line-through text-text-muted"},in_progress:{icon:en.kr,cls:"text-sky-400 animate-spin",line:"text-sky-300 font-semibold"},pending:{icon:en.jl,cls:"text-text-muted",line:"text-text"}},ot=(0,r.memo)(function({tasks:e=[],onClose:t}){let s=e.length,r=e.filter(e=>"completed"===e.status).length,l=e.filter(e=>"in_progress"===e.status).length,a=s-r-l;return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.y8,{size:14}),iconClass:"bg-brand-500/15 text-brand-500",title:`Tasks (${s})`,subtitle:"Checklist the agent is working through",onClose:t,children:[(0,n.jsx)("div",{className:"grid grid-cols-4 gap-2 px-4 py-3 border-b border-border-subtle bg-bg text-center shrink-0",children:[{label:"TOTAL",value:s,cls:"text-text"},{label:"RUNNING",value:l,cls:"text-sky-400"},{label:"DONE",value:r,cls:"text-emerald-400"},{label:"PENDING",value:a,cls:"text-text-muted"}].map(e=>(0,n.jsxs)("div",{className:"p-2 rounded-brand bg-surface-2/40",children:[(0,n.jsx)("div",{className:"text-[10px] text-text-muted font-mono",children:e.label}),(0,n.jsx)("div",{className:`text-base font-bold ${e.cls}`,children:e.value})]},e.label))}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===s?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.y8,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:"No tasks in this session yet."})]}):e.map((e,t)=>{let s=oe[e.status]||oe.pending,r=s.icon;return(0,n.jsxs)("div",{className:"modal-row items-start",children:[(0,n.jsx)(r,{size:14,className:`${s.cls} shrink-0 mt-0.5`}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:`text-xs ${s.line}`,children:e.subject||e.activeForm||"(untitled task)"}),e.activeForm&&"in_progress"===e.status&&(0,n.jsx)("div",{className:"text-[11px] text-sky-400/80 font-mono mt-0.5 truncate",children:e.activeForm})]}),e.taskId&&(0,n.jsxs)("span",{className:"text-[10px] font-mono text-text-muted shrink-0",children:["#",e.taskId]})]},e.id||t)})})]})}),os=(0,r.memo)(function({sessionId:e="",onListPoints:t,onPreview:s,onApply:l,onClose:a}){let[i,o]=(0,r.useState)([]),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(!0),[m,p]=(0,r.useState)(null),[f,h]=(0,r.useState)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)("");(0,r.useEffect)(()=>{let e=!0;return t?.().then(t=>{e&&(t||y("The host did not answer. Try again."),o(t?.points||[]),d(t?.support||null),x(!1))}).catch(()=>{e&&(y("Could not read this conversation."),x(!1))}),()=>{e=!1}},[t]);let w=(0,r.useCallback)(async e=>{(0,eo.e)(),p(e),h(null),y("");let t=await s?.(e.messageId);t?.ok?h(t):y(t?.error||"The host could not preview this rewind.")},[s]),j=(0,r.useCallback)(async()=>{if(!m)return;(0,eo.e)(),g(!0),y("");let e=await l?.(m.messageId);(g(!1),e?.ok)?a?.():y(e?.error||"The rewind did not go through.")},[m,l,a]),k=c&&!c.conversation;return(0,n.jsx)(nl,{icon:(0,n.jsx)(en.BZ,{size:14}),iconClass:"bg-amber-500/15 text-amber-400",title:"Rewind",subtitle:"Go back to an earlier prompt. Turns after it are discarded.",maxWidth:"max-w-xl",onClose:a,children:u?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-text-muted",children:[(0,n.jsx)(en.kr,{size:14,className:"animate-spin"}),(0,n.jsx)("span",{children:"Reading this conversation..."})]}):k?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 py-12 px-6 text-center text-text-muted",children:[(0,n.jsx)(en.RI,{size:28,className:"opacity-60"}),(0,n.jsx)("span",{className:"text-sm",children:c.how||"This engine cannot rewind a conversation."})]}):0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.BZ,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:v||"Nothing to rewind to yet."})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar max-h-[45vh]",children:[...i].reverse().map(e=>(0,n.jsxs)("div",{onClick:()=>w(e),className:`modal-row ${m?.messageId===e.messageId?"modal-row-active":""}`,children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-xs text-text truncate",children:e.text||"Untitled prompt"}),e.createdAt&&(0,n.jsx)("div",{className:"mt-1 text-[10px] font-mono text-text-subtle",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m ago`;let s=Math.round(t/60);return s<24?`${s}h ago`:`${Math.round(s/24)}d ago`}(Date.parse(e.createdAt))})]}),(0,n.jsxs)("span",{className:"modal-row-acts text-[11px] text-brand-500 items-center gap-1",children:[(0,n.jsx)("span",{children:m?.messageId===e.messageId?"Selected":"Pick"}),(0,n.jsx)(en.Lt,{size:11})]})]},e.messageId))}),v&&(0,n.jsx)("div",{className:"px-3 py-2 border-t border-border-subtle text-[11px] text-danger bg-danger/5",children:v}),(0,n.jsxs)("div",{className:"p-3 border-t border-border-subtle bg-bg shrink-0 flex flex-col gap-2",children:[m&&(0,n.jsx)("div",{className:"text-[11px] leading-relaxed text-text-muted",children:f?.files?.length>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text",children:f.files.length})," file",1===f.files.length?"":"s"," will be restored.",(0,n.jsxs)("ul",{className:"mt-1 flex flex-col gap-0.5",children:[f.files.slice(0,8).map(e=>(0,n.jsxs)("li",{className:"truncate font-mono text-[10px]",title:e.file,children:["\xb7 ",e.file,e.status?` (${e.status})`:""]},e.file)),f.files.length>8&&(0,n.jsxs)("li",{className:"text-[10px]",children:["… and ",f.files.length-8," more"]})]}),f.note&&(0,n.jsx)("span",{className:"block mt-1 text-text-subtle",children:f.note})]}):f?(0,n.jsx)("span",{className:"block text-text-subtle",children:f.note}):(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(en.kr,{size:11,className:"animate-spin"}),"Checking what this would change..."]})}),(0,n.jsxs)("button",{type:"button",onClick:j,disabled:!m||b||!f?.ok,className:`px-3 py-1.5 rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors ${m&&!b&&f?.ok?"bg-brand-500 hover:bg-brand-600 text-white cursor-pointer":"bg-surface-2 text-text-muted cursor-not-allowed opacity-50"}`,children:[b?(0,n.jsx)(en.kr,{size:13,className:"animate-spin"}):(0,n.jsx)(en.aJ,{size:13}),(0,n.jsx)("span",{children:b?"Rewinding...":"Rewind to this prompt"})]})]})]})})}),on=(0,r.memo)(function({requestId:e="",tool:t="",input:s={},failed:l=!1,onResolve:a}){let[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),u=function(e){if(e?.kind!=="permission_grant")return"";let t=[],s=String(e.reason||"").trim();return s&&t.push(s),t.push(...function(e={}){let t=[];e?.network?.enabled&&t.push("• network access");let s=e?.fileSystem||{};for(let e of s.read||[])t.push(`• read ${e}`);for(let e of s.write||[])t.push(`• write ${e}`);for(let e of s.entries||[]){var n;let s="string"==typeof(n=e?.path)?n:n?.path||n?.pattern||n?.value||"";s&&t.push(`• ${e.access||"access"} ${s}`)}return t}(e.permissions)),t.join("\n")}(s)||s?.command||s?.path||JSON.stringify(s||{});return(0,n.jsxs)("div",{className:"my-3 p-3 rounded-brand-lg border border-warning/30 bg-surface shadow-sm text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-warning font-medium",children:[(0,n.jsx)(en.ek,{size:16}),(0,n.jsx)("span",{children:"Permission Request"}),(0,n.jsx)("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-warning/15 text-warning uppercase min-w-0 break-all",title:t,children:t||"Action"})]}),(0,n.jsx)("div",{className:"p-2.5 rounded bg-bg font-mono text-[11px] text-text break-all border border-border-subtle mb-3 max-h-[140px] overflow-y-auto",children:u}),c&&(0,n.jsx)("div",{className:"mb-3",children:(0,n.jsx)("input",{type:"text",value:i,onChange:e=>o(e.target.value),placeholder:"Reason for denial or alternative instructions...",className:"w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs text-text placeholder-text-muted focus:outline-none focus:border-brand-500",autoFocus:!0})}),l&&(0,n.jsx)("div",{className:"mb-3 text-[11px] text-danger leading-snug",children:"Not sent — the host did not answer. Try again."}),(0,n.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[c?(0,n.jsx)("button",{type:"button",onClick:()=>d(!1),className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Hide note"}):(0,n.jsx)("button",{type:"button",onClick:()=>d(!0),className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Add note"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),a?.(e,"deny",i||"User denied")},className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-danger/20 text-danger flex items-center gap-1 font-medium transition-colors",children:[(0,n.jsx)(en.X,{size:14}),(0,n.jsx)("span",{children:"Deny"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),a?.(e,"allow")},className:"px-3.5 py-1.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 font-medium transition-colors shadow-sm",children:[(0,n.jsx)(en.aJ,{size:14}),(0,n.jsx)("span",{children:"Allow"})]})]})]})}),or=(0,r.memo)(function({engine:e="",message:t="",reason:s="",escalate:r=null,onEscalate:l,onDismiss:a}){return(0,n.jsxs)("div",{className:"my-3 p-3 rounded-brand-lg border border-danger/40 bg-surface shadow-sm text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-danger font-medium",children:[(0,n.jsx)(en.ek,{size:16}),(0,n.jsx)("span",{children:"Action blocked"}),e&&(0,n.jsx)("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-danger/15 text-danger uppercase",children:e})]}),(0,n.jsx)("div",{className:"p-2.5 rounded bg-bg text-[11px] text-text border border-border-subtle mb-3 whitespace-pre-wrap break-words max-h-[160px] overflow-y-auto",children:t||s||"The CLI refused this action under the current permission mode."}),(0,n.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),a?.()},className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-1",children:[(0,n.jsx)(en.X,{size:13}),(0,n.jsx)("span",{children:"Dismiss"})]}),r?.mode&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),l?.(r?.mode)},className:"px-3.5 py-1.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 font-medium transition-colors shadow-sm",children:[(0,n.jsx)(en.sU,{size:14}),(0,n.jsxs)("span",{children:["Switch to ",r.label||r.mode]})]})]})]})}),ol=[],oa=(0,r.memo)(function({sessionId:e=""}){let[t,s]=(0,r.useState)(!1),l=a7(t=>t.bySession[e]?.tasks),a=(0,r.useMemo)(()=>Array.isArray(l)?l.filter(e=>!!(e&&e.subject&&String(e.subject).trim().length>0)):ol,[l]);if(0===a.length)return null;let i=a.filter(e=>"completed"===e.status).length,o=a.find(e=>"in_progress"===e.status),c=i===a.length;return(0,n.jsxs)("div",{className:"px-4 sm:px-6 py-1 border-b border-border-subtle/40 bg-surface-2/20 shrink-0 text-xs select-none",children:[(0,n.jsx)("div",{onClick:()=>s(!t),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control transition-colors group",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[c?(0,n.jsx)(en.Jl,{size:13,className:"text-success shrink-0"}):o?(0,n.jsx)(en.y8,{size:13,className:"text-brand-500 shrink-0"}):(0,n.jsx)(en.y8,{size:13,className:"text-text-muted shrink-0"}),(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:"TASKS"}),(0,n.jsxs)("span",{className:"font-mono text-[11px] text-text-muted shrink-0",children:[i,"/",a.length]}),o&&(0,n.jsx)("span",{className:"text-[11px] text-brand-500 truncate min-w-0 font-medium",children:o.activeForm||o.subject}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 ml-auto",children:t?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]})}),t&&(0,n.jsx)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 py-1 space-y-0.5 animate-in fade-in duration-100",children:a.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-2 py-0.5",children:["completed"===e.status?(0,n.jsx)(en.Jl,{size:12,className:"text-success shrink-0"}):"in_progress"===e.status?(0,n.jsx)(en.jG,{size:10,className:"text-brand-500 fill-brand-500 shrink-0"}):(0,n.jsx)(en.jl,{size:12,className:"text-text-muted/50 shrink-0"}),(0,n.jsx)("span",{className:`text-[11px] truncate ${"completed"===e.status?"line-through text-text-muted/60":"in_progress"===e.status?"text-text font-medium":"text-text-muted"}`,children:e.subject})]},e.id||t))})]})}),oi=e=>String(e).padStart(2,"0");function oo(e){let t=Math.max(0,Math.floor((Number(e)||0)/1e3)),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}h ${oi(n)}m`:n>0?`${n}m ${oi(r)}s`:`${r}s`}let oc=e=>Number(e?.duration_ms)||0,od={agent:{label:"Sub-agent",icon:en.cC,cls:"bg-accent/15 text-accent"},shell:{label:"Background task",icon:en.BK,cls:"bg-warning/15 text-warning"}},ou={running:"bg-sky-500/15 text-sky-400",completed:"bg-emerald-500/15 text-emerald-400",failed:"bg-danger/15 text-danger",killed:"bg-danger/15 text-danger",stopped:"bg-surface-2 text-text-muted",paused:"bg-warning/15 text-warning"},ox=(0,r.memo)(function({tasks:e=[],messages:t=[],engine:s="claude",sessionId:l="",onStopTask:a,onClose:i}){let[o,c]=(0,r.useState)(()=>Date.now()),[d,u]=(0,r.useState)(null),x=a7(e=>e.bySession[l]?.harnessTasks);(0,r.useEffect)(()=>{let e=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(e)},[]);let m=(0,r.useMemo)(()=>e.map(e=>x?.find(t=>t.taskId===e.taskId)||e),[e,x]),p=m.find(e=>e.taskId===d)||m[0];if(!p)return null;let f=aq(p,o),h=!p.endedAt&&("running"===p.status||"paused"===p.status),b=ou[p.status]||(h?ou.running:ou.stopped);return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.BZ,{size:14}),iconClass:"bg-brand-500/15 text-brand-500",title:h?`Running for ${oo(f)}`:`Ended \xb7 ${oo(f)}`,subtitle:`${m.length} task${m.length>1?"s":""} handed off`,onClose:i,children:[m.length>1&&(0,n.jsx)("div",{className:"flex gap-1 px-3 py-2 border-b border-border-subtle overflow-x-auto custom-scrollbar shrink-0",children:m.map(e=>{let t=od[e.background?"shell":"agent"].icon,s=e.taskId===p.taskId;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),u(e.taskId)},className:`flex items-center gap-1.5 shrink-0 px-2 py-1 rounded-full text-[11px] transition-colors ${s?"bg-brand-500/15 text-brand-400 font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(t,{size:11,className:"shrink-0"}),(0,n.jsx)("span",{className:"max-w-[18ch] truncate",children:e.description||e.subagentType||e.taskId})]},e.taskId)})}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[(0,n.jsx)(om,{task:p,elapsed:f,statusCls:b}),(0,n.jsxs)("div",{className:"p-3",children:[(0,n.jsx)(op,{task:p,messages:t,engine:s}),(0,n.jsx)(of,{task:p,messages:t,engine:s,sessionId:l}),p.usage&&(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 mt-3",children:[(0,n.jsx)(oh,{label:"TOKENS",value:aD(p.usage.total_tokens)}),(0,n.jsx)(oh,{label:"TOOLS",value:p.usage.tool_uses??0}),oc(p.usage)>0&&(0,n.jsx)(oh,{label:"TOOK",value:oo(oc(p.usage))})]}),p.summary&&(0,n.jsx)("p",{className:"mt-3 text-[11px] text-text-muted leading-relaxed border-l-2 border-border-subtle pl-3",children:p.summary}),p.outputFile&&(0,n.jsxs)("p",{className:"mt-3 font-mono text-[10px] text-text-subtle truncate",title:p.outputFile,children:["output \xb7 ",p.outputFile]})]})]}),h&&p.taskId&&a&&(0,n.jsx)("div",{className:"px-3 py-2.5 border-t border-border-subtle bg-bg shrink-0",children:(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),a(p.taskId)},className:"w-full flex items-center justify-center gap-1.5 py-2 rounded-brand text-xs font-semibold text-danger bg-danger/10 hover:bg-danger/20 transition-colors",children:[(0,n.jsx)(en.M6,{size:11}),"Stop this task"]})})]})});function om({task:e,elapsed:t,statusCls:s}){let r=od[e.background?"shell":"agent"],l=r.icon;return(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border-subtle flex items-start gap-3",children:[(0,n.jsx)("div",{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${r.cls}`,children:(0,n.jsx)(l,{size:15})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,n.jsx)("span",{className:"text-sm font-semibold text-text truncate",children:e.description||e.subagentType||"task"}),(0,n.jsx)("span",{className:`text-[10px] font-mono uppercase tracking-wider px-1.5 py-0.5 rounded ${s}`,children:e.status})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1 text-[11px] text-text-muted font-mono flex-wrap",children:[(0,n.jsx)("span",{children:r.label}),e.subagentType&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ob,{}),(0,n.jsx)("span",{className:"text-brand-500",children:e.subagentType})]}),e.taskType&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ob,{}),(0,n.jsx)("span",{children:e.taskType})]}),(0,n.jsx)(ob,{}),(0,n.jsxs)("span",{className:"text-text tabular-nums",title:"since the agent logged the task's start",children:["running ",oo(t)]}),(0,n.jsx)(ob,{}),(0,n.jsx)("span",{className:"text-text-subtle",children:e.taskId})]})]})]})}function op({task:e,messages:t,engine:s}){let r=aS(t,e.toolUseId),l=a$(r,s);if(!l||!r)return null;let a="error"===r.status;return(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-brand bg-surface-2/40 border border-border-subtle/60",children:["running"===e.status?(0,n.jsx)(en.kr,{size:12,className:"animate-spin text-brand-500 shrink-0"}):a?(0,n.jsx)(en.RI,{size:12,className:"text-danger shrink-0"}):(0,n.jsx)(en.Jl,{size:12,className:"text-success shrink-0"}),(0,n.jsx)("span",{className:"font-mono text-[10px] uppercase tracking-wider text-text-muted shrink-0",children:"now"}),(0,n.jsx)("span",{className:"text-[11px] text-text truncate min-w-0",title:l,children:l})]})}function of({task:e,messages:t,engine:s,sessionId:r}){let l=aC(t,e.toolUseId);if(!l)return null;let a=l.children?.length?l.children:[l];return(0,n.jsxs)("div",{className:"mt-3",id:(0,ik.xo)(r,"calls",l.id),children:[(0,n.jsx)("div",{className:"text-[10px] font-mono uppercase tracking-wider text-text-muted mb-1",children:l.children?.length?`${l.children.length} call${l.children.length>1?"s":""}`:"command"}),a.map(e=>iM(s,e,{engine:s})||(0,n.jsx)(ix,{...e,engine:s},e.id))]})}function oh({label:e,value:t}){return(0,n.jsxs)("div",{className:"px-2.5 py-1.5 rounded-brand bg-surface-2/40 min-w-[68px]",children:[(0,n.jsx)("div",{className:"text-[9px] font-mono text-text-muted tracking-wider",children:e}),(0,n.jsx)("div",{className:"text-xs font-semibold text-text tabular-nums",children:t})]})}let ob=()=>(0,n.jsx)("span",{className:"text-text-subtle",children:"\xb7"}),og=[],ov=(0,r.memo)(function({sessionId:e="",engine:t="claude",onStopTask:s}){let l=a7(t=>t.bySession[e]?.messages)||og,a=a7(t=>t.bySession[e]?.harnessTasks)||og,i=(0,r.useMemo)(()=>(function(e=[],t=[]){return t.length>0?t.filter(e=>e?.status==="running").map(e=>({kind:e.background?"shell":"agent",id:e.toolUseId||e.taskId,taskId:e.taskId,label:e.description||e.subagentType||"task",startedAt:e.startedAt,taskType:e.taskType,subagentType:e.subagentType,usage:e.usage,toolUseId:e.toolUseId})):function(e=[]){let t=[],s=e=>{for(let n of e||[]){if(n?.status==="running"){let e=n.startedAt||n.timestamp,s=e?{startedAt:e}:null;aj.has(n?.name)?t.push({kind:"agent",id:n.id,label:ak(n),...s}):n?.async&&t.push({kind:"shell",id:n.id,label:aN(n),...s})}n?.children?.length&&s(n.children)}};for(let n=e.length-1;n>=0&&(!e[n]?.tools?.length||(s(e[n].tools),!(t.length>0)));n--);return t}(e)})(l,a),[l,a]),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(()=>Date.now()),[x,m]=(0,r.useState)(!1),p=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(0===i.length)return;let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[i.length]),(0,r.useEffect)(()=>()=>clearTimeout(p.current),[]);let f=(0,r.useCallback)(()=>{if(!x){m(!0),(0,eo.e)(),clearTimeout(p.current),p.current=setTimeout(()=>m(!1),3e3);return}for(let e of(clearTimeout(p.current),m(!1),(0,eo.e)(),i))e.taskId&&s(e.taskId)},[x,i,s]),h=i.some(e=>e.taskId&&s);if(0===i.length)return null;let b=i.filter(e=>"agent"===e.kind),g=i.filter(e=>"shell"===e.kind);return(0,n.jsxs)("div",{className:"px-4 sm:px-6 py-1 border-b border-border-subtle/40 bg-brand-500/[0.06] shrink-0 text-xs select-none",children:[b.length>0&&(0,n.jsx)(oy,{icon:(0,n.jsx)(en.kr,{size:13,className:"text-brand-500 shrink-0 animate-spin"}),tag:"AGENTS",items:b,messages:l,engine:t,now:d,onOpen:c}),g.length>0&&(0,n.jsx)(oy,{icon:(0,n.jsx)(en.kr,{size:13,className:"text-warning shrink-0 animate-spin"}),tag:"SHELLS",items:g,messages:l,engine:t,now:d,onOpen:c}),h&&i.length>1&&(0,n.jsx)("div",{className:"flex justify-end pb-0.5",children:(0,n.jsx)("button",{type:"button",onClick:f,className:`text-[11px] px-2 py-0.5 rounded transition-colors ${x?"bg-danger/20 text-danger font-semibold":"text-text-muted hover:text-text"}`,children:x?"Press again to stop all":"Stop all"})}),o&&(0,n.jsx)(ox,{tasks:o,messages:l,engine:t,sessionId:e,onStopTask:s,onClose:()=>c(null)})]})});function oy({icon:e,tag:t,items:s,messages:r,engine:l,now:a,onOpen:i}){let o=s.map(e=>e.label).join(", "),c=aq(s.reduce((e,t)=>t.startedAt&&(!e?.startedAt||t.startedAt<e.startedAt)?t:e,null),a),d=s.map(e=>a$(aS(r,e.toolUseId),l)).find(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 min-w-0",children:[e,(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:t}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),i(s)},title:o,className:"flex items-center gap-2 min-w-0 flex-1 text-left hover:bg-surface-2/40 rounded transition-colors px-1",children:[(0,n.jsxs)("span",{className:"font-mono text-[11px] text-brand-500 shrink-0 tabular-nums",children:[s.length," running"]}),c>0&&(0,n.jsx)("span",{className:"font-mono text-[11px] text-text shrink-0 tabular-nums",children:oo(c)}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",children:d||o})]})]})}let ow={model:"",skills:[],mcpServers:[]},oj=[],ok=(0,r.memo)(function({sessionId:e,engine:t="claude",workspacePath:s="",sessionName:l="",bus:a=null,fileBus:i=null,isVisible:o=!0,isFocused:c=!1,isDesktop:d=!0,bgIndex:x=0,onActivate:m=null,onOpenRemote:p=null,onOpenMobile:f=null,onOpenArtifact:b=null,onNewChat:g=null}){let[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(!1),{t:C}=(0,ec.s)(),{sendPrompt:S,removeQueueItem:E,clearQueue:R,resolvePermission:T,stop:$,stopTask:M,runShell:z,rewindToMessage:P,previewRewind:I,listRewindPoints:L,escalateMode:D,dismissBlocked:B,hasOlder:F,loadOlder:K,reload:O,hydrating:W,synced:_,hydrateFailed:H}=function({sessionId:e,engine:t="claude",workspacePath:s="",bus:n=null,isVisible:l=!0}){let a=(0,r.useRef)(n);(0,r.useEffect)(()=>{a.current=n},[n]);let i=a7(e=>e.initSession),o=a7(e=>e.setMetadata),c=a7(e=>e.appendDelta),d=a7(e=>e.appendThinking),x=a7(e=>e.appendDiff),m=a7(e=>e.appendTool),p=a7(e=>e.updateToolResult),f=a7(e=>e.nestTool),h=a7(e=>e.nestToolResult),b=a7(e=>e.upsertTask),g=a7(e=>e.setPermission),v=a7(e=>e.clearPermission),y=a7(e=>e.finishTurn),w=a7(e=>e.setTurnRunning),j=a7(e=>e.addUserMessage),k=(0,u.d)(e=>e.connected),[N,C]=(0,r.useState)(!1),[S,E]=(0,r.useState)(!1),[R,T]=(0,r.useState)(!1),[$,M]=(0,r.useState)(!1),z=(0,r.useRef)(0),P=(0,r.useRef)(!1),I=(0,r.useCallback)((e,s,n)=>{switch(s){case"user_message":j(e,n.text,n.attachments||null,!!n?.replay);break;case"init":{let t=il(a7.getState().bySession[e]?.metadata?.skills),s=new Map(t.map(e=>[e.id||e.name,e])),r=il(n.skills),l=r.length>0?r.map(e=>{let t=s.get(e.id);return t?.description?{...e,description:t.description}:e}):t,{model:a,...i}=n||{};o(e,{...i,skills:l,...a?{model:a}:{}});break}case"goal":o(e,{goal:n?.goal||null});break;case"delta":c(e,n.text);break;case"thinking":d(e,n.text);break;case"diff":x(e,n);break;case"tool_child":f(e,n);break;case"tool_result_child":h(e,n);break;case"tool_start":if(m(e,n),n&&n.name){let s=a7.getState().bySession[e]?.tasks||[],r=(0,aT.Zm)(t,n.name,n.input,n.id,s);r&&b(e,r)}break;case"tool_result":if(p(e,n),n&&n.id){let s=(0,aT.in)(t,n.name||"",n.output||"",n.id);s&&b(e,s)}break;case"permission_request":g(e,n);break;case"permission_resolved":v(e,n.requestId);break;case"blocked":a7.getState().setBlocked(e,n);break;case"options_changed":n?.permissionMode&&a7.getState().setPermissionMode(e,n.permissionMode),n?.model&&o(e,{model:n.model}),n?.effort&&o(e,{effort:n.effort});break;case"queue_update":a7.getState().setQueue(e,n?.queue||[]);break;case"turn_complete":y(e,n.stats,n.turnMs,!!n?.replay),n?.isError&&!ia(a7.getState().bySession[e]?.messages,n.result)&&a7.getState().addNotice(e,{subtype:n.subtype||"",level:"error",content:n.result||"The turn ended in an error."});break;case"stats":n?.stats&&a7.getState().setStats(e,n.stats);break;case"stopped":case"exit":v(e),a7.getState().finishTurn(e,null,n?.turnMs),"exit"===s&&(n?.error||n?.code!=null&&0!==n.code)&&a7.getState().addNotice(e,{subtype:"exit",level:"error",content:n.error||`The AI process exited (code ${n.code}).`});break;case"stall":w(e,!1),y(e,null,n?.turnMs);break;case"error":a7.getState().addNotice(e,{subtype:"error",level:"error",content:n?.message||"AI process failed"}),y(e,null,n?.turnMs);break;case"prompt_refused":a7.getState().addNotice(e,{subtype:"prompt_refused",level:"error",content:ii(n)});break;case"conversation_reset":(0,A.Lq)("ai-status","reset",{sessionId:e,isTurnRunning:n?.isTurnRunning,elapsedMs:n?.elapsedMs,lastTurnMs:n?.lastTurnMs,fromSeq:n?.fromSeq}),a7.getState().clearMessages(e),a7.getState().setTaskRecords(e,n?.taskRecords),a7.getState().restoreTurnState(e,n),Array.isArray(n?.queue)&&a7.getState().setQueue(e,n.queue);break;case"cli_event":{let t=n?.type||"",s=n?.record||null;a7.getState().applyTaskRecords(e,[[t,n?.subtype||"",s,n?.ageMs]]);let r=aQ(t,s);r&&a7.getState().addNotice(e,r)}}},[t,j,o,c,d,x,m,p,f,h,b,g,v,y,w]),L=(0,r.useRef)(I);(0,r.useEffect)(()=>{L.current=I});let D=(0,r.useRef)(i);(0,r.useEffect)(()=>{D.current=i});let B=(0,r.useRef)(0),F=(0,r.useRef)(0),K=(0,r.useRef)(!1),O=(0,r.useRef)([]),W=(0,r.useRef)(0),_=(0,r.useRef)(null);null==_.current&&(_.current=function(e=ir){let t=0,s=!1;return{schedule:n=>s||!n?null:(s=!0,e[Math.min(t++,e.length-1)]),fired(){s=!1},answered(){s=!1,t=0},exhausted:()=>t>=e.length}}());let H=(0,r.useRef)(null),q=(0,r.useRef)(null),U=(0,r.useRef)(null),V=(0,r.useRef)({}),X=(0,r.useRef)(null),G=(0,r.useRef)(l);(0,r.useEffect)(()=>{G.current=l},[l]);let J=(0,r.useRef)(null),Y=(0,r.useRef)(null),Z=(0,r.useRef)(null),Q=(0,r.useCallback)(()=>{H.current&&clearTimeout(H.current),H.current=null,_.current?.answered()},[]),ee=(0,r.useCallback)(()=>{let e=_.current?.schedule(u.d.getState().connected);M(!!_.current?.exhausted()),(0,A.Lq)("ai-hydrate","ladder",{delay:e??null,exhausted:_.current?.exhausted(),connected:u.d.getState().connected,armed:null!=H.current}),null!=e&&(H.current=setTimeout(()=>{H.current=null,_.current?.fired(),V.current.request?.()},e))},[]),et=(0,r.useCallback)(()=>{if(!e||!n)return;if(K.current){(0,A.Lq)("ai-hydrate","blocked (round in flight)",{gen:W.current}),ee();return}let r=++W.current,l=F.current;K.current=!0,E(!0),O.current=[],z.current=0;let a=Date.now();(0,A.Lq)("ai-hydrate","emit ai:create",{gen:r,sessionId:e,engine:t,cwd:s,carrier:u.d.getState().carrier,connected:u.d.getState().connected});let i=()=>{let t=O.current;for(let s of(O.current=[],K.current=!1,E(!1),t)){if("conversation_reset"===s.event){B.current=0,F.current++,z.current=s.data?.fromSeq??0,C(!!s.data?.hasMore),L.current(e,s.event,s.data);continue}if(null!=s.seq){if(s.seq<=B.current)continue;B.current=s.seq}L.current(e,s.event,s.data)}},o=setTimeout(()=>{r===W.current&&K.current&&(i(),ee())},4e3);U.current=o,n.emit("ai:create",{sessionId:e,engine:t,cwd:s,options:{defaultMode:(0,aT.Tw)(t).defaultMode,defaultEffort:(0,aT.Tw)(t).defaultEffort}},s=>{if(!function({isNewest:e,snapshotSeq:t=0,appliedSeq:s=0,sameLog:n=!0}){return!!e||!!n&&(t||0)>(s||0)}({isNewest:r===W.current,snapshotSeq:s?.session?.seq,appliedSeq:B.current,sameLog:l===F.current}))return;let n=null,c=null,d=s?.session?.events;(0,A.Lq)("ai-hydrate","ack",{gen:r,stale:r!==W.current,ms:Date.now()-a,ok:s?.ok??null,error:s?.error??null,events:Array.isArray(d)?d.length:null,hasMore:s?.session?.hasMore??null});try{if(clearTimeout(o),!s?.ok||!Array.isArray(d))return void C(!1);let r=s.session.seq||0;if((0,A.Lq)("ai-status","hydrate ack",{sessionId:e,isTurnRunning:s.session.isTurnRunning,elapsedMs:s.session.elapsedMs,lastTurnMs:s.session.lastTurnMs,events:d.length,hasMore:s.session.hasMore}),z.current=d[0]?.seq??0,C(!!s.session.hasMore&&d.length>0),(0,A.Lq)("ai-page","hydrate",{sessionId:e,replayed:d.length,hasMore:s.session.hasMore,fromSeq:d[0]?.seq??0,lastSeq:r,oldestId:null}),Array.isArray(s?.modelOptions)&&s.modelOptions.length>0&&a7.getState().setMetadata(e,{modelOptions:s.modelOptions}),d.length>0){let n=io(d,t);a7.getState().hydrateSession(e,{messages:n.messages,tasks:n.tasks,metadata:{...a7.getState().bySession[e]?.metadata,...n.metadata,...Array.isArray(s?.modelOptions)?{modelOptions:s.modelOptions}:{},...s.session.effort?{effort:s.session.effort}:{}},stats:{...n.stats,...s.session.stats||{}},isTurnRunning:void 0!==s.session.isTurnRunning?!!s.session.isTurnRunning:n.isTurnRunning,elapsedMs:s.session.elapsedMs||0,lastTurnMs:s.session.lastTurnMs||0,permissionMode:s.session.permissionMode||n.permissionMode,activeBlocked:n.activeBlocked,harnessTasks:aZ(s.session.taskRecords,n.harnessTasks),queue:s.session.queue||[]})}else w(e,!!s.session.isTurnRunning),a7.getState().setTaskRecords(e,s.session.taskRecords),s.session.permissionMode&&a7.getState().setPermissionMode(e,s.session.permissionMode),Array.isArray(s.session.queue)&&a7.getState().setQueue(e,s.session.queue),s.session.stats&&a7.getState().setStats(e,s.session.stats);n=s.session.activePermission||null,c=Array.isArray(s.session.queue)?s.session.queue:null,B.current=r}finally{clearTimeout(o),r===W.current&&i(),n&&r===W.current&&a7.getState().setPermission(e,n),c&&r===W.current&&a7.getState().setQueue(e,c),s?.ok&&void 0!==s.session.isTurnRunning&&(a7.getState().restoreTurnState(e,{isTurnRunning:!!s.session.isTurnRunning,elapsedMs:s.session.elapsedMs||0,lastTurnMs:s.session.isTurnRunning?0:s.session.lastTurnMs||0}),(0,A.Lq)("ai-status","restate",{sessionId:e,isTurnRunning:!!s.session.isTurnRunning,elapsedMs:s.session.elapsedMs||0,lastTurnMs:s.session.lastTurnMs||0})),s?.ok?(T(!0),M(!1),Q()):ee(),(0,A.Lq)("ai-hydrate","settled",{gen:r,stale:r!==W.current,ok:s?.ok??null,hydrating:K.current,synced:!!s?.ok})}})},[e,t,s,n,w,ee,Q]),es=(0,r.useCallback)(()=>{!u.d.getState().connected||q.current||(q.current=setTimeout(()=>{q.current=null,et()},eV.qw))},[et]),en=(0,r.useCallback)(()=>{if(n&&e){if(!G.current){J.current="visible";return}!u.d.getState().connected||K.current||Y.current||(Y.current=setTimeout(()=>{if(Y.current=null,!G.current||K.current)return;let t=!1,s=setTimeout(()=>{t||((0,A.Lq)("ai-hydrate","peekSeq: no ack → full hydrate"),es())},eV.zm);Z.current=s,n.emit("ai:peekSeq",{sessionId:e},n=>{if(t=!0,clearTimeout(s),Z.current=null,!n?.ok||"number"!=typeof n.seq)return void es();let r=B.current,l=!!a7.getState().bySession[e]?.isTurnRunning,a=a7.getState().bySession[e]?.queue?.length||0,i="number"==typeof n.queueLength?n.queueLength:a;n.seq===r&&!!n.isTurnRunning===l&&i===a?(0,A.Lq)("ai-hydrate","peekSeq: nothing missed",{seq:r}):((0,A.Lq)("ai-hydrate","peekSeq: state changed",{fromSeq:r,toSeq:n.seq,turn:n.isTurnRunning}),es())})},eV.qw))}},[n,e,es]),er=(0,r.useCallback)(()=>{Q(),et()},[Q,et]);(0,r.useEffect)(()=>{V.current={request:es}},[es]),(0,r.useEffect)(()=>()=>{q.current&&clearTimeout(q.current),Y.current&&clearTimeout(Y.current),Z.current&&clearTimeout(Z.current),H.current&&clearTimeout(H.current),U.current&&clearTimeout(U.current),q.current=Y.current=Z.current=H.current=U.current=null,K.current=!1,O.current=[]},[]),(0,r.useEffect)(()=>{if(e)return X.current!==e&&(X.current=e,K.current=!1,Q(),T(!1),M(!1)),D.current(e),et()},[e,et,Q]),(0,r.useEffect)(()=>{if(!l)return;let e=J.current;e&&(J.current=null,"reconnect"===e?es():en())},[l,es,en]),(0,r.useEffect)(()=>{if(!n||!e)return;let t=()=>{document.hidden||en()},s=()=>{if(!G.current){J.current="reconnect";return}es()};return n.on("connect",s),document.addEventListener("visibilitychange",t),document.addEventListener("resume",t),()=>{n.off("connect",s),document.removeEventListener("visibilitychange",t),document.removeEventListener("resume",t)}},[n,e,en,es]);let el=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=el.current;if(el.current=k,k&&!e){if(!G.current){J.current="reconnect";return}es()}},[k,es]),(0,r.useEffect)(()=>{if(!n||!e)return;let t="",s="",r=null,l=[],a=!1,i=()=>{null!=r&&cancelAnimationFrame(r),r=null;let n=t,l=s;t="",s="",(n||l)&&a7.getState().appendStream(e,n,l)},o=()=>{a=!1;let t=l;l=[];let s=L.current;for(let n of t)n.stream?a7.getState().appendStream(e,n.data.text,n.data.thinking):s(e,n.event,n.data)},c=(e,n)=>{if("cli_event"!==e&&(t||s)){let e={stream:!0,data:{text:t,thinking:s}};t="",s="",null!=r&&(cancelAnimationFrame(r),r=null),l.push(e)}l.push({event:e,data:n}),a||(a=!0,queueMicrotask(o))},d=n=>{var l,a,o,d;if(!n||n.sessionId!==e)return;if(K.current)return void O.current.push(n);let u="delta"===n.event||"thinking"===n.event;if("conversation_reset"===n.event){B.current=0,F.current++,z.current=n.data?.fromSeq??0,C(!!n.data?.hasMore),c(n.event,n.data);return}if(l=n.seq,a=B.current,null==l||!(l<=(a||0))){if(null!=n.seq&&(B.current=n.seq),u)return void(o=n.event,(d=n.data?.text)&&("delta"===o?t+=d:s+=d,null==r&&(r=requestAnimationFrame(i))));c(n.event,n.data)}};return n.on("ai:event",d),()=>{n.off("ai:event",d),i()}},[n,e,I]);let ea=(0,r.useCallback)((t,{attachments:n=null}={})=>{if(!t&&!n?.length)return;let r=a.current;ey.getState().clearNotification(e),r?.emit("ai:prompt",{sessionId:e,message:t,cwd:s,...n?.length?{attachments:n}:{}})},[e,s]),ei=(0,r.useCallback)(t=>{let s=a7.getState().bySession[e]?.queue||[];a7.getState().setQueue(e,s.filter(e=>e.id!==t));let n=a.current;n?.emit("ai:queueRemove",{sessionId:e,id:t})},[e]),eo=(0,r.useCallback)(()=>{a7.getState().setQueue(e,[]);let t=a.current;t?.emit("ai:queueClear",{sessionId:e})},[e]),ec=(0,r.useCallback)((t,s,n="",r=null)=>{let l=a.current;if(!l)return;let i=!1,o=null,c=n=>{if(!i){if(i=!0,clearTimeout(o),n?.ok||n?.reason==="stale")return void v(e,t);(0,A.Lq)("ai-gate","resolve failed",{requestId:t,behavior:s,res:n??"timeout"}),a7.getState().setGateError(e,t)}};r?l.emit("ai:question",{sessionId:e,requestId:t,answers:r},c):l.emit("ai:permission",{sessionId:e,requestId:t,behavior:s,message:n},c),o=setTimeout(()=>c(null),tb.GX)},[e,v]),ed=(0,r.useCallback)(()=>{let t=a.current;t?.emit("ai:stop",{sessionId:e})},[e]),eu=(0,r.useCallback)(t=>{if(!t)return;let s=a.current;s?.emit("ai:stopTask",{sessionId:e,taskId:t})},[e]),ex=(0,r.useCallback)(e=>{ea(`! ${e}`)},[ea]),em=(0,r.useCallback)(async()=>{let t=a.current;if(!t)return null;let s=await new Promise(s=>{let n=!1,r=e=>{n||(n=!0,clearTimeout(l),s(e))},l=setTimeout(()=>r(null),4e3);t.emit("ai:rewind",{sessionId:e,action:"list"},r)});return s?s.support?.conversation?s.ok?{supported:!0,ok:!0,points:s.points||[],support:s.support}:{supported:!0,ok:!1,points:[],support:s.support}:{supported:!1,ok:!1,points:[],support:s.support}:null},[e]),ep=(0,r.useCallback)(async(t,n,{files:r=!0,preview:l=!1,index:i=null}={})=>{let o=a.current;if(!o)return{ok:!1,error:"Not connected to the host."};let c=await new Promise(s=>{let n=!1,a=e=>{n||(n=!0,clearTimeout(c),s(e))},c=setTimeout(()=>a(null),l?4e3:13e4);o.emit("ai:rewind",{sessionId:e,action:l?"preview":"apply",messageId:t,index:i,files:r},a)});return(l||c&&c.ok||er(),c)?(c.ok&&!l&&n&&o.emit("ai:prompt",{sessionId:e,message:n,cwd:s}),c):{ok:!1,error:"The host did not answer in time."}},[e,s,er]),ef=(0,r.useCallback)((e,{files:t=!0,index:s=null}={})=>ep(e,null,{files:t,preview:!0,index:s}),[ep]),eh=(0,r.useCallback)(t=>{if(!t)return;a7.getState().setPermissionMode(e,t),a7.getState().clearBlocked(e);let s=a.current;s?.emit("ai:options",{sessionId:e,options:{mode:t}})},[e]),eb=(0,r.useCallback)(()=>{a7.getState().clearBlocked(e)},[e]);return{hydrating:S,synced:R,hydrateFailed:$,hasOlder:N,loadOlder:(0,r.useCallback)(async()=>{if(P.current)return!1;let s=a.current;if(!s)return!1;P.current=!0;let n=z.current;try{let r=Date.now(),{messages:l,before:a,hasMore:i,answered:o,chunks:c}=await is({startSeq:n,estimateBytes:ie,fetchChunk:t=>new Promise(n=>{let r=!1,l=e=>{r||(r=!0,clearTimeout(a),n(e))},a=setTimeout(()=>l(null),4e3);s.emit("aiHistory",{sessionId:e,before:t},l)}),reduceChunk:(s,n)=>{let r=a7.getState().bySession[e];return io(s,t,(r?.messages?.length||0)+n+1).messages}});if((0,A.Lq)("ai-page","loadOlder",{sessionId:e,before:n,ms:Date.now()-r,transport:s.transport||s.carrier||"?",chunks:c,messages:l.length,bytes:Math.round(l.reduce((e,t)=>e+ie(t),0)/1024)+"KB",hasMore:i}),z.current!==n||!o||(z.current=a,C(i),!l.length))return!1;return a7.getState().prependMessages(e,l),!0}finally{P.current=!1}},[e,t]),reload:er,sendPrompt:ea,removeQueueItem:ei,clearQueue:eo,resolvePermission:ec,stop:ed,stopTask:eu,runShell:ex,rewindToMessage:ep,previewRewind:ef,listRewindPoints:em,escalateMode:eh,dismissBlocked:eb}}({sessionId:e,engine:t,workspacePath:s,bus:a,isVisible:o}),q=(0,r.useCallback)(()=>{(0,eo.e)(),j(!0),O(),setTimeout(()=>j(!1),700)},[O]),U=a7(t=>t.bySession[e]?.activePermission),V=!!a7(t=>t.bySession[e]?.isTurnRunning),X=a7(t=>t.bySession[e]?.gateError),G=a7(t=>t.bySession[e]?.activeBlocked),J=a7(t=>t.bySession[e]?.metadata)||ow,Y=a7(t=>t.bySession[e]?.tasks)||oj,Z=a7(e=>e.setPermissionMode),Q=eT(e),ee=(0,h.B)(e=>e.terminalBackgroundOpacity),et=(0,h.B)(e=>e.customBackgrounds),es=(0,h.B)(e=>e.terminalBackgrounds),er=(0,h.B)(t=>t.backgroundBySession[e]),el=(0,h.B)(e=>e.terminalTheme),ea=(0,h.B)(e=>e.fontSize),ei=(0,h.B)(e=>e.showFolderButton),ed=(0,h.B)(e=>e.showNoteButton),eu=(0,h.B)(e=>e.setRightPanelRoot),ex=(0,h.B)(e=>e.setRightPanelTab),em=(0,h.B)(e=>e.openRightPanel),ep=(0,h.B)(t=>t.artifactsBySession[e]),ef=nj(s,i,{enabled:c&&ei}),{theme:eh}=(0,n_.D)(),eb=(0,r.useMemo)(()=>(0,nT.In)(eh,el),[eh,el]),eg=(0,r.useMemo)(()=>(0,eV.ar)(ea)+(d?tb.TQ:tb.wM),[ea,d]),ev=(0,r.useMemo)(()=>{let{alpha:e,size:t}=tb.ii,s=`radial-gradient(color-mix(in srgb, ${eb.foreground} ${e}%, transparent) 1px, transparent 1px) 0 0 / ${t}px ${t}px`,n=(0,eV.$Z)(er,es,et,x),r="dark"===eh?(0,eV.RS)(n,et):null;if(r){let e=`rgba(${eV.c},${ee??eV._z})`,t=`rgba(${eV.pZ},${eV.B$})`;return{background:`${s}, linear-gradient(${e},${e}), linear-gradient(${t},${t}), center / cover no-repeat url("${r}")`,backgroundBlendMode:"luminosity, normal, screen, normal"}}return{background:`${s}, ${eb.background}`}},[es,er,et,ee,eb,eh,x]),ew=J.skills||[],ej=J.mcpServers||[],ek=(0,r.useCallback)(e=>{S(`/${e}`)},[S]),eN=(0,r.useCallback)(t=>{a?.emit?.("ai:options",{sessionId:e,options:t})},[a,e]),eC=(0,r.useCallback)(t=>{a7.getState().setMetadata(e,{model:t}),eN({model:t})},[eN,e]),eS=(0,r.useCallback)(e=>{e?.sessionId&&eN({resume:e.sessionId})},[eN]),eE=(0,r.useCallback)(e=>{if(e)return eS(e);y("sessions")},[eS]),eR=(0,r.useCallback)((t,s)=>{t&&("effort"===t&&a7.getState().setMetadata(e,{effort:s}),eN({[t]:s}))},[eN,e]),e$=(0,aT.Tw)(t),eM=(0,r.useCallback)(t=>{Z(e,t),eN({mode:t})},[eN,e,Z]),ez=(0,r.useCallback)((t,s)=>{a7.getState().rewindToMessage(e,t,s)},[e]),eP=(0,r.useCallback)(t=>{if(!v&&t.shiftKey&&"Tab"===t.key){t.preventDefault(),(0,eo.e)();let s=e$.permissionModes||[],n=a7.getState().bySession[e]?.permissionMode||e$.defaultMode,r=s.findIndex(e=>e.id===n),l=-1===r?0:(r+1)%s.length,a=s[l]?.id;a&&eM(a)}},[e,e$,eM,v]),eI=nH({isFocused:c,onActivate:()=>m?.()}),eA=(0,r.useRef)(m);(0,r.useEffect)(()=>{eA.current=m});let eL=(0,r.useCallback)(()=>eA.current?.(),[]),eD=(0,r.useMemo)(()=>({sessionId:e,isFocused:c,activate:eL}),[e,c,eL]);return(0,n.jsx)(ik.fe.Provider,{value:eD,children:(0,n.jsxs)("div",{...eI,onKeyDown:eP,className:"ai-pane w-full h-full flex flex-col bg-bg overflow-hidden relative select-text",style:{...ev,"--color-text":eb.foreground,"--ai-fs":`${eg}px`},children:[(0,n.jsxs)("div",{style:{height:26},className:"sm:hidden flex items-center gap-2 px-2 border-b border-border-subtle bg-surface/70 backdrop-blur-sm text-[11px] select-none shrink-0 relative z-10",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${t9(Q)}`,style:{background:t8(Q).dot}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",children:l||tb.UB[t]?.label||t}),(0,n.jsx)(nW,{onOpenRemote:p,onOpenMobile:f})]}),c&&(0,n.jsxs)("div",{className:"absolute right-2 z-[2] flex flex-col items-end gap-2 pointer-events-auto touch-none top-9 sm:top-2",children:[(0,n.jsxs)("div",{className:"flex flex-row gap-2",children:[ed&&(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,eo.e)(),N(!0)},className:nq,title:C("terminalPane.note"),children:(0,n.jsx)(en.y8,{size:16,className:nU})}),(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),q()},className:nq,title:C("terminalPane.refresh"),children:(0,n.jsx)(en.e9,{size:16,className:`${nU} ${w?"animate-spin":""}`})})]}),ei&&s&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,eo.e)(),eu(s,s),window.innerWidth>=eV.jK?ex("files",s):em()},className:`relative ${nq}`,title:C("terminalPane.openFolderHere"),children:[(0,n.jsx)(en.vd,{size:16,className:nU}),ef>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:ef>eV.KN?`${eV.KN}+`:ef})]}),b&&ep?.length>0&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:t=>{t.stopPropagation(),(0,eo.e)(),b(e,ep[0])},className:`relative ${nq}`,title:C("terminalPane.artifacts"),children:[(0,n.jsx)(en.sU,{size:16,className:nU}),(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:ep.length})]})]}),(0,n.jsx)(oa,{sessionId:e}),(0,n.jsx)(ov,{sessionId:e,engine:t,onStopTask:M}),(0,n.jsx)(iV,{bus:a,sessionId:e,engine:t,workspacePath:s,fileBus:i,onSendPrompt:S,onResolvePermission:T,onRewind:P,onPreviewRewind:I,onListRewindPoints:L,onCutLocal:ez,hasOlder:F,onLoadOlder:K,onOpenResume:eE,hydrating:W,synced:_,hydrateFailed:H,onReload:O}),G&&!U&&(0,n.jsx)("div",{className:"px-3 pb-2 select-none animate-in fade-in slide-in-from-bottom-2 duration-150 flex-shrink-0 z-30",children:(0,n.jsx)(or,{engine:G.engine||t,message:G.message,escalate:G.escalate,onEscalate:D,onDismiss:B})}),U&&(0,n.jsx)("div",{className:"px-3 pb-2 select-none animate-in fade-in slide-in-from-bottom-2 duration-150 flex-shrink-0 z-30",children:"AskUserQuestion"===U.tool?(0,n.jsx)(iy.J,{requestId:U.requestId,questions:U.input?.questions||[],failed:X,onResolve:T}):(0,n.jsx)(on,{requestId:U.requestId,tool:U.tool,input:U.input,failed:X,onResolve:T})}),(0,n.jsx)(iY,{bus:a,sessionId:e,engine:t,onSend:S,onRemoveQueueItem:E,onClearQueue:R,onStop:$,onRunShell:z,onResolvePermission:T,onSelectModel:eC,onModeChange:eM,onOpenModal:y,onOptionChange:eR,onActivate:m,isFocused:c,fileBus:i,workspacePath:s,modalOpen:null!==v}),(0,n.jsx)(iQ,{sessionId:e,fileBus:i,sessionName:l,engine:t,workspacePath:s,isDesktop:d,onModeChange:eM,onNewChat:g}),"skills"===v&&(0,n.jsx)(i0,{skills:ew,onClose:()=>y(null),onSelectSkill:ek}),"mcp"===v&&(0,n.jsx)(i1,{mcpServers:ej,onClose:()=>y(null)}),"model"===v&&(0,n.jsx)(i2,{currentModel:J.model,currentEffort:J.effort||"",models:J.modelOptions?.length?J.modelOptions:e$.models,isTurnRunning:V,onClose:()=>y(null),onSelectModel:eC,onSelectEffort:e=>eN({effort:e})}),"sessions"===v&&(0,n.jsx)(i5,{bus:a,engine:t,workspacePath:s,onClose:()=>y(null),onResume:eS}),"config"===v&&(0,n.jsx)(i6,{engine:t,options:a7.getState().bySession[e]?.metadata,onClose:()=>y(null),onApply:e=>eN(e)}),"mode"===v&&(0,n.jsx)(i9,{modes:e$.permissionModes||[],currentMode:a7.getState().bySession[e]?.permissionMode||e$.defaultMode,onClose:()=>y(null),onSelectMode:eM}),"doctor"===v&&(0,n.jsx)(i7,{bus:a,engine:t,workspacePath:s,onClose:()=>y(null)}),"tasks"===v&&(0,n.jsx)(ot,{tasks:Y,onClose:()=>y(null)}),"rewind"===v&&(0,n.jsx)(os,{sessionId:e,onListPoints:L,onPreview:I,onApply:e=>P(e),onClose:()=>y(null)}),k&&ed&&(0,n.jsx)(nO,{bus:a,sessionId:e,onClose:()=>N(!1)})]})})});class oN extends r.Component{constructor(e){super(e),this.handleReset=()=>{this.setState({hasError:!1,error:null}),this.props.onReset?.()},this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("[ErrorBoundary caught error]:",e,t)}render(){return this.state.hasError?this.props.fallback?"function"==typeof this.props.fallback?this.props.fallback(this.state.error,this.handleReset):this.props.fallback:(0,n.jsxs)("div",{className:"w-full h-full min-h-[160px] flex flex-col items-center justify-center p-6 text-center select-none bg-surface/50 border border-border-subtle/40 rounded-brand m-2",children:[(0,n.jsx)(en.RI,{size:24,className:"text-danger mb-2"}),(0,n.jsx)("div",{className:"text-sm font-semibold text-text mb-1",children:this.props.title||"Something went wrong in this pane"}),(0,n.jsx)("div",{className:"text-xs text-text-muted font-mono max-w-md truncate mb-4",children:this.state.error?.message||"Render error"}),(0,n.jsxs)("button",{type:"button",onClick:this.handleReset,className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-surface-3 text-text text-xs flex items-center gap-1.5 font-medium transition-colors border border-border-subtle",children:[(0,n.jsx)(en.e9,{size:12}),(0,n.jsx)("span",{children:"Try again"})]})]}):this.props.children}}let oC=(0,r.memo)(function({children:e}){return(0,n.jsx)("div",{className:"absolute inset-x-0 top-0 bottom-[37px] overflow-hidden",children:e})}),oS=(0,r.memo)(function({sessionId:e}){let t=eT(e);return"idle"===t?null:(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 z-20 h-[1px] pointer-events-none hidden sm:block",children:"working"===t?(0,n.jsx)(av,{}):"done"===t?(0,n.jsx)("div",{className:"w-full h-full bg-[#f59e0b]",style:{boxShadow:"0 0 4px rgba(245,158,11,0.6)"}}):"blocked"===t?(0,n.jsx)("div",{className:"w-full h-full bg-[#ef4444] animate-pulse",style:{boxShadow:"0 0 4px rgba(239,68,68,0.7)"}}):null})}),oE=(0,r.memo)(function({sessionId:e,placeholder:t}){let s=(0,h.B)(t=>t.drafts[e]??"").replace(/\s+/g," ").trim();return s?(0,n.jsx)("span",{className:"text-text",children:s}):(0,n.jsx)(n.Fragment,{children:t})}),oR=(0,r.memo)(function({bus:e,busRef:t,connected:s,carrier:l,platform:a,agentVersion:i,sessions:o,workspaces:c,activeSessionId:d,activeSession:x,activeWorkspaceId:m,openedSessions:p,livePanes:f,mountedWorkspaces:b,cwdBySession:g,sessionStatus:v,notifications:y,isDesktop:w,isTerminalView:j,slideClass:k,shells:N,sidebarCollapsed:C,sidebarWidth:S,setSidebarWidth:E,toggleSidebar:R,paneWidth:T=null,setPaneWidth:$,paneRegistry:z,bindSwipeTab:P,nav:I,onBack:A,onOpenRemote:L,onOpenMobile:D,onOpenRemoteHost:B=null,onOpenMobileHost:F=null,onOpenFiles:K,onLogout:O,onRenameHost:W,onDeleteHost:_,onMainDisconnect:H,onDeleteWorkspace:q,onRenameWorkspace:U,onReorderSession:V,onSetHiddenRepos:X,atStackBottom:G=!1,onAddWorkspace:J,onOpenSettings:Y,homeDir:Z,recentWorkspaces:Q,rightPanel:ee,editorPanel:es,mobilePanel:en,onOpenArtifact:er,fileBus:el,onCreateAnyHost:ea,onQuickCreateHostAware:ei,tunnelUrl:ed,apiKey:eu,connectionMode:ex,onResumeAgentSessionForeign:em=null,subscribeToPush:ep,unsubscribeFromPush:ef}){let{t:eh}=(0,ec.s)(),eb="mouse"===tF(),eg=(0,u.d)(e=>e.bus),ev=(0,u.d)(e=>e.busRef),ew=(0,u.d)(e=>e.connected),ej=(0,u.d)(e=>e.carrier),ek=e||eg,eN=t||ev,eC=(0,r.useMemo)(()=>o.filter(e=>!e.hostKey),[o]),eS=(0,r.useMemo)(()=>c.filter(e=>!e.hostKey),[c]),eT=(0,r.useCallback)(e=>{let t=eR(e);return t.head?t.bus:ek},[ek]),e$=s??ew,eM=el||et.getState(),ez=(0,r.useMemo)(()=>x?.hostKey?eE(x.hostKey).fileBus:eM,[x?.hostKey,eM]),{panesContainerRef:eP,registerPaneApi:eI,registerPaneElement:eA,registerKeyboardTextApi:eL,handlePasteFallback:eD,handleInputFocusChange:eB,focusPane:eF,focusKeyboardInput:eK,scrollPaneIntoView:eO}=z,[eW,e_]=(0,r.useState)(null),{workspaceSessionIds:eH,workspaceOpenedSessions:eq,renderedSessions:eX,mountedSet:eG,workspaceIndex:eJ}=(0,r.useMemo)(()=>(0,eY.gk)({sessions:o,openedSessions:p,livePanes:f,mountedWorkspaces:b,activeWorkspaceId:m,isDesktop:w}),[o,p,f,b,m,w]),eZ=(0,r.useMemo)(()=>o.filter(e=>(0,eY.xs)(e)===m),[o,m]),eQ=(0,r.useMemo)(()=>new Map(eZ.map((e,t)=>[e.id,t])),[eZ]),e0=c.find(e=>e.id===m),e1=e0?.path||x?.workspacePath||null,e2=(0,h.B)(e=>e.rightPanelRoots),e5=(0,h.B)(e=>e.agentBySession),e3=(0,h.B)(e=>e.fullModes||{})[m??eY.AD]??!1,e4=(0,h.B)(e=>e.hiddenPaneSessionIds||[]),e6=(0,h.B)(e=>e.setRightPanelRoot),e8=(0,h.B)(e=>e.openRightPanel),e9=(0,h.B)(e=>e.reorderOpenedSessions),e7=(0,r.useCallback)(e=>{e9(e),V?.(e)},[e9,V]),te=(0,r.useCallback)(e=>{I.handleSelectSession(e)},[I]),tt=!!o.find(e=>e.id===d)?.hostKey,ts=e0?.hostKey||null,tn=eE(ts).busRef,[tr,tl]=(0,r.useState)([]),ta=(0,M.rh)(e=>ts&&e.hosts[ts]?.status||null),ti=(0,M.rh)(e=>e.hosts),to=(0,M.rh)(e=>e.currentKey);(0,r.useEffect)(()=>{ts&&eE(ts).bus?.emit("getShells",e=>tl(e?.shells||[]))},[ts,ta]);let tc=(0,r.useCallback)((e,t)=>{let s=o.filter(e=>e.id!==t&&(0,eY.xs)(e)===(m??null)).length+1;I.handleReplaceSession(t,`${e.short||e.label} ${s}`,e,!0)},[I,o,m]),td=e2[e1]||e1,tu=(0,r.useCallback)(e=>ee?.onTabChange(e,e1??""),[ee,e1]),tx=(0,r.useCallback)(()=>K?.(td),[K,td]),tm=(0,r.useMemo)(()=>e0?.hiddenRepos||[],[e0?.hiddenRepos]),tf=(0,r.useCallback)(e=>{e0&&X?.(e0.id,e)},[e0,X]),th=d&&(g[d]||o.find(e=>e.id===d)?.cwd)||null;(0,r.useEffect)(()=>{e6(e1,null)},[d,e1,e6]);let tg=!o.length,tv=(0,M.rh)(e=>Object.keys(e.hosts).length),ty=tg&&!c.length&&tv<=1,[tw,tj]=(0,r.useState)(!1);ee?.open&&!tw&&tj(!0);let[tk,tN]=(0,r.useState)(!1);!ee?.open&&tk&&tN(!1),(0,r.useEffect)(()=>{if(!ee?.open)return;let e=requestAnimationFrame(()=>tN(!0));return()=>cancelAnimationFrame(e)},[ee?.open]);let tC=!!es?.filePath,[tS,tE]=(0,r.useState)(!1);tC&&!tS&&tE(!0);let[tR,tT]=(0,r.useState)(!1);!tC&&tR&&tT(!1);let[t$,tM]=(0,r.useState)(null);tC&&t$?.filePath!==es.filePath&&tM({filePath:es.filePath,artifactTitle:es.artifactTitle,previewSeq:es.previewSeq}),(0,r.useEffect)(()=>{if(!tC)return;let e=requestAnimationFrame(()=>tT(!0));return()=>cancelAnimationFrame(e)},[tC]);let[tz,tP]=(0,r.useState)(0),[tI,tA]=(0,r.useState)(!1),tL=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!w)return;let e=tL.current;if(!e)return;let t=new ResizeObserver(e=>tP(e[0].contentRect.width));return t.observe(e),()=>t.disconnect()},[w]),(0,r.useEffect)(()=>{if(!e$||!ek?.emit)return;let e=!1,t=()=>ek.emit("bg:get",{},t=>{!e&&t?.success&&t.dataUrl&&h.B.getState().setCustomBackgrounds([{id:"custom",dataUrl:t.dataUrl}])}),s=setTimeout(()=>{e||t()},eV._O);return ek.emit("bg:list",{},n=>{e||(clearTimeout(s),n?.success&&Array.isArray(n.items)?h.B.getState().setCustomBackgrounds(n.items):t())}),()=>{e=!0,clearTimeout(s)}},[e$,ek]);let tD=(0,r.useMemo)(()=>eq.filter(e=>!e4.includes(e)),[eq,e4]).length,tB=(ee?.open&&tk?ee.width:0)+(tC&&tR?es.width:0)+(en?.open&&"pin"===en.mode?en.width:0),tK=(0,eY.Jc)({rowWidth:tz,paneCount:tD,sidebarWidth:C?0:S,sidePx:tB,gapPx:eV.pS,paddingPx:eV.Jv,minWidth:eV.k9.min}),tO=T??tK,tW=(0,r.useRef)({editorFile:es?.filePath,rightOpen:ee?.open});(0,r.useEffect)(()=>{if(!w||!d)return;let e=tW.current,t=e.editorFile!==es?.filePath||e.rightOpen!==ee?.open;if(tW.current={editorFile:es?.filePath,rightOpen:ee?.open},!t)return;let s=setTimeout(()=>{eO(d)},260);return()=>clearTimeout(s)},[es?.filePath,ee?.open,d,w,eO]),(0,r.useEffect)(()=>{w&&e3&&eP.current&&(eP.current.scrollLeft=0)},[w,e3,eP]);let t_=e=>{let t=tO??e.currentTarget.parentElement?.offsetWidth??eV.k9.min;tA(!0),eU(e,{startWidth:t,onWidth:e=>$?.(e),onEnd:()=>tA(!1)})},tH=(0,r.useCallback)(()=>$?.(null),[$]),[tq,tU]=(0,r.useState)(null),tV=(0,r.useRef)(null),tX=sq(tV,tq?.x??0,tq?.y??0),tG=(0,r.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),tU({x:e.clientX,y:e.clientY})},[]),tJ=(0,r.useCallback)(e=>{if("auto"===e)tH();else{let t=eP.current?.clientWidth||tz-(C?0:S)-tB;if(t>0){let s=Math.max(eV.k9.min,Math.floor((t-(e-1)*eV.pS)/e));$?.(s)}}tU(null)},[tH,eP,tz,C,S,tB,$]);(0,r.useEffect)(()=>{if(!tq)return;let e=e=>{tV.current&&!tV.current.contains(e.target)&&tU(null)},t=e=>{"Escape"===e.key&&tU(null)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",t)}},[tq]),(0,r.useEffect)(()=>{let e=()=>tH();return window.addEventListener("terminal:fitPanes",e),()=>window.removeEventListener("terminal:fitPanes",e)},[tH]),(0,r.useEffect)(()=>{let e=e=>{e.detail?.fraction&&tJ(e.detail.fraction)};return window.addEventListener("terminal:splitPreset",e),()=>window.removeEventListener("terminal:splitPreset",e)},[tJ]);let tY=(e,t,s,r=0)=>{let l=o.find(t=>t.id===e),a=l?.hostKey?eE(l.hostKey).fileBus:eM,i=e5[e],c=tb.H8.find(e=>e.id===i);return c?(0,n.jsx)(oN,{title:"AI Chat Pane",children:(0,n.jsx)(ok,{sessionId:e,engine:c.aiEngine,workspacePath:l?.cwd||l?.workspacePath||e0?.path,sessionName:l?.name,bus:eT(e),fileBus:a,isVisible:t,isFocused:s,isDesktop:w,bgIndex:r,onActivate:()=>I.handleSelectSession(e),onNewChat:()=>tc(c,e),onOpenRemote:L,onOpenMobile:D,onOpenArtifact:er})},e):(0,n.jsx)(nV,{workspacePath:l?.workspacePath,sessionName:l?.name,bus:eT(e),fileBus:a,connected:e$,sessionId:e,isVisible:t,isFocused:s,onActivate:I.handleSelectSession,onRegisterApi:eI,onPasteFallback:eD,showFocusBorder:!1,mountDelay:(0,eY.Mt)(e,s,eJ),bgIndex:r,onOpenArtifact:er,onOpenRemote:L,onOpenMobile:D})},tZ=e=>(0,n.jsx)(t4,{bus:eT(e),sessionId:e,onExpandChange:()=>{},onRefocus:()=>eF(e),onRegisterTextApi:eL,onInputFocusChange:eB,platform:a,onInput:ey.getState().clearNotification,onSwitchSession:I.switchSession,onSwitchToIndex:I.switchToIndex,isDesktop:w,statusStrip:(0,n.jsx)(rj,{sessionId:e,busRef:eN,onReveal:t=>{let s=o.find(t=>t.id===e)?.workspacePath;e6(s,t||s),e8()}})});return(0,n.jsxs)("div",{className:`absolute inset-0 flex flex-col ${j?"translate-x-0 opacity-100 z-10":"translate-x-full opacity-0 z-0 pointer-events-none"}`,children:[(0,n.jsxs)("div",{ref:tL,className:`flex-1 min-h-0 relative ${w?"flex flex-row":"flex flex-col"}`,children:[w&&(0,n.jsx)("div",{className:"hidden sm:block overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out",style:{width:C?0:S},children:(0,n.jsx)(ri,{allSessions:o,mainSessions:eC,workspaces:eS,activeSessionId:d,activeWorkspaceId:m,onSelectSession:I.handleSelectSession,onSelectWorkspace:I.handleSelectWorkspace,onCreateNamedSession:I.handleCreateSession,onResumeAgentSession:tt?em:I.handleResumeAgentSession,shells:N,onRenameSession:I.handleRenameSession,onDeleteSession:I.handleDeleteSession,onReorderSession:e7,onDeleteWorkspace:q,onAddWorkspace:J,onRenameWorkspace:U,onOpenSettings:Y,onOpenRemoteHost:B,onOpenMobileHost:F,onLogout:O,onRenameHost:W,onMainDisconnect:H,onDeleteHost:_,busRef:eN,homeDir:Z,cwdBySession:g,connected:e$,width:S,onResize:E,onCollapse:R})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 min-h-0 flex flex-col",children:[(!tg||!w)&&(0,n.jsx)(nh,{sessions:eZ,allSessions:o,activeSessionId:d,isActive:j,connected:e$,onSwitchSession:te,onCreateSession:ts?ei:I.handleQuickCreateSession,onRenameSession:I.handleRenameSession,onDeleteSession:I.handleDeleteSession,onCreateNamedSession:ea,modalBusRef:tn,modalHostKey:ts||"main",modalShells:ts?tr:null,onResumeAgentSession:tt?em:I.handleResumeAgentSession,onBack:w||G?null:A,workspaces:c,activeWorkspaceId:m,onSelectWorkspace:I.handleSelectWorkspace,hasUngrouped:o.some(e=>!(0,eY.xs)(e)),onOpenRemote:L,onOpenMobile:D,onOpenRemoteHost:B,onOpenMobileHost:F,hostKey:ts,onOpenFiles:K,onLogout:O,tunnelUrl:ed,apiKey:eu,connectionMode:ex,subscribeToPush:ep,unsubscribeFromPush:ef,agentVersion:i,busRef:eN,carrier:l||ej,shells:N,onToggleSidebar:w?R:null,sidebarCollapsed:C,onReorderSession:e7,onToggleRightPanel:ee?.onToggle,rightPanelOpen:ee?.open,fileBus:eM,homeDir:Z,isDesktop:w}),ty?(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(aw,{onAddWorkspace:J,onOpenRemote:L,recent:Q,homeDir:Z,onOpenRecent:e=>J?.(e)})}):(0,n.jsx)("div",{ref:eP,className:`flex-1 min-h-0 ${w?`flex flex-row ${e3?"overflow-hidden":"overflow-x-auto"} overflow-y-hidden px-0 pb-0 scrollbar-none`:"relative"}`,...P({enabled:!w,sessionIds:eq,activeSessionId:d,onSwitch:I.handleSelectSession}),children:eX.map(e=>{let t=eH.has(e),s=e===d,r=e4.includes(e),l=t&&!r&&(w&&!e3||s),a=!!ti[eR(e).head||to]?.updating,i=eQ.get(e)??0;return(0,n.jsxs)("div",{ref:t=>eA(e,t),className:!t||w&&e3&&!s||w&&r?"hidden":w?`h-full relative bg-bg ${a?"opacity-50 pointer-events-none":""} ${e3?"w-full flex-1":`border-r-2 border-border-subtle last:border-r-0 ${tI?"":"transition-[width] duration-200 ease-out"}`}`:`absolute inset-0 ${a?"opacity-50 pointer-events-none":s?`opacity-100 z-10 ${k}`:"opacity-0 z-0 pointer-events-none"}`,style:t&&w?e3?{width:"100%",flex:"1 1 0"}:null!=tO?{width:tO,flexShrink:0}:{flex:"1 1 0",minWidth:eV.k9.min}:void 0,children:[eG.has(e)?e5[e]?.endsWith("-ui")?(0,n.jsx)("div",{onMouseDown:()=>{s||I.handleSelectSession(e)},onTouchStart:()=>{s||I.handleSelectSession(e)},className:"w-full h-full flex flex-col relative overflow-hidden",children:tY(e,l,s,i)}):w?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(oC,{children:[tY(e,l,s,i),(0,n.jsx)(oS,{sessionId:e})]}),(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 z-20 border-t border-border-subtle bg-surface",children:s?tZ(e):(0,n.jsx)("button",{type:"button",tabIndex:-1,onClick:()=>{I.handleSelectSession(e),setTimeout(eK,60)},className:"group block w-full text-left","aria-label":"Focus this terminal input",children:(0,n.jsx)("span",{className:"block w-full pl-9 pr-16 py-2 text-sm text-text-muted/60 group-hover:bg-surface-2/70 group-hover:text-text-muted transition-colors truncate",children:(0,n.jsx)(oE,{sessionId:e,placeholder:eh("mobileKeyboard.typeCommand")})})})})]}):tY(e,l,s,i):(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center text-text-muted text-xs"}),t&&w&&!e3&&!r&&(0,n.jsx)("div",{onPointerDown:t_,onDoubleClick:tH,onContextMenu:tG,className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-30",title:eb?tp(eh("shortcuts.fitPanes")||"Auto-fit panes","fitPanes"):void 0})]},e)})}),!w&&d&&!e5[d]?.endsWith("-ui")&&tZ(d)]}),(es?.filePath||w&&tS)&&(0,n.jsx)("div",{className:w?"overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out":"absolute inset-0 z-40 animate-in slide-in-from-bottom duration-200",style:w?{width:tC&&tR?es.width:0}:void 0,"aria-hidden":w&&!tC,children:(0,n.jsx)(ab,{filePath:tC?es.filePath:t$?.filePath,artifactTitle:tC?es.artifactTitle:t$?.artifactTitle,previewSeq:tC?es.previewSeq:t$?.previewSeq,workspace:td,fileBus:ez,width:es.width,onResize:es.onResize,onClose:es.onClose,onOpenFull:es.onOpenFull,onOpenFile:es.onOpen,isDesktop:w})}),w&&en?.open&&"pin"===en.mode&&(0,n.jsx)("div",{ref:e_,className:"relative overflow-hidden flex-shrink-0 border-l border-border",style:{width:en.width},children:(0,n.jsx)("div",{onPointerDown:en.onResizeStart,className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})}),w&&en?.open&&(0,n.jsx)(rB,{busRef:en.busRef||eN,protocolRef:en.protocolRef,connected:en.connected??e$,pinSlot:eW}),ee?.open&&!w&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 bg-black/50 animate-in fade-in duration-200",onClick:ee.onToggle}),(ee?.open||w&&tw)&&(0,n.jsx)("div",{className:w?"overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out":"absolute inset-y-0 right-0 z-30 w-[85%] max-w-sm shadow-elev animate-in slide-in-from-right duration-200",style:w?{width:ee?.open&&tk?ee.width:0}:void 0,"aria-hidden":w&&!ee?.open,children:(0,n.jsx)(lB,{workspacePath:e1,filesRoot:td,cwdHint:th,activeFile:es?.filePath,fileBus:ez,tab:ee.tabs?.[e1??""]||"files",onTabChange:tu,width:ee.width,onResize:ee.onResize,onClose:ee.onToggle,onOpenFiles:K?tx:null,onOpenFile:es?.onOpen,onNewTerminal:ee.onNewTerminal,onAddWorkspace:J,homeDir:Z,hiddenRepos:tm,onHiddenReposChange:e0&&X?tf:null,isDesktop:w})})]}),(0,n.jsx)(ag,{}),w&&!tg&&(0,n.jsx)(rk,{cwd:d&&(g[d]||x?.cwd||e0?.path)||"",sessionId:d,hostKey:x?.hostKey||null,sessionName:x?x?.name:"",agentVersion:i,platform:a,homeDir:Z}),tq&&(0,n.jsxs)("div",{ref:tV,className:"fixed z-[70] menu-popover p-1 min-w-[130px] animate-in fade-in zoom-in-95 duration-100 shadow-xl",style:{left:tX.left,top:tX.top},children:[(0,n.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold text-text-subtle uppercase tracking-wider",children:"Split"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),tJ("auto")},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Auto Fit"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"Auto"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),tJ(2)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/2"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"50%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),tJ(3)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/3"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"33%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),tJ(4)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/4"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"25%"})]})]})]})});var oT=s(45111);function o$({label:e,inline:t=!1}){let{t:s}=(0,ec.s)();return(0,n.jsxs)("div",{className:`${t?"absolute inset-0 z-10":"fixed inset-0 z-40"} flex items-center justify-center animate-in fade-in duration-300`,children:[(0,n.jsx)("div",{className:"cine-bg","aria-hidden":!0,children:(0,n.jsx)("div",{className:"cine-grid"})}),(0,n.jsxs)("div",{className:"relative z-10 flex flex-col items-center gap-3 px-6 text-center",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-text animate-pulse-glow"}),(0,n.jsx)("span",{className:"text-[15px] font-semibold text-text tracking-wide",children:"9Remote"})]}),(0,n.jsx)(oT.A,{size:"lg"}),(0,n.jsx)("p",{className:"text-sm text-text-muted",children:e||s("connection.retrying")})]})]})}var oM=s(30240);function oz({sessions:e,cwdBySession:t={},connected:s,onSelect:l,onCreate:a,onDelete:i,onRename:o,onLogout:c,onOpenRemote:d,tunnelUrl:x,apiKey:m,connectionMode:p="tunnel",isActive:f=!0,busRef:b,subscribeToPush:g,unsubscribeFromPush:v,onResumeAgentSession:y=null,notifications:w,sessionStatus:j,agentVersion:k,carrier:N,workspaces:C=[],onRenameWorkspace:S,onDeleteWorkspace:E,onAddWorkspace:R,onOpenRemoteHost:T=null,fileBus:$,homeDir:z,recentWorkspaces:P=[],shells:I=[],onReorderSession:A,onRenameHost:L=null,onDeleteHost:D=null,onMainDisconnect:B=null,onMainReconnect:F=null}){let K,{t:O}=(0,ec.s)(),W=$||et.getState(),_=Object.values((0,M.rh)(e=>e.hosts)),H=(0,M.rh)(e=>e.currentKey),q=_.find(e=>e.key===H),U=(0,u.d)(e=>e.connected),V=(0,u.d)(e=>e.carrier),X=(0,u.d)(e=>e.busRef),G=s??U,J=N||V||"ws",Y=b||X,Z=ey(e=>e.notifications),Q=e$(),ee=w||Z,es=j||Q,er=eb(e=>e.open),el=eb(e=>e.setContext),ea=eb(e=>e.setCallbacks),ei=(0,h.B)(e=>e.hiddenHeaderButtons),[ed,eu]=(0,r.useState)(null),[ex,em]=(0,r.useState)(null),[ep,ef]=(0,r.useState)(!1),[eh,eg]=(0,r.useState)(!1),ev=_.filter(e=>("full"===e.status||"online"===e.status)&&e.remoteAvailable),ew=eN(_,q?.key);(0,r.useEffect)(()=>{if(!f)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.altKey&&!e.shiftKey&&"t"===e.key.toLowerCase()&&(e.preventDefault(),em({workspaceId:null}))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[f]),(0,r.useEffect)(()=>{f&&(el({connected:G,remoteAvailable:!!d,showTheme:!1,theme:"default",busRef:Y,hideActions:["remote","files","sites"],tunnelUrl:x,apiKey:m,connectionMode:p,subscribeToPush:g,unsubscribeFromPush:v,notifications:ee,agentVersion:k,carrier:J}),ea({onRemote:null,onFiles:null,onSelectSite:null,onRefreshSites:null,onLogout:c,onThemeChange:null}))},[f,G,d,c,el,ea,Y,p,g,v,k,J,x,m,ee]);let ej=new Set(e.map(e=>e.id)),ek=!_.some(e=>e.updating)&&!e.length&&!C.length&&_.length<=1;return(0,n.jsxs)("div",{className:"h-full flex flex-col overflow-hidden relative",children:[(0,n.jsxs)("header",{className:`relative z-10 bg-surface/80 backdrop-blur-md px-4 py-3 ${s1} flex items-center justify-between gap-2 flex-shrink-0 border-b border-border-subtle`,style:{paddingTop:"calc(0.75rem + env(safe-area-inset-top, 0px))"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("div",{className:"p-1.5 bg-brand-500/10 rounded-brand flex-shrink-0",children:(0,n.jsx)(en.Kq,{className:"text-brand-500 w-5 h-5"})}),(0,n.jsx)("h1",{className:"text-text text-lg font-semibold truncate",children:O("sessions.headerTitle")}),(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${G?"bg-green-500":"bg-red-500 animate-pulse"}`,title:G?O("sessions.connected"):O("sessions.disconnected")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[!ei.includes("remote")&&ev.length>0&&(0,n.jsx)(oP,{icon:en.VA,label:O("menu.remoteDesktop"),onClick:()=>{((0,eo.e)(),1===ev.length)?T?.(ev[0].key):eg(!0)},disabled:!G}),(0,n.jsx)(oP,{icon:en.kV,label:O("hosts.addHost"),onClick:()=>{(0,eo.e)(),ef(!0)}}),(0,n.jsx)(oP,{icon:en.wB,label:O("menu.title"),onClick:er})]})]}),(0,n.jsx)("div",{className:"relative z-10 flex-1 overflow-auto modal-scrollable pt-2 pb-12",style:{overflowAnchor:"none"},children:ek?(0,n.jsx)("div",{className:"absolute inset-0 z-10",children:(0,n.jsx)(oI,{onAddWorkspace:R,onOpenRemote:d,recent:P,homeDir:z,connected:G})}):(0,n.jsx)(n.Fragment,{children:ew.map((s,r)=>(0,n.jsx)("div",{className:0===r?"pl-1 pr-3":"mt-3 border-t border-border-subtle pt-2 pl-1 pr-3",children:s.key===(q?.key||"main")&&q?(0,n.jsx)(rl,{mobile:!0,host:{...q,workspaces:C,sessions:e,statusMap:es,onDisconnect:B,onConnect:F},busRef:Y,actions:{selectSession:l,createSession:a,renameSession:o,deleteSession:i,backgroundSession:e=>eu(e),reorderSession:A,renameWorkspace:S,deleteWorkspace:E,renameHost:L,deleteHost:D},connected:G,fileBus:W,homeDir:z,cwdBySession:t,onAddWorkspace:R,menuAddWorkspace:R,onOpenRemoteHost:T,treeCls:"pl-5",rowCls:"active:bg-surface-2 active:text-text"}):(0,n.jsx)(rl,{mobile:!0,host:{...s,onDisconnect:()=>M.rh.getState().disconnectHost(s.key)},actions:{...tt(s,{onSelectSession:l}),renameHost:L,deleteHost:D},connected:G,onOpenRemoteHost:T,treeCls:"pl-5",rowCls:"active:bg-surface-2 active:text-text"})},s.key))})}),ed&&(0,n.jsx)(sJ,{sessionId:ed.id,title:ed.name,busRef:Y,onClose:()=>eu(null)}),ex&&(0,n.jsx)(s_,{onClose:()=>em(null),onCreate:(e,t,s,n,r,l)=>{a?.(e,ex.workspaceId,t,r||null,s,n,l),em(null)},shells:I,busRef:Y,onResumeAgentSession:y,onSelectSession:l,liveSessionIds:ej,connected:G,workspacePath:C.find(e=>e.id===ex.workspaceId)?.path||null,workspaceName:C.find(e=>e.id===ex.workspaceId)?.name||"",fileBus:W,homeDir:z,suggestName:`${O("terminal.defaultName")} ${(K=ex.workspaceId,e.filter(e=>(0,eY.xs)(e)===K)).length+1}`}),ep&&(0,n.jsx)(nQ,{onClose:()=>ef(!1)}),eh&&(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50 backdrop-blur-[4px] animate-in fade-in duration-150",onClick:()=>eg(null),children:(0,n.jsx)("div",{className:"card-elev w-full sm:max-w-sm max-h-[60%] overflow-auto modal-scrollable rounded-t-2xl sm:rounded-2xl p-2 animate-in slide-in-from-bottom-4 duration-150",onClick:e=>e.stopPropagation(),children:ev.map(e=>(0,n.jsxs)("button",{onClick:()=>{let t=e.key;eg(!1),T?.(t)},className:"w-full flex items-center gap-2.5 px-3 py-3 text-left rounded-brand hover:bg-surface-2 active:bg-surface-2 transition-colors",children:[(0,n.jsx)(en.VA,{size:16,className:"text-text-muted shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm text-text",children:e.label||O("agentSwitcher.unnamed")})]},e.key))})})]})}function oP({icon:e,label:t,onClick:s,disabled:r,className:l=""}){return(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),s()},disabled:r,title:t,className:`p-2 rounded-brand transition-colors active:scale-[0.96] ${r?"text-text-subtle cursor-not-allowed":`text-text-muted hover:text-text hover:bg-surface-2 ${l}`}`,children:(0,n.jsx)(e,{className:"w-5 h-5"})})}function oI({onAddWorkspace:e,onOpenRemote:t,recent:s,homeDir:r,connected:l}){let{t:a}=(0,ec.s)(),i=l&&!!t;return(0,n.jsxs)("div",{className:"empty-stage w-full h-full",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),e?.()},disabled:!l,className:"empty-half text-left active:opacity-80 enabled:active:scale-[0.99] transition-all duration-150 disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",a("workspaces.emptyTagWorkspace")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordTerminal")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaWorkspace")}}),(0,n.jsxs)("span",{className:"empty-go",children:[a("workspaces.selectFolder"),(0,n.jsx)(en.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]}),!!s.length&&(0,n.jsx)("span",{className:"flex flex-wrap gap-1.5 mt-4 max-w-full",children:s.slice(0,3).map(t=>(0,n.jsx)("span",{role:"button",title:t.path,onClick:s=>{s.stopPropagation(),(0,eo.e)(),e?.(t.path)},className:"welcome-chip path-tail px-2 py-1 text-[11px] font-mono text-text-muted rounded-full truncate max-w-[46%]",children:sf(t.path,r)},t.path))})]}),!!t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"empty-hairline","aria-hidden":!0}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),t?.()},disabled:!i,className:"empty-half text-left active:opacity-80 enabled:active:scale-[0.99] transition-all duration-150 disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"02"})," / ",a("workspaces.emptyTagRemote")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordRemote")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaRemote")}}),i&&(0,n.jsxs)("span",{className:"empty-go",children:[a("menu.remoteDesktop"),(0,n.jsx)(en.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]})]})]})]})}let oA=(e,t,s)=>Math.max(t,Math.min(s,e));function oL({clientX:e,clientY:t,containerRect:s,pan:n,totalScale:r}){return{x:(e-s.left-n.x)/r,y:(t-s.top-n.y)/r}}function oD(e,t){return{x:Math.min(0,e.width-t.width),y:Math.min(0,e.height-t.height)}}function oB(e,t){return{x:oA(e.x,t.x,0),y:oA(e.y,t.y,0)}}function oF({prevZoom:e,prevPan:t,focal:s,nextZoomRaw:n,maxZoom:r,containerSize:l,displaySizeAt:a}){let i=oA(n,1,r),o=i/e,c=oD(l,a(i));return{zoom:i,pan:oB({x:s.x-(s.x-t.x)*o,y:s.y-(s.y-t.y)*o},c)}}function oK({accum:e,delta:t,threshold:s,multiplier:n}){let r=e+t;if(Math.abs(r)<s)return{accum:r,scroll:null};let l=Math.max(1,Math.round(Math.abs(r)*n));return{accum:0,scroll:r>0?l:-l}}let oO=!!window.chrome,oW=e=>new Blob([e]),o_=(e,t)=>()=>{e.current[t]=null},oH=null,oq=0,oU=new Map;async function oV(e){if("u"<typeof createImageBitmap)return null;if(oO)return createImageBitmap(e);let t=new Image,s=URL.createObjectURL(e);t.src=s,await t.decode();let n=await createImageBitmap(t);return URL.revokeObjectURL(s),n}let oX={fps:0,latency:0,tilesPerSec:0,bandwidthMBps:0,webrtcTiles:0,wsTiles:0,webrtcPercent:0};function oG({list:e,activeIndex:t,onSelect:s}){if(!Array.isArray(e)||e.length<=1)return null;let r=e=>e.stopPropagation();return(0,n.jsx)("div",{className:"absolute bottom-1.5 right-1.5 z-40 flex gap-1.5",children:e.map(e=>{let l=e.index===t,a=`${e.index+1}`;return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),s?.(e.index)},onMouseDown:e=>e.preventDefault(),onPointerDown:r,onPointerUp:r,onPointerMove:r,onTouchStart:r,onTouchMove:r,onTouchEnd:r,onWheel:r,className:`px-1.5 py-0.5 rounded-md text-xs font-medium backdrop-blur-md border transition-colors inline-flex items-center gap-1 ${l?"bg-blue-500/70 text-white border-blue-400/70":"bg-black/30 text-white/80 border-white/10 hover:bg-black/50"}`,title:`${e.name} (${e.width}\xd7${e.height})`,children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]}),a]},e.index)})})}function oJ({canvasRef:e,canvasContainerRef:t,canvasZoom:s,canvasPan:l,fitScale:a,streaming:i,hasFrame:o=!0,selectionRect:d,clickIndicator:u,pointerMode:x,selectionMode:m,handMode:p,handHolding:f,scrollLock:h,virtualCursor:b,cursorShape:g,inputMode:v,keyboardOn:y,monitors:w,activeMonitorIndex:j,onSelectMonitor:k,onPointerDown:N,onPointerMove:C,onPointerUp:S,onWheel:E,onContextMenu:R,onDoubleClick:T,onTouchStart:$,onTouchMove:M,onTouchEnd:z,onKeyDown:P,screenLocked:I,unlockReady:A,unlockResult:L,onUnlockSubmit:D}){let B=a*s,F="mouse"===v,{t:K}=(0,ec.s)(),[O,W]=(0,r.useState)(!1),[_,H]=(0,r.useState)(""),[q,U]=(0,r.useState)(!1),[V,X]=(0,r.useState)(!1);(0,r.useEffect)(()=>{I||(H(""),U(!1))},[I]),(0,r.useEffect)(()=>{L&&U(!1)},[L]);let G={ew:"cursor-ew-resize",ns:"cursor-ns-resize",nwse:"cursor-nwse-resize",nesw:"cursor-nesw-resize",all:"cursor-move"},J=m?"cursor-crosshair":p?f?"cursor-grabbing":"cursor-grab":F&&O?"cursor-grabbing":F&&g&&G[g]?G[g]:"trackpad"===x?"cursor-grab active:cursor-grabbing":"cursor-default",Y=(0,r.useRef)(E);return(0,r.useEffect)(()=>{Y.current=E},[E]),(0,r.useEffect)(()=>{let t=e.current;if(!t)return;let s=e=>Y.current?.(e);return t.addEventListener("wheel",s,{passive:!1}),()=>t.removeEventListener("wheel",s)},[e]),(0,r.useEffect)(()=>{F&&i&&e.current?.focus()},[e,F,i]),(0,r.useEffect)(()=>{if(!O)return;let e=()=>W(!1);return window.addEventListener("pointerup",e),window.addEventListener("pointercancel",e),window.addEventListener("blur",e),()=>{window.removeEventListener("pointerup",e),window.removeEventListener("pointercancel",e),window.removeEventListener("blur",e)}},[O]),(0,n.jsxs)("div",{className:"w-full h-full overflow-hidden relative flex-1",children:[(0,n.jsxs)("div",{className:"absolute inset-0",ref:t,style:{touchAction:"none"},onTouchStart:$,onTouchMove:M,onTouchEnd:z,children:[(0,n.jsx)("canvas",{ref:e,className:`block ${J} bg-black outline-none`,style:{touchAction:"none",transformOrigin:"top left",userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent",transform:`translate3d(${l.x}px, ${l.y}px, 0) scale(${B})`,imageRendering:"auto",willChange:"transform"},onPointerDown:t=>{let s=document.activeElement;if(s?.name==="remote-batch-input")if(y){let e=document.querySelector('textarea[name="remote-keyboard-sink"]');e?.focus()}else s.blur();F&&(e.current?.focus(),"mouse"===t.pointerType&&W(!0)),N?.(t)},onPointerMove:C,onPointerUp:e=>{F&&"mouse"===e.pointerType&&W(!1),S?.(e)},onDoubleClick:T,onContextMenu:R,tabIndex:0,onKeyDown:P}),i&&!o&&!I&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 flex items-center justify-center pointer-events-none",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-black/60 text-white/80 text-[11px] font-mono",children:[(0,n.jsx)(en.kr,{size:12,className:"animate-spin"}),K("remote.receivingImage",{defaultValue:"Receiving screen…"})]})}),d&&(0,n.jsx)("div",{className:"absolute border-2 border-blue-400 bg-blue-400/20 z-10",style:{left:`${d.x}px`,top:`${d.y}px`,width:`${d.width}px`,height:`${d.height}px`}}),"trackpad"===x&&b&&(0,n.jsx)("div",{className:"absolute pointer-events-none z-30",style:{left:`${b.x*B+l.x}px`,top:`${b.y*B+l.y}px`,width:`${c.eR.trackpadCursorSize}px`,height:`${c.eR.trackpadCursorSize}px`,transform:g||p||h||m?"translate(-50%, -50%)":"translate(-2px, -2px)"},children:h?(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center text-yellow-400 drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{fontSize:`${c.eR.trackpadCursorSize}px`,lineHeight:1},children:"✥"}):m?(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full text-yellow-400 drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",children:(0,n.jsx)("path",{d:"M12 3 V21 M3 12 H21",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})}):p?(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{fontSize:`${c.eR.trackpadCursorSize}px`,lineHeight:1},children:f?"✊":"✋"}):g?(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{transform:`rotate(${"ns"===g?90:"nwse"===g?45:"nesw"===g?-45:0}deg)`},children:"all"===g?(0,n.jsx)("path",{d:"M12 3 V21 M3 12 H21 M8 6 L12 2 L16 6 M8 18 L12 22 L16 18 M6 8 L2 12 L6 16 M18 8 L22 12 L18 16",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"}):(0,n.jsx)("path",{d:"M3 12 H21 M7 8 L3 12 L7 16 M17 8 L21 12 L17 16",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",children:(0,n.jsx)("path",{d:"M4 2 L4 18 L8.5 14 L11 20 L14 18.5 L11.5 13 L18 12.5 Z",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinejoin:"round"})})}),u&&(0,n.jsxs)("div",{className:"absolute pointer-events-none z-20",style:{left:`${u.x-u.size/2}px`,top:`${u.y-u.size/2}px`,width:`${u.size}px`,height:`${u.size}px`},children:[(0,n.jsx)("div",{className:"w-full h-full rounded-full border-2 border-blue-400 bg-blue-400/30 animate-ping"}),(0,n.jsx)("div",{className:"absolute inset-0 w-full h-full rounded-full border-2 border-blue-400 bg-blue-400/50"})]})]}),(0,n.jsx)(oG,{list:w,activeIndex:j,onSelect:k}),I&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center",style:{background:"radial-gradient(circle at 50% 40%, rgba(40,60,140,0.55) 0%, rgba(10,12,30,0.92) 60%, rgba(0,0,0,0.96) 100%)"},children:(0,n.jsx)("div",{className:"w-full max-w-[300px] mx-4 rounded-2xl p-5 shadow-2xl backdrop-blur-md",style:{background:"rgba(20,22,40,0.85)",border:"1px solid rgba(120,140,220,0.25)"},children:A?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 mb-4",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center",style:{background:"rgba(120,140,220,0.18)"},children:(0,n.jsx)(en.LM,{size:26,color:"#a9b8ff"})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-white",children:K("remote.lockTitle")}),(0,n.jsx)("p",{className:"text-xs text-center",style:{color:"rgba(220,225,245,0.7)"},children:K("remote.lockDesc")})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{type:V?"text":"password",value:_,autoFocus:!0,disabled:q,onChange:e=>H(e.target.value),onKeyDown:e=>{"Enter"===e.key&&_&&!q&&(U(!0),D?.(_))},placeholder:K("remote.lockPlaceholder"),className:"w-full rounded-xl px-4 py-2 pr-11 text-sm text-white focus:outline-none focus:border-blue-400",style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(120,140,220,0.35)"}}),(0,n.jsx)("button",{type:"button",onClick:()=>X(e=>!e),tabIndex:-1,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 rounded-lg",style:{color:"rgba(220,225,245,0.7)"},"aria-label":V?"Hide password":"Show password",children:V?(0,n.jsx)(en.X_,{size:18}):(0,n.jsx)(en.kU,{size:18})})]}),(0,n.jsx)("button",{type:"button",disabled:!_||q,onClick:()=>{U(!0),D?.(_)},className:"w-full mt-2.5 rounded-xl py-2.5 text-sm font-semibold text-white transition-opacity disabled:opacity-40",style:{background:"linear-gradient(135deg, #4a6cf7 0%, #6b8aff 100%)"},children:K(q?"remote.unlocking":"remote.unlock")}),L&&!L.ok&&(0,n.jsx)("p",{className:"mt-3 text-xs text-center text-red-300",children:K("remote.unlockFailed")})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center",style:{background:"rgba(120,140,220,0.18)"},children:(0,n.jsx)(en.LM,{size:26,color:"#a9b8ff"})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-white",children:K("remote.lockTitle")}),(0,n.jsx)("p",{className:"text-xs",style:{color:"rgba(220,225,245,0.85)"},children:K("remote.lockGrantDesc")})]})})})]})}var oY=s(80186);let oZ=(e,...t)=>{(0,eo.e)(),e?.(...t)};function oQ({active:e,primary:t,pinned:s,children:r,className:l="",onClick:a,...i}){return(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:a,className:`shrink-0 px-1 h-8 rounded-brand text-xs font-semibold shadow-sm disabled:opacity-50 disabled:cursor-not-allowed min-w-[34px] flex items-center justify-center ${e?"bg-brand-500 text-white shadow-sm transition-all duration-150 ease-out active:scale-[0.94]":s?"bg-brand-500/15 hover:bg-brand-500/25 text-brand-400 transition-all duration-150 ease-out active:scale-[0.94]":t?"bg-green-600 hover:bg-green-700 text-white shadow-sm transition-all duration-150 ease-out active:scale-[0.94]":"bg-surface-2 hover:bg-surface-3 text-text transition-all duration-150 ease-out active:scale-[0.94]"} ${l}`,style:{touchAction:"manipulation",WebkitTapHighlightColor:"transparent"},...i,children:r})}function o0({streaming:e,canvasZoom:t,clipboardNew:s,clipboardText:l,onOpenClipboard:a,selectionMode:i,pointerMode:o,handMode:d,inputMode:u,onToggleHandMode:x,onTogglePointerMode:m,modifierKeys:p,textInputValue:f,textInputRef:h,keyboardOn:b,showTextPanel:g,onResetZoom:v,onRefresh:y,onToggleSelection:w,onToggleModifier:j,onToggleKeyboard:k,onToggleTextPanel:N,onToggleHelp:C,onToggleDebug:S,debugOn:E,onEmitKey:R,onTextInputChange:T,onTextInputFocus:$,onTextInputBlur:M,onTextInputKeyDown:z,onDirectInputChange:P,onSendText:I,onClose:A,onDesktopSwitch:L,controlsHidden:D,onToggleControlsHidden:B,tallLandscape:F}){let K,O,W,_,{t:H,locale:q}=(0,ec.s)(),U=(0,r.useRef)(null),[V]=tI(q),[X,G]=(0,r.useState)(!1),J=tD({lang:tz(V),onText:e=>{T(e);let t=U.current;t&&requestAnimationFrame(()=>{try{t.selectionStart=t.selectionEnd=t.value.length}catch{}t.scrollTop=t.scrollHeight})}});(0,r.useEffect)(()=>{let e=U.current;e&&!window.matchMedia("(orientation: landscape)").matches&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,72)}px`)},[f]);let Y=()=>{J.listening&&J.stop(),oZ(I,e)},Z=`flex gap-1.5 overflow-auto scroll-thin-x py-0.5 pr-2 ${F?"":"landscape:flex-wrap landscape:overflow-y-auto landscape:overflow-x-hidden landscape:py-2 landscape:pr-0 landscape:content-center landscape:justify-center"} rounded-lg`,[Q,ee]=(0,r.useState)(!1),[et,es]=(0,r.useState)(!1),[er,el]=(0,r.useState)(0);(0,r.useEffect)(()=>{if(!s)return void el(0);el(Math.ceil(c.eR.clipboardBadgeTimeout/1e3));let e=setInterval(()=>{el(e=>e<=1?0:e-1)},1e3);return()=>clearInterval(e)},[s,l]);let ea=tO("remoteDesktop.bottomKeys",c.ij,c.D5,"flat"),ei=tO("remoteDesktop.extraKeys",c.ij,c.I9,"grid");(0,r.useEffect)(()=>{if(!g)return;let e=setTimeout(()=>U.current?.focus(),350);return()=>clearTimeout(e)},[g]);let ed=c.eR.pcModeControls,eu=e=>"mouse"!==u||ed[e],ex=window.innerWidth<768,em=(t,s,r=!1,l="")=>{let a=t.label.length>1?"text-[11px]":"",i=`${l} ${a}`.trim();if("modifier"===t.type)return(0,n.jsx)(oQ,{onClick:()=>oZ(j,t.modifier),disabled:!e,active:p[t.modifier],pinned:r,className:i,children:t.label},t.id+s);if("desktop"===t.type){let l="prev"===t.direction?en.JG:"next"===t.direction?en.c_:en.FW;return(0,n.jsxs)(oQ,{onClick:()=>oZ(L,t.direction),disabled:!e,pinned:r,className:i,title:`${t.direction} desktop`,children:[(0,n.jsx)(en.VA,{size:12}),(0,n.jsx)(l,{size:"new"===t.direction?10:12,className:"-ml-0.5"})]},t.id+s)}return(0,n.jsx)(oQ,{onClick:()=>oZ(R,t.key,t.modifiers||[],t.osAdaptive),disabled:!e,primary:!r&&t.primary,pinned:r,className:i,children:t.label},t.id+s)};return(0,n.jsxs)("div",{className:`bg-bg select-none relative landscape:flex landscape:flex-col landscape:shrink-0 ${F||D?"":"landscape:h-full landscape:justify-end"} ${D?"landscape:w-12":F?"landscape:w-full landscape:pl-12":"landscape:w-64"}`,children:[(0,n.jsx)("textarea",{ref:h,rows:1,value:f,onChange:e=>{b?P?.(e.target.value):T(e.target.value)},onKeyDown:z,onFocus:$,onBlur:M,"aria-hidden":"true",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"data-lpignore":"true","data-1p-ignore":"true","data-form-type":"other",name:"remote-keyboard-sink",style:{position:"absolute",opacity:.01,width:1,height:1,border:0,padding:0,left:0,top:0,fontSize:16,resize:"none",pointerEvents:"none",zIndex:-1}}),(0,n.jsx)("div",{className:`absolute top-1 right-1 z-30 ${D||F?"hidden":"hidden landscape:flex"}`,children:(0,n.jsx)(oQ,{onClick:()=>{(0,eo.e)(),B?.(!0)},title:H("remote.hideControls"),children:(0,n.jsx)(en.X_,{size:14})})}),(0,n.jsxs)("div",{className:D?"landscape:hidden":"contents",children:[(0,n.jsxs)("div",{className:`${g?"flex":"hidden"} landscape:flex ${F?"":"landscape:flex-col"} relative z-30 px-2 py-1 gap-2 ${F?"landscape:px-0":"landscape:gap-1 landscape:order-last"}`,children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsx)(t$,{value:f,store:tj,isMobile:ex,onSelect:e=>{T(e),U.current?.focus()}}),(0,n.jsx)("textarea",{ref:U,rows:1,cols:1,value:f,onChange:e=>T(e.target.value),onFocus:$,onKeyDown:t=>{"mouse"===u&&"Enter"===t.key&&!t.shiftKey&&(t.preventDefault(),e&&Y())},placeholder:"mouse"===u?H("remoteControls.enterToSend"):H("remoteControls.typeToSend"),autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"data-lpignore":"true","data-1p-ignore":"true","data-form-type":"other",name:"remote-batch-input",className:`block w-full px-3 py-2 pr-8 bg-surface-2 rounded text-text text-sm placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out resize-none overflow-y-auto ${F?"":"landscape:!h-16"}`,disabled:!e}),f?(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{T(""),U.current?.focus()},title:H("voice.clear"),className:"absolute right-1.5 top-1.5 w-5 h-5 flex items-center justify-center text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(en.X,{size:14})}):(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>G(!0),title:H("history.title"),className:"absolute right-1.5 top-1.5 w-5 h-5 flex items-center justify-center text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(en.BZ,{size:14})})]}),(0,n.jsxs)("div",{className:"flex gap-2 items-center justify-end",children:[J.active&&(0,n.jsx)("div",{className:"relative shrink-0",children:(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{J.listening?J.stop():(document.activeElement?.blur(),J.start(f))},disabled:!e,title:"not-allowed"===J.error||"service-not-allowed"===J.error?H("voice.denied"):H("voice.dictate"),className:`h-9 w-9 flex items-center justify-center rounded-full transition-all duration-150 ease-out disabled:opacity-40 ${J.listening?"bg-red-500/90 text-white animate-pulse":J.error?"bg-surface-2 text-red-400":"bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text"}`,children:J.listening?(0,n.jsx)(en.jj,{size:18}):(0,n.jsx)(en.GO,{size:18})})}),(0,n.jsx)(oY.A,{variant:"primary",size:"sm",className:"!px-2.5 shrink-0",onMouseDown:e=>e.preventDefault(),onClick:Y,disabled:!e,children:f.trim()?H("remoteControls.send"):(0,n.jsx)(en.Lt,{size:16,strokeWidth:2.5})})]})]}),(0,n.jsx)("div",{className:`overflow-hidden transition-all duration-300 ${Q?"max-h-56 opacity-100":"hidden"}`,children:(0,n.jsx)("div",{className:"px-2 py-1",children:(0,n.jsx)("div",{className:"space-y-1",children:ei.rows.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0 flex gap-1.5 overflow-x-auto scroll-thin-x pr-3 rounded-lg",children:e.map((e,s)=>{let n=c.ij.find(t=>t.id===e);return n?em(n,100*t+s):null})}),0===t&&(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,eo.e)(),es(!0)},className:"shrink-0 h-10 w-10 flex items-center justify-center text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-all duration-150 ease-out",title:H("remote.customizeKeys"),children:(0,n.jsx)(en.wB,{size:16})}),t>0&&(0,n.jsx)("div",{className:"shrink-0 h-10 w-10"})]},t))})})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 landscape:hidden",children:[(0,n.jsxs)("div",{className:`${Z} flex-1 min-w-0 px-0 py-0 landscape:py-0`,children:[(0,n.jsx)(oQ,{onClick:()=>oZ(A),title:H("remote.back"),pinned:!0,className:"landscape:hidden",children:(0,n.jsx)(en.JG,{size:16})}),s&&l?(0,n.jsxs)(oQ,{onClick:()=>oZ(a),className:"!text-red-500 landscape:hidden",title:H("common.clipboard"),children:[(0,n.jsx)(en.Ir,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"tabular-nums",children:er})]}):(0,n.jsxs)(oQ,{onClick:()=>oZ(v),disabled:!e,className:"text-text landscape:hidden",title:H("remote.resetZoom"),children:[Math.round(100*t),"%"]}),(0,n.jsx)(oQ,{onClick:()=>oZ(y),disabled:!e,title:H("remote.refresh"),className:"landscape:hidden",children:(0,n.jsx)(en.e9,{size:14})}),eu("rectangleSelect")&&(0,n.jsx)(oQ,{onClick:()=>oZ(w),disabled:!e,active:i,title:H("remote.rectangleSelection"),className:"landscape:hidden",children:"□"}),eu("pointerModeToggle")&&(0,n.jsx)(oQ,{onClick:()=>oZ(m),disabled:!e,active:"trackpad"===o,title:"trackpad"===o?H("remoteControls.trackpadMode"):H("remoteControls.directMode"),className:"landscape:hidden",children:(0,n.jsx)("span",{className:"text-base leading-none",children:"\uD83D\uDDB1️"})}),eu("handMode")&&"trackpad"===o&&(0,n.jsx)(oQ,{onClick:()=>oZ(x),disabled:!e,active:d,title:H("remote.handMode"),className:"landscape:hidden",children:(0,n.jsx)(en.Ud,{size:14})}),eu("keyboardToggle")&&(0,n.jsx)(oQ,{onClick:()=>oZ(k),disabled:!e,active:b,title:H("remote.toggleKeyboard"),className:"landscape:hidden",children:(0,n.jsx)(en.s3,{size:14})}),eu("textPanel")&&(0,n.jsx)(oQ,{onClick:()=>oZ(N),disabled:!e,active:g,title:H("remote.textBatchInput"),className:"landscape:hidden",children:"Aa"}),eu("help")&&(0,n.jsx)(oQ,{onClick:()=>oZ(C),title:H("remote.help"),className:"landscape:hidden",children:(0,n.jsx)(en.mN,{size:14})})]}),(0,n.jsx)(oQ,{onClick:()=>{(0,eo.e)(),ee(e=>!e)},active:Q,pinned:!0,className:"landscape:hidden shrink-0",title:H("remote.extraKeys"),children:Q?(0,n.jsx)(en.X,{size:16}):(0,n.jsx)(en.a4,{size:16})})]}),eu("modifierRow")&&(K=ea.keys.filter(e=>e.id!==c.Ic),O=c.ij.find(e=>e.id===c.Ic),W=(0,n.jsx)(oQ,{onClick:()=>{(0,eo.e)(),ee(e=>!e)},active:Q,pinned:!0,title:H("remote.extraKeys"),children:Q?(0,n.jsx)(en.X,{size:16}):(0,n.jsx)(en.a4,{size:16})}),_=O?em(O,"pinned",!0):null,(0,n.jsxs)("div",{className:`px-2 py-1 safe-area-bottom ${F?"landscape:px-0":"landscape:py-2"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 landscape:hidden",children:[(0,n.jsx)("div",{className:`${Z} flex-1 min-w-0`,children:K.map((e,t)=>em(e,t))}),_]}),(0,n.jsxs)("div",{className:`${Z} hidden ${F?"landscape:flex":""}`,children:[K.map((e,t)=>em(e,t)),W,_]}),(0,n.jsxs)("div",{className:`hidden ${F?"":"landscape:flex"} landscape:flex-col gap-1`,children:[(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[K.slice(0,5).map((e,t)=>em(e,t)),W]}),(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[K.slice(5).map((e,t)=>em(e,t)),_]})]})]}))]}),(0,n.jsxs)("div",{className:`flex-col gap-1.5 p-1.5 ${D?"hidden landscape:flex":"hidden"}`,children:[(0,n.jsx)(oQ,{onClick:()=>{(0,eo.e)(),B?.(!1)},title:H("remote.showControls"),children:(0,n.jsx)(en.kU,{size:16})}),(0,n.jsx)(oQ,{onClick:()=>oZ(k),disabled:!e,active:b,title:H("remote.toggleKeyboard"),children:(0,n.jsx)(en.s3,{size:16})})]}),(0,n.jsx)(tU,{isOpen:et,onClose:()=>es(!1),title:H("remote.customizeRemoteKeys"),tabs:[{id:"bottom",label:H("remoteControls.bottomRow"),hook:ea,excludeIds:[c.Ic]},{id:"extra",label:H("remoteControls.extraPanel"),hook:ei}]}),(0,n.jsx)(tC,{isOpen:X,store:tj,onSelect:e=>{T(e),U.current?.focus()},onClose:()=>G(!1)})]})}let o1="bg-surface-2 hover:bg-surface-3 text-text",o2="bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text",o5="bg-brand-500 text-white";function o3({onClick:e,title:t,disabled:s,className:r,children:l}){return(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,eo.e)(),e()},disabled:s,title:t,className:`shrink-0 w-9 h-9 rounded-brand flex items-center justify-center transition-all duration-150 active:scale-[0.94] ${r} ${s?"disabled:opacity-50":""}`,children:l})}function o4({streaming:e,canvasZoom:t,pointerMode:s,handMode:r,keyboardOn:l,selectionMode:a,show:i,onBack:o,onRefresh:c,onResetZoom:d,onTogglePointerMode:u,onToggleHandMode:x,onToggleKeyboard:m,onShowHelp:p,onToggleSelection:f}){let{t:h}=(0,ec.s)();return(0,n.jsxs)("div",{className:"hidden landscape:flex flex-col items-center gap-1.5 py-2 px-1 bg-bg shrink-0 landscape:w-12 z-20",children:[(0,n.jsx)(o3,{onClick:o,title:h("remote.back"),className:"bg-brand-500/15 hover:bg-brand-500/25 text-brand-400",children:(0,n.jsx)(en.JG,{size:18})}),(0,n.jsx)(o3,{onClick:c,disabled:!e,title:h("remote.refresh"),className:o2,children:(0,n.jsx)(en.e9,{size:16})}),(0,n.jsxs)(o3,{onClick:d,disabled:!e,title:h("remote.resetZoom"),className:`text-[10px] font-semibold ${o1}`,children:[Math.round(100*t),"%"]}),i("pointerModeToggle")&&(0,n.jsx)(o3,{onClick:u,disabled:!e,title:h("trackpad"===s?"remoteControls.trackpadMode":"remoteControls.directMode"),className:`text-base leading-none ${"trackpad"===s?o5:o1}`,children:"\uD83D\uDDB1️"}),i("handMode")&&"trackpad"===s&&(0,n.jsx)(o3,{onClick:x,disabled:!e,title:h("remote.handMode"),className:r?o5:o1,children:(0,n.jsx)(en.Ud,{size:16})}),i("keyboardToggle")&&(0,n.jsx)(o3,{onClick:m,disabled:!e,title:h("remote.toggleKeyboard"),className:l?o5:o2,children:(0,n.jsx)(en.s3,{size:16})}),i("help")&&(0,n.jsx)(o3,{onClick:p,title:h("remote.help"),className:o2,children:(0,n.jsx)(en.mN,{size:16})}),i("rectangleSelect")&&(0,n.jsx)(o3,{onClick:f,disabled:!e,title:h("remote.rectangleSelection"),className:a?o5:o1,children:"□"})]})}function o6({onClose:e,inputMode:t="touch",pointerMode:s="direct"}){let{t:l}=(0,ec.s)();(0,r.useEffect)(()=>{let t=t=>{"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),e?.())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e]);let a="mouse"===t?[{title:l("remoteHelp.mouseTitle"),items:[{key:l("remoteHelp.mouseClickKey"),desc:l("remoteHelp.mouseClickDesc")},{key:l("remoteHelp.mouseRightKey"),desc:l("remoteHelp.mouseRightDesc")},{key:l("remoteHelp.mouseWheelKey"),desc:l("remoteHelp.mouseWheelDesc")},{key:l("remoteHelp.mouseDoubleKey"),desc:l("remoteHelp.mouseDoubleDesc")}]},{title:l("remoteHelp.keyboardTitle"),items:[{key:l("remoteHelp.keyPhysicalKey"),desc:l("remoteHelp.keyPhysicalDesc")},{key:l("remoteHelp.keyModifierKey"),desc:l("remoteHelp.keyModifierDesc")}]}]:"trackpad"===s?[{title:l("remoteHelp.gesturesTrackpadTitle"),items:[{key:l("remoteHelp.trackpadSwipeKey"),desc:l("remoteHelp.trackpadSwipeDesc")},{key:l("remoteHelp.trackpadScrollLockKey"),desc:l("remoteHelp.trackpadScrollLockDesc")},{key:l("remoteHelp.trackpadTapKey"),desc:l("remoteHelp.trackpadTapDesc")},{key:l("remoteHelp.trackpad2TapKey"),desc:l("remoteHelp.trackpad2TapDesc")},{key:l("remoteHelp.trackpad2SwipeKey"),desc:l("remoteHelp.trackpad2SwipeDesc")},{key:l("remoteHelp.trackpadPinchKey"),desc:l("remoteHelp.trackpadPinchDesc")}]},{title:l("remoteHelp.toolbarTitle"),items:[{key:"✋",desc:l("remoteHelp.toolbarHandDesc")},{key:"\uD83D\uDDB1️",desc:l("remoteHelp.toolbarMouseDirectDesc")},{key:"⌨️ / Aa",desc:l("remoteHelp.toolbarKeyboardDesc")}]}]:[{title:l("remoteHelp.gesturesDirectTitle"),items:[{key:l("remoteHelp.directTapKey"),desc:l("remoteHelp.directTapDesc")},{key:l("remoteHelp.directLongKey"),desc:l("remoteHelp.directLongDesc")},{key:l("remoteHelp.directDoubleKey"),desc:l("remoteHelp.directDoubleDesc")},{key:l("remoteHelp.directScrollKey"),desc:l("remoteHelp.directScrollDesc")},{key:l("remoteHelp.directPinchKey"),desc:l("remoteHelp.directPinchDesc")},{key:l("remoteHelp.directPanKey"),desc:l("remoteHelp.directPanDesc")}]},{title:l("remoteHelp.toolbarTitle"),items:[{key:"\uD83D\uDDB1️",desc:l("remoteHelp.toolbarMouseTrackpadDesc")},{key:"⌨️ / Aa",desc:l("remoteHelp.toolbarKeyboardDesc")},{key:"□",desc:l("remoteHelp.toolbarRectDesc")}]}],i=l("mouse"===t?"remoteHelp.modePc":"trackpad"===s?"remoteHelp.modeTrackpad":"remoteHelp.modeDirect");return(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 bg-black/60 flex items-center justify-center p-4",onClick:e,children:(0,n.jsxs)("div",{className:"card-elev max-w-lg w-full max-h-full overflow-y-auto",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border sticky top-0 bg-surface z-10",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h2",{className:"text-text text-base font-semibold",children:l("remote.help")}),(0,n.jsx)("span",{className:"text-brand-400 text-xs font-mono",children:i})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-surface-2 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(en.X,{size:18})})]}),(0,n.jsx)("div",{className:"p-4 space-y-4",children:a.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-brand-400 text-xs font-semibold uppercase tracking-wider mb-2",children:e.title}),(0,n.jsx)("ul",{className:"space-y-1.5",children:e.items.map(e=>(0,n.jsxs)("li",{className:"flex gap-3 text-sm",children:[(0,n.jsx)("span",{className:"text-text font-mono bg-bg px-2 py-0.5 rounded text-xs shrink-0 min-w-[120px] text-center",children:e.key}),(0,n.jsx)("span",{className:"text-text-muted",children:e.desc})]},e.key))})]},e.title))})]})})}function o8({stats:e,mode:t,onReset:s,onClose:l,onCopy:a,onForceWsDisconnect:i,onToggleWsBlock:o,isWsBlocked:c}){var d,u;let x,{t:m}=(0,ec.s)(),[p,f]=(0,r.useState)(!1);return p?(0,n.jsx)("div",{className:"fixed top-4 right-4 z-50",children:(0,n.jsxs)("button",{onClick:()=>f(!1),className:"bg-surface-2 text-text px-4 py-2 rounded-lg shadow-md hover:bg-surface-3 transition-all duration-150 ease-out active:scale-[0.97]",children:["\uD83D\uDD0D ",m("remote.debug")]})}):(0,n.jsxs)("div",{className:"fixed top-4 right-4 z-50 card-elev p-4 min-w-[280px] text-sm",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3 pb-2 border-b border-border",children:[(0,n.jsxs)("h3",{className:"text-text font-semibold flex items-center gap-2",children:["\uD83D\uDD0D ",m("remote.debugTitle")]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>f(!0),className:"text-text-muted hover:text-text transition-colors",title:m("remote.minimize"),children:"─"}),(0,n.jsx)("button",{onClick:l,className:"text-text-muted hover:text-text transition-colors",title:m("common.close"),children:"✕"})]})]}),(0,n.jsxs)("div",{className:"space-y-2 mb-3",children:[(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Mode:"}),(0,n.jsx)("span",{className:"rtc"===t?"text-blue-400 font-semibold":"text-yellow-400 font-semibold",children:"rtc"===t?"RTC enabled":"WS only"})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.transport"),":"]}),(0,n.jsx)("span",{className:e.webrtcPercent>50?"text-blue-400 font-semibold":"text-text-muted",children:e.webrtcPercent>50?"WebRTC ✅":"WebSocket"})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.fps"),":"]}),(0,n.jsx)("span",{className:`font-semibold ${(d=e.fps)>=15?"text-green-400":d>=10?"text-yellow-400":"text-red-400"}`,children:e.fps})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.latency"),":"]}),(0,n.jsx)("span",{className:`font-semibold ${(u=e.latency)<50?"text-green-400":u<100?"text-yellow-400":"text-red-400"}`,children:(x=e.latency,`${Math.round(x)}ms`)})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.tilesPerSec"),":"]}),(0,n.jsx)("span",{className:"text-text font-semibold",children:e.tilesPerSec})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.bandwidth"),":"]}),(0,n.jsxs)("span",{className:"text-text font-semibold",children:[e.bandwidthMBps," MB/s"]})]})]}),(0,n.jsxs)("div",{className:"border-t border-border pt-3 mb-3 space-y-1",children:[(0,n.jsxs)("div",{className:"flex justify-between items-center text-xs",children:[(0,n.jsx)("span",{className:"text-blue-400",children:"WebRTC:"}),(0,n.jsxs)("span",{className:"text-text-muted",children:[e.webrtcTiles.toLocaleString()," tiles (",e.webrtcPercent,"%)"]})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center text-xs",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"WebSocket:"}),(0,n.jsxs)("span",{className:"text-text-muted",children:[e.wsTiles.toLocaleString()," tiles (",100-e.webrtcPercent,"%)"]})]})]}),(0,n.jsxs)("div",{className:"flex gap-2 border-t border-border pt-3",children:[(0,n.jsx)("button",{onClick:s,className:"flex-1 bg-surface hover:bg-surface-2 text-text py-2 px-3 rounded transition-colors text-xs",children:m("remote.clearStats")}),(0,n.jsx)("button",{onClick:a,className:"flex-1 bg-surface hover:bg-surface-2 text-text py-2 px-3 rounded transition-colors text-xs",children:"Copy"})]}),(i||o)&&(0,n.jsxs)("div",{className:"flex gap-2 mt-2",children:[i&&(0,n.jsx)("button",{onClick:i,className:"flex-1 bg-red-900/40 hover:bg-red-900/60 text-red-300 py-2 px-3 rounded transition-colors text-xs",title:"Disconnect WS once (auto-reconnect)",children:"⚡ Kill WS"}),o&&(0,n.jsx)("button",{onClick:o,className:`flex-1 py-2 px-3 rounded transition-colors text-xs ${c?"bg-yellow-900/60 hover:bg-yellow-900/80 text-yellow-200":"bg-surface hover:bg-surface-2 text-text"}`,title:"Block WS reconnect to test RTC standalone",children:c?"\uD83D\uDD12 WS Blocked":"\uD83D\uDEAB Block WS"})]})]})}function o9({text:e,onClose:t}){let[s,l]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t]);let a=async()=>{try{await navigator.clipboard?.writeText(e),l(!0),setTimeout(()=>l(!1),1500)}catch{}};return(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 bg-black/60 flex items-center justify-center p-4",onClick:t,children:(0,n.jsxs)("div",{className:"card-elev max-w-lg w-full max-h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(en.m0,{size:16,className:"text-brand-400"}),(0,n.jsx)("h2",{className:"text-text text-base font-semibold",children:"Clipboard"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-surface-2 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(en.X,{size:18})})]}),(0,n.jsx)("div",{className:"p-4 overflow-y-auto flex-1",children:(0,n.jsx)("pre",{className:"text-text text-sm whitespace-pre-wrap break-all bg-bg rounded p-3 font-mono min-h-[120px] max-h-[55dvh] overflow-y-auto scroll-thin",children:e||""})}),(0,n.jsx)("div",{className:"flex justify-end gap-2 p-4 border-t border-border",children:(0,n.jsxs)("button",{onClick:a,disabled:!e,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-brand bg-brand-500 hover:bg-brand-600 disabled:opacity-50 text-white text-sm font-semibold transition-colors",children:[s?(0,n.jsx)(en.aJ,{size:14}):(0,n.jsx)(en.m0,{size:14}),"Copy"]})})]})})}function o7({onClose:e,busRef:t,protocolRef:l,connected:a,carrier:i,hostPlatform:o}){let{t:u}=(0,ec.s)(),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(!1),[h,b]=(0,r.useState)(!1),[g,v]=tK("remoteDesktop.showTextPanel",!0),[y,w]=tK("remoteDesktop.keyboard",!1),[j,k]=tK("remoteDesktop.controlsHidden",!1),[N,C]=tK("remoteDesktop.pointerMode",c.eR.pointerMode),[S,E]=tK("remoteDesktop.handMode",!1),R=tF(),T=c.eR.pcModeControls,[$,M]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=window.matchMedia("(orientation: landscape)"),t=()=>M(e.matches);return t(),e.addEventListener?.("change",t),()=>e.removeEventListener?.("change",t)},[]);let z=$&&Math.min(window.screen.width,window.screen.height)>=700;(0,r.useEffect)(()=>{"mouse"===R&&"direct"!==N&&C("direct")},[R,N,C]);let{stats:P,trackTilesReceived:I,resetStats:A}=function(){let[e,t]=(0,r.useState)(oX),s=(0,r.useRef)({frameCount:0,lastFpsTime:Date.now(),tilesReceived:0,lastTilesTime:Date.now(),bytesReceived:0,lastBandwidthTime:Date.now(),latencies:[],webrtcTilesTotal:0,wsTilesTotal:0});return{stats:e,trackTilesReceived:(0,r.useCallback)((e,n)=>{let r=s.current,l=Date.now();r.frameCount++;let a=e.tiles?.length||0;r.tilesReceived+=a;let i="number"==typeof e.bytes?e.bytes:e.tiles?.reduce((e,t)=>e+(t.imageBuffer?.byteLength||t.imageBuffer?.length||0),0)||0;if(r.bytesReceived+=i,e.timestamp){let t=Date.now()-e.timestamp;r.latencies.push({value:t,time:l}),r.latencies=r.latencies.filter(e=>l-e.time<6e4)}if(n?.startsWith("dc")||"webrtc"===n?r.webrtcTilesTotal+=a:r.wsTilesTotal+=a,l-r.lastFpsTime>=500){let e=(l-r.lastFpsTime)/1e3,s=Math.round(r.frameCount/e),n=r.latencies.length>0?Math.round(r.latencies.reduce((e,t)=>e+t.value,0)/r.latencies.length):0,a=Math.round(r.tilesReceived/e),i=(r.bytesReceived/e/1024/1024).toFixed(2),o=r.webrtcTilesTotal+r.wsTilesTotal,c=o>0?Math.round(r.webrtcTilesTotal/o*100):0;t({fps:s,latency:n,tilesPerSec:a,bandwidthMBps:parseFloat(i),webrtcTiles:r.webrtcTilesTotal,wsTiles:r.wsTilesTotal,webrtcPercent:c}),r.frameCount=0,r.tilesReceived=0,r.bytesReceived=0,r.lastFpsTime=l}},[]),resetStats:(0,r.useCallback)(()=>{let e=s.current;e.frameCount=0,e.lastFpsTime=Date.now(),e.tilesReceived=0,e.lastTilesTime=Date.now(),e.bytesReceived=0,e.lastBandwidthTime=Date.now(),e.latencies=[],e.webrtcTilesTotal=0,e.wsTilesTotal=0,t(oX)},[])}}(),[L,D]=(0,r.useState)(c.eR.debug?.panel??!1),[B,F]=(0,r.useState)(!1),K=c.eR.enableWebRTC?"rtc":"ws",O=(0,r.useCallback)(()=>{let e={mode:K,...P,ts:new Date().toISOString()};navigator.clipboard?.writeText(JSON.stringify(e,null,2)).catch(()=>{})},[P,K]),W=(0,r.useRef)(P);(0,r.useEffect)(()=>{W.current=P},[P]),(0,r.useEffect)(()=>{(0,d.c)("remote",`[stats] interval started, mode=${K}`);let e=setInterval(()=>{(0,d.c)("remote",`[stats][${K}]`,JSON.stringify(W.current))},5e3);return()=>{(0,d.c)("remote","[stats] interval stopped"),clearInterval(e)}},[K]);let{streaming:_,emitRequestScreenWithHashes:H,emitMousePress:q,emitMouseRelease:U,emitMouseClick:V,emitMouseMove:X,emitMouseDragSelect:G,emitKeyPress:J,emitTypeText:Y,emitScroll:Z,emitBoostStream:Q,emitSetFocus:ee,emitDesktopSwitch:et}=function(e,t){let[s,n]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(t&&e?.current)return n(!0),()=>n(!1)},[t,e]);let l=(0,r.useCallback)((t,s)=>{e?.current?.emit(t,s)},[e]),a=(0,r.useCallback)((e,t,n="left")=>{s&&l("mouse-press",{x:e,y:t,button:n})},[l,s]),i=(0,r.useCallback)((e,t,n="left")=>{s&&l("mouse-release",{x:e,y:t,button:n})},[l,s]),o=(0,r.useCallback)((e,t,n="left",r=!1)=>{s&&l("mouse-click",{x:e,y:t,button:n,double:r})},[l,s]),c=(0,r.useCallback)((e,t)=>{s&&l("mouse-move",{x:e,y:t})},[l,s]),d=(0,r.useCallback)((e,t,n,r)=>{s&&l("mouse-drag-select",{startX:e,startY:t,endX:n,endY:r})},[l,s]),u=(0,r.useCallback)((e,t=[])=>{s&&l("key-press",{key:e,modifier:t})},[l,s]),x=(0,r.useCallback)(e=>{s&&l("type-text",{text:e})},[l,s]),m=(0,r.useCallback)((e,t=20,n=!1)=>{s&&l("scroll",{direction:e,amount:t,horizontal:n})},[l,s]),p=(0,r.useCallback)(()=>{s&&l("boost-stream")},[l,s]),f=(0,r.useCallback)((e,t=1)=>{s&&l("set-focus",{rect:e,zoom:t,viewerWidth:window.innerWidth,dpr:window.devicePixelRatio||1})},[l,s]),h=(0,r.useCallback)(e=>{s&&l("request-screen-with-hashes",{tileHashes:e})},[l,s]),b=(0,r.useCallback)(e=>{s&&l("desktop-switch",{direction:e})},[l,s]);return{streaming:s,emitRequestScreenWithHashes:h,emitMousePress:a,emitMouseRelease:i,emitMouseClick:o,emitMouseMove:c,emitMouseDragSelect:d,emitKeyPress:u,emitTypeText:x,emitScroll:m,emitBoostStream:p,emitSetFocus:f,emitDesktopSwitch:b}}(t,a),es={emitRequestScreenWithHashes:H,emitMousePress:q,emitMouseRelease:U,emitMouseClick:V,emitMouseMove:X,emitMouseDragSelect:G,emitKeyPress:J,emitTypeText:Y,emitScroll:Z,emitBoostStream:Q},en=(0,r.useCallback)(()=>{f(!0)},[]);(0,r.useEffect)(()=>{i&&(0,d.c)("remote",`[remote] carrier: ${i}`)},[i]);let{canvasRef:er,canvasContainerRef:el,canvasZoom:ea,canvasPan:ed,fitScale:eu,baseCanvasSize:ex,zoomGestureTimeoutRef:em,clickIndicator:ep,virtualCursor:ef,handHolding:eh,scrollLock:eb,getCanvasCoordinates:eg,resetZoom:ev,resetPan:ey,panForKeyboard:ew,centerVirtualCursor:ej,startHandHold:ek,releaseHandHold:eN,handleCanvasInteraction:eC,handleCanvasDimensions:eS,serverDimensionsRef:eE}=function(e){let t=function(){let e=(0,r.useRef)(null),t=(0,r.useRef)(null),[s,n]=(0,r.useState)(1),[l,a]=(0,r.useState)({x:0,y:0}),[i,o]=(0,r.useState)(1),[d,u]=(0,r.useState)({width:0,height:0}),x=(0,r.useRef)({width:0,height:0}),m=(0,r.useRef)({x:0,y:0}),p=i*s,f=(0,r.useCallback)(()=>{let e=t.current;return e?{width:e.clientWidth,height:e.clientHeight}:null},[]),h=(0,r.useCallback)(e=>({width:d.width*e,height:d.height*e}),[d]),b=(0,r.useCallback)((n,r)=>{let a=e.current,o=t.current;return a&&o&&0!==a.width?function({canvasPoint:e,canvasWidth:t,canvasHeight:s}){return{percentX:oA(e.x/t*100,0,100),percentY:oA(e.y/s*100,0,100)}}({canvasPoint:oL({clientX:n,clientY:r,containerRect:o.getBoundingClientRect(),pan:l,totalScale:i*s}),canvasWidth:a.width,canvasHeight:a.height}):{percentX:0,percentY:0}},[l,s,i]),g=(0,r.useCallback)((e,t)=>{let n=i*s;n<=0||(m.current={x:(e-l.x)/n,y:(t-l.y)/n})},[i,s,l]),v=(0,r.useCallback)(()=>{n(1),a({x:0,y:0})},[]),y=(0,r.useCallback)(()=>a({x:0,y:0}),[]),w=(0,r.useCallback)((e,t)=>{let n=f();if(!n)return;let r=i*s;if(r<=0)return;let l=t||m.current,o=oD(n,h(s));a(t=>{if(!e||s<=1)return oB(t,o);let{y:a}=function({focus:e,containerHeight:t,totalScale:s}){return{y:t/3-e.y*s}}({focus:l,containerHeight:n.height,totalScale:r});return oB({x:t.x,y:a},o)})},[f,h,i,s]),j=(0,r.useCallback)(()=>{let s,n=t.current,r=e.current,l=x.current;if(!n||!r||0===l.width||0===l.height)return;let a=(s={width:n.clientWidth,height:n.clientHeight},Math.min(s.width/l.width,s.height/l.height));o(a),u({width:l.width*a,height:l.height*a})},[]);(0,r.useEffect)(()=>{let e=null,s=null,n=()=>{let e=t.current;if(!e)return void j();let n=e.clientWidth,r=e.clientHeight,l=0,a=0,i=()=>{let t=e.clientWidth,o=e.clientHeight;if(t===n&&o===r){if(++l>=c.eR.resizeStableFrames){s=null,j();return}}else l=0,n=t,r=o;if(a++>=c.eR.resizeMaxFrames){s=null,j();return}s=requestAnimationFrame(i)};s=requestAnimationFrame(i)},r=()=>{e&&clearTimeout(e),s&&(cancelAnimationFrame(s),s=null),e=setTimeout(n,c.eR.resizeDebounceMs)};return window.addEventListener("resize",r),window.addEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.addEventListener("resize",r),()=>{e&&clearTimeout(e),s&&cancelAnimationFrame(s),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.removeEventListener("resize",r)}},[j]),(0,r.useEffect)(()=>{a(e=>{let n=t.current;if(!n)return e;let r=oB(e,oD({width:n.clientWidth,height:n.clientHeight},{width:d.width*s,height:d.height*s}));return r.x===e.x&&r.y===e.y?e:r})},[d,s]);let k=(0,r.useCallback)((s,n)=>{x.current={width:s.width,height:s.height};let r=e.current,l=t.current;if(!r||!l)return!1;let a=r.width!==s.width||r.height!==s.height;r.width=s.width,r.height=s.height;let i=r.getContext("2d");return i.imageSmoothingEnabled=!1,a&&(i.clearRect(0,0,r.width,r.height),i.fillStyle="#2a2a2a",i.fillRect(0,0,r.width,r.height),n?.current&&n.current.clear()),j(),a},[j]);return{canvasRef:e,canvasContainerRef:t,canvasZoom:s,setCanvasZoom:n,canvasPan:l,setCanvasPan:a,fitScale:i,totalScale:p,baseCanvasSize:d,serverDimensionsRef:x,containerSize:f,displaySizeAt:h,getCanvasCoordinates:b,recordInteractPx:g,resetZoom:v,resetPan:y,panForKeyboard:w,handleCanvasDimensions:k}}(),{canvasRef:s,canvasContainerRef:n,canvasZoom:l,setCanvasZoom:a,canvasPan:i,setCanvasPan:o,fitScale:d,baseCanvasSize:u,containerSize:x,displaySizeAt:m,getCanvasCoordinates:p,recordInteractPx:f}=t,[h,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(0),w=(0,r.useRef)({x:0,y:0}),[j,k]=(0,r.useState)(!1),N=(0,r.useRef)(null),[C,S]=(0,r.useState)(null),E=(0,r.useRef)(null),R=(0,r.useRef)(!1),T=(0,r.useRef)({x:0,y:0}),$=(0,r.useRef)(0),M=(0,r.useRef)({x:0,y:0}),[z,P]=(0,r.useState)(!1),I=(0,r.useRef)({x:0,y:0}),A=(0,r.useRef)({x:0,y:0}),L=(0,r.useRef)(0),D=(0,r.useRef)(null),[B,F]=(0,r.useState)({x:0,y:0}),K=(0,r.useRef)(0),O=(0,r.useRef)(0),W=(0,r.useRef)(null),_=(0,r.useRef)({time:0,distance:0,centerX:0,centerY:0}),H=(0,r.useRef)(!1),q=(0,r.useRef)(0),U=(0,r.useRef)(!1),V=(0,r.useRef)(null),X=(0,r.useRef)(!1),[G,J]=(0,r.useState)(!1),Y=(0,r.useRef)(null),Z=(0,r.useRef)(!1),[Q,ee]=(0,r.useState)(!1),et=(0,r.useRef)(null),es=(0,r.useRef)({x:0,y:0}),en=(0,r.useRef)(!1),er=(0,r.useRef)(null),el=(0,r.useRef)(0),ea=(0,r.useCallback)((e,t)=>{let s=n.current;if(!s)return;let r=s.getBoundingClientRect(),a=e-r.left,i=t-r.top,o=oA(7.5*l,5,15);f(a,i),S({x:a,y:i,size:o}),setTimeout(()=>S(null),500)},[l,n,f]),ei=(0,r.useCallback)(()=>{E.current&&(clearTimeout(E.current),E.current=null)},[]),ec=(0,r.useCallback)((t,s,n,r)=>{ei(),R.current=!1,T.current={x:t,y:s},E.current=setTimeout(()=>{R.current=!0,ea(t,s),e?.emitMouseClick(n,r,"right")},c.eR.longPressDelay)},[ei,ea,e]),ed=(0,r.useCallback)((e,t)=>{let s=Date.now(),n=function({now:e,lastTime:t,lastPos:s,x:n,y:r,cfg:l}){let a=Math.abs(n-s.x),i=Math.abs(r-s.y);return e-t<l.doubleClickDelay&&a<l.moveThreshold&&i<l.moveThreshold}({now:s,lastTime:$.current,lastPos:M.current,x:e,y:t,cfg:c.eR});return $.current=s,M.current={x:e,y:t},n},[]),eu=(0,r.useCallback)(()=>{D.current&&(cancelAnimationFrame(D.current),D.current=null),A.current={x:0,y:0},I.current={x:0,y:0},P(!1)},[]),ex=(0,r.useCallback)(()=>{let t=()=>{var s,n;let r=(s=A.current,n=c.eR,Math.abs(s.y)<n.momentumMinVelocity?null:{scrollY:Math.round(s.y*n.edgeScrollMultiplier),nextVelocity:{x:s.x*n.momentumFriction,y:s.y*n.momentumFriction}});if(!r)return eu();Math.abs(r.scrollY)>=1&&e?.emitScroll(r.scrollY>0?"up":"down",Math.abs(r.scrollY),!1),A.current=r.nextVelocity,D.current=requestAnimationFrame(t)};D.current=requestAnimationFrame(t)},[e,eu]);(0,r.useEffect)(()=>()=>{ei(),eu()},[ei,eu]);let em=(0,r.useCallback)(t=>{let{edgeScrollThreshold:s,edgeScrollMultiplier:n}=c.eR,r=oK({accum:I.current.y,delta:t,threshold:s,multiplier:n});I.current.y=r.accum,r.scroll&&e?.emitScroll(r.scroll>0?"up":"down",Math.abs(r.scroll),!1)},[e]),ep=(0,r.useCallback)(t=>{let{edgeScrollThreshold:s,edgeScrollMultiplier:n}=c.eR,r=oK({accum:I.current.x,delta:t,threshold:s,multiplier:n});I.current.x=r.accum,r.scroll&&e?.emitScroll(r.scroll>0?"right":"left",Math.abs(r.scroll),!0)},[e]),ef=(0,r.useCallback)((e,t)=>({percentX:oA(e.x/t.width*100,0,100),percentY:oA(e.y/t.height*100,0,100)}),[]),eh=(0,r.useCallback)(t=>{let n=s.current;if(!n||0===n.width)return;let{percentX:r,percentY:l}=ef(t,n);e?.emitMouseMove?.(r,l)},[e,s,ef]);(0,r.useEffect)(()=>{let t=t=>{if(null==et.current||t.pointerType&&"mouse"!==t.pointerType)return;let r=s.current,l=n.current;if(!r||!l)return;let{percentX:a,percentY:i}=p(t.clientX,t.clientY),o=et.current;et.current=null,e?.emitMouseRelease?.(a,i,o)};return window.addEventListener("pointerup",t),window.addEventListener("pointercancel",t),()=>{window.removeEventListener("pointerup",t),window.removeEventListener("pointercancel",t)}},[p,e,s,n]);let eb=(0,r.useCallback)((t,r,u)=>{let{streaming:f,pointerMode:C="direct"}=u;if(!f||!e)return;let S={canvasRef:s,canvasContainerRef:n,containerSize:x,displaySizeAt:m,getCanvasCoordinates:p,socketEmitFunctions:e,canvasZoom:l,fitScale:d,virtualCursor:B,canvasPan:i,setCanvasZoom:a,setCanvasPan:o,setVirtualCursor:F,isZooming:h,isPanning:g,isEdgeScrolling:z,recentZoomGesture:j,lastTouchDistanceRef:y,lastTouchCenterRef:w,setIsZooming:b,setIsPanning:v,setIsEdgeScrolling:P,setRecentZoomGesture:k,gestureLockRef:W,gestureStartRef:_,multiTouchLatchRef:H,twoFingerMaxMovedRef:q,touchOutsideRef:U,longPressTriggeredRef:R,touchStartPosRef:T,edgeScrollAccumRef:I,velocityRef:A,lastTouchTimeRef:L,touchStartTimeRef:K,touchTotalMoveRef:O,handLongPressTimerRef:V,handHoldingRef:X,setHandHolding:J,scrollLongPressTimerRef:Y,scrollLockRef:Z,setScrollLock:ee,mouseDownButtonRef:et,wheelAccumRef:es,wheelActiveRef:en,wheelEndTimerRef:er,wheelLastBoostRef:el,zoomGestureTimeoutRef:N,showClickIndicator:ea,cancelLongPress:ei,startLongPress:ec,checkDoubleClick:ed,stopMomentum:eu,startMomentumScroll:ex,emitScrollFromDelta:em,emitHScrollFromDelta:ep,cursorPercent:ef,emitVirtualCursor:eh};if(t.nativeEvent?.pointerType==="mouse"||"wheel"===t.type||"contextmenu"===t.type||"dblclick"===t.type)return("wheel"===t.type||"contextmenu"===t.type)&&t.preventDefault(),function(e,t,s,n){let{socketEmitFunctions:r,getCanvasCoordinates:l,showClickIndicator:a}=e,{streaming:i,selectionMode:o,handleSelection:d}=n;if(!i||!r)return;let u=c.eR.mouseButtonMap[t.button]||"left";if("wheel"===s){var x,m;let{percentX:s,percentY:n}=l(t.clientX,t.clientY),a=(x=t.deltaMode,m=c.eR,1===x?m.wheelLineHeight:2===x?m.wheelPageHeight:1),i=t.deltaY*a,o=t.deltaX*a;if(t.ctrlKey||t.metaKey){let s=e.canvasContainerRef.current,n=e.canvasRef.current;if(!s||!n)return;let r=s.getBoundingClientRect(),l={x:t.clientX-r.left,y:t.clientY-r.top},a={width:s.clientWidth,height:s.clientHeight},o=i>0?-1:1;e.setCanvasZoom(t=>{let s=oA(t+o*c.eR.wheelZoomStep,1,4);return s===t?t:(e.setCanvasPan(n=>oF({prevZoom:t,prevPan:n,focal:l,nextZoomRaw:s,maxZoom:4,containerSize:a,displaySizeAt:e.displaySizeAt}).pan),s)});return}if(e.wheelActiveRef.current){let t=Date.now();t-e.wheelLastBoostRef.current>=c.eR.wheelBoostInterval&&(r.emitBoostStream?.(),e.wheelLastBoostRef.current=t)}else r.emitBoostStream?.(),r.emitMouseMove?.(s,n),e.wheelActiveRef.current=!0,e.wheelLastBoostRef.current=Date.now();e.wheelEndTimerRef.current&&clearTimeout(e.wheelEndTimerRef.current),e.wheelEndTimerRef.current=setTimeout(()=>{e.wheelActiveRef.current=!1,e.wheelAccumRef.current.x=0},150);let d=c.eR.wheelScrollMultiplier;if(i&&e.emitScrollFromDelta(-i*d),o){let{edgeScrollThreshold:t,edgeScrollMultiplier:s}=c.eR,n=oK({accum:e.wheelAccumRef.current.x,delta:o*d,threshold:t,multiplier:s});e.wheelAccumRef.current.x=n.accum,n.scroll&&r.emitScroll?.(n.scroll>0?"right":"left",Math.abs(n.scroll),!0)}return}if("contextmenu"===s){let{percentX:e,percentY:s}=l(t.clientX,t.clientY);a(t.clientX,t.clientY),r.emitMouseClick?.(e,s,"right");return}if("dblclick"===s)return;if(o){"pointerdown"===s?d?.(t.clientX,t.clientY,"start"):"pointermove"===s&&null!=e.mouseDownButtonRef.current?d?.(t.clientX,t.clientY,"move"):"pointerup"===s&&(d?.(t.clientX,t.clientY,"end"),e.mouseDownButtonRef.current=null),"pointerdown"===s&&(e.mouseDownButtonRef.current=u);return}let{percentX:p,percentY:f}=l(t.clientX,t.clientY);if("pointerdown"===s){e.mouseDownButtonRef.current=u,a(t.clientX,t.clientY),r.emitMousePress?.(p,f,u);return}if("pointermove"===s){null!=e.mouseDownButtonRef.current&&r.emitMouseMove?.(p,f);return}if("pointerup"===s){let t=e.mouseDownButtonRef.current||u;e.mouseDownButtonRef.current=null,r.emitMouseRelease?.(p,f,t)}}(S,t,r,u);t.preventDefault(),t.type.startsWith("touch")&&t.touches?.length>=2&&(H.current=!0,Y.current&&(clearTimeout(Y.current),Y.current=null),Z.current&&(Z.current=!1,ee(!1),I.current={x:0,y:0}),V.current&&(clearTimeout(V.current),V.current=null)),"trackpad"===C&&t.type.startsWith("touch")&&function(e,t,s,n){let r=e.canvasRef.current;if(!r||0===r.width)return!0;let{selectionMode:l,dragMode:a,isDragging:i,setIsDragging:o,setDragMode:d,handleSelection:u,handMode:x=!1,onHandRelease:m}=n;if(t.touches?.length>=2||!(!e.multiTouchLatchRef.current&&(t.touches?.length===1||"touchend"===s)))return!1;let p=t.touches?.[0]||t.changedTouches?.[0];if(!p)return!0;if("touch"===s){if(e.touchStartTimeRef.current=Date.now(),e.touchTotalMoveRef.current=0,e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=Date.now(),l){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);return u?.(0,0,"start",{...n,percentOverride:{percentX:t,percentY:s}}),!0}return x&&!e.handHoldingRef.current&&(e.handLongPressTimerRef.current&&clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=setTimeout(()=>{e.handLongPressTimerRef.current=null;let t=e.canvasRef.current;if(!t||0===t.width)return;let{percentX:s,percentY:n}=e.cursorPercent(e.virtualCursor,t);e.handHoldingRef.current=!0,e.setHandHolding(!0),(0,eo.e)(15),e.socketEmitFunctions.emitMousePress?.(s,n,"left")},c.eR.longPressDelay)),x||e.scrollLockRef.current||(e.scrollLongPressTimerRef.current&&clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=setTimeout(()=>{e.scrollLongPressTimerRef.current=null,e.scrollLockRef.current=!0,e.setScrollLock(!0),e.edgeScrollAccumRef.current={x:0,y:0},(0,eo.e)(15)},c.eR.longPressDelay)),!0}if("touchmove"===s){let t=p.clientX-e.lastTouchCenterRef.current.x,s=p.clientY-e.lastTouchCenterRef.current.y;if(e.touchTotalMoveRef.current+=Math.abs(t)+Math.abs(s),e.scrollLockRef.current)return e.emitScrollFromDelta(s),e.emitHScrollFromDelta(t),e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=Date.now(),!0;e.scrollLongPressTimerRef.current&&e.touchTotalMoveRef.current>c.eR.trackpadTapMaxMove&&(clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=null);let a=Date.now(),i=function({deltaX:e,deltaY:t,dt:s,cfg:n}){let r=Math.sqrt(e*e+t*t)/s,l=1+Math.min(n.trackpadAcceleration,r*n.trackpadAcceleration);return n.trackpadSensitivity*l}({deltaX:t,deltaY:s,dt:Math.max(1,a-e.lastTouchTimeRef.current),cfg:c.eR}),o=Math.max(1e-4,e.fitScale*e.canvasZoom),d=t*i/o,m=s*i/o;return l?e.setVirtualCursor(t=>{let s={x:oA(t.x+d,0,r.width-1),y:oA(t.y+m,0,r.height-1)},{percentX:l,percentY:a}=e.cursorPercent(s,r);return e.emitVirtualCursor(s),u?.(0,0,"move",{...n,percentOverride:{percentX:l,percentY:a}}),s}):(x&&!e.handHoldingRef.current&&e.handLongPressTimerRef.current&&e.touchTotalMoveRef.current>c.eR.trackpadTapMaxMove&&(clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=null),e.setVirtualCursor(t=>{let s={x:oA(t.x+d,0,r.width-1),y:oA(t.y+m,0,r.height-1)};if(e.emitVirtualCursor(s),e.handHoldingRef.current){let{percentX:t,percentY:n}=e.cursorPercent(s,r);e.socketEmitFunctions.emitMouseMove?.(t,n)}let n=e.containerSize();if(n&&e.canvasZoom>1){let t={width:r.width*o,height:r.height*o},l=oD(n,t);e.setCanvasPan(e=>{let r=function({cursor:e,pan:t,containerSize:s,displaySize:n,totalScale:r,marginRatio:l}){let a=s.width*l,i=s.height*l,o=e.x*r+t.x,c=e.y*r+t.y,d={x:0,y:0};return o<a?d.x=a-o:o>s.width-a&&(d.x=-(o-(s.width-a))),c<i?d.y=i-c:c>s.height-i&&(d.y=-(c-(s.height-i))),d}({cursor:s,pan:e,containerSize:n,displaySize:t,totalScale:o,marginRatio:c.eR.trackpadEdgeMarginRatio});return oB({x:e.x+r.x,y:e.y+r.y},l)})}return s})),e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=a,!0}if("touchend"===s){if(l){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);return u?.(0,0,"end",{...n,percentOverride:{percentX:t,percentY:s}}),!0}if(x){if(e.handLongPressTimerRef.current&&(clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=null),e.handHoldingRef.current){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);e.socketEmitFunctions.emitMouseRelease?.(t,s,"left"),e.handHoldingRef.current=!1,e.setHandHolding(!1),m?.()}return!0}if(e.scrollLongPressTimerRef.current&&(clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=null),e.scrollLockRef.current)return e.scrollLockRef.current=!1,e.setScrollLock(!1),e.edgeScrollAccumRef.current={x:0,y:0},!0;let t=Date.now()-e.touchStartTimeRef.current;if(e.touchTotalMoveRef.current<=c.eR.trackpadTapMaxMove&&t<=c.eR.trackpadTapMaxDuration){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r),n=e.checkDoubleClick(e.virtualCursor.x,e.virtualCursor.y);a?i?(o(!1),d(!1),e.socketEmitFunctions.emitMouseRelease(t,s,"left")):(o(!0),e.socketEmitFunctions.emitMousePress(t,s,"left")):e.socketEmitFunctions.emitMouseClick(t,s,"left",n)}return!0}return!1}(S,t,r,u)||function(e,t,s,n){let r,l,{selectionMode:a,selectionStart:i,dragMode:o,isDragging:d,setIsDragging:u,setDragMode:x,isMobile:m,handleSelection:p,pointerMode:f="direct"}=n;if(t.type.startsWith("touch")&&t.touches?.length>=2&&!a){var h;let n,r,l,a=(n=(h=t.touches)[0].clientX-h[1].clientX,Math.sqrt(n*n+(r=h[0].clientY-h[1].clientY)*r)),i={x:((l=t.touches)[0].clientX+l[1].clientX)/2,y:(l[0].clientY+l[1].clientY)/2};if("touch"===s){e.setIsZooming(!0),e.lastTouchDistanceRef.current=a,e.lastTouchCenterRef.current=i,e.gestureLockRef.current=null,e.gestureStartRef.current={time:Date.now(),distance:a,centerX:i.x,centerY:i.y},e.twoFingerMaxMovedRef.current=0;return}if("touchmove"===s&&e.isZooming){let t=e.canvasContainerRef.current;if(!t)return;if(null===e.gestureLockRef.current){let t=Date.now()-e.gestureStartRef.current.time,s=Math.abs(a-e.gestureStartRef.current.distance),n=Math.sqrt((i.x-e.gestureStartRef.current.centerX)**2+(i.y-e.gestureStartRef.current.centerY)**2);e.twoFingerMaxMovedRef.current=Math.max(e.twoFingerMaxMovedRef.current,s,n),e.gestureLockRef.current=function({elapsed:e,deltaDistance:t,deltaCentroid:s,cfg:n}){let r=t>=n.gestureDistanceThreshold,l=s>=n.gestureCentroidThreshold;if(!r&&!l&&e<n.gestureLockDelay)return null;let a=s>.5?t/s:1/0;return a>=n.gestureDominanceRatio&&r?"zoom":a<=1/n.gestureDominanceRatio&&l?"scroll":r&&!l?"zoom":l&&!r?"scroll":null}({elapsed:t,deltaDistance:s,deltaCentroid:n,cfg:c.eR})}if("scroll"===e.gestureLockRef.current){let t=i.y-e.lastTouchCenterRef.current.y;if(!e.isEdgeScrolling){let t=e.canvasRef.current,s="trackpad"===f&&t&&t.width>0?e.cursorPercent(e.virtualCursor,t):e.getCanvasCoordinates(i.x,i.y);e.socketEmitFunctions?.emitBoostStream?.(),e.socketEmitFunctions?.emitMouseMove?.(s.percentX,s.percentY),e.setIsEdgeScrolling(!0)}e.emitScrollFromDelta(t),e.lastTouchDistanceRef.current=a,e.lastTouchCenterRef.current=i;return}if("zoom"===e.gestureLockRef.current&&e.lastTouchDistanceRef.current>0){let s=t.getBoundingClientRect(),n={width:t.clientWidth,height:t.clientHeight},r={x:i.x-s.left,y:i.y-s.top},l=e.canvasZoom*(a/e.lastTouchDistanceRef.current);e.setCanvasPan(t=>oF({prevZoom:e.canvasZoom,prevPan:t,focal:r,nextZoomRaw:l,maxZoom:4,containerSize:n,displaySizeAt:e.displaySizeAt}).pan),e.setCanvasZoom(oA(l,1,4)),e.lastTouchDistanceRef.current=a}e.lastTouchCenterRef.current=i;return}}if(t.type.startsWith("touch")&&t.touches?.length===1){let n=t.touches[0];if(e.isZooming){e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY};return}if("touch"===s){if(e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY},e.lastTouchTimeRef.current=Date.now(),e.velocityRef.current={x:0,y:0},e.edgeScrollAccumRef.current={x:0,y:0},e.stopMomentum(),e.touchOutsideRef.current=!function(e,t,s){let n=e.canvasRef.current,r=e.canvasContainerRef.current;if(!n||!r||0===n.width)return!1;let l=oL({clientX:t,clientY:s,containerRect:r.getBoundingClientRect(),pan:e.canvasPan,totalScale:e.fitScale*e.canvasZoom});return l.x>=0&&l.x<=n.width&&l.y>=0&&l.y<=n.height}(e,n.clientX,n.clientY),a)p(n.clientX,n.clientY,"start");else if(!o&&!e.touchOutsideRef.current){let{percentX:t,percentY:s}=e.getCanvasCoordinates(n.clientX,n.clientY);e.startLongPress(n.clientX,n.clientY,t,s)}return}if("touchmove"===s){let t=Math.abs(n.clientX-e.touchStartPosRef.current.x),s=Math.abs(n.clientY-e.touchStartPosRef.current.y);if((t>c.eR.moveThreshold||s>c.eR.moveThreshold)&&e.cancelLongPress(),a&&i)return p(n.clientX,n.clientY,"move");if(!a&&!o){let t=n.clientX-e.lastTouchCenterRef.current.x,s=n.clientY-e.lastTouchCenterRef.current.y,r=Date.now(),l=r-e.lastTouchTimeRef.current;if(l>0&&(e.velocityRef.current={x:t/l*16,y:s/l*16},e.lastTouchTimeRef.current=r),Math.abs(t)>5||Math.abs(s)>5){e.cancelLongPress();let r=e.getCanvasCoordinates(n.clientX,n.clientY),l=Math.abs(s)>1.5*Math.abs(t),a=t=>{l&&(e.isEdgeScrolling||(e.socketEmitFunctions?.emitBoostStream?.(),e.socketEmitFunctions?.emitMouseMove?.(r.percentX,r.percentY),e.setIsEdgeScrolling(!0)),e.emitScrollFromDelta(t))};if(1===e.canvasZoom){l&&a(s),e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY};return}e.setIsPanning(!0);let i=e.containerSize()||{width:0,height:0},o=e.displaySizeAt(e.canvasZoom);e.setCanvasPan(n=>{let r=function({prevPan:e,deltaX:t,deltaY:s,containerSize:n,displaySize:r}){let l=oD(n,r),a=oB({x:e.x+t,y:e.y+s},l),i=Math.abs(a.y-e.y)>.5?0:e.y+s-a.y;return{pan:a,overflowY:i}}({prevPan:n,deltaX:t,deltaY:s,containerSize:i,displaySize:o});return Math.abs(r.overflowY)>0?a(r.overflowY):(e.edgeScrollAccumRef.current.y=0,e.setIsEdgeScrolling(!1)),r.pan}),e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY}}return}}}if("touchend"===s){if(e.cancelLongPress(),"trackpad"===f&&e.isZooming&&0===(t.touches?.length||0)&&null===e.gestureLockRef.current&&Date.now()-e.gestureStartRef.current.time<=c.eR.trackpadTapMaxDuration&&e.twoFingerMaxMovedRef.current<=c.eR.trackpadTapMaxMove){let t=e.canvasRef.current;if(t&&t.width>0&&e.socketEmitFunctions?.emitMouseClick){let{percentX:s,percentY:n}=e.cursorPercent(e.virtualCursor,t);e.socketEmitFunctions.emitMouseClick(s,n,"right"),(0,eo.e)(15)}}e.gestureLockRef.current=null,0===(t.touches?.length||0)&&(e.multiTouchLatchRef.current=!1);let s=e.isZooming,n=e.isPanning,r=e.isEdgeScrolling,l=e.longPressTriggeredRef.current;if(e.longPressTriggeredRef.current=!1,s&&(e.setRecentZoomGesture(!0),e.zoomGestureTimeoutRef.current&&clearTimeout(e.zoomGestureTimeoutRef.current),e.zoomGestureTimeoutRef.current=setTimeout(()=>e.setRecentZoomGesture(!1),200)),r&&(Math.abs(e.velocityRef.current.x)>c.eR.momentumMinVelocity||Math.abs(e.velocityRef.current.y)>c.eR.momentumMinVelocity)?e.startMomentumScroll():e.stopMomentum(),e.setIsZooming(!1),e.setIsPanning(!1),s||n||r||e.recentZoomGesture||l)return;if(t.type.startsWith("touch")){let s=t.changedTouches?.[0];if(s){if(a)p(s.clientX,s.clientY,"end");else if(!e.touchOutsideRef.current){let{percentX:t,percentY:n}=e.getCanvasCoordinates(s.clientX,s.clientY);if(e.showClickIndicator(s.clientX,s.clientY),o)d?(u(!1),x(!1),e.socketEmitFunctions.emitMouseRelease(t,n,"left")):(u(!0),e.socketEmitFunctions.emitMousePress(t,n,"left"));else{let r=e.checkDoubleClick(s.clientX,s.clientY);e.socketEmitFunctions.emitMouseClick(t,n,"left",r)}}}}return}if(e.isZooming||e.isPanning)return;if(t.type.startsWith("touch")){if(t.touches?.length!==1)return;r=t.touches[0].clientX,l=t.touches[0].clientY}else r=t.clientX,l=t.clientY;let{percentX:b,percentY:g}=e.getCanvasCoordinates(r,l);if("click"===s)if(a)p(r,l,i?"end":"start");else if(e.showClickIndicator(r,l),o)d?(u(!1),x(!1),e.socketEmitFunctions.emitMouseRelease(b,g,"left")):(u(!0),e.socketEmitFunctions.emitMousePress(b,g,"left"));else{let t=e.checkDoubleClick(r,l);e.socketEmitFunctions.emitMouseClick(b,g,"left",t)}else if("move"===s&&!m){if(a&&i)return p(r,l,"move");e.socketEmitFunctions.emitMouseMove(b,g)}}(S,t,r,u)},[h,g,z,l,j,d,B,i,p,ea,e,ei,ec,ed,eu,ex,eh,em,ep,s,n,x,m,o,a,ef]);(0,r.useEffect)(()=>{let e=s.current;e&&0!==e.width&&F(t=>0===t.x&&0===t.y?{x:e.width/2,y:e.height/2}:t)},[u,s]);let eg=(0,r.useCallback)(()=>{let e=s.current,t=x();if(!e||!t||0===e.width)return;let n=d*l;n<=0||F({x:oA((t.width/2-i.x)/n,0,e.width-1),y:oA((t.height/2-i.y)/n,0,e.height-1)})},[d,l,i,s,x]),ev=(0,r.useCallback)(()=>{let t=s.current;if(!t||0===t.width||X.current)return;V.current&&(clearTimeout(V.current),V.current=null);let{percentX:n,percentY:r}=ef(B,t);X.current=!0,J(!0),(0,eo.e)(15),e?.emitBoostStream?.(),e?.emitMousePress?.(n,r,"left")},[B,e,s,ef]),ey=(0,r.useCallback)(()=>{if(!X.current)return;let t=s.current,n=t&&t.width>0?B.x/t.width*100:0,r=t&&t.height>0?B.y/t.height*100:0;e?.emitMouseRelease?.(n,r,"left"),X.current=!1,J(!1)},[B,e,s]);return{canvasRef:s,canvasContainerRef:n,canvasZoom:l,canvasPan:i,fitScale:d,baseCanvasSize:u,zoomGestureTimeoutRef:N,clickIndicator:C,virtualCursor:B,handHolding:G,scrollLock:Q,getCanvasCoordinates:p,resetZoom:t.resetZoom,resetPan:t.resetPan,panForKeyboard:t.panForKeyboard,centerVirtualCursor:eg,startHandHold:ev,releaseHandHold:ey,handleCanvasInteraction:eb,handleCanvasDimensions:t.handleCanvasDimensions,serverDimensionsRef:t.serverDimensionsRef}}(es),eR=(0,r.useCallback)(()=>{C(e=>{let t="trackpad"===e?"direct":"trackpad";return"trackpad"===t&&ej(),t})},[ej,C]),{textInputValue:eT,setTextInputValue:e$,textInputRef:eM,modifierKeys:ez,selectionMode:eP,selectionStart:eI,selectionRect:eA,dragMode:eL,isDragging:eD,setIsDragging:eB,setDragMode:eF,toggleModifierKey:eK,toggleSelectionMode:eO,handleTextInputFocus:eW,handleCanvasKeyPress:e_,sendTextInput:eH,handleSelection:eq,handleModifiedTextInput:eU,handleDirectInputChange:eV,emitKeyWithActiveModifiers:eX}=function(e){let[t,s]=(0,r.useState)(""),[n,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(null),[d,u]=(0,r.useState)({ctrl:!1,cmd:!1,alt:!1,shift:!1}),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(null),[h,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),j=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=()=>{let e=window.innerWidth<=768||/Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);return l(e),e},t=()=>{e()?i((window.visualViewport?.height||window.innerHeight)<.75*window.screen.height):i(!1)};return e(),window.addEventListener("resize",t),window.visualViewport&&window.visualViewport.addEventListener("resize",t),()=>{window.removeEventListener("resize",t),window.visualViewport&&window.visualViewport.removeEventListener("resize",t)}},[]),(0,r.useEffect)(()=>()=>{j.current&&clearInterval(j.current)},[]);let k=(0,r.useCallback)(e=>{u(t=>({...t,[e]:!t[e]})),n&&o.current&&o.current.focus()},[n]),N=(0,r.useCallback)(()=>{m(e=>!e),f(null),b(null)},[]),C=(0,r.useCallback)(()=>{v(e=>!e),y&&w(!1)},[y]),S=(0,r.useCallback)(()=>{},[]),E=(0,r.useCallback)((t,s)=>{if(!s||!e?.emitKeyPress)return;let n=t.key;if("Shift"===n||"Control"===n||"Meta"===n||"Alt"===n)return;"F12"!==n&&t.preventDefault();let r=[];t.ctrlKey&&r.push("control"),t.metaKey&&r.push("command"),t.altKey&&r.push("alt"),t.shiftKey&&r.push("shift");let l=Object.keys(d).filter(e=>d[e]);for(let e of l){let t=c.tC[e];t&&!r.includes(t)&&r.push(t)}let a=c.FO[n]??(1===n.length?n:n.toLowerCase());e.emitKeyPress(a,r),l.length>0&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1})},[d,e]),R=(0,r.useCallback)((t,s,r=!1)=>{s&&e?.emitScroll&&(j.current&&clearInterval(j.current),e.emitScroll(t,20,r),j.current=setInterval(()=>{e?.emitScroll&&s&&e.emitScroll(t,20,r)},c.eR.scrollInterval),n&&o.current&&a&&setTimeout(()=>o.current?.focus(),10))},[n,a,e]),T=(0,r.useCallback)(e=>R("up",e),[R]),$=(0,r.useCallback)(e=>R("down",e),[R]),M=(0,r.useCallback)(e=>R("left",e,!0),[R]),z=(0,r.useCallback)(e=>R("right",e,!0),[R]),P=(0,r.useCallback)(()=>{j.current&&(clearInterval(j.current),j.current=null)},[]),I=tj(e=>e.addCommand),A=(0,r.useCallback)(n=>{if(!n||!e?.emitTypeText)return;if(!t.trim())return void e.emitKeyPress?.("enter",[]);let r=document.activeElement===o.current;e.emitTypeText(t),I(t),s(""),r&&o.current?.focus()},[t,e,o,I]),L=(0,r.useRef)(""),D=(0,r.useRef)(null),B=(0,r.useCallback)((t,n)=>{n&&t&&e?.emitTypeText&&(L.current+=t,s(""),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{let t=L.current;L.current="",D.current=null,t&&e.emitTypeText(t)},150))},[e]),F=(0,r.useCallback)(t=>{if(!e?.emitKeyPress)return;let s=Object.keys(d).filter(e=>d[e]),n=s.map(e=>c.tC[e]);e.emitKeyPress(t,n),s.length>0&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1})},[d,e]),K=(0,r.useCallback)(e=>{e&&(F("backspace"),n&&o.current&&a&&o.current.focus())},[n,a,F]),O=(0,r.useCallback)((e,t)=>{t&&(F(e),n&&o.current&&a&&o.current.focus())},[n,a,F]),W=(0,r.useCallback)(e=>{e&&(F("escape"),n&&o.current&&a&&o.current.focus())},[n,a,F]),_=(0,r.useCallback)(e=>{e&&(F("tab"),n&&o.current&&a&&o.current.focus())},[n,a,F]),H=(0,r.useCallback)((e,t)=>{t&&(F("enter"),e&&e.preventDefault(),n&&o.current&&a&&o.current.focus())},[n,a,F]),q=(0,r.useCallback)((t,s,n,r)=>{let{streaming:l,getCanvasCoordinates:a,baseCanvasSize:i,canvasZoom:o,canvasPan:c,percentOverride:d}=r;if(!x||!l||!e?.emitMouseDragSelect)return;let{percentX:u,percentY:h}=d||a(t,s);if("start"===n)f({x:u,y:h}),b(null);else if("move"===n&&p){let e=i.width*o,t=i.height*o;b({x:Math.min(p.x,u)*e/100+c.x,y:Math.min(p.y,h)*t/100+c.y,width:Math.abs(u-p.x)*e/100,height:Math.abs(h-p.y)*t/100})}else"end"===n&&p&&(e.emitMouseDragSelect(p.x,p.y,u,h),setTimeout(()=>{f(null),m(!1),b(null)},500))},[x,p,e]),U=(0,r.useCallback)((n,r,l=!1)=>{if(!r||!e?.emitTypeText||!e?.emitKeyPress)return;let a=n.key.toLowerCase();if(["shift","control","meta","alt"].includes(a)||"Unidentified"===n.key||229===n.keyCode)return;let i=Object.keys(d).filter(e=>d[e]),o=i.length>0,x=n.ctrlKey||n.metaKey||n.altKey||n.shiftKey;if(l){n.preventDefault();let t=i.map(e=>c.tC[e]);n.ctrlKey&&!t.includes("control")&&t.push("control"),n.metaKey&&!t.includes("command")&&t.push("command"),n.altKey&&!t.includes("alt")&&t.push("alt"),n.shiftKey&&!t.includes("shift")&&t.push("shift"),c.FO[a]?a=c.FO[a]:" "===a?a="space":1===n.key.length&&(a=n.key),e.emitKeyPress(a,t),o&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1}),s("");return}if("Enter"===n.key){n.preventDefault(),t.trim()&&(e.emitTypeText(t),I(t),s(""));return}let m=/^[a-z0-9]$/i.test(n.key);if((o||x)&&(!m||o)){n.preventDefault();let t=i.map(e=>c.tC[e]);n.ctrlKey&&!t.includes("control")&&t.push("control"),n.metaKey&&!t.includes("command")&&t.push("command"),n.altKey&&!t.includes("alt")&&t.push("alt"),n.shiftKey&&!t.includes("shift")&&t.push("shift"),c.FO[a]?a=c.FO[a]:" "===a&&(a="space"),e.emitKeyPress(a,t),u({ctrl:!1,cmd:!1,alt:!1,shift:!1}),s("")}},[d,t,e,I]);return{textInputValue:t,setTextInputValue:s,textInputRef:o,keyboardVisible:a,modifierKeys:d,selectionMode:x,selectionStart:p,selectionRect:h,dragMode:g,isDragging:y,setIsDragging:w,setDragMode:v,toggleModifierKey:k,toggleSelectionMode:N,toggleDragMode:C,handleTextInputFocus:S,handleCanvasKeyPress:E,startScrollUp:T,startScrollDown:$,startScrollLeft:M,startScrollRight:z,stopScrolling:P,sendTextInput:A,sendBackspace:K,sendArrowKey:O,sendEscKey:W,sendTabKey:_,sendEnterKey:H,handleSelection:q,handleModifiedTextInput:U,handleDirectInputChange:B,emitKeyWithActiveModifiers:F}}(es),{keyboardOnRef:eG,toggleKeyboard:eJ,toggleTextPanel:eY,handleTextInputBlur:eZ}=function({streaming:e,keyboardOn:t,setKeyboardOn:s,showTextPanel:n,setShowTextPanel:l,textInputRef:a,canvasContainerRef:i,panForKeyboard:o,pointerMode:c,virtualCursor:d}){let u=(0,r.useRef)(t);(0,r.useEffect)(()=>{u.current=t},[t]);let x=(0,r.useCallback)(()=>{let e=!t;u.current=e,s(e),e?a.current?.focus():a.current?.blur()},[t]),m=(0,r.useRef)(!1);(0,r.useEffect)(()=>{e&&!m.current&&u.current&&(m.current=!0,a.current?.focus())},[e]);let p=(0,r.useCallback)(()=>{let e=!n;!e&&t&&a.current?.focus(),l(e)},[n,t]),f=(0,r.useCallback)(()=>{u.current&&!n&&setTimeout(()=>a.current?.focus(),0)},[n]),h=(0,r.useRef)(null);return(0,r.useEffect)(()=>{h.current="trackpad"===c?d:null},[c,d]),(0,r.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=e.height,s=0,n=()=>{let n=e.height<t;t=e.height;let r=i.current;if(!r)return;let l=r.clientHeight;cancelAnimationFrame(s);let a=0,c=()=>{r.clientHeight!==l||a++>30?o(n,h.current):s=requestAnimationFrame(c)};s=requestAnimationFrame(c)};return e.addEventListener("resize",n),()=>{cancelAnimationFrame(s),e.removeEventListener("resize",n)}},[i,o]),{keyboardOnRef:u,toggleKeyboard:x,toggleTextPanel:p,handleTextInputBlur:f}}({streaming:_,keyboardOn:y,setKeyboardOn:w,showTextPanel:g,setShowTextPanel:v,textInputRef:eM,canvasContainerRef:el,panForKeyboard:ew,pointerMode:N,virtualCursor:ef}),eQ=(0,r.useCallback)((e,t=[],s=!1)=>{_&&(t.length>0?J(e,s&&"darwin"===o?t.map(e=>"control"===e?"command":e):t):eX(e))},[_,o,J,eX]),e0=(0,r.useCallback)(()=>{E(e=>{let t=!e;return t?(eP&&eO(),ek()):eN(),t})},[E,eP,eO,ek,eN]),e1=function(e,t,n){let[l,a]=(0,r.useState)(126),[i,o]=(0,r.useState)(!1),d=(0,r.useRef)(new Set),u=(0,r.useRef)(new Map),x=(0,r.useRef)([]),m=(0,r.useRef)(!1),p=(0,r.useRef)(0),f=(0,r.useRef)(new Set),h=(0,r.useRef)(new Set),b=(0,r.useRef)(new Map),g=(0,r.useRef)(new Map),v=(0,r.useRef)(null),y=(0,r.useRef)(t);(0,r.useEffect)(()=>{y.current=t},[t]);let w=(0,r.useCallback)(()=>{v.current=null;let t=n?.current;if(!t)return void g.current.clear();let s=t.getContext("2d"),r=0;for(let[e,t]of g.current){let{bitmap:n,x:l,y:a,width:i,height:c,frameTs:u,invalidateTileHash:x}=t;if((b.current.get(e)??u)>u){n?.close?.();continue}try{s.drawImage(n,l,a,i,c),d.current.add(e),o(!0),u>r&&(r=u),n?.close?.()}catch{x()}}g.current.clear(),r>0&&e?.current?.emit("tile-ack",{ts:r})},[n,e]),j=(0,r.useCallback)((e=!1)=>{e&&v.current&&(cancelAnimationFrame(v.current),v.current=null),v.current||(v.current=requestAnimationFrame(w))},[w]),k=(0,r.useCallback)(e=>{if(n?.current)try{let t=n.current.getContext("2d");t.imageSmoothingEnabled=!1;let s=new Image;s.onload=()=>{if(n?.current)try{t.drawImage(s,0,0,e.screen.width,e.screen.height),d.current.clear();for(let e=0;e<l;e++)d.current.add(e);o(!0)}catch(e){}},s.src=e.screen.imageBase64}catch(e){console.error("Full screen error:",e)}},[n,l]),N=(0,r.useCallback)(e=>{if(n?.current)try{if(n.current.getContext("2d"),p.current=Date.now(),e.currentHashes&&Array.isArray(e.currentHashes)&&(x.current=e.currentHashes,m.current=!1),!e.tiles?.length)return;let t=e.timestamp||Date.now();for(let s of e.tiles){let e=u.current.get(s.tileIndex),n=b.current.get(s.tileIndex)??0;t>=n&&(e?.controller&&(e.controller.cancelled=!0),b.current.set(s.tileIndex,t),null!=s.hash&&(x.current[s.tileIndex]=s.hash))}if(void 0!==e.hasBitmap){for(let s of e.tiles){if(!s.bitmap&&!s.imageBuffer)continue;if((b.current.get(s.tileIndex)??t)>t){s.bitmap?.close?.();continue}let e=o_(x,s.tileIndex);s.bitmap?g.current.set(s.tileIndex,{bitmap:s.bitmap,x:s.x,y:s.y,width:s.width,height:s.height,frameTs:t,invalidateTileHash:e}):oV(oW(s.imageBuffer)).then(n=>{n&&(g.current.set(s.tileIndex,{bitmap:n,x:s.x,y:s.y,width:s.width,height:s.height,frameTs:t,invalidateTileHash:e}),j(!0))}).catch(()=>{e()})}j(!0);return}let s=[];for(let t=0;t<e.tiles.length;t+=c.eR.batchSize)s.push(e.tiles.slice(t,t+c.eR.batchSize));s.forEach((e,s)=>{let r=setTimeout(()=>{f.current.delete(r),e.forEach(e=>{if(!e.imageBuffer&&!e.imageBase64)return;if((b.current.get(e.tileIndex)??t)>t)return void u.current.delete(e.tileIndex);let s={cancelled:!1};u.current.set(e.tileIndex,{controller:s});let r=setTimeout(()=>{s.cancelled=!0,u.current.delete(e.tileIndex),x.current[e.tileIndex]=null},c.eR.tileLoadTimeout),l=o_(x,e.tileIndex),a=a=>{s.cancelled||!n?.current?a?.close?.():(clearTimeout(r),u.current.delete(e.tileIndex),g.current.set(e.tileIndex,{bitmap:a,x:e.x,y:e.y,width:e.width,height:e.height,frameTs:t,invalidateTileHash:l}),j())};if(e.imageBuffer&&"u">typeof createImageBitmap)oV(oW(e.imageBuffer)).then(a).catch(()=>{if(s.cancelled)return;let t=new Image,n=URL.createObjectURL(oW(e.imageBuffer));t.onload=()=>{a(t),URL.revokeObjectURL(n)},t.onerror=()=>{URL.revokeObjectURL(n),clearTimeout(r),u.current.delete(e.tileIndex),l()},t.src=n});else{let t=new Image;if(e.imageBuffer){let s=URL.createObjectURL(oW(e.imageBuffer));t.onload=()=>{a(t),URL.revokeObjectURL(s)},t.onerror=()=>{URL.revokeObjectURL(s),clearTimeout(r),u.current.delete(e.tileIndex),l()},t.src=s}else t.onload=()=>a(t),t.onerror=()=>{clearTimeout(r),u.current.delete(e.tileIndex),l()},t.src=`data:image/jpeg;base64,${e.imageBase64}`}})},s*c.eR.batchDelay);f.current.add(r)})}catch(e){console.error("Tiles data error:",e)}},[n]),C=(0,r.useCallback)((e,t,n="ws")=>{if(!e)return;let r=e instanceof ArrayBuffer?e:e?.buffer;if(!r)return;let l=function(){if(!1===oH)return null;if(oH)return oH;try{return(oH=new Worker(s.tu(new URL(s.p+s.u(1311),s.b)))).onmessage=({data:{tiles:e,timestamp:t,id:s,hasBitmap:n,error:r}})=>{let l=oU.get(s);if(!l){if(e)for(let t of e)t.bitmap?.close?.();return}clearTimeout(l.timer),oU.delete(s),l.resolve(r?null:{tiles:e,timestamp:t,hasBitmap:n})},oH}catch{return oH=!1,null}}();if(!l)return;let a=r.byteLength,i=++oq;new Promise(e=>{let s=setTimeout(()=>{oU.has(i)&&(oU.delete(i),e(null))},c.eR.tileLoadTimeout),n=c.eR.decodeQueueCap;for(;oU.size>=n;){let e=oU.keys().next().value,t=oU.get(e);if(!t)break;clearTimeout(t.timer),oU.delete(e),t.resolve(null)}oU.set(i,{resolve:e,timer:s}),l.postMessage({buffer:r,id:i,v:t},[r])}).then(e=>{e&&(2===t&&(m.current=!1),N({tiles:e.tiles,timestamp:e.timestamp,hasBitmap:e.hasBitmap,bytes:a,transport:n}))})},[N]),S=(0,r.useCallback)(e=>C(e,1,"ws"),[C]),E=(0,r.useCallback)(e=>C(e,2,"ws"),[C]),R=(0,r.useCallback)(e=>{e&&(p.current=Date.now(),e.currentHashes&&Array.isArray(e.currentHashes)&&(x.current=e.currentHashes,m.current=!1))},[]),T=(0,r.useCallback)(e=>{e()},[]),$=(0,r.useCallback)(e=>{e.tileCount&&a(e.tileCount)},[]),M=(0,r.useCallback)(()=>{if(!e?.current||!y.current||m.current||0===x.current.length||Date.now()-p.current<c.eR.lastDataThreshold)return;m.current=!0,e.current.emit("request-screen-with-hashes",{tileHashes:x.current});let t=setTimeout(()=>{h.current.delete(t),m.current=!1},1e3);h.current.add(t)},[]),z=(0,r.useCallback)(()=>{for(let[,e]of u.current.entries())e.controller&&(e.controller.cancelled=!0);if(u.current.clear(),x.current=[],d.current.clear(),b.current.clear(),p.current=0,m.current=!1,o(!1),oH&&!1!==oH)try{oH.terminate()}catch{}for(let e of(oH=null,oU.values()))try{e.resolve(null)}catch{}oU.clear(),v.current&&(cancelAnimationFrame(v.current),v.current=null),g.current.clear()},[]);return(0,r.useEffect)(()=>{let e=f.current,t=h.current;return()=>{e.forEach(clearTimeout),e.clear(),t.forEach(clearTimeout),t.clear()}},[]),{renderedTilesRef:d,totalTileCount:l,hasFrame:i,handleFullScreenData:k,handleTilesData:N,handleTilesBinary:S,handleTilesBinaryV2:E,handleTilesMeta:R,startStreamingWithTiles:T,handleScreenDimensions:$,cleanupTiles:z,requestScreenWithHashes:M}}(t,_,er),{screenLocked:e2,unlockReady:e5,unlockResult:e3,setUnlockResult:e4,clipboardText:e6,clipboardNew:e8,setClipboardNew:e9,monitors:e7,activeMonitorIndex:te,cursorShape:tt}=function({busRef:e,connected:t,streaming:s,canvasRef:n,serverDimensionsRef:l,handleCanvasDimensions:a,resetPan:i,zoomGestureTimeoutRef:o,trackTilesReceived:u,tiles:x}){let[m,p]=(0,r.useState)(!1),[f,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(""),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)([]),[C,S]=(0,r.useState)(0),[E,R]=(0,r.useState)(null),T=(0,r.useRef)(null),{renderedTilesRef:$,handleFullScreenData:M,handleTilesData:z,handleTilesBinary:P,handleTilesBinaryV2:I,handleTilesMeta:A,handleScreenDimensions:L,cleanupTiles:D,requestScreenWithHashes:B}=x;return(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t)return;D();let n=e=>{L(e),a(e,$)},r=e=>M(e),l=e=>{let t=e.transport||"ws";t!==T.current&&(T.current=t,(0,d.c)("remote",`[remote] tiles via ${t}`)),u(e,t),z(e)},c=e=>console.error("Screen error:",e),x=({locked:e,ready:t}={})=>{p(!!e),h(!!t),e&&g(null)},m=e=>g(e||null),f=(e,t)=>{"ws"!==T.current&&(T.current="ws",(0,d.c)("remote",`[remote] tiles via ws${t}`)),u(function(e,t=Date.now()){let{tileCount:s,timestamp:n,bytes:r}=function(e,t=Date.now()){let s=e instanceof ArrayBuffer?e:e?.buffer,n=s?.byteLength||0,r=0,l=t;if(s&&s.byteLength>=12){let e=new DataView(s);r=e.getUint32(0,!0),l=e.getFloat64(4,!1)}return{tileCount:r,timestamp:l,bytes:n}}(e,t);return{tiles:Array(s),timestamp:n,bytes:r}}(e),"ws")},b=e=>{f(e,""),P(e)},v=e=>A(e),w=e=>{f(e," v2"),I(e)},k=()=>{D(),s.emit("get-screen-dimensions"),s.emit("get-unlock-state"),s.emit("start-streaming")},C=()=>k(),E=({text:e,hash:t})=>{y(s=>t&&t===E._lastHash?s:(E._lastHash=t||null,e||"")),j(!0)},B=({list:e,activeIndex:t})=>{N(Array.isArray(e)?e:[]),"number"==typeof t&&S(t)},F=e=>{D(),i(),"number"==typeof e?.monitorIndex&&S(e.monitorIndex)};s.on("screen-dimensions",n),s.on("full-screen-data",r),s.on("tiles-data",l),s.on("tiles-data-binary",b),s.on("tiles-bin-v2",w),s.on("tiles-meta",v),s.on("screen-error",c),s.on("screen-locked",x),s.on("unlock-result",m),s.on("remote:ready",C),s.on("clipboard-update",E),s.on("monitors",B),s.on("frame_meta",F);let K=e=>R(e?.shape??null);return s.on("cursor-shape",K),k(),()=>{s.emit("stop-streaming"),s.off("screen-dimensions",n),s.off("full-screen-data",r),s.off("tiles-data",l),s.off("tiles-data-binary",b),s.off("tiles-bin-v2",w),s.off("tiles-meta",v),s.off("screen-error",c),s.off("screen-locked",x),s.off("unlock-result",m),s.off("remote:ready",C),s.off("clipboard-update",E),s.off("monitors",B),s.off("frame_meta",F),s.off("cursor-shape",K),D(),o.current&&clearTimeout(o.current)}},[t]),(0,r.useEffect)(()=>{if(!s||!t||!e?.current)return;let n=setInterval(()=>{0===$.current.size?e.current.emit("request-screen-with-hashes",{tileHashes:[]}):B()},c.eR.hashRequestInterval);return()=>clearInterval(n)},[s,t,e,B,$]),(0,r.useEffect)(()=>{if(!t)return;let s=()=>{let t=n.current;if(!t||t.width>0)return!0;let{width:s,height:r}=l.current||{};return s>0?a({width:s,height:r},$):e.current?.emit("get-screen-dimensions"),!1};if(s())return;let r=setInterval(()=>{s()&&clearInterval(r)},c.eR.restreamDelay);return()=>clearInterval(r)},[t,e,n,l,a,$]),(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t)return;let n=()=>{document.hidden?s.emit("stop-streaming"):s.emit("start-streaming")};return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[t,e]),{screenLocked:m,unlockReady:f,unlockResult:b,setUnlockResult:g,clipboardText:v,clipboardNew:w,setClipboardNew:j,monitors:k,activeMonitorIndex:C,cursorShape:E}}({busRef:t,connected:a,streaming:_,canvasRef:er,serverDimensionsRef:eE,handleCanvasDimensions:eS,resetPan:ey,zoomGestureTimeoutRef:em,trackTilesReceived:I,tiles:e1});(0,r.useEffect)(()=>{if(!e8)return;let e=setTimeout(()=>e9(!1),c.eR.clipboardBadgeTimeout);return()=>clearTimeout(e)},[e8,e6,e9]),(0,r.useEffect)(()=>{if(!_)return;let e=setTimeout(()=>{let e=er.current,t=el.current;if(!e||!t||0===e.width)return;if(ea<=1)return void ee(null,1);let s=eu*ea;if(s<=0)return;let n=Math.max(0,-ed.x/s),r=Math.max(0,-ed.y/s),l=Math.min(e.width-n,t.clientWidth/s),a=Math.min(e.height-r,t.clientHeight/s);ee({x:Math.floor(n),y:Math.floor(r),w:Math.ceil(l),h:Math.ceil(a)},ea)},c.eR.focusDebounce);return()=>clearTimeout(e)},[_,ea,ed,eu,er,el,ee]);let ts=(0,r.useCallback)(()=>E(!1),[E]),tn=(0,r.useCallback)(e=>{t?.current?.emit("select_monitor",{index:e})},[t]),tr=(0,r.useCallback)(()=>{S&&E(!1),eO()},[S,E,eO]),tl=e=>t=>{eC(t,e,{streaming:_,selectionMode:eP,selectionStart:eI,dragMode:eL,isDragging:eD,setIsDragging:eB,setDragMode:eF,isMobile:e.includes("touch"),pointerMode:N,handMode:S,onHandRelease:ts,handleSelection:(e,t,s,n)=>eq(e,t,s,{streaming:_,getCanvasCoordinates:eg,baseCanvasSize:ex,canvasZoom:ea,canvasPan:ed,...n})})};return(0,n.jsxs)("div",{className:`bg-bg text-text flex flex-col h-full w-full ${z?"":"landscape:flex-row"}`,style:{userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent"},onContextMenu:e=>e.preventDefault(),children:[(0,n.jsxs)("div",{className:"flex flex-row flex-1 min-h-0",children:[a&&(0,n.jsx)(o4,{streaming:_,canvasZoom:ea,pointerMode:N,handMode:S,keyboardOn:y,selectionMode:eP,show:e=>"mouse"!==R||T?.[e],onBack:en,onRefresh:()=>{_&&H([])},onResetZoom:ev,onTogglePointerMode:eR,onToggleHandMode:e0,onToggleKeyboard:eJ,onShowHelp:()=>m(!0),onToggleSelection:tr}),a?(0,n.jsx)(oJ,{canvasRef:er,canvasContainerRef:el,canvasZoom:ea,canvasPan:ed,fitScale:eu,streaming:_,hasFrame:e1.hasFrame,selectionRect:eA,clickIndicator:ep,pointerMode:N,selectionMode:eP,handMode:S,handHolding:eh,scrollLock:eb,virtualCursor:ef,cursorShape:tt,inputMode:R,keyboardOn:y,monitors:e7,activeMonitorIndex:te,onSelectMonitor:tn,onPointerDown:tl("pointerdown"),onPointerMove:tl("pointermove"),onPointerUp:tl("pointerup"),onWheel:tl("wheel"),onContextMenu:tl("contextmenu"),onDoubleClick:tl("dblclick"),onTouchStart:tl("touch"),onTouchMove:tl("touchmove"),onTouchEnd:tl("touchend"),onKeyDown:e=>e_(e,_),screenLocked:e2,unlockReady:e5,unlockResult:e3,onUnlockSubmit:e=>{e4(null),t?.current?.emit("desktop-unlock",{text:e})}}):(0,n.jsxs)("div",{className:"flex-1 min-w-0 empty-stage",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("div",{className:"empty-half",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",u("workspaces.emptyTagRemote")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:u("workspaces.emptyWordRemote")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:u("workspaces.emptyMetaRemote")}}),(0,n.jsxs)("span",{className:"empty-go",children:[(0,n.jsx)(oT.A,{size:"sm"}),u("remote.connecting")]})]})]})]}),(0,n.jsx)(o0,{streaming:_,canvasZoom:ea,clipboardNew:e8,clipboardText:e6,onOpenClipboard:()=>{e9(!1),b(!0)},onDesktopSwitch:et,selectionMode:eP,pointerMode:N,handMode:S,inputMode:R,onToggleHandMode:e0,onTogglePointerMode:eR,modifierKeys:ez,textInputValue:eT,textInputRef:eM,keyboardOn:y,showTextPanel:g,onResetZoom:ev,onRefresh:()=>_&&H([]),onToggleSelection:tr,onToggleModifier:eK,onToggleKeyboard:eJ,onToggleTextPanel:eY,controlsHidden:j,onToggleControlsHidden:k,tallLandscape:z,onToggleHelp:()=>m(!0),onEmitKey:eQ,onTextInputChange:e$,onTextInputFocus:eW,onTextInputBlur:eZ,onTextInputKeyDown:e=>eU(e,_,y),onDirectInputChange:e=>eV(e,_),onSendText:eH,onClose:en,onToggleDebug:()=>D(e=>!e),debugOn:L}),L&&(0,n.jsx)(o8,{onForceWsDisconnect:()=>t?.current?.disconnect(),onToggleWsBlock:()=>{let e=l?.current;if(!e)return;let t=!e.wsBlocked;e.setWsBlocked(t),F(t)},isWsBlocked:B,stats:P,mode:K,onReset:A,onCopy:O,onClose:()=>D(!1)}),x&&(0,n.jsx)(o6,{inputMode:R,pointerMode:N,onClose:()=>{m(!1),y&&eM.current?.focus()}}),h&&(0,n.jsx)(o9,{text:e6,onClose:()=>b(!1)}),(0,n.jsx)(ei.A,{isOpen:p,onClose:()=>{f(!1),y&&eM.current?.focus()},onConfirm:()=>e?.(),title:u("remote.exitRemote"),message:u("remoteControls.exitConfirmMessage"),confirmText:u("connection.exit"),cancelText:u("common.cancel")})]})}let ce={"9remote.cc":"sites.9remote.cc","dev.9remote.cc":"sites-dev.9remote.cc",localhost:"sites.localhost","127.0.0.1":"sites.localhost","::1":"sites.localhost"},ct=function(){let e=window.location;if(!e)return"https://sites.9remote.cc";let{hostname:t,protocol:s,port:n}=e,r=ce[t];return r?n?`${s}//${r}:${n}`:`${s}//${r}`:(console.warn(`[sites] no sites host is known for ${t}; local sites are unavailable here`),null)}(),cs="site-nav",cn="site-error",cr=null,cl=!1,ca=new Map;function ci(e){if(!e||"string"!=typeof e.reqId)return;let t=ca.get(e.reqId);if(e.error){if(!t?.resolve)return;clearTimeout(t.timer),ca.delete(e.reqId),t.resolve({reqId:e.reqId,error:e.error});return}if(!t)return;0===e.seq&&(t.total=e.total,t.status=e.status,t.headers=e.headers),t.slots[e.seq]=e.b64||"";let s=function(e){let t=ca.get(e);if(!t||null==t.total)return null;for(let e=0;e<t.total;e++)if(void 0===t.slots[e])return null;let s=t.slots.join("");return clearTimeout(t.timer),ca.delete(e),{reqId:e,status:t.status,headers:t.headers,bodyB64:s}}(e.reqId);s&&t.resolve&&t.resolve(s)}function co(e){var t;if("string"!=typeof(t=e.origin)||""===t||"null"===t||t!==ct)return;let s=e.data;if(s&&"object"==typeof s){if("site:request"===s.type)return void(function(e){let{reqId:t}=e;return new Promise(s=>{let n={slots:[],total:null,status:null,headers:null,resolve:s,timer:null};n.timer=setTimeout(()=>{ca.delete(t),s({reqId:t,error:"timeout"})},75e3),ca.set(t,n),cr?.emit?.("site:httpRequest",e,()=>{})})})(s.payload).then(t=>{try{e.source?.postMessage({type:"site:reply",id:s.id,payload:t},ct)}catch{}});if("site:nav"===s.type)return void window.dispatchEvent(new CustomEvent(cs,{detail:{port:s.port,path:s.path}}));if("site:ready"!==s.type){if("site:swBlocked"===s.type)return void window.dispatchEvent(new CustomEvent(cn,{detail:{message:"service-worker-blocked"}}));if("site-error"===s.type)return void window.dispatchEvent(new CustomEvent(cn,{detail:{message:s.message,port:s.port}}))}}}async function cc(e){e&&(cr=e,cr.off?.("site:httpChunk",ci),cr.on?.("site:httpChunk",ci)),cl||(cl=!0,window.addEventListener("message",co))}function cd({isOpen:e,onClose:t,onOpenSite:s,busRef:l,connected:a}){let{t:i}=(0,ec.s)(),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)([]),[x,m]=(0,r.useState)({}),[p,f]=(0,r.useState)(""),[h,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(""),y=(0,r.useRef)(null),w=()=>{if(a){var e;let t;c(null),(e=l?.current,t=e?.current||e,new Promise(e=>{if(!t?.connected)return e(null);let s=setTimeout(()=>e(null),8e3);t.emit("getLocalSites",t=>{clearTimeout(s),e(Array.isArray(t?.sites)?t.sites:null)})})).then(e=>c(e||[]))}};if((0,r.useEffect)(()=>{if(!e)return;u(si()),m(so()),w();let t=requestAnimationFrame(()=>y.current?.focus());return()=>cancelAnimationFrame(t)},[e,a,l]),(0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&null===h&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener("keydown",s,!0),()=>window.removeEventListener("keydown",s,!0)},[e,h,t]),!e||"u"<typeof document)return null;let j=o||[],k=new Set(j.map(e=>e.port)),N=e=>x[e.port]||e.name||`Port ${e.port}`,C=e=>{(0,eo.e)(),s(Number(e)),t()},S=()=>{let e=parseInt(p,10);if(!isNaN(e)&&!(e<1)&&!(e>65535)){if(!k.has(e)&&!d.includes(e)){let t=[...d,e];u(t),sa(sn,t)}f(""),C(e)}},E=()=>{if(null==h)return;let e=g.trim(),t={...x};e?t[h]=e:delete t[h],m(t),sa(sr,t),b(null),v("")},R=d.filter(e=>!k.has(e));return(0,sU.createPortal)((0,n.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center px-4",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[4px] animate-in fade-in duration-150",onClick:t}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:"relative card-elev w-full max-w-md max-h-[85vh] flex flex-col animate-in zoom-in-95 duration-200",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 shrink-0",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:i("sites.newTabTitle")}),(0,n.jsx)("p",{className:"text-sm text-text-muted mt-0.5 truncate",children:i("sites.selectSitePreview")})]}),(0,n.jsx)("button",{onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors shrink-0",title:i("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsx)("div",{className:"px-4 pb-3 border-b border-border shrink-0",children:(0,n.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,n.jsx)("span",{className:"text-text-muted text-sm whitespace-nowrap",children:"http://localhost:"}),(0,n.jsx)("input",{ref:y,type:"number",value:p,onChange:e=>f(e.target.value),onKeyDown:e=>"Enter"===e.key&&S(),placeholder:i("sites.portPlaceholder"),min:"1",max:"65535",className:"flex-1 px-3 py-2 bg-surface-2 rounded-brand text-text placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 text-sm min-w-0 transition-all duration-150"}),(0,n.jsx)("button",{onClick:S,disabled:!p,className:"px-4 py-2 bg-brand-500 hover:bg-brand-600 disabled:bg-surface-2 disabled:cursor-not-allowed text-white text-sm font-medium rounded-brand transition-all duration-150",children:i("sites.open")})]})}),(0,n.jsx)("div",{className:"p-4 overflow-y-auto modal-scrollable",style:{maxHeight:"45vh"},children:a?null===o?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-8 text-brand-500 text-sm",children:[(0,n.jsx)(en.kr,{size:16,className:"animate-spin"}),(0,n.jsx)("span",{children:i("sites.loadingSites")})]}):(0,n.jsxs)("div",{className:"space-y-2",children:[R.map(e=>(0,n.jsx)(cu,{port:e,label:N({port:e}),detected:!1,editing:h===e,editValue:g,onEditValue:v,onStartEdit:()=>{b(e),v(x[e]||"")},onSaveEdit:E,onCancelEdit:()=>{b(null),v("")},onRemove:()=>{var t;let s;return t=e,void(u(s=d.filter(e=>e!==t)),sa(sn,s))},onOpen:()=>C(e),t:i},`saved-${e}`)),j.map(e=>(0,n.jsx)(cu,{port:e.port,label:N(e),protocol:e.protocol,detected:!0,editing:h===e.port,editValue:g,onEditValue:v,onStartEdit:()=>{b(e.port),v(x[e.port]||"")},onSaveEdit:E,onCancelEdit:()=>{b(null),v("")},onOpen:()=>C(e.port),t:i},`auto-${e.port}`)),0===j.length&&0===R.length&&(0,n.jsxs)("div",{className:"text-center py-8",children:[(0,n.jsx)(en.qz,{size:24,className:"text-text-muted mx-auto mb-2"}),(0,n.jsx)("p",{className:"text-text text-sm font-medium",children:i("sites.noSitesFound")}),(0,n.jsx)("p",{className:"text-text-muted text-xs mt-1",children:i("sites.startServerHint")})]})]}):(0,n.jsx)("div",{className:"py-8 text-center text-sm text-text-muted",children:i("sites.notConnected",{defaultValue:"Not connected to the agent"})})}),(0,n.jsxs)("div",{className:"px-5 py-3 border-t border-border flex items-center justify-between shrink-0",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted",children:j.length>0?i("sites.foundCount",{n:j.length,suffix:j.length>1?"s":""}):""}),(0,n.jsxs)("button",{onClick:w,disabled:!a,className:"flex items-center gap-2 px-3 py-1.5 text-sm text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-50",children:[(0,n.jsx)(en.e9,{className:null===o&&a?"animate-spin text-brand-500":"",size:16}),i("sites.refresh")]})]})]})]}),document.body)}function cu({port:e,label:t,protocol:s,detected:r,editing:l,editValue:a,onEditValue:i,onStartEdit:o,onSaveEdit:c,onCancelEdit:d,onRemove:u,onOpen:x,t:m}){return(0,n.jsxs)("div",{className:"w-full px-4 py-3 bg-surface-2 hover:bg-surface-3 rounded-brand-lg transition-colors group flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:x,className:"flex-1 flex items-center gap-3 text-left min-w-0",children:[(0,n.jsx)("span",{className:`w-2.5 h-2.5 rounded-full shrink-0 ${r?"bg-green-500 animate-pulse":"bg-surface-3"}`}),(0,n.jsxs)("span",{className:"min-w-0 flex-1",children:[l?(0,n.jsx)("input",{type:"text",value:a,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&c(),"Escape"===e.key&&d()},onClick:e=>e.stopPropagation(),autoFocus:!0,placeholder:`Port ${e}`,className:"w-full px-2 py-1 bg-surface ring-2 ring-brand-500/40 rounded-brand text-text text-sm focus:outline-none"}):(0,n.jsx)("span",{className:"block text-text font-medium truncate",children:t}),(0,n.jsxs)("span",{className:"block text-xs text-text-muted mt-0.5",children:[s?`${s} \xb7 `:"","Port ",e]})]})]}),l?(0,n.jsx)("button",{onClick:c,className:"px-3 py-1.5 text-sm font-medium text-brand-500 hover:bg-surface-3 rounded-brand transition-colors shrink-0",title:m("sites.saveTitle"),children:m("sites.saveTitle")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),o()},className:"p-2 text-text-muted hover:text-brand-500 hover:bg-surface-3 rounded-brand transition-colors shrink-0",title:m("sites.editNameTitle"),children:(0,n.jsx)(en.gH,{size:16})}),!r&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-2 text-text-muted hover:text-red-400 hover:bg-surface-3 rounded-brand transition-colors shrink-0",title:m("sites.removeTitle"),children:(0,n.jsx)(en.TB,{size:16})})]})]})}let cx=0,cm=(e,t)=>{let s={port:e,path:t||"/"};return{key:`site-${++cx}`,port:e,path:s.path,srcTick:0,hist:[s],histIdx:0}},cp=e=>e?`localhost:${e.port}${e.path||"/"}`:"",cf={"service-worker-blocked":"sites.errorSwBlocked","bridge not connected — open the 9Remote app":"sites.errorNoBridge","no-session":"sites.errorNoSession",timeout:"sites.errorTimeout","no reply from the agent":"sites.errorNoReply"};function ch({busRef:e,connected:t=!1,initialPort:s,initialPath:l,onBack:a}){let{t:i}=(0,ec.s)(),[o,c]=(0,r.useState)(()=>{if(!s)return{tabs:[],activeKey:"",address:""};let e=cm(s,l);return{tabs:[e],activeKey:e.key,address:cp(e)}}),[d,u]=(0,r.useState)(!1),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(null),{tabs:h,activeKey:b,address:g}=o,v=h.find(e=>e.key===b)||null,y=(0,r.useRef)(new Set),w=(0,r.useCallback)(t=>{y.current.has(t)||(y.current.add(t),e?.current?.emit?.("startProxySession",t))},[e]),j=(0,r.useCallback)(t=>{y.current.delete(t),e?.current?.emit?.("endProxySession",t)},[e]);(0,r.useEffect)(()=>{cc(e?.current)},[e]),(0,r.useEffect)(()=>{let e=e=>{let{message:t,port:s}=e.detail||{};t&&(u(!1),f({message:i(cf[t]||"sites.errorGeneric",{port:s})}))};return window.addEventListener(cn,e),()=>window.removeEventListener(cn,e)},[i]),(0,r.useEffect)(()=>{let e=e=>{let{port:t,path:s}=e.detail||{};t&&c(e=>({tabs:e.tabs.map(n=>{if(n.key!==e.activeKey)return n;let r=n.hist[n.histIdx];if(r&&r.port===t&&r.path===(s||"/"))return{...n,port:t,path:s};let l=[...n.hist.slice(0,n.histIdx+1),{port:t,path:s||"/"}];return{...n,port:t,path:s,hist:l,histIdx:l.length-1}}),activeKey:e.activeKey,address:`localhost:${t}${s||"/"}`}))};return window.addEventListener(cs,e),()=>window.removeEventListener(cs,e)},[]),(0,r.useEffect)(()=>{let e=new Set(h.map(e=>e.port));for(let t of[...y.current])e.has(t)||j(t)},[h,j]),(0,r.useEffect)(()=>()=>{for(let t of y.current)e?.current?.emit?.("endProxySession",t);y.current.clear()},[e]);let k=(e,t="/")=>{(0,eo.e)(),w(e),u(!0),f(null),c(s=>{if(s.tabs.find(e=>e.key===s.activeKey))return{tabs:s.tabs.map(n=>{if(n.key!==s.activeKey)return n;let r=n.hist[n.histIdx];if(r&&r.port===e&&r.path===t)return{...n,port:e,path:t,srcTick:n.srcTick+1};let l=[...n.hist.slice(0,n.histIdx+1),{port:e,path:t}];return{...n,port:e,path:t,srcTick:n.srcTick+1,hist:l,histIdx:l.length-1}}),activeKey:s.activeKey,address:`localhost:${e}${t}`};let n=cm(e,t);return{tabs:[...s.tabs,n],activeKey:n.key,address:cp(n)}})},N=()=>{v&&((0,eo.e)(),u(!0),f(null),c(e=>({...e,tabs:e.tabs.map(t=>t.key===e.activeKey?{...t,srcTick:t.srcTick+1}:t)})))},C=e=>{if(!v)return;let t=v.histIdx+e,s=v.hist[t];s&&((0,eo.e)(),w(s.port),u(!0),c(e=>({tabs:e.tabs.map(n=>n.key===e.activeKey?{...n,port:s.port,path:s.path,srcTick:n.srcTick+1,histIdx:t}:n),activeKey:e.activeKey,address:cp(s)})))},S=()=>{(0,eo.e)(),m(!0)};return(0,n.jsxs)("div",{className:"absolute inset-0 z-20 flex flex-col bg-surface text-text transition-all duration-300 ease-out animate-in slide-in-from-bottom",children:[(0,n.jsxs)("div",{className:"h-11 flex items-center gap-1 px-2 border-b border-border-subtle shrink-0 overflow-x-auto modal-scrollable",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),a?.()},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors shrink-0",title:i("common.close"),children:(0,n.jsx)(en.JG,{size:18})}),h.map(e=>(0,n.jsxs)("div",{className:`group flex items-center gap-1.5 pl-3 pr-1.5 h-8 rounded-brand text-xs cursor-pointer max-w-[160px] shrink-0 transition-colors ${e.key===b?"bg-surface-3 text-text":"bg-surface-2 text-text-muted hover:bg-surface-3"}`,onClick:()=>c(t=>({...t,activeKey:e.key,address:cp(e)})),children:[(0,n.jsx)(en.qz,{size:13,className:"shrink-0"}),(0,n.jsxs)("span",{className:"truncate",children:[":",e.port]}),(0,n.jsx)("button",{onClick:t=>{var s;t.stopPropagation(),s=e.key,(0,eo.e)(),c(e=>{let t=e.tabs.findIndex(e=>e.key===s),n=e.tabs.filter(e=>e.key!==s);if(s!==e.activeKey)return{...e,tabs:n};let r=n[Math.min(t,n.length-1)];return{tabs:n,activeKey:r?.key||"",address:cp(r)}})},className:"p-0.5 rounded opacity-60 hover:opacity-100 hover:bg-surface shrink-0",title:i("common.close"),children:(0,n.jsx)(en.X,{size:12})})]},e.key)),(0,n.jsx)("button",{onClick:S,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors shrink-0",title:i("sites.browserNewTab"),children:(0,n.jsx)(en.FW,{size:16})}),d&&(0,n.jsx)(en.kr,{size:14,className:"animate-spin text-brand-500 shrink-0 ml-1"})]}),(0,n.jsxs)("div",{className:"h-11 flex items-center gap-1 px-2 border-b border-border-subtle shrink-0",children:[(0,n.jsx)("button",{onClick:()=>C(-1),disabled:!v||0===v.histIdx,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-40 shrink-0",title:i("sites.goBack"),children:(0,n.jsx)(en.JG,{size:16})}),(0,n.jsx)("button",{onClick:()=>C(1),disabled:!v||v.histIdx>=v.hist.length-1,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-40 shrink-0",title:i("sites.goForward"),children:(0,n.jsx)(en.c_,{size:16})}),(0,n.jsx)("button",{onClick:()=>{v&&k(v.port,"/")},disabled:!v,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-40 shrink-0",title:i("menu.home"),children:(0,n.jsx)(en.ww,{size:15})}),(0,n.jsx)("input",{type:"text",value:g,onChange:e=>c(t=>({...t,address:e.target.value})),onKeyDown:e=>{let t;return"Enter"===e.key&&void((t=function(e,t){let s=(e||"").trim();if(!s)return null;let n=s.match(/^(?:https?:\/\/)?localhost:(\d{1,5})(\/.*)?$/i);return n||(n=s.match(/^:(\d{1,5})(\/.*)?$/))||(n=s.match(/^(\d{1,5})(\/.*)?$/))&&Number(n[1])>=1&&65535>=Number(n[1])?{port:Number(n[1]),path:n[2]||"/"}:s.startsWith("/")&&t?{port:t,path:s}:null}(g,v?.port))&&k(t.port,t.path))},placeholder:i("sites.browserAddressPlaceholder"),spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"flex-1 min-w-0 px-3 py-1.5 bg-surface-2 rounded-brand text-sm text-text placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40"}),(0,n.jsx)("button",{onClick:N,disabled:!v,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-40 shrink-0",title:i("editor.reload"),children:(0,n.jsx)(en.kt,{size:15})})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-white relative",children:[!t&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center text-sm text-text-muted bg-surface",children:i("sites.browserNotConnected")}),h.map(e=>(0,n.jsx)("iframe",{src:function(e,t,s=0){let n=Number(e);if(!Number.isInteger(n)||n<1||n>65535||!ct)return null;let r=s?`?r=${s}`:"";return`${ct}/proxy.html${r}#port=${n}&path=${encodeURIComponent(t||"/")}`}(e.port,e.path,e.srcTick),title:`site-${e.port}`,className:`w-full h-full border-0 absolute inset-0 ${e.key===b?"":"hidden"}`,onLoad:()=>{e.key===b&&u(!1)}},e.key)),!v&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 p-6 text-center bg-surface",children:[(0,n.jsx)(en.qz,{size:28,className:"text-text-muted"}),(0,n.jsx)("p",{className:"text-text text-sm font-medium",children:i("sites.noSitesFound")}),(0,n.jsxs)("button",{onClick:S,className:"flex items-center gap-2 px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-medium rounded-brand transition-colors",children:[(0,n.jsx)(en.FW,{size:16}),i("sites.newTabTitle")]})]}),p&&v&&(0,n.jsxs)("div",{className:"absolute inset-x-0 top-0 z-20 flex items-start gap-3 px-4 py-3 bg-red-500/90 text-white text-sm",children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 break-words",children:p.message}),(0,n.jsx)("button",{onClick:N,className:"px-2 py-1 rounded bg-white/20 hover:bg-white/30 shrink-0 font-medium",children:i("sites.refresh")}),(0,n.jsx)("button",{onClick:()=>f(null),className:"p-1 shrink-0 opacity-80 hover:opacity-100",title:i("common.close"),children:(0,n.jsx)(en.X,{size:14})})]})]}),(0,n.jsx)(cd,{isOpen:x,onClose:()=>m(!1),onOpenSite:e=>k(e),busRef:e,connected:t})]})}function cb({files:e,loading:t,onFileClick:s,onFolderClick:r,onMoreClick:l,selectedPath:a,gitStatusMap:i={},workspacePath:o}){let{t:c}=(0,ec.s)();return t?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-text-muted",children:c("common.loading")})}):0===e.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-text-muted",children:c("files.emptyFolder")})}):(0,n.jsx)("div",{children:e.map((e,t)=>{var d;let u=i[d=e.path,!o?d:d.replace(o+"/","")],x="folder-changed"===u?"text-yellow-400":F.vs[u]||"";return(0,n.jsxs)("div",{className:`w-full px-4 py-1.5 flex items-center gap-2.5 border-b border-border hover:bg-surface-2 transition ${a===e.path?"bg-surface-2":""}`,children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),"folder"===e.type?r(e):s(e)},className:"flex-1 flex items-center gap-2.5 text-left min-w-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:r6(e,18)}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:`truncate text-sm ${x||"text-text"}`,title:e.name,children:[e.name,u&&"folder-changed"!==u&&(0,n.jsxs)("span",{className:"ml-2 text-xs opacity-70",children:["[",u,"]"]})]}),"folder"!==e.type&&e.sizeFormatted&&(0,n.jsx)("div",{className:"text-text-subtle text-xs",children:e.sizeFormatted})]})]}),l&&(0,n.jsx)("button",{onClick:t=>{let s;(0,eo.e)(),t.stopPropagation(),s=t.currentTarget.getBoundingClientRect(),l?.(e,{x:s.right,y:s.top})},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded transition flex-shrink-0",title:c("menu.settings"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"19",r:"2"})]})}),"folder"===e.type&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),r(e)},className:"p-1 text-text-muted flex-shrink-0",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:"M9 5l7 7-7 7"})})})]},e.path)})})}function cg({workspace:e,initialPath:t,fileBus:s,onBack:l,onOpenFile:a,onOpenGit:i,onSetWorkspace:o,onSwitchWorkspace:c,onPathChange:d,isBrowsing:u=!1,hideSwitchWorkspace:x=!1,scope:m=""}){let{t:p}=(0,ec.s)(),[f,h]=(0,r.useState)(t||e),[b,g]=(0,r.useState)([]),[v,y]=(0,r.useState)(!0),[w,j]=(0,r.useState)(""),[k,N]=(0,r.useState)(null),[C,S]=(0,r.useState)(!1),[E,R]=(0,r.useState)("file"),[T,$]=(0,r.useState)(""),[M,z]=(0,r.useState)({isOpen:!1}),[P,I]=(0,r.useState)(null),[A,L]=(0,r.useState)(!1),[D,B]=(0,r.useState)({}),[K,O]=(0,r.useState)(!1),[W,_]=(0,r.useState)(""),[H,q]=(0,r.useState)([]),[U,V]=(0,r.useState)(!1),X=(0,r.useRef)(null),[G]=(0,r.useState)(()=>window.innerWidth>=eV.jK),J=(0,r.useCallback)(async e=>{if(u){L(!1),B({});return}let t=await rU(s,e);L(t.hasGit);let n=t.map;B(e=>!function(e,t){let s=Object.keys(e||{}),n=Object.keys(t||{});if(s.length!==n.length)return!1;for(let s of n)if(e[s]!==t[s])return!1;return!0}(e,n)?n:e)},[s,u]),Y=(0,r.useCallback)(async e=>{y(!0),j("");let t=await s.getFiles(e,!0);if(t.success){let e=t.files;u&&(e=t.files.filter(e=>"folder"===e.type)),g(t=>{if(t.length!==e.length)return e;for(let s=0;s<e.length;s++)if(t[s]?.name!==e[s]?.name)return e;return t}),h(t.currentPath)}else j(t.error),g([]);y(!1)},[s,u]),{transfer:Z,dragOver:Q,conflict:ee,downloadState:et,startUpload:es,handleDrop:er,handleDragOver:el,handleDragLeave:ea,handleDownload:ed,resolveConflict:eu}=function({fileBus:e,currentPath:t,isBrowsing:s,onDone:n,onError:l}){let[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),p=(0,r.useRef)(0),f=(0,r.useCallback)(async s=>{if(!s.length||!e.uploadFiles)return;let r=++p.current;i({total:s.length,done:0,current:s[0]?.file?.name||"",ratio:0}),await e.uploadFiles(t,s,{onConflict:({file:e},t)=>new Promise(s=>{u({name:t||e.name,resolve:s})}),onProgress:(e,t)=>{r===p.current&&i(s=>s?{...s,current:e.name,ratio:t}:s)},onFileDone:e=>{r===p.current&&i(e=>e?{...e,done:e.done+1}:e)}}),r===p.current&&i(null),n?.(t)},[e,t,n]),h=(0,r.useCallback)(async e=>{if(e.preventDefault(),c(!1),s)return;let t=await ln(e.dataTransfer);t.length&&((0,eo.e)(),f(t))},[s,f]),b=(0,r.useCallback)(e=>{e.preventDefault(),s||c(!0)},[s]),g=(0,r.useCallback)(e=>{e.preventDefault(),c(!1)},[]);(0,r.useEffect)(()=>{if(s)return;let e=async e=>{let t=Array.from(e.clipboardData?.files||[]);if(!t.length)return;let s=t.map(e=>({file:e,relativePath:e.name}));(0,eo.e)(),f(s)};return window.addEventListener("paste",e),()=>window.removeEventListener("paste",e)},[s,f]);let v=(0,r.useRef)(0),y=(0,r.useCallback)(t=>{if(!e.downloadFile)return;let s=++v.current;m({name:t.name,ratio:0}),e.downloadFile(t.path,{onSave:(e,n)=>{let r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=n?.fileName||t.name,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(r.href),s===v.current&&m(null)},onProgress:e=>{s===v.current&&m(t=>t?{...t,ratio:e}:t)},onError:e=>{l?.(e.message||"Download failed"),s===v.current&&m(null)}})},[e,l]),w=(0,r.useCallback)(e=>{d?.resolve(e),u(null)},[d]);return{transfer:a,dragOver:o,conflict:d,downloadState:x,startUpload:f,handleDrop:h,handleDragOver:b,handleDragLeave:g,handleDownload:y,resolveConflict:w}}({fileBus:s,currentPath:f,isBrowsing:u,onDone:Y,onError:j}),ex=(0,r.useCallback)(t=>{if(_(t),X.current&&clearTimeout(X.current),!t||t.length<2){q([]),V(!1);return}V(!0),X.current=setTimeout(async()=>{let n=await s.searchFiles(e,t);n.success&&q(n.files),V(!1)},300)},[e,s]),em=(0,r.useCallback)(()=>{O(!1),_(""),q([])},[]);(0,r.useEffect)(()=>{Y(t||e),u||J(e)},[e,t,u]),(0,r.useEffect)(()=>()=>{X.current&&clearTimeout(X.current)},[]),(0,r.useEffect)(()=>{!u&&d&&d(f)},[f,u,d]);let ef=e=>{Y(e.path)},eh=()=>N(null),eb=async()=>{if(!P||!P.newName.trim())return;let e=f+"/"+P.newName.trim(),t=await s.renameItem(P.file.path,e);t.success?Y(f):j(t.error),I(null)},eg=async()=>{if(!T.trim())return;let e=f+"/"+T.trim(),t=await s.createItem(e,E);t.success?(Y(f),S(!1),$("")):j(t.error)},ev=(0,r.useRef)(null),ey=(0,r.useRef)(null),ew=e=>{let t=Array.from(e.target.files||[]);if(e.target.value="",!t.length)return;let s=t.map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}));S(!1),es(s)},ej=async t=>{if(!e||!s||!t?.path)return;eh();let n=t.path.startsWith(e)?t.path.slice(e.length).replace(/^\/+/,""):t.path,r=await lm(s,e,n,"folder"===t.type);r?.success&&(J(e),window.dispatchEvent(new CustomEvent(F.GW)))},ek=f===e,eN="p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]";return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface px-4 py-3 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),l()},className:eN,title:p("common.close"),children:(0,n.jsx)(en.X,{size:20})}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("div",{className:"text-text font-medium truncate text-sm",children:f.replace(/^\/Users\/[^/]+/,"~")})}),u&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),ep(f,m),o(f)},className:"px-3 py-2 bg-brand-500 hover:bg-brand-600 text-white text-xs rounded-brand transition-all duration-150 ease-out active:scale-[0.97] font-medium shadow-sm",title:p("files.setAsWorkspaceTitle"),children:p("files.setWorkspace")}),!u&&c&&!x&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),c()},className:eN,title:p("files.switchWorkspace"),children:(0,n.jsx)(en.Bm,{className:"text-brand-500",size:20})}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),O(!0)},className:eN,title:p("files.searchFiles"),children:(0,n.jsx)(en.vj,{className:"text-brand-500",size:20})}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),i()},disabled:!A,className:`p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.96] ${A?"bg-surface-2 hover:bg-surface-3 text-text":"bg-surface-2/30 text-text-muted cursor-not-allowed"}`,title:A?p("git.title"):p("files.noGitRepo"),children:(0,n.jsx)(en.Zr,{className:A?"text-brand-500":"text-text-muted",size:20})})]}),K&&(0,n.jsx)(lc,{query:W,loading:U,onChange:ex,onClose:em}),w&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm",children:w}),Z&&(0,n.jsx)(lo,{label:`${p("files.copying")} ${Z.done+1}/${Z.total}: ${Z.current}`,ratio:Z.ratio}),et&&(0,n.jsx)(lo,{label:`${p("files.downloading")}: ${et.name}`,ratio:et.ratio}),K&&W.length>=2?(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto",children:U?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.searching")}):0===H.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.noFilesFound")}):(0,n.jsx)("div",{children:H.map(t=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),a(t.path),em()},className:"w-full px-4 py-3 flex items-center gap-3 border-b border-border hover:bg-surface transition-colors text-left",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:"binary"===t.type?(0,n.jsx)(en.lP,{size:20,className:"text-red-500/70"}):(0,n.jsx)(en.ZH,{size:20,className:"text-text-subtle"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-text truncate",title:t.name,children:t.name}),(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",title:t.path,children:t.path.replace(e,"").replace(/^\//,"")})]}),t.sizeFormatted&&(0,n.jsx)("span",{className:"text-text-muted text-xs flex-shrink-0",children:t.sizeFormatted})]},t.path))})}):(0,n.jsxs)(n.Fragment,{children:["/"!==f&&!ek&&!K&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),Y(f.split("/").slice(0,-1).join("/")||"/")},className:"w-full px-4 py-3 flex items-center gap-3 border-b border-border hover:bg-surface transition-colors text-left flex-shrink-0",children:[(0,n.jsx)(en.JG,{className:"text-green-500",size:28}),(0,n.jsx)("span",{className:"text-green-500",children:f.split("/").pop()||"/"})]}),(0,n.jsx)("div",{className:`flex-1 min-h-0 overflow-auto ${!u?"pb-20":""} ${Q?"bg-brand-500/5 ring-2 ring-inset ring-brand-500/40":""}`,onDrop:er,onDragOver:el,onDragLeave:ea,children:u?(0,n.jsx)("div",{className:"p-4",children:v?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("common.loading")}):0===b.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.emptyFolder")}):(0,n.jsx)("div",{className:"grid grid-cols-2 gap-3",children:b.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),ef(e)},className:"bg-surface hover:bg-surface-2 rounded-brand-lg p-2 flex flex-col items-center gap-1 transition-all duration-150 ease-out active:scale-[0.98] text-center",children:[(0,n.jsx)(en.vd,{size:48,className:"text-yellow-500/80"}),(0,n.jsx)("span",{className:"text-text text-xs font-medium truncate w-full",title:e.name,children:e.name})]},e.path))})}):(0,n.jsx)(cb,{files:b,loading:v,onFileClick:e=>{if(!u){if("binary"===e.type){j(p("files.cannotOpenBinary")),setTimeout(()=>j(""),3e3);return}a?.(e.path,f)}},onFolderClick:ef,onMoreClick:(e,t)=>{N({file:e,x:t.x,y:t.y})},gitStatusMap:D,workspacePath:e})})]}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),S(!0)},className:"absolute bottom-[max(1.5rem,calc(env(safe-area-inset-bottom)+0.5rem))] right-6 w-14 h-14 bg-brand-500 hover:bg-brand-600 text-white rounded-full shadow-lg shadow-brand-500/30 flex items-center justify-center transition-all duration-200",children:(0,n.jsx)(en.FW,{size:24})}),k&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-40",onClick:eh}),(0,n.jsxs)("div",{className:"fixed z-50 card-elev overflow-hidden min-w-[140px]",style:{right:16,top:Math.min(k.y,window.innerHeight-160)},children:[(0,n.jsxs)("button",{onClick:()=>{var e;(0,eo.e)(),e=k.file,eh(),I({file:e,newName:e.name})},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.gH,{size:16}),p("files.rename")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),navigator.clipboard?.writeText(k.file.path).catch(()=>{}),eh()},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.QR,{size:16}),p("files.copyPath")]}),G&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),eh(),ed(k.file)},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.f5,{size:16}),p("files.download")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),ej(k.file)},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.X_,{size:16}),p("git.addToGitignore",{defaultValue:"Add to .gitignore"})]}),(0,n.jsxs)("button",{onClick:()=>{var e;(0,eo.e)(),e=k.file,eh(),z({isOpen:!0,title:p("files.deleteConfirmTitle"),message:p("files.deleteConfirmMessage",{name:e.name}),onConfirm:async()=>{let t=await s.deleteItem(e.path);t.success?Y(f):j(t.error)}})},className:"w-full px-4 py-3 text-left text-red-400 hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.TB,{size:16}),p("files.delete")]})]})]}),C&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ld,{type:E,name:T,onTypeChange:R,onNameChange:$,onSubmit:eg,onPickFile:()=>ev.current?.click(),onPickFolder:()=>ey.current?.click(),onClose:()=>S(!1)}),(0,n.jsx)("input",{ref:ev,type:"file",multiple:!0,className:"hidden",onChange:ew}),(0,n.jsx)("input",{ref:ey,type:"file",className:"hidden",webkitdirectory:"",onChange:ew})]}),P&&(0,n.jsx)(lu,{value:P.newName,onChange:e=>I({...P,newName:e}),onSubmit:eb,onClose:()=>I(null)}),(0,n.jsx)(ei.A,{isOpen:M.isOpen,onClose:()=>z({isOpen:!1}),onConfirm:M.onConfirm,title:M.title,message:M.message}),ee&&(0,n.jsx)(lx,{name:ee.name,onResolve:eu})]})}let cv=[{label:"Esc",key:"Escape"},{label:"Tab",key:"Tab"},{label:"←",key:"ArrowLeft"},{label:"→",key:"ArrowRight"},{label:"↑",key:"ArrowUp"},{label:"↓",key:"ArrowDown"},{label:"Ctrl",modifier:"ctrl"},{label:"Opt",modifier:"alt"}],cy=[{label:"Undo",key:"z",ctrl:!0},{label:"Redo",key:"y",ctrl:!0},{label:"{}",text:"{}"},{label:"()",text:"()"},{label:"[]",text:"[]"},{label:'""',text:'""'},{label:"=>",text:" => "},{label:"Aa",toggleTextInput:!0}];function cw({viewRef:e}){let{t}=(0,ec.s)(),[s,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(""),x=(0,r.useRef)(null),m=t=>{let s=e.current;if(!s)return;let{from:n,to:r}=s.state.selection.main;s.dispatch({changes:{from:n,to:r,insert:t},selection:{anchor:n+t.length}}),s.focus()},p=(t,{ctrl:n=!1,alt:r=!1}={})=>{let o=e.current;o&&(o.contentDOM.dispatchEvent(new KeyboardEvent("keydown",{key:t,code:1===t.length?`Key${t.toUpperCase()}`:t,ctrlKey:n||s,altKey:r||a,metaKey:n||s,bubbles:!0,cancelable:!0})),o.focus(),l(!1),i(!1))},f=e=>`flex-1 py-2 text-text text-xs rounded-brand transition-all duration-200 border ${e?"bg-brand-500 border-brand-400 shadow-md shadow-brand-500/30":"bg-surface-2 hover:bg-surface-2 border-border hover:border-brand-500"}`;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:`bg-surface transition-all duration-300 overflow-hidden ${o?"max-h-24 opacity-100":"max-h-0 opacity-0"}`,children:(0,n.jsxs)("div",{className:"p-2 flex gap-2 items-center",children:[(0,n.jsx)("textarea",{ref:x,value:d,onChange:e=>u(e.target.value),placeholder:t("editor.typeText"),rows:1,className:"w-full px-3 py-2 bg-surface-2 rounded text-text text-base placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out resize-none"}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d.trim()&&(m(d),u("")),c(!1)},disabled:!d.trim(),className:"px-4 py-2 bg-brand-500 hover:bg-brand-600 disabled:bg-surface-2 disabled:opacity-50 text-white text-sm font-medium rounded transition-all duration-150 ease-out active:scale-[0.97] shadow-sm flex-shrink-0",children:t("editor.insert")})]})}),(0,n.jsxs)("div",{className:"bg-surface border-t border-border px-2 pt-2 pb-safe flex flex-col gap-1 flex-shrink-0",children:[(0,n.jsx)("div",{className:"flex gap-1",children:cv.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),"ctrl"===e.modifier?(l(e=>!e),i(!1)):"alt"===e.modifier?(i(e=>!e),l(!1)):p(e.key)},className:f("ctrl"===e.modifier&&s||"alt"===e.modifier&&a),children:e.label},e.label))}),(0,n.jsx)("div",{className:"flex gap-1",children:cy.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),e.toggleTextInput?(c(e=>!e),o||setTimeout(()=>x.current?.focus(),350)):e.text?m(e.text):e.key&&p(e.key,{ctrl:e.ctrl,alt:e.alt})},className:f(e.toggleTextInput&&o),children:e.label},e.label))})]})]})}function cj({filePath:e,fileBus:t,onBack:s,line:l,column:a,workspace:i,diffStatus:o,preview:c=!1}){let{t:d}=(0,ec.s)(),u=lH(e),x=!!o,m=e.split("/").pop(),p=lU({filePath:x||u?"":e,fileBus:t}),f=lV({dirty:!x&&!u&&p.dirty,onSave:p.save}),h=(0,r.useRef)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(!1),C=x||u?null:(0,F.YO)(e),[S,E]=(0,r.useState)(c&&!!C),[R,T]=(0,r.useState)(0),[$,M]=(0,r.useState)(e),[z,P]=(0,r.useState)(!1);$!==e&&(M(e),E(c&&!!C)),p.justSaved!==z&&(P(p.justSaved),p.justSaved&&T(e=>e+1));let I=(0,r.useCallback)((e,t)=>{h.current=t},[]);(0,r.useEffect)(()=>{if(x||!i||!e)return;let s=!1;return t.gitFileStatus(i,e).then(e=>{s||y(e?.success&&e.status?e:null)}),()=>{s=!0}},[e,i,t]);let A=async()=>{if(!v||!i)return;if((0,F.u)(e))return void j("image");N(!0);let s=await t.gitDiff(i,v.file,v.status);N(!1),s?.success&&j(s.diff||"")};(0,r.useEffect)(()=>{if(!o||!i||!e)return;let s=!1,n=setTimeout(async()=>{if((0,F.u)(e))return void j("image");N(!0);let n=await t.gitDiff(i,e,o);!s&&(N(!1),n?.success&&j(n.diff||""))},0);return()=>{s=!0,clearTimeout(n)}},[o,i,e,t]);let L=async()=>{let e=h.current?.state.doc.toString();if(null!=e)try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),1500)}catch{}};return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface px-4 py-3 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),f.guard(s)},className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",children:(0,n.jsx)(en.JG,{size:20})}),(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"text-text font-medium truncate",children:m}),p.dirty&&(0,n.jsx)("span",{className:"w-2 h-2 bg-yellow-400 rounded-full flex-shrink-0",title:d("editor.unsaved")}),p.justSaved&&(0,n.jsx)("span",{className:"text-green-400 text-xs flex-shrink-0",children:d("editor.saved")}),b&&(0,n.jsx)("span",{className:"text-green-400 text-xs flex-shrink-0",children:d("editor.copied",{defaultValue:"Copied"})})]}),v&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),A()},disabled:k,className:"p-2 bg-surface-2 hover:bg-surface-3 text-orange-400 rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",title:d("editor.gitDiff"),children:k?(0,n.jsx)(en.kr,{className:"animate-spin",size:16}):(0,n.jsx)(en.Zr,{size:16})}),C&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),E(e=>!e)},title:d(S?"editor.editCode":"editor.preview"),className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",children:S?(0,n.jsx)(en.GD,{size:16}):(0,n.jsx)(en.kU,{size:16})}),!u&&!x&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),L()},className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",title:d("editor.copy",{defaultValue:"Copy"}),children:(0,n.jsx)(en.QR,{size:16})}),!u&&!x&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),p.save()},disabled:!p.dirty||p.saving,className:`px-3 py-2 rounded-brand transition-all duration-150 ease-out flex items-center gap-1 ${p.dirty&&!p.saving?"bg-brand-500 hover:bg-brand-600 text-white shadow-sm active:scale-[0.97]":"bg-surface-2 text-text-muted cursor-not-allowed"}`,children:[p.saving?(0,n.jsx)(en.kr,{className:"animate-spin",size:16}):(0,n.jsx)(en.eM,{size:16}),(0,n.jsx)("span",{className:"hidden sm:inline",children:d("editor.save")})]})]}),p.error&&!u&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm break-words",children:p.error}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:x?(0,F.u)(e)?(0,n.jsx)(af,{filePath:e,status:o,workspace:i,fileBus:t}):(0,n.jsx)("div",{className:"h-full overflow-auto p-2",children:k?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted",children:d("common.loading")}):w?(0,n.jsx)(am,{diff:w}):(0,n.jsx)("div",{className:"h-32 flex items-center justify-center text-text-muted text-sm",children:d("git.noChanges")})}):u?(0,n.jsx)(lq,{filePath:e,fileBus:t}):S&&C?(0,n.jsx)(ad,{kind:C,filePath:e,fileBus:t,content:p.content,reloadKey:R}):p.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted",children:d("common.loading")}):(0,n.jsx)(l9,{filePath:e,content:p.content,onTextChanged:p.onTextChanged,onRegisterView:(e,t)=>{p.register(e),I(e,t)},onSave:p.save,line:l,column:a})}),!x&&null!==w&&(0,n.jsxs)("div",{className:"absolute inset-0 z-30 bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface-2 px-4 py-3 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-text font-medium truncate",children:d("editor.gitDiff")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),j(null)},className:"p-2 text-text-muted hover:text-text rounded-brand",children:(0,n.jsx)(en.X,{size:18})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto p-2",children:(0,F.u)(e)?(0,n.jsx)(af,{filePath:e,status:v?.status,workspace:i,fileBus:t}):w?(0,n.jsx)(am,{diff:w}):(0,n.jsx)("div",{className:"h-32 flex items-center justify-center text-text-muted text-sm",children:d("git.noChanges")})})]}),!u&&!x&&!p.loading&&!S&&(0,n.jsx)(cw,{viewRef:h}),(0,n.jsx)(lX,{isOpen:f.asking,fileName:m,onSave:f.saveThenLeave,onDiscard:f.discardAndLeave,onCancel:f.cancel})]})}function ck({workspace:e,fileBus:t,branch:s,changedCount:l,onDone:a,onClose:i}){let{t:o}=(0,ec.s)(),[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||u||i()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i,u]);let f=c.trim().length>0&&!u,h=async()=>{let s=await t.gitAdd(e);if(!s.success)return{ok:!1,text:s.error||o("git.stageFailed")};let n=await t.gitCommit(e,c.trim());return n.success?{ok:!0,text:lk(o,n.output)}:{ok:!1,text:n.output||n.error||o("git.commitFailed")}},b=async()=>{if(!f)return;(0,eo.e)(),x(!0),p(null);let e=await h();x(!1),p(e),e.ok&&(d(""),a?.())},g=async()=>{if(u)return;(0,eo.e)(),x(!0),p(null);let s=await t.gitPush(e);x(!1),p({ok:s.success,text:s.success?lN(o,s.output):s.output||s.error||o("git.pushFailed")}),s.success&&a?.()},v=async()=>{if(!f)return;(0,eo.e)(),x(!0),p(null);let s=await h();if(!s.ok){x(!1),p(s);return}d("");let n=await t.gitPush(e);x(!1),p({ok:n.success,text:n.success?lN(o,n.output):n.output||n.error||o("git.pushFailed")}),a?.()};return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:()=>!u&&i()}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsxs)("h3",{className:"text-lg font-semibold text-text flex items-center gap-2",children:[(0,n.jsx)(en.Zr,{size:18,className:"text-brand-500"}),o("git.title"),s?` \xb7 ${s}`:""]}),(0,n.jsx)("button",{onClick:()=>!u&&i(),className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":o("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsxs)("div",{className:"px-5 pb-5 flex flex-col gap-4",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)("textarea",{value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),v())},rows:2,placeholder:o("git.commitPlaceholder"),disabled:u,className:"w-full px-3 py-2 bg-surface-2 text-text text-sm rounded-brand outline-none focus:ring-1 focus:ring-brand-500 resize-y min-h-[54px] max-h-[200px] disabled:opacity-60"}),(0,n.jsx)("span",{className:"text-xs text-text-subtle",children:o("git.stageAllNote",{count:l})})]}),(0,n.jsxs)("button",{onClick:v,disabled:!f,className:"w-full px-4 py-2.5 text-sm bg-brand-500 hover:bg-brand-500/80 text-white font-medium rounded-brand transition-colors flex items-center justify-center gap-2 disabled:opacity-40 disabled:cursor-not-allowed",children:[u?(0,n.jsx)(en.kr,{size:16,className:"animate-spin"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(en.aJ,{size:16}),(0,n.jsx)(en.Do,{size:16})]}),(0,n.jsx)("span",{children:o("git.commitAndPush")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1.5 py-0.5 rounded bg-white/20 text-white leading-none",children:"⌘↵"})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:b,disabled:!f,className:"flex-1 px-4 py-2 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)(en.aJ,{size:16}),o("git.commit")]}),(0,n.jsxs)("button",{onClick:g,disabled:u,className:"flex-1 px-4 py-2 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)(en.Do,{size:16}),o("git.push")]})]}),m&&(0,n.jsx)("pre",{className:`text-xs whitespace-pre-wrap break-words px-3 py-2 rounded-brand max-h-32 overflow-y-auto ${m.ok?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:m.text})]})]})]})}function cN({workspace:e,fileBus:t,onBack:s,onOpenFile:l}){let{t:a}=(0,ec.s)(),[i,o]=(0,r.useState)("status"),[c,d]=(0,r.useState)(!0),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(""),[f,h]=(0,r.useState)([]),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(""),[k,N]=(0,r.useState)(!1),[C,S]=(0,r.useState)({isOpen:!1}),[E,R]=(0,r.useState)(""),[T,$]=(0,r.useState)(null),[M,z]=(0,r.useState)(null),[P,I]=(0,r.useState)(!1),A=(0,r.useCallback)(async()=>{d(!0),p("");let s=await t.gitStatus(e);s.success?h(s.files):p(s.error),t.gitBranch(e).then(e=>{e?.success&&(R(e.branch),$(e.ahead??null),z(e.behind??null))}),d(!1)},[e,t]),L=(0,r.useCallback)(async(s=null,n=null)=>{if(g(s),y(n),s&&(0,F.u)(s)){j("image"),N(!0),x(!1);return}x(!0),p("");let r=await t.gitDiff(e,s,n);r.success?(j(r.diff),N(!0)):p(r.error),x(!1)},[e,t]);(0,r.useEffect)(()=>{A()},[A]);let D=(0,r.useCallback)(()=>{if(o("diff"),!k&&f.length>0){let e=f[0];L(e.path,e.status)}},[k,L,f]),B=(0,r.useCallback)(()=>{b&&v&&K(b,v)},[b,v]),K=(0,r.useCallback)((s,n)=>{let r=s.split("/").pop(),l="?"===n;S({isOpen:!0,title:a("git.discardConfirmTitle"),message:l?a("git.discardConfirmDelete",{name:r}):a("git.discardConfirmDiscard",{name:r}),onConfirm:async()=>{let r=await t.gitDiscard(e,s,n);if(r.success){if(await A(),"diff"===i){let e=f.filter(e=>e.path!==s);e.length>0?L(e[0].path,e[0].status):(o("status"),g(null),j(""),N(!1))}}else p(r.error)}})},[t,e,A,L,f,i,a]),O=(0,r.useCallback)(t=>{let s=e.endsWith("/")?`${e}${t}`:`${e}/${t}`;l?.(s)},[e,l]),[W,_]=(0,r.useState)(null),H=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),q=(0,r.useCallback)((e,t)=>{t.preventDefault(),t.stopPropagation(),(0,eo.e)(),_({file:e,x:t.clientX,y:t.clientY})},[]),U=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=await lm(t,e,s.path);n?.success&&(window.dispatchEvent(new CustomEvent(F.GW)),A())},[e,t,A]),V=(0,r.useCallback)(t=>{let s=e.endsWith("/")?`${e}${t.path}`:`${e}/${t.path}`;return[{key:"open",label:a("common.open",{defaultValue:"Open"}),icon:ly.ExternalLink,disabled:"D"===t.status,onClick:()=>O(t.path)},{key:"copyPath",label:a("files.copyPath",{defaultValue:"Copy Path"}),icon:ly.Copy,onClick:()=>H(s)},{key:"copyRel",label:a("files.copyRelPath",{defaultValue:"Copy Relative Path"}),icon:ly.FileText,onClick:()=>H(t.path)},{key:"copyName",label:a("files.copyName",{defaultValue:"Copy Filename"}),icon:ly.FileText,onClick:()=>H(t.path.split("/").pop())},{key:"addToGitignore",label:a("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:ly.EyeOff,onClick:()=>U(t)},{key:"discard",label:a("git.discardChangesTitle",{defaultValue:"Discard Changes"}),icon:ly.Undo2,danger:!0,onClick:()=>K(t.path,t.status)}]},[e,a,O,H,U,K]),X={modified:f.filter(e=>"M"===e.status),added:f.filter(e=>"A"===e.status),deleted:f.filter(e=>"D"===e.status),untracked:f.filter(e=>"?"===e.status)},G=e=>{let t=e.path.split("/").pop(),s=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")+1):"",r=e.added>0||e.deleted>0;return(0,n.jsx)("div",{className:"px-3 py-2 bg-surface rounded hover:bg-surface-2 transition",onContextMenu:t=>q(e,t),children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:r6({name:t,path:e.path,type:"file"},18)}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),L(e.path,e.status),o("diff")},className:"flex-1 min-w-0 text-left",children:[(0,n.jsx)("div",{className:"text-text font-medium truncate",title:e.path,children:t}),s&&(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",title:s,children:s})]}),r&&(0,n.jsxs)("div",{className:"flex items-center gap-1 text-xs flex-shrink-0",children:[e.added>0&&(0,n.jsxs)("span",{className:"text-[var(--success)]",children:["+",e.added]}),e.deleted>0&&(0,n.jsxs)("span",{className:"text-[var(--danger)]",children:["-",e.deleted]})]}),"D"!==e.status&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eo.e)(),O(e.path)},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-200 flex-shrink-0",title:a("git.openFile"),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:"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:t=>{t.stopPropagation(),(0,eo.e)(),K(e.path,e.status)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-all duration-200 flex-shrink-0",title:a("git.discardChangesTitle"),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)("span",{className:`font-mono font-bold w-5 h-5 flex items-center justify-center text-[11px] rounded flex-shrink-0 bg-surface-2 ${F.vs[e.status]}`,children:e.status})]})},e.path)};return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-4 py-3 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),s()},className:"p-2 bg-surface-2 hover:bg-surface-2 text-text rounded-brand transition-all duration-200",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:"M15 19l-7-7 7-7"})})}),(0,n.jsxs)("h1",{className:"text-text text-lg font-semibold truncate flex items-center gap-2",children:[a("git.title"),E?(0,n.jsxs)("span",{className:"text-text-muted font-normal",children:[" \xb7 ",E]}):null,T>0&&(0,n.jsxs)("span",{className:"text-xs font-medium px-1.5 py-0.5 rounded-brand bg-brand-500/15 text-brand-500",children:["↑",T]}),M>0&&(0,n.jsxs)("span",{className:"text-xs font-medium px-1.5 py-0.5 rounded-brand bg-surface-3 text-text-muted",children:["↓",M]})]}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),I(!0)},className:"ml-auto p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-200",title:a("git.gitActions"),children:(0,n.jsx)(en.Zr,{className:"w-5 h-5"})}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),"status"===i?A():L(b,v)},className:"p-2 bg-surface-2 hover:bg-surface-2 text-text rounded-brand transition-all duration-200",title:a("common.refresh"),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:"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.jsxs)("div",{className:"flex border-b border-border flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),o("status")},className:`flex-1 py-3 text-center font-medium transition ${"status"===i?"text-text border-b-2 border-brand-500":"text-text-muted hover:text-text"}`,children:a("git.status")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),D()},className:`flex-1 py-3 text-center font-medium transition ${"diff"===i?"text-text border-b-2 border-brand-500":"text-text-muted hover:text-text"}`,children:a("git.diffTab")})]}),m&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm",children:m}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden modal-scrollable",children:"status"===i?c?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("common.loading")}):(0,n.jsx)("div",{className:"p-4 space-y-4",children:0===f.length?(0,n.jsx)("div",{className:"text-center text-text-muted py-8",children:a("git.noChanges")}):(0,n.jsxs)(n.Fragment,{children:[X.modified.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.modified")," (",X.modified.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:X.modified.map(G)})]}),X.added.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.added")," (",X.added.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:X.added.map(G)})]}),X.deleted.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.deleted")," (",X.deleted.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:X.deleted.map(G)})]}),X.untracked.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.untrackedTitle")," (",X.untracked.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:X.untracked.map(G)})]})]})}):(0,n.jsxs)("div",{className:"p-4 min-w-0",children:[f.length>0&&(0,n.jsxs)("div",{className:"flex gap-2 mb-4",children:[(0,n.jsx)("select",{value:b||"",onChange:e=>{(0,eo.e)();let t=f.find(t=>t.path===e.target.value);t&&L(t.path,t.status)},className:"flex-1 min-w-0 px-3 py-2 bg-surface-2 rounded-brand text-text focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out",children:f.map(e=>(0,n.jsxs)("option",{value:e.path,children:["[",e.status,"] ",e.path]},e.path))}),b&&"D"!==v&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,eo.e)(),O(b)},disabled:u,className:"h-9 w-9 flex-shrink-0 bg-surface-2 hover:bg-surface-3 disabled:cursor-not-allowed text-text rounded-brand transition-all duration-200 flex items-center justify-center",title:a("git.openFile"),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:"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:()=>{(0,eo.e)(),B()},disabled:!b||u,className:"h-9 w-9 flex-shrink-0 bg-red-500/10 hover:bg-red-500/20 disabled:bg-surface-2 disabled:cursor-not-allowed text-red-400 rounded-brand transition-all duration-200 flex items-center justify-center",title:a("git.discardChangesTitle"),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"})})})]}),u?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("common.loading")}):b&&(0,F.u)(b)?(0,n.jsx)(af,{filePath:b,status:v,workspace:e,fileBus:t}):w?(0,n.jsx)(am,{diff:w}):(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("git.noChanges")})]})}),(0,n.jsx)(ei.A,{isOpen:C.isOpen,onClose:()=>S({isOpen:!1}),onConfirm:C.onConfirm,title:C.title,message:C.message}),P&&(0,n.jsx)(ck,{workspace:e,fileBus:t,branch:E,changedCount:f.length,onDone:A,onClose:()=>I(!1)}),W&&(0,n.jsx)(lv,{x:W.x,y:W.y,items:V(W.file),onClose:()=>_(null)})]})}let cC=[{id:F.Kr.explorer,Icon:en.sv,label:"Explorer"},{id:F.Kr.search,Icon:en.vj,label:"Search"},{id:F.Kr.scm,Icon:en.Zr,label:"Source Control"}];function cS({active:e,onClick:t,label:s,children:r}){return(0,n.jsx)("button",{type:"button",title:s,onClick:t,className:`relative w-10 h-10 flex items-center justify-center rounded-brand transition-all duration-150 ease-out active:scale-[0.96] ${e?"bg-surface-2 text-text border-l-2 border-brand-500":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:r})}function cE({activePanel:e,onSelectPanel:t,onBack:s}){let r=e=>{(0,eo.e)(10),t?.(e)};return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-between bg-surface border-r border-border py-2",style:{width:F.zT},children:[(0,n.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,n.jsx)(cS,{onClick:()=>{(0,eo.e)(10),s?.()},label:"Back",children:(0,n.jsx)(en.JG,{size:20})}),cC.map(({id:t,Icon:s,label:l})=>(0,n.jsx)(cS,{active:e===t,onClick:()=>r(t),label:l,children:(0,n.jsx)(s,{size:20})},t))]}),(0,n.jsx)("div",{className:"flex flex-col items-center gap-1",children:(0,n.jsx)(cS,{active:e===F.Kr.settings,onClick:()=>r(F.Kr.settings),label:"Settings",children:(0,n.jsx)(en.wB,{size:20})})})]})}function cR({active:e,onClick:t,title:s,children:r}){return(0,n.jsx)("button",{type:"button",title:s,onClick:()=>{(0,eo.e)(),t()},className:`px-2 h-6 text-xs rounded-brand border transition-colors ${e?"bg-brand-500 text-white border-brand-500":"bg-surface-2 text-text-muted border-border hover:bg-surface-3"}`,children:r})}function cT({workspace:e,fileBus:t,onOpenFile:s}){let[l,a]=(0,r.useState)(""),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),[f,h]=(0,r.useState)(""),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)([]),[C,S]=(0,r.useState)(!1),[E,R]=(0,r.useState)(!1),[T,$]=(0,r.useState)(new Set),[M,z]=(0,r.useState)(!1),P=(0,r.useRef)(null),I=(0,r.useCallback)(async()=>{if(!l||!e||!t?.searchInFiles){N([]),R(!1);return}S(!0);let s=await t.searchInFiles(e,l,{caseSensitive:c,wholeWord:u,regex:m,includeGlob:f,excludeGlob:b});if(S(!1),s?.success){R(!1);let e=s.results||[];N(e),$(new Set(e.map(e=>e.path)))}else R(!0),N([])},[l,e,t,c,u,m,f,b]);(0,r.useEffect)(()=>{if(P.current&&clearTimeout(P.current),!l){N([]),S(!1);return}return P.current=setTimeout(I,400),()=>clearTimeout(P.current)},[l,c,u,m,f,b,I]);let A=(0,r.useMemo)(()=>{let e=0;for(let t of k)e+=(t.matches||[]).length;return{files:k.length,matches:e}},[k]),L=(0,r.useCallback)(e=>{$(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),D=(0,r.useCallback)(async()=>{if(!l||!e||!t?.replaceInFiles||!k.length)return;let s=k.map(e=>e.path);S(!0),await t.replaceInFiles(e,l,i,{caseSensitive:c,wholeWord:u,regex:m,includeGlob:f,excludeGlob:b},s),S(!1),I()},[l,i,e,t,k,c,u,m,f,b,I]);return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text",children:[(0,n.jsxs)("div",{className:"px-3 pt-3 pb-2 space-y-2 border-b border-border",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(en.vj,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-subtle"}),(0,n.jsx)("input",{value:l,onChange:e=>a(e.target.value),placeholder:"Search",className:"w-full bg-surface-2 border border-border rounded-brand pl-7 pr-7 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),l&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),a("")},className:"absolute right-1 top-1/2 -translate-y-1/2 p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(en.X,{size:12})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,n.jsx)(cR,{active:c,onClick:()=>d(!c),title:"Match Case",children:"Aa"}),(0,n.jsx)(cR,{active:u,onClick:()=>x(!u),title:"Whole Word",children:"ab"}),(0,n.jsx)(cR,{active:m,onClick:()=>p(!m),title:"Regex",children:".*"}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)(cR,{active:w,onClick:()=>j(!w),title:"Toggle Replace",children:"↔"}),(0,n.jsx)(cR,{active:v,onClick:()=>y(!v),title:"Filters",children:"…"})]}),w&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{value:i,onChange:e=>o(e.target.value),placeholder:"Replace",className:"flex-1 bg-surface-2 border border-border rounded-brand px-2 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),(0,n.jsx)("button",{type:"button",disabled:!l||!k.length,onClick:()=>{(0,eo.e)(),z(!0)},className:"px-2 h-8 text-xs rounded-brand bg-brand-500 text-white hover:opacity-90 disabled:opacity-40 disabled:cursor-not-allowed",children:"Replace All"})]}),v&&(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("input",{value:f,onChange:e=>h(e.target.value),placeholder:"files to include",className:"w-full bg-surface-2 border border-border rounded-brand px-2 h-7 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),(0,n.jsx)("input",{value:b,onChange:e=>g(e.target.value),placeholder:"files to exclude",className:"w-full bg-surface-2 border border-border rounded-brand px-2 h-7 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"})]}),(0,n.jsx)("div",{className:`text-[11px] ${E?"text-danger":"text-text-muted"}`,children:C?"Searching...":E?"Search failed — try again":l?`${A.matches} results in ${A.files} files`:"Type to search"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:k.map(e=>{let t=T.has(e.path),r=function(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}(e.path),a=function(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(0,t):""}(e.path);return(0,n.jsxs)("div",{className:"border-b border-border/60",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),L(e.path)},className:"w-full flex items-center gap-1 px-2 py-1 hover:bg-surface-2 text-left",children:[t?(0,n.jsx)(en.yQ,{size:12,className:"text-text-subtle"}):(0,n.jsx)(en.c_,{size:12,className:"text-text-subtle"}),(0,n.jsx)("span",{className:"truncate text-xs text-text",title:e.path,children:r}),(0,n.jsx)("span",{className:"truncate text-[11px] text-text-muted flex-1",title:a,children:a}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 rounded-brand bg-surface-3 text-text-muted",children:e.matches?.length||0})]}),t&&(0,n.jsx)("div",{className:"pl-5",children:(e.matches||[]).map((t,r)=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),s?.(e.path,{line:t.line,column:t.column})},className:"w-full text-left px-2 py-0.5 text-[11px] text-text-muted hover:bg-surface-2 truncate font-mono",title:t.lineText,children:[(0,n.jsx)("span",{className:"text-text-subtle mr-2",children:t.line}),function(e,t,{caseSensitive:s,wholeWord:r,regex:l}){let a,i;if(!t)return e;try{let e=l?t:t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");r&&!l&&(e=`\\b${e}\\b`),a=new RegExp(e,s?"g":"gi")}catch{return e}let o=[],c=0,d=0;for(;null!==(i=a.exec(e))&&d++<500;)i.index>c&&o.push(e.slice(c,i.index)),o.push((0,n.jsx)("span",{className:"bg-brand-500/30 text-text rounded-sm",children:i[0]},`${i.index}-${d}`)),c=i.index+i[0].length,i.index===a.lastIndex&&a.lastIndex++;return c<e.length&&o.push(e.slice(c)),o}(t.lineText||"",l,{caseSensitive:c,wholeWord:u,regex:m})]},`${e.path}-${r}`))})]},e.path)})}),(0,n.jsx)(ei.A,{isOpen:M,onClose:()=>z(!1),onConfirm:D,title:"Replace All",message:`Replace ${A.matches} matches in ${A.files} files?`,confirmText:"Replace All",cancelText:"Cancel"})]})}let c$="px-3 my-2 text-[11px] uppercase tracking-wider text-text-muted",cM="flex items-center justify-between px-3 py-2 hover:bg-surface-2";function cz({value:e,onChange:t}){return(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),t(!e)},className:`relative w-9 h-5 rounded-full transition-colors ${e?"bg-brand-500":"bg-surface-3"}`,children:(0,n.jsx)("span",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${e?"translate-x-4":"translate-x-0.5"}`})})}function cP(){let[e,t]=tK(F.d5.editorFontSize,F.A0),[s,r]=tK(F.d5.wordWrap,!1),[l,a]=tK("fileExplorer.showHidden",!0),i=e=>{t(Math.max(F.xr,Math.min(F.bd,Number(e)||F.A0)))};return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text overflow-auto",children:[(0,n.jsx)("div",{className:c$,children:"Editor"}),(0,n.jsxs)("div",{className:cM,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Font Size"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"range",min:F.xr,max:F.bd,value:e,onChange:e=>i(e.target.value),className:"w-24 accent-brand-500"}),(0,n.jsx)("input",{type:"number",min:F.xr,max:F.bd,value:e,onChange:e=>i(e.target.value),className:"w-12 bg-surface-2 border border-border rounded-brand px-1 h-6 text-xs text-text text-center focus:outline-none focus:border-brand-500"})]})]}),(0,n.jsxs)("div",{className:cM,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Word Wrap"}),(0,n.jsx)(cz,{value:s,onChange:r})]}),(0,n.jsx)("div",{className:c$,children:"Files"}),(0,n.jsxs)("div",{className:cM,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Show Hidden Files"}),(0,n.jsx)(cz,{value:l,onChange:a})]}),(0,n.jsx)("div",{className:c$,children:"About"}),(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-text-muted",children:"VSCode-like File Explorer for 9remote"})]})}let cI={[F.Kr.explorer]:"Explorer",[F.Kr.search]:"Search",[F.Kr.scm]:"Source Control",[F.Kr.settings]:"Settings"};function cA({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a}){let i=cI[e]||"",o=e===F.Kr.explorer;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[!o&&(0,n.jsxs)("div",{style:{height:32},className:"bg-surface px-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"uppercase tracking-wider text-xs text-text-muted",children:i}),(0,n.jsx)("button",{type:"button",title:"Refresh",onClick:()=>{(0,eo.e)(10),s?.refresh?.()},className:"w-7 h-7 flex items-center justify-center rounded-brand text-text-muted hover:text-text hover:bg-surface-2 transition-all duration-150 ease-out active:scale-[0.96]",children:(0,n.jsx)(en.e9,{size:14})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:function({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a}){switch(e){case F.Kr.explorer:return(0,n.jsx)(lg,{workspace:t,fileBus:s,onOpenFile:r,activeFile:a,onSwitchWorkspace:l});case F.Kr.search:return(0,n.jsx)(cT,{workspace:t,fileBus:s,onOpenFile:r});case F.Kr.scm:return(0,n.jsx)(lM,{workspace:t,fileBus:s,onOpenFile:r});case F.Kr.settings:return(0,n.jsx)(cP,{});default:return null}}({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a})})]})}function cL({openedFiles:e,activeFile:t,dirtyFiles:s,onActivate:l,onClose:a,onCloseOthers:i,onCloseAll:o}){let[c,d]=(0,r.useState)(null),u=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!c)return;let e=e=>{u.current&&!u.current.contains(e.target)&&d(null)};return window.addEventListener("mousedown",e),()=>window.removeEventListener("mousedown",e)},[c]),e?.length)?(0,n.jsxs)("div",{className:"flex overflow-x-auto bg-surface border-b border-border flex-shrink-0 relative",children:[e.map(e=>{let r=e===t,i=s?.has(e),o=(0,F.pA)(e),c=o?(0,F.Ax)(e).absPath:e,u=o?`${c.split("/").pop()} (diff)`:c.split("/").pop(),x=o?null:r6({name:c.split("/").pop()||c,type:"file",path:c},14);return(0,n.jsxs)("div",{onClick:()=>{(0,eo.e)(),l(e)},onMouseDown:t=>{1===t.button&&(t.preventDefault(),(0,eo.e)(),a(e))},onContextMenu:t=>{t.preventDefault(),d({path:e,x:t.clientX,y:t.clientY})},className:`group flex items-center gap-2 px-3 py-1.5 border-r border-border cursor-pointer text-sm flex-shrink-0 select-none ${r?"bg-bg text-text border-t-2 border-t-brand-500":"bg-surface text-text-muted hover:text-text"}`,children:[x?(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:x}):(0,n.jsx)(en.Ay,{name:"File",size:14,className:"text-text-muted"}),(0,n.jsx)("span",{className:"truncate max-w-[160px]",title:c,children:u}),i?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand-500 flex-shrink-0"}):null,(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eo.e)(),a(e)},className:`p-0.5 rounded hover:bg-surface-3 transition-opacity ${r||i?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:(0,n.jsx)(en.X,{size:14})})]},e)}),c&&(0,n.jsx)("div",{ref:u,style:{top:c.y,left:c.x},className:"fixed z-50 bg-surface-2 border border-border rounded-brand shadow-lg py-1 text-sm min-w-[160px]",children:[{label:"Close",action:()=>a(c.path)},{label:"Close Others",action:()=>i(c.path)},{label:"Close All",action:()=>o()}].map(e=>(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),e.action(),d(null)},className:"w-full text-left px-3 py-1.5 text-text hover:bg-surface-3 transition-colors",children:e.label},e.label))})]}):null}function cD({workspace:e,filePath:t}){if(!t)return(0,n.jsx)("div",{className:"bg-bg border-b border-border px-3 py-1 text-xs text-text-muted h-7"});let s=e?e.split("/").filter(Boolean).pop():"",l=(e&&t.startsWith(e+"/")?t.slice(e.length+1):t).split("/").filter(Boolean),a=s?[s,...l]:l,i=a.length-1;return(0,n.jsx)("div",{className:"bg-bg border-b border-border px-3 py-1 text-xs text-text-muted flex items-center gap-1 overflow-x-auto whitespace-nowrap",children:a.map((e,t)=>(0,n.jsxs)(r.Fragment,{children:[(0,n.jsx)("span",{className:t===i?"text-text font-medium":"hover:text-text cursor-default",children:e}),t<i&&(0,n.jsx)(en.c_,{size:12,className:"flex-shrink-0"})]},t))})}function cB({filePath:e,workspace:t,fileBus:s,isActive:l,onCursorChange:a,onDirtyChange:i,onRegisterSaver:o,previewSeq:c=0}){let{t:d}=(0,ec.s)(),u=!(0,F.pA)(e)&&!lH(e),x=lU({filePath:u?e:"",fileBus:s}),m=u?(0,F.YO)(e):null,[p,f]=(0,r.useState)(!!c&&!!m),[h,b]=(0,r.useState)(0),[g,v]=(0,r.useState)(e),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(c);return(g!==e?(v(e),f(!1)):j!==c&&(k(c),c&&m&&f(!0)),x.justSaved!==y&&(w(x.justSaved),x.justSaved&&b(e=>e+1)),(0,r.useEffect)(()=>{i?.(e,u&&x.dirty)},[e,u,x.dirty,i]),(0,r.useEffect)(()=>{if(u)return o?.(e,x.save),()=>{o?.(e,null),i?.(e,!1)}},[e,u,x.save,o,i]),(0,r.useEffect)(()=>{if(!l||!u)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()&&(e.preventDefault(),x.save())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l,u,x]),(0,F.pA)(e))?(0,n.jsx)(ah,{diffPath:e,workspace:t,fileBus:s}):lH(e)?(0,n.jsx)(lq,{filePath:e,fileBus:s}):(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[x.error&&(0,n.jsx)("div",{className:"px-4 py-2 text-sm text-red-400 bg-red-500/15 border-b border-red-500/40 break-words",children:x.error}),m&&(0,n.jsx)("div",{className:"px-3 py-1.5 flex items-center justify-end bg-surface border-b border-border-subtle flex-shrink-0",children:(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),f(e=>!e)},title:d(p?"editor.editCode":"editor.preview"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:p?(0,n.jsx)(en.GD,{size:13}):(0,n.jsx)(en.kU,{size:13})})}),x.dirty&&(0,n.jsxs)("div",{className:"px-3 py-1.5 flex items-center gap-2 bg-surface border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("span",{className:"flex-1 text-[11px] text-text-muted",children:d("editor.unsaved")}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),x.save()},disabled:x.saving,className:"px-2.5 py-1 flex items-center gap-1.5 text-[11px] font-medium text-white bg-brand-500 hover:bg-brand-600 rounded-brand disabled:opacity-50 transition-colors",children:[(0,n.jsx)(en.eM,{size:12})," ",d(x.saving?"editor.saving":"editor.save")]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:p&&m?(0,n.jsx)(ad,{kind:m,filePath:e,fileBus:s,content:x.content,reloadKey:h}):x.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:d("common.loading")}):(0,n.jsx)(l9,{filePath:e,content:x.content,onTextChanged:x.onTextChanged,onRegisterView:x.register,onSave:x.save,onCursorChange:a})})]})}function cF({workspace:e,fileBus:t,openedFiles:s,activeFile:l,onActivateFile:a,onCloseFile:i,onCloseOthers:o,onCloseAll:c,onOpenFile:d,onEditorStateChange:u,previewRequest:x}){let[m,p]=(0,r.useState)(()=>new Set),[f,h]=(0,r.useState)(null),b=(0,r.useRef)(new Map);(0,r.useEffect)(()=>{if(!m.size)return;let e=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[m.size]);let g=(0,r.useCallback)((e,t)=>{p(s=>{if(s.has(e)===t)return s;let n=new Set(s);return t?n.add(e):n.delete(e),n})},[]),v=(0,r.useCallback)((e,t)=>{t?b.current.set(e,t):b.current.delete(e)},[]),y=(0,r.useCallback)(e=>{if(!m.has(e))return i?.(e);h(e)},[m,i]),w=(0,r.useCallback)(async e=>{for(let t of s.filter(t=>t!==e&&m.has(t)))if(!1===await b.current.get(t)?.())return;e?o?.(e):c?.()},[s,m,o,c]),j=(0,r.useCallback)(async()=>{!1!==await b.current.get(f)?.()&&(h(null),i?.(f))},[f,i]),k=(0,r.useCallback)(()=>{h(null),i?.(f)},[f,i]);return l?(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-bg min-h-0",children:[(0,n.jsx)(cL,{openedFiles:s,activeFile:l,dirtyFiles:m,onActivate:a,onClose:y,onCloseOthers:e=>w(e),onCloseAll:()=>w(null)}),(0,n.jsx)(cD,{workspace:e,filePath:l}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.map(s=>(0,n.jsx)("div",{className:s===l?"h-full":"hidden",children:(0,n.jsx)(cB,{filePath:s,workspace:e,fileBus:t,isActive:s===l,onCursorChange:u,onDirtyChange:g,onRegisterSaver:v,previewSeq:x?.path===s?x.seq:0})},s))}),(0,n.jsx)(lX,{isOpen:!!f,fileName:f?.split("/").pop(),onSave:j,onDiscard:k,onCancel:()=>h(null)})]}):(0,n.jsx)("div",{className:"flex-1 flex flex-col bg-bg min-h-0",children:(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-text-muted gap-3 p-6",children:[(0,n.jsx)(en.Bm,{size:64,className:"opacity-40"}),(0,n.jsx)("div",{className:"text-sm",children:"Open a file from the Explorer to get started"}),(0,n.jsxs)("div",{className:"text-xs flex items-center gap-2",children:[(0,n.jsx)("kbd",{className:"px-2 py-0.5 bg-surface-2 border border-border rounded text-text-subtle font-mono",children:"Cmd/Ctrl+P"}),(0,n.jsx)("span",{children:"Quick Open"})]})]})})}function cK({gitBranch:e,line:t,column:s,language:r,encoding:l,activeFile:a,sidebarVisible:i,onToggleSidebar:o,bottomVisible:c,onTogglePanel:d}){return(0,n.jsx)(rb,{left:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),o?.()},className:rg,title:i?"Hide Sidebar":"Show Sidebar",children:(0,n.jsx)(en.Ay,{name:i?"PanelLeftClose":"PanelLeftOpen",size:12})}),a&&(0,n.jsxs)("span",{className:rv,children:[(0,n.jsx)(en.Zr,{size:12,className:"opacity-60"}),e||"no branch"]})]}),right:(0,n.jsxs)(n.Fragment,{children:[d&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:rg,title:c?"Hide Terminal":"Show Terminal",children:(0,n.jsx)(en.Ay,{name:"Terminal",size:12})}),a&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:rv,children:`Ln ${t||1}, Col ${s||1}`}),(0,n.jsx)("span",{className:rv,children:r||"plaintext"}),(0,n.jsx)("span",{className:rv,children:l||"UTF-8"})]})]})})}let cO=ti()?"⌘":"Ctrl+",cW=[{id:"openExplorer",label:"View: Show Explorer",icon:"FolderOpen",shortcut:""},{id:"openSearch",label:"View: Show Search",icon:"Search",shortcut:""},{id:"openScm",label:"View: Show Source Control",icon:"GitBranch",shortcut:""},{id:"openSettings",label:"View: Show Settings",icon:"Settings",shortcut:""},{id:"toggleSidebar",label:"View: Toggle Sidebar Visibility",icon:"PanelLeft",shortcut:`${cO}B`},{id:"togglePanel",label:"View: Toggle Terminal Panel",icon:"Terminal",shortcut:`${cO}J`},{id:"closeAll",label:"View: Close All Editors",icon:"X",shortcut:""},{id:"switchWorkspace",label:"Workspaces: Switch Workspace",icon:"Folder",shortcut:""}];function c_({mode:e="files",onSetMode:t,workspace:s,fileBus:l,onClose:a,onOpenFile:i,onAction:o}){let[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(0),[m,p]=(0,r.useState)([]),[f,h]=(0,r.useState)(!1),b=(0,r.useRef)(null),g=(0,r.useRef)(null),v=(0,r.useMemo)(()=>{let e=c.trim().toLowerCase();return e?cW.filter(t=>t.label.toLowerCase().includes(e)):cW},[c]),y="commands"===e?v:m;(0,r.useEffect)(()=>{x(0)},[e,c,m]),(0,r.useEffect)(()=>{if("files"!==e)return;let t=c.trim();if(!t||!l||!s){p([]),h(!1);return}return h(!0),g.current&&clearTimeout(g.current),g.current=setTimeout(async()=>{let e=await l.searchFiles(s,t);p(e?.success&&Array.isArray(e.files)?e.files:[]),h(!1)},200),()=>{g.current&&clearTimeout(g.current)}},[c,e,l,s]);let w=(0,r.useCallback)(s=>{let n=s.target.value;if("files"===e&&n.startsWith(">")){t?.("commands"),d(n.slice(1));return}d(n)},[e,t]),j=(0,r.useCallback)(t=>{let s=y[t];s&&((0,eo.e)(8),"commands"===e?o?.(s.id):i?.(s.path),a?.())},[y,e,o,i,a]),k=(0,r.useCallback)(e=>{if("Escape"===e.key){e.preventDefault(),a?.();return}if("ArrowDown"===e.key){e.preventDefault(),x(e=>Math.min(e+1,Math.max(y.length-1,0)));return}if("ArrowUp"===e.key){e.preventDefault(),x(e=>Math.max(e-1,0));return}"Enter"===e.key&&(e.preventDefault(),j(u))},[y.length,u,a,j]),N="files"===e?"Type `>` for commands":"Type `?` for help",C="files"===e?"Search files by name…":"Type a command…";return(0,n.jsx)("div",{className:"fixed inset-0 z-50 bg-black/40",onMouseDown:a,children:(0,n.jsxs)("div",{className:"absolute top-20 left-1/2 -translate-x-1/2 w-[640px] max-w-[90vw] card-elev bg-surface border border-border rounded-brand overflow-hidden",onMouseDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border",children:[(0,n.jsx)(en.Ay,{name:"commands"===e?"Command":"Search",size:16,className:"text-text-muted"}),(0,n.jsx)("input",{ref:b,autoFocus:!0,type:"text",value:c,onChange:w,onKeyDown:k,placeholder:C,className:"flex-1 bg-transparent outline-none border-0 text-text placeholder:text-text-muted text-sm"}),(0,n.jsx)("span",{className:"text-xs text-text-muted hidden sm:inline",children:N})]}),(0,n.jsx)("div",{className:"max-h-[400px] overflow-auto",children:0===y.length?"files"!==e||c.trim()?f?(0,n.jsxs)("div",{className:"px-4 py-6 text-center text-text-muted text-sm flex items-center justify-center gap-2",children:[(0,n.jsx)(en.Ay,{name:"Loader2",size:14,className:"animate-spin"}),"Searching…"]}):(0,n.jsx)("div",{className:"px-4 py-10 text-center text-text-muted text-sm",children:"No results"}):(0,n.jsx)("div",{className:"px-4 py-10 text-center text-text-muted text-sm",children:"Start typing to search files in workspace"}):(0,n.jsx)("ul",{className:"py-1",children:y.map((t,s)=>{let r=s===u;if("commands"===e)return(0,n.jsxs)("li",{onMouseEnter:()=>x(s),onClick:()=>j(s),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${r?"bg-brand-500/20 text-text":"text-text-muted hover:bg-surface-2"}`,children:[(0,n.jsx)(en.Ay,{name:t.icon,size:16}),(0,n.jsx)("span",{className:"flex-1 text-sm",children:t.label}),t.shortcut?(0,n.jsx)("kbd",{className:"text-xs text-text-muted px-1.5 py-0.5 bg-surface-2 rounded",children:t.shortcut}):null]},t.id);let l=t.name||(t.path?t.path.split(/[\\/]/).pop():""),a=t.relativePath||t.path||"";return(0,n.jsxs)("li",{onMouseEnter:()=>x(s),onClick:()=>j(s),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${r?"bg-brand-500/20 text-text":"text-text-muted hover:bg-surface-2"}`,children:[(0,n.jsx)(en.Ay,{name:"File",size:16}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-sm font-semibold text-text truncate",title:l,children:l}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",title:a,children:a})]})]},t.path||s)})})})]})})}function cH({height:e,onResize:t,onClose:s,bus:l,connected:a,sessions:i=[],onCreateSession:o,onDeleteSession:c,onRenameSession:d}){let[u,x]=(0,r.useState)(i[0]?.id||null),m=(0,r.useRef)(null),p=(0,r.useRef)(!1);(0,r.useEffect)(()=>{0!==i.length&&(u&&i.find(e=>e.id===u)||x(i[0].id))},[i,u]),(0,r.useEffect)(()=>{0===i.length&&o&&!p.current&&(p.current=!0,o(e=>x(e))),i.length>0&&(p.current=!1)},[i.length,o]);let f=(0,r.useCallback)(()=>{(0,eo.e)(),o?.(e=>x(e))},[o]),h=(0,r.useCallback)((e,t)=>{e.stopPropagation(),(0,eo.e)(),c?.(t)},[c]),b=(0,r.useCallback)(e=>{e.preventDefault();let s=m.current?.parentElement;if(!s)return;let n=s.getBoundingClientRect(),r=e=>{if(0===e.buttons)return void l();let s=(n.bottom-e.clientY)/n.height*100;t(Math.max(F.kS,Math.min(F._C,s)))},l=()=>{window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),window.removeEventListener("blur",l),document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.body.style.cursor="row-resize",window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),window.addEventListener("blur",l)},[t]);return(0,n.jsxs)("div",{ref:m,className:"bg-bg border-t border-border flex flex-col flex-shrink-0",style:{height:`${e}%`},children:[(0,n.jsx)("div",{onMouseDown:b,className:"h-1 cursor-row-resize bg-border hover:bg-surface-3 transition-colors -mt-1 relative z-10"}),(0,n.jsxs)("div",{className:"bg-surface border-b border-border flex items-center px-2 flex-shrink-0 overflow-x-auto",children:[(0,n.jsxs)("div",{className:"flex items-center text-text-muted text-xs uppercase tracking-wider px-2 py-1.5 mr-1",children:[(0,n.jsx)(en.BK,{size:12,className:"mr-1"}),"Terminal"]}),i.map(e=>{let t=e.id===u;return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),x(e.id)},className:`group flex items-center gap-1.5 px-2 py-1.5 text-xs transition-colors max-w-[160px] ${t?"text-text bg-bg border-t-2 border-text-muted":"text-text-muted hover:text-text"}`,title:e.name,children:[(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)(en.X,{size:12,onClick:t=>h(t,e.id),className:"opacity-0 group-hover:opacity-100 hover:text-danger flex-shrink-0"})]},e.id)}),(0,n.jsx)("button",{onClick:f,className:"p-1 text-text-muted hover:text-text rounded hover:bg-surface-2 ml-1 flex-shrink-0",title:"New Terminal",children:(0,n.jsx)(en.FW,{size:14})}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),s()},className:"p-1 text-text-muted hover:text-text rounded hover:bg-surface-2 ml-1 flex-shrink-0",title:"Close Panel",children:(0,n.jsx)(en.X,{size:14})})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[i.map((e,t)=>(0,n.jsx)("div",{className:"absolute inset-0",style:{display:e.id===u?"block":"none"},children:(0,n.jsx)(nV,{bus:l,connected:a,sessionId:e.id,isVisible:e.id===u,isFocused:e.id===u,showFocusBorder:!1,bgIndex:t})},e.id)),0===i.length&&(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:"Creating terminal session..."})]})]})}function cq({workspace:e,fileBus:t,onBack:s,onSwitchWorkspace:l,initialOpenedFiles:a,onOpenedFilesChange:i,bus:o,connected:c,sessions:d,onCreateTerminalSession:u,onDeleteTerminalSession:x,onRenameTerminalSession:m,initialActiveFile:p,viewType:f,openFileRef:h}){let[b,g]=tK(F.d5.activityPanel,F.Kr.explorer);(0,r.useEffect)(()=>{"git"===f?g(F.Kr.scm):"files"===f&&g(F.Kr.explorer)},[f,g]);let[v,y]=tK(F.d5.sidebarVisible,!0),[w,j]=tK(F.d5.sidebarWidth,F.Qw),[k,N]=tK(F.d5.bottomPanelVisible,!1),[C,S]=tK(F.d5.bottomPanelHeight,F.LN),E=(0,r.useRef)(null),[R,T]=(0,r.useState)(!1),$=(0,r.useCallback)(e=>{e.preventDefault();let t=E.current;if(!t)return;let s=t.getBoundingClientRect();T(!0);let n=e=>{if(0===e.buttons)return void r();let t=(e.clientX-s.left)/s.width*100;j(Math.max(F.hh,Math.min(F.vd,t)))},r=()=>{window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",r),window.removeEventListener("blur",r),document.body.style.userSelect="",document.body.style.cursor="",T(!1)};document.body.style.userSelect="none",document.body.style.cursor="col-resize",window.addEventListener("mousemove",n),window.addEventListener("mouseup",r),window.addEventListener("blur",r)},[j]),[M,z]=(0,r.useState)(a||[]),[P,I]=(0,r.useState)(p||a?.[0]||null),[A,L]=(0,r.useState)({line:1,column:1,language:"",encoding:"UTF-8"}),[D,B]=(0,r.useState)(""),[K,O]=(0,r.useState)({path:null,seq:0}),[W,_]=(0,r.useState)(!1),[H,q]=(0,r.useState)("commands");(0,r.useEffect)(()=>{i?.(M,P)},[M,P,i]);let U=(0,r.useCallback)((e,t={})=>{z(t=>[e,...t.filter(t=>t!==e)].slice(0,F.L0)),I(e),t.line&&L(e=>({...e,jumpLine:t.line,jumpColumn:t.column})),t.preview&&O(t=>({path:e,seq:t.seq+1}))},[]);(0,r.useEffect)(()=>{h&&(h.current=U)},[h,U]);let V=(0,r.useCallback)(e=>{z(t=>{let s=t.filter(t=>t!==e);return P===e&&I(s[0]||null),s})},[P]),X=(0,r.useCallback)(e=>{z([e]),I(e)},[]),G=(0,r.useCallback)(()=>{z([]),I(null)},[]);return(0,r.useEffect)(()=>{e&&t&&t.gitBranch?.(e).then(e=>{e?.success&&B(e.branch||"")}).catch(()=>{})},[e,t]),!function({onToggleSidebar:e,onSave:t,onCloseTab:s,onCommandPalette:n,onQuickOpen:l,onTogglePanel:a}={}){let i=(0,r.useRef)({});(0,r.useEffect)(()=>{i.current={onToggleSidebar:e,onSave:t,onCloseTab:s,onCommandPalette:n,onQuickOpen:l,onTogglePanel:a}}),(0,r.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey,s=e.key.toLowerCase(),n=e.shiftKey,r=i.current;if(t&&n&&"p"===s||t&&!n&&"k"===s){e.preventDefault(),r.onCommandPalette?.();return}if(t&&!n&&"p"===s){e.preventDefault(),r.onQuickOpen?.();return}if(t&&!n&&"s"===s){e.preventDefault(),r.onSave?.();return}if(t&&!n&&"w"===s){e.preventDefault(),r.onCloseTab?.();return}if(t&&!n&&"b"===s){e.preventDefault(),r.onToggleSidebar?.();return}t&&!n&&"j"===s&&r.onTogglePanel&&(e.preventDefault(),r.onTogglePanel())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[])}({onToggleSidebar:()=>y(e=>!e),onTogglePanel:()=>N(e=>!e),onSave:()=>{window.dispatchEvent(new CustomEvent("fileExplorer:save"))},onCloseTab:()=>P&&V(P),onCommandPalette:()=>{q("commands"),_(!0)},onQuickOpen:()=>{q("files"),_(!0)}}),(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)(cE,{activePanel:b,onSelectPanel:e=>{b===e&&v?y(!1):(g(e),y(!0))},onBack:s}),(0,n.jsxs)("div",{ref:E,className:"flex-1 min-w-0 min-h-0 flex relative",children:[(0,n.jsx)("div",{className:`bg-surface flex-shrink-0 overflow-hidden min-h-0 flex flex-col ${R?"":"transition-[width] duration-200 ease-out"}`,style:{width:v?`${w}%`:0},"aria-hidden":!v,children:(0,n.jsx)(cA,{activePanel:b,workspace:e,fileBus:t,onOpenFile:U,onSwitchWorkspace:l,activeFile:P})}),(0,n.jsx)("div",{onMouseDown:$,className:`cursor-col-resize bg-border hover:bg-brand-500/50 flex-shrink-0 ${R?"":"transition-[width,background-color] duration-200 ease-out"} ${v?"w-1":"w-0"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 min-h-0 flex flex-col",children:[(0,n.jsx)(cF,{workspace:e,fileBus:t,openedFiles:M,activeFile:P,onActivateFile:I,onCloseFile:V,onCloseOthers:X,onCloseAll:G,onOpenFile:U,onEditorStateChange:L,previewRequest:K}),k&&o&&(0,n.jsx)(cH,{height:C,onResize:S,onClose:()=>N(!1),bus:o,connected:c,sessions:d,onCreateSession:u,onDeleteSession:x,onRenameSession:m})]})]})]}),(0,n.jsx)(cK,{gitBranch:D,line:A.line,column:A.column,language:A.language,encoding:A.encoding,activeFile:P,sidebarVisible:v,onToggleSidebar:()=>y(e=>!e),bottomVisible:k,onTogglePanel:()=>N(e=>!e)}),W&&(0,n.jsx)(c_,{mode:H,workspace:e,fileBus:t,onClose:()=>_(!1),onOpenFile:U,onSetMode:q,onAction:e=>{_(!1),"toggleSidebar"===e?y(e=>!e):"togglePanel"===e?N(e=>!e):"closeAll"===e?G():"switchWorkspace"===e?l?.():"openExplorer"===e?(g(F.Kr.explorer),y(!0)):"openSearch"===e?(g(F.Kr.search),y(!0)):"openScm"===e?(g(F.Kr.scm),y(!0)):"openSettings"===e&&(g(F.Kr.settings),y(!0))}})]})}function cU({isOpen:e,onClose:t}){let{t:s}=(0,ec.s)(),l=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!e)return;document.activeElement?.blur?.();let s=requestAnimationFrame(()=>{l.current?.focus()}),n=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener("keydown",n,!0),()=>{cancelAnimationFrame(s),window.removeEventListener("keydown",n,!0)}},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:t}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",tabIndex:-1,className:"relative card-elev max-w-md w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200 outline-none",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:s("shortcuts.title")}),(0,n.jsx)("button",{ref:l,onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out focus:outline-none focus:ring-2 focus:ring-brand-500/40","aria-label":s("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable px-5 pb-5",children:(0,n.jsx)("ul",{className:"flex flex-col divide-y divide-border-subtle/40",children:tr.map(e=>(0,n.jsxs)("li",{className:"flex items-center justify-between gap-4 py-2 first:pt-1",children:[(0,n.jsx)("span",{className:"text-sm text-text min-w-0 truncate",children:s(`shortcuts.${e.id}`)}),(0,n.jsx)("span",{className:"inline-flex items-center gap-1 flex-shrink-0",children:tu(e).map(e=>(0,n.jsx)("kbd",{className:tc,children:e},e))})]},e.id))})})]})]}):null}function cV({retryStatus:e,approvalStatus:t,connected:s,onLogout:r,onRetryNow:l,suppress:a=!1,firstConnect:i=!1}){let{t:o}=(0,ec.s)(),c=t===z.J2.pending||t===z.J2.rejected;if(a&&!c)return null;let d=()=>{r?r():(sessionStorage.clear(),window.location.replace("/login"))};return t===z.J2.pending?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(oT.A,{size:"lg"}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.waitingApproval")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.approvalDescription")}),(0,n.jsx)("p",{className:"text-text-muted text-sm mt-1",children:o("connection.approvalHint")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:"mt-4 w-full py-2 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.cancel")})]})})}):t===z.J2.rejected?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto bg-red-500/20 rounded-full flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-8 h-8 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"})})}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.rejectedTitle")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.rejectedDescription")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:"mt-6 w-full py-3 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.backToLogin")})]})})}):s||!e?.isRetrying&&!e?.failed||i&&!e?.failed||e?.isRetrying&&e.attempt<z.si?null:(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:e.isRetrying?(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(oT.A,{size:"lg"}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.retrying")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.attemptOf",{n:e.attempt,total:e.maxAttempts})}),(0,n.jsx)("div",{className:"mt-4 w-full bg-surface-2 rounded-full h-2",children:(0,n.jsx)("div",{className:"bg-brand-500 h-2 rounded-full transition-all duration-300",style:{width:`${e.attempt/e.maxAttempts*100}%`}})}),l&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),l()},className:"mt-4 w-full py-2 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:"mt-2 w-full py-2 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.exit")})]}):(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto bg-red-500/20 rounded-full flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-8 h-8 text-red-500",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)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.failed")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.failedDescription",{n:e.maxAttempts})}),l&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),l()},className:"mt-6 w-full py-3 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:`w-full py-3 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98] ${l?"mt-2":"mt-6"}`,children:o("connection.backToLogin")})]})})})}let cX={remote:en.VA,mobile:en.wO,sites:en.qz,notifications:en.Ir,folder:en.Bm,note:en.y8},cG=e=>{let t={hiddenHeaderButtons:e.hiddenHeaderButtons,toggleHeaderButton:e.toggleHeaderButton};for(let s of eV.Fz)"pane"===s.group&&(t[s.storeKey]=e[s.storeKey],t[s.setterKey]=e[s.setterKey]);return t};function cJ(){let e=(0,h.B)((0,D.k)(cG));return{buttons:eV.Fz,isOn:t=>"header"===t.group?!e.hiddenHeaderButtons.includes(t.id):!!e[t.storeKey],toggle:t=>"header"===t.group?e.toggleHeaderButton(t.id):e[t.setterKey](!e[t.storeKey])}}function cY(e,t){let s=!!window.ReactNativeWebView,n=s||"u">typeof navigator&&"serviceWorker"in navigator&&"PushManager"in window,[l,a]=(0,r.useState)(()=>!!window.ReactNativeWebView&&"1"!==localStorage.getItem(eI)),[i,o]=(0,r.useState)(!1);(0,r.useEffect)(()=>{s||"serviceWorker"in navigator&&"PushManager"in window&&navigator.serviceWorker.ready.then(e=>e.pushManager?.getSubscription()).then(e=>a(!!e)).catch(()=>{})},[s]);let c=(0,r.useCallback)(async()=>{if(!i){if((0,eo.e)(),o(!0),l)await t?.(),a(!1);else{await e?.();let t=s;if(!s&&"serviceWorker"in navigator&&"PushManager"in window)try{let e=await navigator.serviceWorker.ready;t=!!await e.pushManager?.getSubscription()}catch{t=!1}a(t)}o(!1)}},[l,i,e,t,s]);return{supported:n,enabled:l,loading:i,toggle:c,isExpoWebView:s}}function cZ(e,t){let s=(0,h.B)(e=>e.artifactEnabled),n=(0,h.B)(e=>e.setArtifactEnabled),l=!!(0,h.B)(e=>e.agentCaps?.artifact),[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(!0);(0,r.useEffect)(()=>()=>{o.current=!1},[]),!t&&a&&i(!1);let c=(0,r.useCallback)(r=>{let l=e?.current;if(!l||!t||a)return;(0,eo.e)();let c="boolean"==typeof r?r:!s;i(!0),n(c),l.emit("setArtifactEnabled",{enabled:c},e=>{o.current&&(i(!1),e?.success||n(!c))})},[e,t,a,s,n]);return{supported:l,enabled:s,loading:a,toggle:c}}var cQ=s(52345);let c0=cQ.dI.filter(e=>tM[e.code]);function c1({isOpen:e,value:t,onSelect:s,onClose:l}){let{t:a}=(0,ec.s)();return((0,r.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[e,l]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:l}),(0,n.jsxs)("div",{className:"relative card-elev max-w-lg w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:a("voice.language")}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":a("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable p-3",children:(0,n.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:c0.map(e=>{let r=e.code===t;return(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.code,void((0,eo.e)(),s(t),l())},className:`px-2 py-2 rounded-brand flex items-center gap-2 transition-all duration-150 ease-out active:scale-[0.97] min-w-0 ${r?"bg-brand-500 text-white":"text-text hover:bg-surface-2"}`,children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${e.country}.png`,alt:e.label,className:"w-[17px] h-[12px] object-cover rounded-[2px] flex-shrink-0",loading:"lazy"}),(0,n.jsx)("span",{className:"flex-1 text-sm font-medium truncate text-left",children:e.label}),r&&(0,n.jsx)(en.aJ,{size:14,className:"flex-shrink-0"})]},e.code)})})})]})]}):null}let c2="w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs font-mono text-text placeholder-text-muted focus:outline-none focus:border-brand-500",c5="px-3 py-1.5 rounded-brand text-xs font-medium transition-colors",c3=[{value:"browser",label:"Browser"},{value:"ai",label:"AI Speech To Text"}];function c4({active:e,onClick:t,children:s}){return(0,n.jsx)("button",{type:"button",onClick:t,className:`px-2.5 py-1 rounded-brand text-[11px] border transition-colors ${e?"border-brand-500 bg-brand-500/10 text-brand-400":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"}`,children:s})}function c6({state:e}){if(!e)return null;let t=e.busy?"text-text-muted animate-pulse":e.ok?"text-green-500":"text-red-400";return(0,n.jsx)("p",{className:`text-[11px] leading-relaxed break-words ${t}`,children:e.msg})}function c8({onClose:e}){let t=$(),{mode:s,setMode:l,preset:a,setPreset:i,setField:o}=t,{locale:c}=(0,ec.s)(),[d,u]=tI(c),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(null),[h,b]=(0,r.useState)(null),v=p?.busy||h?.busy,N=cQ.dI.find(e=>e.code===d),C="gemini"===a?t.geminiKeys.some(e=>e.trim()):"openrouter"===a?!!t.openrouterKey.trim():!!t.customKey.trim(),R="custom"===a?t.customModel:(t[`${a}Model`]||"").trim()||y[a].model,T=async()=>{(0,eo.e)(),f({busy:!0,msg:"Testing…"});try{let e=S($.getState());await w(e,{model:e.model,messages:[{role:"user",content:"hi"}],max_tokens:1}),f({ok:!0,msg:"Key & model OK"})}catch(e){f({ok:!1,msg:j(e)})}},M=async()=>{if((0,eo.e)(),!C)return void b({ok:!1,msg:"Enter an API key first"});b({busy:!0,msg:"Recording…"});try{let e=await E($.getState(),await k());b({ok:!!e,msg:e||"(empty reply)"})}catch(e){b({ok:!1,msg:j(e)})}};return(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:e}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:"Voice input"}),(0,n.jsx)("button",{onClick:e,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":"Close",children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable px-5 pb-5 flex flex-col gap-3",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),m(!0)},className:"w-full px-3 py-2 rounded-brand bg-surface-2/50 text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors",children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:"Language"}),N&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 text-xs text-text-muted",children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${N.country}.png`,alt:"",className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{children:N.label})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:c3.map(e=>(0,n.jsx)(c4,{active:s===e.value,onClick:()=>{(0,eo.e)(),l(e.value)},children:e.label},e.value))}),"browser"===s?(0,n.jsx)("p",{className:"text-xs leading-relaxed text-text-muted",children:"Uses the browser's built-in speech recognition (Chrome, Safari, Edge). Not available in Firefox."}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:Object.entries(y).map(([e,t])=>(0,n.jsx)(c4,{active:a===e,onClick:()=>{(0,eo.e)(),i(e)},children:t.label},e))}),(0,n.jsxs)("p",{className:`text-[11px] leading-relaxed ${C?"text-text-muted":"text-amber-500"}`,children:["custom"===a?"Any OpenAI-compatible /chat/completions endpoint":`${y[a].note}`,!C&&" \xb7 No key yet"]}),"custom"!==a&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Model"}),(0,n.jsx)("input",{type:"text",value:t[`${a}Model`]||"",onChange:e=>o(`${a}Model`,e.target.value),placeholder:R,className:c2,autoComplete:"off"})]}),"gemini"===a&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-semibold text-text",children:"API keys — one per line"}),(0,n.jsxs)("a",{href:"https://aistudio.google.com/app/apikey",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-[11px] text-brand-500 hover:text-brand-400 hover:underline transition-colors",children:["AI Studio ",(0,n.jsx)(en.Gr,{size:10})]})]}),(0,n.jsx)("textarea",{rows:3,value:t.geminiKeys.join("\n"),onChange:e=>o("geminiKeys",e.target.value.split("\n")),placeholder:"AIza…\nAIza…",className:`${c2} resize-y`,autoComplete:"off"})]}),"openrouter"===a&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-semibold text-text",children:"API key"}),(0,n.jsxs)("a",{href:"https://openrouter.ai/settings/keys",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-[11px] text-brand-500 hover:text-brand-400 hover:underline transition-colors",children:["OpenRouter ",(0,n.jsx)(en.Gr,{size:10})]})]}),(0,n.jsx)("input",{type:"password",value:t.openrouterKey,onChange:e=>o("openrouterKey",e.target.value),placeholder:"sk-or-…",className:c2,autoComplete:"off"})]}),"custom"===a&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Endpoint"}),(0,n.jsx)("input",{type:"text",value:t.customEndpoint,onChange:e=>o("customEndpoint",e.target.value),placeholder:g,className:c2,autoComplete:"off"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Model"}),(0,n.jsx)("input",{type:"text",value:t.customModel,onChange:e=>o("customModel",e.target.value),placeholder:"e.g. google/gemini-2.5-flash",className:c2,autoComplete:"off"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"API key"}),(0,n.jsx)("input",{type:"password",value:t.customKey,onChange:e=>o("customKey",e.target.value),placeholder:"sk-…",className:c2,autoComplete:"off"})]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:T,disabled:v,className:`${c5} bg-brand-500 hover:bg-brand-600 text-white disabled:opacity-50`,children:"Test key"}),(0,n.jsx)("button",{type:"button",onClick:M,disabled:v,className:`${c5} bg-surface-2/70 hover:bg-surface-2 text-text disabled:opacity-50`,children:"Test voice"})]}),p&&(0,n.jsx)(c6,{state:p}),h&&(0,n.jsx)(c6,{state:h})]})]})]}),x&&(0,n.jsx)(c1,{isOpen:x,value:d,onSelect:u,onClose:()=>m(!1)})]})}function c9({dense:e=!1}){let t=$(e=>e.enabled),s=$(e=>e.mode),l=$(e=>e.preset),a=$(e=>e.setEnabled),[i,o]=(0,r.useState)(!1),c="ai"===s?y[l]?.label||"AI":"Browser",d=()=>{(0,eo.e)(),o(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:e?"w-full py-1 text-sm text-text flex items-center gap-2.5 cursor-pointer select-none":"w-full px-3 py-2 rounded-brand flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 cursor-pointer select-none transition-colors",onClick:d,children:[(0,n.jsx)(en.GO,{size:16,className:`${e?"text-text":"text-brand-500"} flex-shrink-0`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"truncate",children:"Voice input"}),(0,n.jsx)("span",{className:"text-xs text-text-muted shrink-0",children:c})]}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:"Speak instead of typing — chat, terminal, remote"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Voice configuration","aria-label":"Voice configuration",className:"shrink-0 px-2 h-7 flex items-center justify-center rounded-brand border border-border-subtle/60 hover:border-border hover:bg-surface-3/50 text-text-muted hover:text-text text-xs transition-colors",children:"Config"}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)(),a(!t)},"aria-label":"Toggle voice input",className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${t?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${t?"translate-x-4":"translate-x-0.5"}`})})]}),i&&(0,n.jsx)(c8,{onClose:()=>o(!1)})]})}function c7({onRemote:e,onFiles:t,onCommandNotes:s,onCommunity:l,onInstallApp:a,canInstall:i=!1,isInstalled:o=!1,onLogout:c,connected:d=!0,remoteAvailable:u=!1,showTheme:x=!1,theme:m="default",onThemeChange:p,hideActions:f=[],busRef:b=null,subscribeToPush:g=null,unsubscribeFromPush:v=null,onOpenBackgroundPicker:y}){let{t:w}=(0,ec.s)(),j=tF(),k=tf(e=>e.open),N=eb(e=>e.close),{connectionMode:C="tunnel",agentVersion:S}=eb(e=>e.context),E=cJ(),R=ne(e=>!1),T=(0,h.B)(e=>e.webglEnabled),$=(0,h.B)(e=>e.setWebglEnabled),M=(0,h.B)(e=>e.fontSize),z=(0,h.B)(e=>e.setFontSize),P=(0,h.B)(e=>e.terminalTheme),I=(0,h.B)(e=>e.setTerminalTheme),A=(0,h.B)(e=>e.terminalBackgrounds),{theme:L}=(0,n_.D)(),[D,B]=(0,r.useState)(!1),[F,K]=(0,r.useState)(!1),[O,W]=(0,r.useState)(!1),[_,H]=(0,r.useState)(!1),[q,U]=(0,r.useState)(!1),V=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!D)return;let e=e=>{V.current&&!V.current.contains(e.target)&&B(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[D]);let X=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!_)return;let e=e=>{X.current&&!X.current.contains(e.target)&&H(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[_]);let[G,J]=(0,r.useState)(!1);(0,r.useEffect)(()=>{J(window.innerWidth<768)},[]);let Y=cY(g,v),Z=cZ(b,d),Q=Y.isExpoWebView||!!window.ReactNativeWebView||/9Remote-Mobile/i.test(navigator.userAgent),ee=window.matchMedia("(display-mode: standalone)").matches||Q,[et,es]=(0,r.useState)(()=>window.CURRENT_ORIENTATION||localStorage.getItem("expo_orientation")||"portrait");return(0,r.useEffect)(()=>{if(!Q)return;let e=e=>{if(e){es(e);try{localStorage.setItem("expo_orientation",e)}catch{}}};window.handleScreenOrientationChange=e;try{window.ReactNativeWebView?.postMessage(JSON.stringify({type:"GET_SCREEN_ORIENTATION"}))}catch{}return()=>{window.handleScreenOrientationChange===e&&(window.handleScreenOrientationChange=void 0)}},[Q]),(0,r.useCallback)(e=>{(0,eo.e)(),es(e);try{localStorage.setItem("expo_orientation",e)}catch{}try{window.ReactNativeWebView?.postMessage(JSON.stringify({type:"SET_SCREEN_ORIENTATION",orientation:e}))}catch{}},[]),(0,n.jsxs)("div",{className:"p-3 space-y-0.5",children:[!ee&&!o&&a&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),a()},className:"w-full px-3 py-1.5 mb-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.f5,{className:"text-brand-500 flex-shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0 truncate",children:w("menu.installApp")}),i&&(0,n.jsx)("span",{className:"flex-shrink-0 px-2 py-0.5 bg-brand-500 text-white text-xs font-medium rounded-full",children:w("pwaGuide.installNow")})]}),Y.supported&&(0,n.jsxs)("button",{onClick:Y.toggle,disabled:Y.loading,className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 disabled:opacity-50 text-text rounded-brand-lg text-left flex items-center justify-between gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(en.Ir,{className:"text-brand-500",size:16}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsx)("span",{className:"text-sm",children:w("menu.notifications")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:w("menu.notificationsHint")})]})]}),Y.loading?(0,n.jsx)(en.kr,{className:"animate-spin text-text-muted",size:16}):(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Y.enabled?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${Y.enabled?"translate-x-4":"translate-x-0.5"}`})})]}),!f.includes("headerButtons")&&(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),K(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.jz,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.settingsButtons")}),(0,n.jsx)(en.yQ,{className:`text-text-muted transition-transform duration-200 ${F?"rotate-180":""}`,size:16})]}),F&&(0,n.jsx)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:eV.GL.map(({group:e,titleKey:t})=>(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)("p",{className:"pt-1 text-[11px] font-semibold uppercase tracking-wide text-text-muted",children:w(t)}),E.buttons.filter(t=>t.group===e).map(e=>{if("remote"===e.id||"mobile"===e.id)return null;let t=cX[e.id],s=E.isOn(e);return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),E.toggle(e)},className:"w-full py-1 hover:bg-surface-2 text-text rounded-brand text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(t,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w(e.labelKey)}),(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${s?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-0.5"}`})})]},e.id)})]},e))})]}),!f.includes("terminalSettings")&&(0,n.jsxs)("div",{ref:V,className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),B(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.BK,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.terminalSettings")}),(0,n.jsx)(en.yQ,{className:`text-text-muted transition-transform duration-200 ${D?"rotate-180":""}`,size:16})]}),D&&(0,n.jsxs)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),$(!T)},className:"w-full py-1 hover:bg-surface-2 text-text rounded-brand text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.VA,{className:"text-text",size:16}),(0,n.jsxs)("div",{className:"flex flex-col flex-1",children:[(0,n.jsx)("span",{className:"text-sm",children:w("menu.webgl")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:w("menu.webglHint")})]}),(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${T?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${T?"translate-x-4":"translate-x-0.5"}`})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 pt-1.5",children:[(0,n.jsx)(en.ZU,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.fontSize")}),(0,n.jsx)("select",{value:M??(G?12:14),onChange:e=>{(0,eo.e)(),z(Number(e.target.value))},className:"ml-auto bg-surface-2 text-text text-sm rounded-brand px-2 py-1 focus:outline-none focus:ring-2 focus:ring-brand-500/40",children:Array.from({length:G?7:9},(e,t)=>t+10).map(e=>(0,n.jsxs)("option",{value:e,children:[e,"px"]},e))})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(en.es,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.terminalTheme")}),(0,n.jsxs)("select",{value:P,onChange:e=>{(0,eo.e)(),I(e.target.value)},className:"ml-auto bg-surface-2 text-text text-xs rounded-brand px-2 py-1 max-w-[55%] focus:outline-none focus:ring-2 focus:ring-brand-500/40",children:[(0,n.jsx)("option",{value:"default",children:"Vesper (Default)"}),nT.g4.filter(e=>e.mode===L).map(e=>(0,n.jsx)("option",{value:e.key,children:e.label},e.key))]})]})]})]}),(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),W(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.Kq,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.settingsMcp")}),(0,n.jsx)(en.yQ,{className:`text-text-muted transition-transform duration-200 ${O?"rotate-180":""}`,size:16})]}),O&&(0,n.jsxs)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:[(0,n.jsx)(c9,{dense:!0}),Z.supported&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(en.jz,{className:"text-text shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0",children:w("menu.artifactPanel")}),(0,n.jsx)("button",{onClick:Z.toggle,disabled:Z.loading||!d,className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors disabled:opacity-60 ${Z.enabled?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${Z.enabled?"translate-x-4":"translate-x-0.5"}`})})]}),(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-text-muted",children:w("menu.artifactHint")})]})]})]}),"dark"===L&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),y?.()},className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.de,{className:"text-brand-500 flex-shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0",children:w("menu.terminalBackground")}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate max-w-[90px]","data-tip":A.length>1?`${(0,eV.Pz)(A[0])} +${A.length-1}`:(0,eV.Pz)(A[0]),children:A.length>1?`${(0,eV.Pz)(A[0])} +${A.length-1}`:(0,eV.Pz)(A[0])}),(0,n.jsx)(en.c_,{size:16,className:"text-text-muted flex-shrink-0"})]}),R&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),N(),ne.getState().toggle()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(en.cC,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:"Jarvis"})]}),s&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),s()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(en.iU,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.commandNotes")})]}),"mouse"===j&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),N(),k()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(en.s3,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("shortcuts.menuLabel")})]}),l&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),l()},className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.zW,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.community")})]}),(0,n.jsxs)("div",{ref:X,className:"rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),H(e=>!e)},className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.e9,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.reloadRestart")}),(0,n.jsx)(en.yQ,{className:`text-text-muted transition-transform duration-200 ${_?"rotate-180":""}`,size:16})]}),_&&(0,n.jsx)("div",{className:"bg-surface-2/50 px-3 pb-1.5 space-y-0",children:(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),U(!0),setTimeout(()=>window.location.reload(),150)},disabled:q,className:"w-full py-1.5 text-text text-left flex items-center gap-2.5 rounded-brand transition duration-150 ease-out hover:text-brand-500 active:scale-[0.99] disabled:opacity-70",children:[(0,n.jsx)(en.e9,{size:16,className:`ml-3 ${q?"animate-spin":""}`}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.reload")})]})})]}),c&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),c()},className:"w-full px-3 py-1.5 bg-surface hover:bg-red-500/15 text-text hover:text-red-400 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.nU,{className:"text-red-400",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.logout")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 mt-4 mr-1",children:["local"===C&&(0,n.jsx)("span",{className:"text-xs font-semibold px-2 py-0.5 rounded-full bg-green-500/15 text-green-400",children:"LAN"}),(0,n.jsxs)("p",{className:"text-text-muted text-sm",children:[w("menu.version")," ","3.0.24",S?` / 9Remote ${S}`:""]})]})]})}var de=s(2163);function dt(){if("u"<typeof navigator)return"unknown";let e=navigator.userAgent.toLowerCase();return/iphone|ipad|ipod/.test(e)?"ios":/android/.test(e)?"android":/mac/.test(e)?"macos":/win/.test(e)?"windows":"desktop"}function ds(){let{t:e}=(0,ec.s)(),[t]=(0,r.useState)(dt),[s,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)("idle"),o=eb(e=>e.context.apiKey),c=eG(e=>e.canInstall),d=eG(e=>e.isInstalled),u=eG(e=>e.install),x=async()=>{i("installing"),i("accepted"===await u()?"done":"idle")},m=async e=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return!1}},p=async()=>{!o||await m(o)&&(l(!0),setTimeout(()=>l(!1),2e3))},f=+!!o,h=()=>o?(0,n.jsxs)("div",{className:"flex items-start gap-3 mb-4",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:"1"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-2",children:e("pwaGuide.copyYourKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm mb-2",children:e("pwaGuide.copyKeyHint")}),(0,n.jsxs)("div",{className:`w-full flex items-center justify-between gap-2 px-3 py-2.5 rounded-brand border transition-colors ${s?"bg-green-500/10 border-green-500/30":"bg-bg border-border hover:border-brand-500/50 focus-within:border-brand-500/50"}`,children:[(0,n.jsx)("button",{type:"button",onClick:p,className:"flex-1 min-w-0 text-left bg-transparent outline-none border-0 p-0 cursor-pointer","aria-label":e("pwaGuide.tapToCopyApiKey"),children:(0,n.jsx)("code",{className:"block text-sm text-text font-mono truncate",children:(0,de.o)(o)})}),(0,n.jsx)("button",{type:"button",onClick:p,className:`flex items-center gap-1 text-sm flex-shrink-0 ${s?"text-green-400":"text-brand-500"}`,children:s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(en.aJ,{size:14})," ",e("pwaGuide.copiedBang")]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(en.QR,{size:14})," ",e("pwaGuide.copy")]})})]})]})]}):null,b=()=>c?(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.installNow")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.installNowHint")})]}),(0,n.jsxs)("button",{type:"button",onClick:x,disabled:"installing"===a,className:"flex-shrink-0 flex items-center gap-1 px-3 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-medium rounded-brand transition-all duration-150 active:scale-[0.97] disabled:opacity-70 disabled:cursor-wait",children:[(0,n.jsx)(en.f5,{size:14}),"installing"===a?e("pwaGuide.installing"):e("pwaGuide.installNow")]})]}):null;return d?(0,n.jsx)("div",{className:"p-6",children:(0,n.jsxs)("div",{className:"text-center py-12",children:[(0,n.jsx)("div",{className:"inline-flex p-4 bg-green-500/10 rounded-brand-lg mb-4",children:(0,n.jsx)(en.aJ,{className:"text-green-500",size:48})}),(0,n.jsx)("p",{className:"text-text font-semibold mb-2",children:e("pwaGuide.alreadyInstalled")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.alreadyInstalledHint")})]})}):(0,n.jsxs)("div",{className:"p-6 space-y-6",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 pb-4 border-b border-border",children:[(0,n.jsx)("div",{className:"p-2 bg-brand-500/10 rounded-brand",children:(()=>{switch(t){case"ios":case"android":return(0,n.jsx)(en.wO,{className:"text-brand-500",size:24});default:return(0,n.jsx)(en.VA,{className:"text-brand-500",size:24})}})()}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-text font-medium",children:e("pwaGuide.installationGuide")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:(()=>{switch(t){case"ios":return e("pwaGuide.iosPlatform");case"android":return e("pwaGuide.androidPlatform");case"macos":return e("pwaGuide.macosPlatform");case"windows":return e("pwaGuide.windowsPlatform");default:return e("pwaGuide.desktopPlatform")}})()})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-text font-medium mb-4",children:e("pwaGuide.installationSteps")}),(()=>{switch(t){case"ios":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1.5",children:"Download 9Remote on App Store"}),(0,n.jsxs)("a",{href:"https://apps.apple.com/us/app/9remote/id6796664210",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-semibold rounded-brand transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.81-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M15.97 6.38c.62-.75 1.04-1.8 0.92-2.85-.9.04-2 .6-2.65 1.35-.58.66-1.09 1.73-.95 2.76.99.08 2.03-.51 2.68-1.26z"})}),"Get on App Store"]})]})]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]})]});case"android":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1.5",children:"Download 9Remote on Google Play"}),(0,n.jsxs)("a",{href:"https://play.google.com/store/apps/details?id=cc.remote9.app&pli=1",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-semibold rounded-brand transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M3.609 1.814L13.793 12 3.61 22.186a2.128 2.128 0 0 1-.22-.964V2.778c0-.36.08-.694.22-.964zm11.233 11.234l2.584 2.584-11.834 6.83 9.25-9.414zm0-2.096L5.592 1.538l11.834 6.83-2.584 2.584zm1.485 1.048l3.633 2.098a1.328 1.328 0 0 0 0-2.296l-3.633-2.098-1.048 1.048 1.048 1.048z"})}),"Get on Google Play"]})]})]}),c&&(0,n.jsxs)("div",{className:"pt-2 border-t border-border",children:[(0,n.jsx)("p",{className:"text-xs text-text-muted mb-2",children:"Or install directly as Web App (PWA):"}),b()]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]})]});case"macos":case"windows":case"desktop":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),b(),c&&(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]}),!c&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.lookInstallIcon")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.lookInstallIconHint")})]})]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.clickInstallPaste")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.clickInstallPasteHint")})]})]}),(0,n.jsx)("div",{className:"mt-6 p-3 bg-blue-500/10 rounded-brand",children:(0,n.jsxs)("p",{className:"text-blue-200 text-sm",children:["\uD83D\uDCA1 ",e("pwaGuide.alternativeHint")]})})]})]});default:return(0,n.jsx)("p",{className:"text-text-muted text-center py-8",children:e("pwaGuide.loadingPlatform")})}})()]})]})}let dn=[{command:"npm i 9router -g"},{command:"curl -fsSL https://claude.ai/install.sh | bash"},{command:"npm i -g @openai/codex"},{command:"curl -fsSL https://opencode.ai/install | bash"}],{storageKey:dr,maxNotes:dl}={storageKey:"9remote_command_notes_v2",maxNotes:50};function da({isOpen:e,onClose:t}){let{t:s}=(0,ec.s)(),{notes:l,addNote:a,updateNote:i,deleteNote:o}=function(){let[e,t]=(0,r.useState)([]),s=(0,r.useCallback)(()=>{try{let e=localStorage.getItem(dr);if(e)return JSON.parse(e);let t=dn.map((e,t)=>({id:`default_${t}`,...e}));return localStorage.setItem(dr,JSON.stringify(t)),t}catch(e){return console.error("Failed to load command notes:",e),[]}},[]);(0,r.useEffect)(()=>{t(s())},[s]);let n=(0,r.useCallback)(e=>{try{localStorage.setItem(dr,JSON.stringify(e)),t(e)}catch(e){console.error("Failed to persist command notes:",e)}},[]),l=(0,r.useCallback)(t=>{n([{id:Date.now().toString(),command:t},...e].slice(0,dl))},[e,n]),a=(0,r.useCallback)((t,s)=>{n(e.map(e=>e.id===t?{...e,command:s}:e))},[e,n]),i=(0,r.useCallback)(t=>{n(e.filter(e=>e.id!==t))},[e,n]);return{notes:e,addNote:l,updateNote:a,deleteNote:i}}(),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(null),[m,p]=(0,r.useState)(""),f=(0,r.useRef)(null),[h,b]=(0,r.useState)(null);(0,r.useEffect)(()=>{e&&setTimeout(()=>f.current?.focus(),100)},[e,u]),(0,r.useEffect)(()=>{if(!e||!window.visualViewport)return;let t=window.visualViewport,s=()=>b(t.height);return s(),t.addEventListener("resize",s),t.addEventListener("scroll",s),()=>{t.removeEventListener("resize",s),t.removeEventListener("scroll",s)}},[e]),(0,r.useEffect)(()=>{let s=s=>{"Escape"===s.key&&e&&t()};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[e,t]);let g=(0,r.useCallback)((e,t)=>{(0,eo.e)(),navigator.clipboard?.writeText(t).catch(()=>{}),d(e),setTimeout(()=>d(null),2e3)},[]),v=(0,r.useCallback)(e=>{(0,eo.e)(),x(e.id),p(e.command)},[]),y=(0,r.useCallback)(()=>{m.trim()&&((0,eo.e)(),u?(i(u,m.trim()),x(null)):a(m.trim()),p(""))},[m,u,a,i]),w=(0,r.useCallback)(e=>{(0,eo.e)(),o(e),u===e&&(x(null),p(""))},[o,u]),j=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),y())},[y]);return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:t}),(0,n.jsxs)("div",{className:"absolute top-0 right-0 w-[85vw] sm:w-96 max-w-md bg-surface border-l border-border shadow-2xl flex flex-col slide-in-right",style:{height:h?`${h}px`:"100%"},onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0 safe-area-top",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(en.iU,{size:20,className:"text-brand-500"}),(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("commandNotes.title")})]}),(0,n.jsx)("button",{onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable",children:[0===l.length&&(0,n.jsxs)("div",{className:"text-center text-text-muted py-8",children:[(0,n.jsx)(en.iU,{size:32,className:"mx-auto mb-3 text-text-muted"}),(0,n.jsx)("p",{className:"text-sm",children:s("commandNotes.noSavedCommands")}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-1",children:s("commandNotes.addFirstBelow")})]}),l.map(e=>(0,n.jsx)("div",{className:"px-4 py-3 border-b border-border/50 hover:bg-surface-2/30 transition-colors group",children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>g(e.id,e.command),title:s("commandNotes.clickToCopy"),children:[(0,n.jsx)("p",{className:"text-sm text-text font-mono break-all",children:e.command}),c===e.id&&(0,n.jsx)("span",{className:"text-xs text-green-400 mt-1 inline-block",children:s("commandNotes.copiedBang")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:()=>g(e.id,e.command),className:"p-1.5 text-text-muted hover:text-brand-400 rounded transition-colors",title:s("commandNotes.copy"),children:c===e.id?(0,n.jsx)(en.aJ,{size:14,className:"text-green-400"}):(0,n.jsx)(en.QR,{size:14})}),(0,n.jsx)("button",{onClick:()=>v(e),className:"p-1.5 text-text-muted hover:text-brand-400 rounded transition-colors",title:s("commandNotes.edit"),children:(0,n.jsx)(en.gH,{size:14})}),(0,n.jsx)("button",{onClick:()=>w(e.id),className:"p-1.5 text-text-muted hover:text-red-400 rounded transition-colors",title:s("commandNotes.delete"),children:(0,n.jsx)(en.TB,{size:14})})]})]})},e.id))]}),(0,n.jsx)("div",{className:"px-3 py-3 border-t border-border flex-shrink-0 safe-area-bottom",children:(0,n.jsxs)("div",{className:"flex gap-2 items-end",children:[(0,n.jsx)("textarea",{ref:f,value:m,onChange:e=>p(e.target.value),onKeyDown:j,placeholder:u?s("commandNotes.editCommandPlaceholder"):s("commandNotes.addCommandPlaceholder"),rows:2,className:"flex-1 bg-surface-2 rounded-brand px-3 py-2 text-text text-sm placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out font-mono resize-none"}),(0,n.jsx)("button",{onClick:y,disabled:!m.trim(),className:"p-2.5 bg-brand-600 hover:bg-brand-500 disabled:bg-surface-2 disabled:cursor-not-allowed text-text rounded-brand transition-colors flex-shrink-0",title:u?s("commandNotes.update"):s("commandNotes.add"),children:(0,n.jsx)(en.Vn,{size:18})})]})})]})]}):null}let di=[{id:"facebook",label:"Facebook Group",description:"Report bugs & suggest features to 9Team community",url:"https://www.facebook.com/groups/9teamvn",icon:"Facebook",color:"#1877F2"},{id:"github",label:"GitHub",description:"Source code & issue tracker",url:"https://github.com/decolua/9remote",icon:"Github",color:"#ffffff"}];function dc({isOpen:e,onClose:t}){let{t:s}=(0,ec.s)();return((0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&t?.()};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-md card-elev slide-in-top",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("community.title")}),(0,n.jsx)("button",{onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-2",children:[(0,n.jsx)("p",{className:"text-text-muted text-sm px-1 mb-2",children:s("community.description")}),di.map(e=>(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.url,void((0,eo.e)(),window.open(t,"_blank","noopener,noreferrer"))},className:"w-full px-4 py-3 bg-surface-2 hover:bg-surface-3 text-text rounded-brand-lg text-left flex items-center gap-3 transition-all duration-150 ease-out active:scale-[0.99] group",children:[(0,n.jsx)("span",{className:"flex items-center justify-center w-10 h-10 rounded-brand flex-shrink-0",style:{backgroundColor:`${e.color}1a`,color:e.color},children:(0,n.jsx)(en.Ay,{name:e.icon,size:22})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium truncate",children:e.label}),e.description&&(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",children:e.description})]}),(0,n.jsx)(en.Gr,{className:"text-text-muted group-hover:text-brand-500 flex-shrink-0",size:18})]},e.id))]})]})]}):null}var dd=s(18057);let du=[{id:"general",labelKey:"menu.settingsGeneral",icon:"Settings"},{id:"appearance",labelKey:"menu.settingsAppearance",icon:"Palette"},{id:"terminal",labelKey:"menu.settingsTerminalTab",icon:"Terminal"},{id:"background",labelKey:"menu.terminalBackground",icon:"Image"},{id:"buttons",labelKey:"menu.settingsButtons",icon:"PanelRight"},{id:"mcp",labelKey:"menu.settingsMcp",icon:"Zap"},{id:"shortcuts",labelKey:"shortcuts.menuLabel",icon:"Keyboard"}];function dx({isOpen:e,onClose:t,busRef:s,inline:l=!1}){let{t:a}=(0,ec.s)(),i=(0,h.B)(e=>e.terminalBackgrounds);(0,h.B)(e=>e.setTerminalBackgrounds);let o=(0,h.B)(e=>e.terminalBackgroundOpacity),c=(0,h.B)(e=>e.setTerminalBackgroundOpacity),d=(0,h.B)(e=>e.customBackgrounds),{saving:u,error:x,setError:m,fileInput:p,openPicker:f}=sX(s),[b,g]=(0,r.useState)(()=>window.innerWidth>=eV.jK);(0,r.useEffect)(()=>{let e=()=>g(window.innerWidth>=eV.jK);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&(m(""),t())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,t,m]);let v=()=>{m(""),t()};if(!l&&!e)return null;let y=o??eV._z,{min:w,max:j,step:k}=eV.DW,N=`${(y-w)/(j-w)*100}%`,C=(0,eV.IJ)(i,d),S=(e,t,s)=>{let r="none"===e,l=r?-1:C.indexOf(e),a=r?0===C.length:-1!==l;return(0,n.jsxs)("button",{onClick:()=>(e=>{(0,eo.e)();let{terminalBackgrounds:t,setTerminalBackgrounds:s}=h.B.getState();s("none"===e?[]:t.includes(e)?t.filter(t=>t!==e):[...t,e])})(e),className:"group relative block w-full aspect-[9/16] rounded-2xl overflow-hidden transition-transform duration-200 ease-out active:scale-[0.97] shadow-sm",children:[s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("img",{src:s,alt:t,className:"absolute inset-0 h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.03]",loading:"lazy"}),(0,n.jsx)("span",{className:"pointer-events-none absolute inset-0",style:{background:`rgba(0,0,0,${eV.t})`}}),(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 h-1/4 bg-gradient-to-t from-black/75 to-transparent"}),(0,n.jsx)("span",{className:"absolute bottom-2 left-0 right-0 px-2 text-xs font-medium text-white truncate",children:t})]}):(0,n.jsxs)("span",{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 transition-colors ${a?"bg-brand-500/10 text-brand-500":"bg-surface-2 text-text-muted group-hover:text-text"}`,children:[(0,n.jsx)(en.P6,{size:24,strokeWidth:1.75}),(0,n.jsx)("span",{className:"text-xs font-medium",children:t})]}),(0,n.jsx)("span",{className:`pointer-events-none absolute inset-0 rounded-2xl transition-shadow duration-200 ${a?"ring-1 ring-inset ring-brand-500":"ring-1 ring-inset ring-white/15 group-hover:ring-brand-500/60"}`}),a&&!r&&(0,n.jsx)("span",{className:"absolute top-2 right-2 flex items-center justify-center w-6 h-6 bg-brand-500 rounded-full shadow-lg text-white text-xs font-semibold",children:l+1})]})},E=(0,n.jsxs)("div",{className:l||b?"grid grid-cols-3 gap-3":"grid grid-cols-2 gap-3",children:[Object.entries(eV.vk).map(([e,t])=>(0,n.jsx)("div",{children:S(e,t.label,t.src)},e)),d.map(e=>(0,n.jsxs)("div",{className:"relative",children:[S(`custom:${e.id}`,a("menu.bgCustomLabel"),e.dataUrl),(0,n.jsx)("button",{onClick:()=>{var t;let n;return t=e.id,(0,eo.e)(),n=s?.current,void(n?.emit&&n.emit("bg:delete",{id:t},e=>{if(!e?.success)return void m(e?.error||a("menu.bgDeleteFailed"));let s=`custom:${t}`,{customBackgrounds:n,setCustomBackgrounds:r,terminalBackgrounds:l,setTerminalBackgrounds:i}=h.B.getState();r(n.filter(e=>e.id!==t)),i(l.filter(e=>e!==s))}))},className:"absolute top-2 left-2 flex items-center justify-center w-7 h-7 rounded-full bg-black/55 text-white backdrop-blur-sm hover:bg-red-500/80 transition-colors","aria-label":a("common.delete"),children:(0,n.jsx)(en.X,{size:13})})]},`custom:${e.id}`)),(0,n.jsxs)("button",{onClick:f,disabled:u,className:"group relative block w-full aspect-[9/16] rounded-2xl overflow-hidden border-2 border-dashed border-border flex flex-col items-center justify-center gap-2 text-text-muted hover:border-brand-500 hover:text-brand-500 transition-colors disabled:opacity-40",children:[u?(0,n.jsx)(en.kr,{size:24,className:"animate-spin"}):(0,n.jsx)(en.FW,{size:24,strokeWidth:1.75}),(0,n.jsx)("span",{className:"text-xs font-medium",children:a("menu.bgAdd")})]})]}),R=C.length>0&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-3 px-1 pt-1",children:[(0,n.jsx)("span",{className:"text-xs text-text flex-shrink-0",children:a("menu.bgDim")}),(0,n.jsx)("input",{type:"range",min:w,max:j,step:k,value:y,onChange:e=>c(Number(e.target.value)),className:"brand-range flex-1 min-w-0",style:{"--pct":N},"aria-label":a("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums flex-shrink-0",children:[Math.round(100*y),"%"]})]}),T=C.length>0&&(0,n.jsxs)("div",{className:"flex-shrink-0 border-t border-border px-5 pt-3 pb-[max(1.25rem,env(safe-area-inset-bottom))]",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-sm text-text",children:a("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums",children:[Math.round(100*y),"%"]})]}),(0,n.jsx)("input",{type:"range",min:w,max:j,step:k,value:y,onChange:e=>c(Number(e.target.value)),className:"brand-range brand-range-lg",style:{"--pct":N},"aria-label":a("menu.bgDim")})]}),$=x&&(0,n.jsx)("div",{className:`px-3 py-2 rounded-brand bg-red-500/10 border border-red-500/30 text-red-500 text-xs break-all ${l?"":"flex-shrink-0 mx-5 mb-2"}`,children:x});return l?(0,n.jsxs)("div",{className:"h-full flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[E,$]}),R,p]}):(0,sU.createPortal)((0,n.jsxs)("div",{className:b?"fixed inset-0 z-[60] flex items-center justify-center p-4":"fixed inset-0 z-[60] flex flex-col justify-end",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:v}),(0,n.jsxs)("div",{className:b?"relative w-full max-w-lg max-h-[80vh] rounded-brand-lg border border-border-subtle bg-surface shadow-2xl flex flex-col overflow-hidden animate-in zoom-in-95 duration-200":"relative rounded-t-3xl border-t border-border bg-surface/95 backdrop-blur-xl shadow-2xl max-h-[88dvh] flex flex-col animate-in slide-in-from-bottom duration-300 ease-out",children:[!b&&(0,n.jsx)("div",{className:"pt-3 pb-1 flex justify-center flex-shrink-0",children:(0,n.jsx)("div",{className:"w-10 h-1 rounded-full bg-border"})}),(0,n.jsxs)("div",{className:`px-6 pb-3 flex items-center justify-between flex-shrink-0 ${b?"pt-4":""}`,children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:a("menu.terminalBackground")}),(0,n.jsx)("button",{onClick:v,className:"p-2 -mr-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-full transition-colors","aria-label":a("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable px-5 pb-4",children:E}),$,T]}),p]}),document.body)}let dm={Settings:en.wB,Palette:en.es,Terminal:en.BK,Bell:en.Ir,Sparkles:en.sU,Keyboard:en.s3,Zap:en.Kq,PanelRight:en.jz,Image:en._V,Bot:en.cC};function dp({context:e,callbacks:t,canInstall:s,isInstalled:l,install:a,onClose:i}){let{t:o,locale:c}=(0,ec.s)(),{theme:d,setTheme:u}=(0,n_.D)(),[x,m]=(0,r.useState)("general"),[p,f]=(0,r.useState)(!1),[b,g]=(0,r.useState)(!1),v=cQ.dI.find(e=>e.code===c),y=(0,h.B)(e=>e.webglEnabled),w=(0,h.B)(e=>e.setWebglEnabled),j=(0,h.B)(e=>e.fontSize),k=(0,h.B)(e=>e.setFontSize),N=(0,h.B)(e=>e.terminalTheme),C=(0,h.B)(e=>e.setTerminalTheme),S=cJ(),E=cY(e.subscribeToPush,e.unsubscribeFromPush),R=cZ(e.busRef,e.connected),T=ne(e=>!1),$=R.supported,M=e.agentVersion,z=(0,r.useMemo)(()=>e.hideActions||[],[e.hideActions]),P=!(window.matchMedia("(display-mode: standalone)").matches||window.ReactNativeWebView)&&!l,I=(0,r.useMemo)(()=>du.filter(e=>"codespace"!==e.id&&("terminal"!==e.id||!z.includes("terminalSettings"))),[z]),A=I.find(e=>e.id===x);(0,r.useEffect)(()=>{document.activeElement?.blur?.();let e=e=>{"Escape"!==e.key||b||(e.preventDefault(),e.stopPropagation(),i())};return window.addEventListener("keydown",e,!0),document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",e,!0),document.body.style.overflow=""}},[i,b]);let L=(0,r.useCallback)(e=>{(0,eo.e)(),i(),setTimeout(()=>e?.(),50)},[i]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:i}),(0,n.jsxs)("div",{className:"relative w-full max-w-4xl h-[85vh] max-h-[640px] bg-surface border border-border rounded-brand-lg shadow-2xl flex overflow-hidden",role:"dialog","aria-modal":"true","aria-label":o("menu.settings"),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("nav",{className:"w-52 flex-shrink-0 bg-bg/40 border-r border-border flex flex-col",children:[(0,n.jsx)("div",{className:"h-12 flex items-center px-4 border-b border-border",children:(0,n.jsx)("h2",{className:"text-base font-semibold text-text",children:o("menu.settings")})}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-0.5 modal-scrollable",children:I.map(e=>{let t=dm[e.icon],s=x===e.id;return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),m(e.id)},className:`w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm transition-colors ${s?"bg-brand-500/15 text-brand-500":"text-text-muted hover:bg-surface-2 hover:text-text"}`,children:[(0,n.jsx)(t,{size:16}),(0,n.jsx)("span",{children:o(e.labelKey)})]},e.id)})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center gap-2",children:["local"===e.connectionMode&&(0,n.jsx)("span",{className:"text-[10px] font-semibold px-1.5 py-0.5 rounded-full bg-green-500/15 text-green-400",children:"LAN"}),(0,n.jsxs)("p",{className:"text-text-muted text-xs truncate",children:["3.0.24",M?` / ${M}`:""]})]})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("div",{className:"h-12 flex items-center justify-between gap-2 pl-6 pr-3 border-b border-border",children:["install"===x?(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),m("general")},className:"-ml-2 px-2 py-1 text-sm font-medium text-text hover:bg-surface-2 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)(en.JG,{size:16}),o("pwa.title")]}):(0,n.jsx)("h3",{className:"text-sm font-medium text-text truncate",children:o(A?.labelKey||"menu.settings")}),(0,n.jsx)("button",{onClick:i,className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0","aria-label":o("common.close"),children:(0,n.jsx)(en.X,{size:18})})]}),(0,n.jsxs)("div",{className:`flex-1 overflow-y-auto modal-scrollable px-6 ${"background"===x?"py-4":"py-5"}`,children:["background"===x&&(0,n.jsx)(dx,{inline:!0,busRef:e.busRef}),"general"===x&&(0,n.jsxs)("div",{className:"space-y-6",children:[(E.supported||P)&&(0,n.jsxs)(df,{children:[E.supported&&(0,n.jsx)(db,{icon:en.Ir,label:o("menu.notifications"),hint:o("menu.notificationsHint"),value:E.enabled,loading:E.loading,onChange:E.toggle}),P&&(0,n.jsx)(dh,{icon:en.f5,label:o("menu.installApp"),badge:s?o("pwaGuide.installNow"):null,onClick:()=>s?L(a):m("install")})]}),(0,n.jsx)(df,{title:o("menu.reloadRestart"),children:(0,n.jsx)(dh,{icon:en.e9,iconClass:p?"animate-spin":"",label:o("menu.reload"),disabled:p,onClick:()=>{(0,eo.e)(),f(!0),setTimeout(()=>window.location.reload(),150)}})}),t.onLogout&&(0,n.jsx)(df,{title:o("menu.settingsAccount"),children:(0,n.jsx)(dh,{icon:en.nU,label:o("menu.logout"),danger:!0,onClick:()=>L(t.onLogout)})})]}),"appearance"===x&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(df,{title:o("menu.theme"),children:(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,n.jsx)(dv,{icon:en.bd,label:o("menu.themeLight"),active:"light"===d,onClick:()=>{(0,eo.e)(),u("light")}}),(0,n.jsx)(dv,{icon:en.AX,label:o("menu.themeDark"),active:"dark"===d,onClick:()=>{(0,eo.e)(),u("dark")}})]})}),(0,n.jsx)(df,{title:o("menu.language"),children:(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),g(!0)},className:"w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors",children:[(0,n.jsx)(en.qz,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:o("menu.language")}),v&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 text-text-muted",children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${v.country}.png`,alt:"",className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{className:"text-xs",children:v.label})]}),(0,n.jsx)(en.c_,{size:15,className:"text-text-muted flex-shrink-0"})]})})]}),"terminal"===x&&(0,n.jsx)("div",{className:"space-y-6",children:(0,n.jsxs)(df,{title:o("menu.terminalSettings"),children:[(0,n.jsx)(dg,{icon:en.ZU,label:o("menu.fontSize"),children:(0,n.jsx)("select",{value:j??14,onChange:e=>{(0,eo.e)(),k(Number(e.target.value))},className:"bg-surface-2 text-text text-sm rounded-brand px-2 py-1 focus:outline-none focus:ring-2 focus:ring-brand-500/40",children:Array.from({length:9},(e,t)=>t+10).map(e=>(0,n.jsxs)("option",{value:e,children:[e,"px"]},e))})}),(0,n.jsx)(dg,{icon:en.es,label:o("menu.terminalTheme"),children:(0,n.jsxs)("select",{value:N,onChange:e=>{(0,eo.e)(),C(e.target.value)},className:"bg-surface-2 text-text text-sm rounded-brand px-2 py-1 max-w-[220px] focus:outline-none focus:ring-2 focus:ring-brand-500/40",children:[(0,n.jsx)("option",{value:"default",children:"Vesper (Default)"}),nT.g4.filter(e=>e.mode===d).map(e=>(0,n.jsx)("option",{value:e.key,children:e.label},e.key))]})}),(0,n.jsx)(db,{icon:en.VA,label:o("menu.webgl"),hint:o("menu.webglHint"),value:y,onChange:w})]})}),"buttons"===x&&(0,n.jsx)("div",{className:"space-y-6",children:eV.GL.map(({group:e,titleKey:t})=>(0,n.jsx)(df,{title:o(t),children:S.buttons.filter(t=>t.group===e).map(e=>(0,n.jsx)(db,{icon:cX[e.id],label:o(e.labelKey),value:S.isOn(e),onChange:()=>S.toggle(e)},e.id))},e))}),"mcp"===x&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(c9,{}),$&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(db,{icon:en.jz,label:o("menu.artifactPanel"),hint:o("menu.artifactHint"),value:R.enabled,loading:R.loading,disabled:!e.connected,onChange:R.toggle}),(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-text-muted",children:o("menu.mcpRestartHint")})]})]}),"jarvis"===x&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(db,{icon:en.cC,label:o("menu.jarvisToggle"),hint:o("menu.jarvisToggleHint"),value:T,onChange:e=>{ne.getState().setSettings({enabled:e}),e||ne.getState().setOpen(!1)}}),$&&!R.enabled&&(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-amber-400",children:o("menu.jarvisMcpOff")}),(0,n.jsx)(nd,{busRef:e.busRef})]}),"shortcuts"===x&&(0,n.jsx)("ul",{className:"flex flex-col divide-y divide-border-subtle/40",children:tr.map(e=>(0,n.jsxs)("li",{className:"flex items-center justify-between gap-4 px-3 py-2 rounded-brand hover:bg-surface-2 first:pt-1",children:[(0,n.jsx)("span",{className:"text-sm text-text min-w-0 truncate",children:o(`shortcuts.${e.id}`)}),(0,n.jsx)("span",{className:"inline-flex items-center gap-1 flex-shrink-0",children:tu(e).map(e=>(0,n.jsx)("kbd",{className:tc,children:e},e))})]},e.id))}),"install"===x&&(0,n.jsx)(ds,{})]})]})]}),(0,n.jsx)(dd.A,{isOpen:b,onClose:()=>g(!1)})]})}function df({title:e,children:t}){return(0,n.jsxs)("section",{children:[e&&(0,n.jsx)("h4",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-muted mb-2",children:e}),(0,n.jsx)("div",{className:"space-y-1",children:t})]})}function dh({icon:e,iconClass:t="",label:s,badge:r,danger:l,disabled:a,onClick:i}){return(0,n.jsxs)("button",{onClick:i,disabled:a,className:`w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm transition-colors ${a?"text-text-muted cursor-not-allowed opacity-60":l?"text-text hover:bg-red-500/15 hover:text-red-400":"text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(e,{size:16,className:`${l?"text-red-400":"text-brand-500"} ${t}`}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:s}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 px-2 py-0.5 bg-brand-500 text-white text-xs font-medium rounded-full",children:r})]})}function db({icon:e,label:t,hint:s,value:r,loading:l,disabled:a,onChange:i}){return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),i(!r)},disabled:l||a,className:"w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors disabled:opacity-60",children:[(0,n.jsx)(e,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"block truncate",children:t}),s&&(0,n.jsx)("span",{className:"block text-xs text-text-muted truncate",children:s})]}),l?(0,n.jsx)(en.kr,{size:16,className:"animate-spin text-text-muted"}):(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors flex-shrink-0 ${r?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${r?"translate-x-4":"translate-x-0.5"}`})})]})}function dg({icon:e,label:t,children:s}){return(0,n.jsxs)("div",{className:"w-full px-3 py-2 rounded-brand flex items-center gap-2.5 text-sm text-text",children:[(0,n.jsx)(e,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:t}),s]})}function dv({icon:e,label:t,active:s,onClick:r}){return(0,n.jsxs)("button",{onClick:r,className:`px-3 py-3 rounded-brand flex items-center gap-2.5 text-sm border transition-colors ${s?"border-brand-500 bg-brand-500/10 text-brand-500":"border-border text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(e,{size:16}),(0,n.jsx)("span",{children:t})]})}function dy(){let e,t,{t:s,locale:l}=(0,ec.s)(),{formattedStars:a}=(0,sQ.w)(),i=cQ.dI.find(e=>e.code===l)||cQ.dI[0],o=eb(e=>e.isOpen),c=eb(e=>e.activePanel),d=eb(e=>e.context),x=eb(e=>e.callbacks),m=(0,u.d)(e=>e.carrier),p=eb(e=>e.close),f=eb(e=>e.setActivePanel);eb(e=>e.openMenu);let h=eG(e=>e.install),b=eG(e=>e.canInstall),g=eG(e=>e.isInstalled),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(!1),[C,S]=(0,r.useState)(!1),{theme:E,toggleTheme:R}=(0,n_.D)(),[T,$]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=()=>$(window.innerWidth>=eV.jK);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>(o?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[o]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o&&p()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[o,p]);let M=(0,r.useCallback)(()=>f("pwa"),[f]),z=(0,r.useCallback)(()=>{(0,eo.e)(),f("menu")},[f]),P=(0,r.useCallback)(()=>{p(),x.onRemote?.()},[p,x]),I=(0,r.useCallback)(()=>{p(),x.onFiles?.()},[p,x]),A=(0,r.useCallback)(()=>{b?(p(),h()):M()},[b,p,h,M]),L=(0,r.useCallback)(()=>{p(),setTimeout(()=>{x.onLogout?.()},50)},[p,x]),D=(0,r.useCallback)(e=>{x.onThemeChange?.(e)},[x]);(0,r.useCallback)(()=>{p(),y(!0)},[p]);let B=(0,r.useCallback)(()=>{y(!1)},[]);(0,r.useCallback)(()=>{p(),j(!0)},[p]);let F=(0,r.useCallback)(()=>{j(!1)},[]),K=(0,r.useCallback)(()=>{p(),S(!0)},[p]),O=(0,r.useCallback)(()=>{S(!1)},[]),W=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(da,{isOpen:v,onClose:B}),(0,n.jsx)(dc,{isOpen:w,onClose:F}),(0,n.jsx)(dx,{isOpen:C,onClose:O,busRef:d.busRef})]});return o?T?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(dp,{context:d,callbacks:x,canInstall:b,isInstalled:g,install:h,onClose:p}),W]}):(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:p}),(0,n.jsxs)("div",{className:"absolute top-0 right-0 bottom-0 w-[85vw] sm:w-96 max-w-md bg-surface border-l border-border shadow-2xl flex flex-col slide-in-right pt-[var(--safe-top)] pb-[var(--safe-bottom)]",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:["menu"!==c&&(0,n.jsx)("button",{onClick:z,className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors mr-1","aria-label":s("common.back"),children:(0,n.jsx)(en.JG,{size:20})}),(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("pwa"===c?"pwa.title":"menu.title")}),"menu"===c&&(t=(e=m||d.carrier)&&"ws"!==e,(0,n.jsx)("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider ${t?"bg-blue-500/15 text-blue-400 border border-blue-500/30":"bg-yellow-500/15 text-yellow-500 border border-yellow-500/30"}`,title:`Carrier: ${t?`WebRTC (${e})`:"WebSocket"}`,children:t?"RTC":"WS"}))]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:["menu"===c&&(0,n.jsxs)(n.Fragment,{children:[s0.l7&&(0,n.jsxs)("a",{href:s0.rl,target:"_blank",rel:"noopener noreferrer",className:"px-2 py-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex items-center gap-1.5 text-xs font-medium",title:"Star on GitHub","aria-label":"Star on GitHub",children:[(0,n.jsx)(en.Cp,{size:16}),(0,n.jsx)(en.FE,{size:13,className:"text-yellow-500 fill-yellow-500"}),a&&(0,n.jsx)("span",{className:"font-mono text-[11px] leading-none",children:a})]}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),R()},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("menu.theme"),title:s("menu.theme"),children:"dark"===E?(0,n.jsx)(en.bd,{size:18}):(0,n.jsx)(en.AX,{size:18})}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),N(!0)},className:"px-2 py-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex items-center gap-1.5 text-sm font-medium","aria-label":s("menu.language"),title:s("menu.language"),children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${i.country}.png`,alt:i.label,className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{className:"uppercase",children:i.code})]})]}),(0,n.jsx)("button",{onClick:p,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("common.close"),children:(0,n.jsx)(en.X,{size:20})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable",children:["menu"===c&&(0,n.jsx)(c7,{onRemote:d.remoteAvailable?P:null,onFiles:I,onInstallApp:A,canInstall:b,isInstalled:g,onLogout:L,connected:d.connected,remoteAvailable:d.remoteAvailable,showTheme:d.showTheme,theme:d.theme,onThemeChange:D,hideActions:d.hideActions||[],busRef:d.busRef,subscribeToPush:d.subscribeToPush,unsubscribeFromPush:d.unsubscribeFromPush,onOpenBackgroundPicker:K}),"pwa"===c&&(0,n.jsx)(ds,{})]})]}),(0,n.jsx)(da,{isOpen:v,onClose:B}),(0,n.jsx)(dc,{isOpen:w,onClose:F}),(0,n.jsx)(dx,{isOpen:C,onClose:O,busRef:d.busRef}),(0,n.jsx)(dd.A,{isOpen:k,onClose:()=>N(!1)})]}):W}var dw=s(61826),dj=s(31735);function dk({hydrated:e,apiKey:t}){return!function(e){let t=(0,l.usePathname)(),s=(0,l.useSearchParams)(),n=(0,l.useRouter)(),{viewStack:a,pushView:i,setViewStack:o}=(0,h.B)((0,D.k)(e=>({viewStack:e.viewStack,pushView:e.pushView,setViewStack:e.setViewStack}))),c=a[a.length-1],d=dw.yP.includes(c?.type)?a[a.length-2]:c,u=(0,r.useRef)(null),x=(0,r.useRef)(null),m=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!e)return;let n=(0,dw.mn)(t,s);if(!n)return;let r=(0,dw.O5)(n);if(r===u.current||(u.current=r,d&&(0,dw.O5)(d)===r))return;m.current="url";let l=(0,dw.dX)(a,n);l?o(l):i(n)},[e,t,s]),(0,r.useEffect)(()=>{if(!e||dw.yP.includes(c?.type))return;let r=(0,dw.O5)(c);if(r===u.current)return;let l=(0,dw.O5)((0,dw.mn)(t,s)),i="url"===m.current;i&&(m.current=null);let o=x.current?.type==="terminal"&&c?.type==="terminal",d=c?.type==="list"&&1===a.length;m.current="store",u.current=r,x.current=c,i||r===l||(o||d?n.replace(r):n.push(r))},[e,c,t,s])}(e),(0,dj.H$)(t),null}function dN({children:e}){let t,s,b,g,v,y,w,j,k,N,C,S,E,R,T,K,{t:O}=(0,ec.s)(),[W,_]=(0,r.useState)(!1);(0,r.useEffect)(()=>{!function(){if(eJ)return;eJ=!0;let e=eG.getState();(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),eG.getState().setDeferredPrompt(e)}),window.addEventListener("appinstalled",()=>{eG.getState().setDeferredPrompt(null),eG.getState().setIsInstalled(!0)}),window.matchMedia("(display-mode: standalone)").matches)?e.setIsInstalled(!0):navigator.getInstalledRelatedApps&&navigator.getInstalledRelatedApps().then(t=>{t?.length&&e.setIsInstalled(!0)}).catch(()=>{})}()},[]);let{viewStack:H,openedSessions:q,pushView:U,popView:V,setViewStack:X,addOpenedSession:G,removeOpenedSession:J,reorderOpenedSessions:Y,activeWorkspaceId:Z,setActiveWorkspaceId:Q,livePanes:ee,touchLivePane:et,mountedWorkspaces:en,markWorkspaceMounted:er,reset:el,cwdBySession:eo,sidebarCollapsed:eu,toggleSidebar:ex,sidebarWidth:eh,setSidebarWidth:eg,paneWidths:ev,setPaneWidth:ew,rightPanelOpen:eN,rightPanelTabs:eC,rightPanelWidth:eS,toggleRightPanel:eR,setRightPanelTab:eT,setRightPanelWidth:eM,editorFilePath:ez,editorPanelWidth:eA,setEditorPanelWidth:eL,openEditorFile:eD,closeEditorFile:eB,editorPreviewSeq:eF,mobileOpen:eK,mobileMode:eO,mobilePanelWidth:eW,setMobileOpen:e_,setMobileMode:eH,setMobilePanelWidth:eX,setMobileSession:eZ,artifactTitle:eQ,pushArtifact:e0,removeArtifact:e1}=(0,h.B)((0,D.k)(e=>({viewStack:e.viewStack,openedSessions:e.openedSessions,pushView:e.pushView,popView:e.popView,setViewStack:e.setViewStack,addOpenedSession:e.addOpenedSession,removeOpenedSession:e.removeOpenedSession,reorderOpenedSessions:e.reorderOpenedSessions,activeWorkspaceId:e.activeWorkspaceId,setActiveWorkspaceId:e.setActiveWorkspaceId,livePanes:e.livePanes,touchLivePane:e.touchLivePane,mountedWorkspaces:e.mountedWorkspaces,markWorkspaceMounted:e.markWorkspaceMounted,reset:e.reset,cwdBySession:e.cwdBySession,sidebarCollapsed:e.sidebarCollapsed,toggleSidebar:e.toggleSidebar,sidebarWidth:e.sidebarWidth,setSidebarWidth:e.setSidebarWidth,paneWidths:e.paneWidths,setPaneWidth:e.setPaneWidth,rightPanelOpen:e.rightPanelOpen,rightPanelTabs:e.rightPanelTabs,rightPanelWidth:e.rightPanelWidth,toggleRightPanel:e.toggleRightPanel,setRightPanelTab:e.setRightPanelTab,setRightPanelWidth:e.setRightPanelWidth,editorFilePath:e.editorFilePath,editorPanelWidth:e.editorPanelWidth,setEditorPanelWidth:e.setEditorPanelWidth,openEditorFile:e.openEditorFile,closeEditorFile:e.closeEditorFile,editorPreviewSeq:e.editorPreviewSeq,mobileOpen:e.mobileOpen,mobileMode:e.mobileMode,mobilePanelWidth:e.mobilePanelWidth,setMobileOpen:e.setMobileOpen,setMobileMode:e.setMobileMode,setMobilePanelWidth:e.setMobilePanelWidth,setMobileSession:e.setMobileSession,artifactTitle:e.artifactTitle,pushArtifact:e.pushArtifact,removeArtifact:e.removeArtifact}))),e2=(0,l.useRouter)(),{getAuth:e4,setAuth:e6,clearAuth:e8}=(0,a.Fo)(),[e9,e7]=(0,r.useState)(()=>e4()),ts=(0,u.d)(e=>e.authKey);(0,r.useEffect)(()=>{ts&&e7(e4())},[ts,e4]),(0,r.useEffect)(()=>{_(!0),!e9?.apiKey&&(0,x._r)()&&window.location.port===String(m._8)&&fetch(m.Go).then(e=>e.ok?e.json():null).then(e=>{if(e?.permanentKey){let t=e.permanentKey,s=(0,p.Uo)(t),n=(0,p.Cj)(t);(0,f.LG)(s,{tail:n});let r={apiKey:s,tunnelUrl:window.location.origin,mode:"local",tempKey:null,localIp:null};e6(r),e7(r)}}).catch(()=>{})},[e9,e6]),(0,r.useEffect)(()=>{if(!window.__TAURI__)return;let e=e=>{("F5"===e.key||(e.metaKey||e.ctrlKey)&&"r"===e.key.toLowerCase())&&(e.preventDefault(),window.location.reload())},t=e=>{let t=e.target?.tagName;"INPUT"===t||"TEXTAREA"===t||e.target?.isContentEditable||e.preventDefault()};return window.addEventListener("keydown",e),window.addEventListener("contextmenu",t),()=>{window.removeEventListener("keydown",e),window.removeEventListener("contextmenu",t)}},[]);let{bus:tr,busRef:ta,protocolRef:to,disconnect:tc,reconnect:td,connected:tu,connectionMode:tp,carrier:tg,remoteAvailable:tv,mobileAvailable:ty,platform:tw,agentVersion:tj,retryStatus:tk,approvalStatus:tN,admitted:tC,loadSessions:tS,createSession:tE,deleteSession:tR,renameSession:tT,createWorkspace:t$,renameWorkspace:tM,deleteWorkspace:tz,setWorkspaceHiddenRepos:tP,reorderSession:tI}=function(){let[e,t]=(0,r.useState)([]),[s,n]=(0,r.useState)([]),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(null),C=(0,u.d)(e=>e.approvalStatus),S=(0,u.d)(e=>e.admitted),{getAuth:E}=(0,a.Fo)(),R=(0,r.useCallback)(e=>{u.d.getState().applyApproval(e)},[]),T=(0,r.useCallback)(async()=>{let e=E();if(e?.tempKey)try{await fetch(`${m.O}/api/temp-key/remove`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({tempKey:e.tempKey})}),sessionStorage.removeItem("tempKey")}catch(e){console.error("Failed to remove temp key:",e)}},[E]),D=(0,r.useRef)(null),B=(0,r.useRef)({sessions:!1,workspaces:!1}),F=e=>{B.current[e]=!0},K=(0,r.useCallback)(e=>{(0,A.Lq)("switch",`lists untrusted (${e}) → refetch`),B.current={sessions:!1,workspaces:!1}},[]),O=(0,r.useCallback)(e=>{if(!Array.isArray(e))return;for(let t of(F("sessions"),e))t?.id&&t?.agent&&h.B.getState().setSessionAgent(t.id,t.agent);t(t=>(0,P.nk)(t,e)?t:e);let s=M.rh.getState();(0,P.nk)(s.hosts[s.currentKey]?.sessions,e)||L({sessions:e})},[]),W=(0,r.useCallback)(e=>{if(!Array.isArray(e))return;F("workspaces"),n(t=>(0,P.nk)(t,e)?t:e);let t=M.rh.getState();(0,P.nk)(t.hosts[t.currentKey]?.workspaces,e)||L({workspaces:e})},[]),_=(0,r.useRef)(0),H=(0,r.useRef)(0),q=(0,r.useRef)(null),U=(0,r.useRef)(0),V=(0,r.useCallback)(e=>{let t=++_.current;e.emit("getSessions",e=>{(0,A.Lq)("diag",`getSessions ack seq=${t} type=${Array.isArray(e)?"list":typeof e} n=${Array.isArray(e)?e.length:"-"}`),t===_.current&&O(e)})},[O]),X=(0,r.useCallback)(e=>{let t=++H.current;e.emit("getWorkspaces",e=>{t===H.current&&W(e)})},[W]),G=(0,r.useCallback)((e,t=!1)=>{if(e){if(t)clearTimeout(q.current);else if(q.current)return;else if(Date.now()-U.current<1e3)return;q.current=setTimeout(()=>{q.current=null,U.current=Date.now(),(0,A.Lq)("diag",`fetchLists FIRE (bus=${e?"ok":"null"} connected-already=${B.current.sessions}/${B.current.workspaces})`),X(e),V(e)},120)}},[V,X]),J={fragOut:!0,binOut:!0,hb:1,env2:1,fragCtl:1},Y=e=>{(0,A.Lq)("switch",`caps → ${JSON.stringify(J)} announced`),e.emit("caps",J)},Z=(0,r.useRef)(null),{bus:Q,busRef:ee,protocolRef:et,connected:es,connectionMode:en,carrier:er,retryStatus:el,disconnect:ea,reconnect:ei}=function(e={}){let{namespace:t="",socketOptions:s={},redirectOnNoAuth:n="/",onConnect:h,onDisconnect:b,onApproval:g}=e,v=(0,l.useRouter)(),{getAuth:y,setAuth:w}=(0,a.Fo)(),j=function(){let[e]=(0,r.useState)(()=>{let e=localStorage.getItem(i);return e||(e=globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,localStorage.setItem(i,e)),e});return e}(),k=(0,r.useRef)(null),N=(0,r.useRef)(null),[C,S]=(0,r.useState)(!1),[E,R]=(0,r.useState)("tunnel"),[T,$]=(0,r.useState)("ws"),[M,z]=(0,r.useState)({isRetrying:!1,attempt:0,maxAttempts:10,failed:!1}),P=(0,u.d)(e=>e.authKey),I=(0,r.useRef)(!1),[A,L]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e=!1,r=null;return(async()=>{let l=y();if((0,x._r)()&&window.location.port===String(m._8)&&!P&&l?.tunnelUrl!==window.location.origin)try{let e=await fetch(m.Go),t=e.ok?await e.json():null;if(e.ok&&t?.permanentKey){let e=t.permanentKey,s=(0,p.Uo)(e),n=(0,p.Cj)(e);(0,f.LG)(s,{tail:n}),l={apiKey:s,tunnelUrl:window.location.origin,mode:"local",tempKey:null,localIp:t.localIp||null},w(l)}}catch{}if(e)return;if(!l?.apiKey){u.d.getState().reset(),v.push(n);return}try{if("1"===sessionStorage.getItem("9remote_manual_disconnect"))return void u.d.getState().setConnection({deliberate:!0})}catch{}let a={tunnelUrl:l.tunnelUrl,localIp:l.localIp||null,namespace:t,socketOptions:{...s,auth:{apiKey:l.apiKey,tempKey:l.tempKey??null,deviceId:j,...s.auth}},apiKey:l.apiKey,deviceId:j,tempKey:l.tempKey??null,onConnect:(t,s)=>{if(e)return;I.current=!0,k.current=t,u.d.getState().setConnection({deliberate:!1,everConnected:!0});let n=s||N.current?.connectionMode||"tunnel";S(!0),R(n),u.d.getState().setConnection({bus:t,connected:!0,connectionMode:n,endpoint:l.tunnelUrl}),(0,d.c)("transport","[transport] ws connected"),h?.(t,l)},onDisconnect:t=>{e||((0,d.c)("transport",`[transport] ws disconnect reason=${t}`),k.current=null,S(!1),u.d.getState().setConnection({connected:!1}),b?.(t))},onApproval:g,onRetryStatus:t=>{e||(z(t),u.d.getState().setRetryStatus(t))}},i=l.tunnelUrl===window.location.origin,C=c.eR.enableWebRTC&&!i?{enableWebRTC:!0,enableTurn:c.eR.enableTurn,apiKey:l.apiKey,onUpgrade:e=>(0,d.c)("transport",`[transport] upgraded to ${e}`),onFallback:e=>(0,d.c)("transport",`[transport] fallback to ${e}`),onTransportChange:t=>{e||($(t),u.d.getState().setCarrier(t),(0,d.c)("transport",`[transport] active=${t}`))}}:null;N.current=r=new o.g(a,C),k.current=r.busRef.current,u.d.getState().setConnection({bus:k.current,busRef:k,protocolRef:N,deliberate:!1,...I.current?{}:{connected:!1,admitted:!1},connectionMode:"tunnel",carrier:"ws"}),r.connect()})(),()=>{e=!0,r?.disconnect(),N.current=null,k.current=null}},[P,A]),{bus:k.current,busRef:k,protocolRef:N,connected:C,connectionMode:E,carrier:T,retryStatus:M,disconnect:()=>{N.current?.disconnect(),N.current=null,k.current=null,S(!1),u.d.getState().reset(),u.d.getState().setConnection({deliberate:!0});try{sessionStorage.setItem("9remote_manual_disconnect","1")}catch{}},reconnect:()=>{try{sessionStorage.removeItem("9remote_manual_disconnect")}catch{}L(e=>e+1)}}}({namespace:"",redirectOnNoAuth:"/",onConnect:(0,r.useCallback)((e,s)=>{(R(z.J2.reconnect),L({status:"full"}),K("pm-connect"),Z.current===e)?G(e):(Z.current=e,e.on("device:pendingApproval",()=>{(0,A.Lq)("diag","EVENT device:pendingApproval arrived"),(0,d.c)("auth","[auth] agent says: waiting for host approval"),R(z.J2.pending)}),e.on("device:approved",()=>{(0,A.Lq)("diag","EVENT device:approved arrived → applying"),R(z.J2.approved),u.d.getState().setAdmitted(!0),(0,f.I8)(),T()}),e.on("terminal:ready",()=>{(0,d.c)("auth","[auth] terminal:ready (NOT an admission signal)"),G(e)}),e.on("connect",()=>{K("carrier-connect"),e.emit("device:clientReady"),Y(e),G(e)}),e.on("device:rejected",()=>{(0,A.Lq)("diag","EVENT device:rejected arrived → applying"),R(z.J2.rejected),D.current?.()}),e.on("device:tailRejected",e=>{if(e?.reason===z.ML.sealUnreadable)return;D.current?.();let t=E();(0,f.cH)(t?.apiKey),(0,f.cH)(t?.tempKey),sessionStorage.clear(),sessionStorage.setItem(z.Jd,e?.reason||z.ML.mismatch),window.location.replace("/login")}),e.on("serverInfo",e=>{let t=M.rh.getState(),s=!!t.hosts[t.currentKey]?.updating;if(L({platform:e.platform||null,version:e.version||null,isCodespaces:!!e.isCodespaces,updateAvailable:!s&&(0,I.U)(e.updateAvailable?.version,e.version)?e.updateAvailable:null,canSelfUpdate:!!e.canSelfUpdate,remoteAvailable:!!e.remoteAvailable,mobileAvailable:!!e.mobileAvailable}),g(e.remoteAvailable),y(!!e.mobileAvailable),j(e.platform),N(e.version||null),h.B.getState().setAgentCaps(e.caps||{}),h.B.getState().setArtifactEnabled(e.artifactEnabled),h.B.getState().setMcpClients(e.mcpClients),e.voiceConfig)$.getState().syncFromAgent(e.voiceConfig);else{let e=$.getState();(e.geminiKeys.some(e=>e.trim())||e.openrouterKey||e.customKey||e.customEndpoint)&&e.pushToAgent()}}),e.on("sessionClosed",e=>{t(t=>t.filter(t=>t.id!==e));let s=M.rh.getState(),n=s.hosts[s.currentKey]?.sessions;n?.some(t=>t.id===e)&&L({sessions:n.filter(t=>t.id!==e)}),h.B.getState().closeSession(e)}),e.on("session-renamed",({sessionId:e,name:s}={})=>{if(!e)return;t(t=>t.map(t=>t.id===e?{...t,name:s}:t));let n=M.rh.getState(),r=n.hosts[n.currentKey]?.sessions;r?.some(t=>t.id===e)&&L({sessions:r.map(t=>t.id===e?{...t,name:s}:t)})}),e.on("sessionAgentChanged",({sessionId:e,agent:t}={})=>{e&&t&&(h.B.getState().setSessionAgent(e,t),h.B.getState().invalidateAgentHistory())}),e.on("sessionsChanged",()=>G(e,!0)),e.on("workspacesChanged",()=>G(e)),Y(e),u.d.getState().setConnection({approvalStatus:null}),e.emit("device:clientReady"))},[T,G,R,E,K]),onApproval:R});(0,r.useEffect)(()=>{D.current=ea},[ea]);let eo=(0,r.useCallback)(()=>G(ee.current),[ee,G]),ec=(0,r.useCallback)(()=>G(ee.current,!0),[ee,G]);(0,r.useEffect)(()=>()=>{q.current&&(clearTimeout(q.current),q.current=null)},[]),(0,r.useEffect)(()=>{if(!es)return;let e=setInterval(()=>{B.current.sessions&&B.current.workspaces||eo()},2e3);return()=>clearInterval(e)},[es,eo]),(0,r.useEffect)(()=>{if(!es)return;let e=()=>{"visible"===document.visibilityState&&eo()};return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[es,eo]);let ed=(0,r.useCallback)((e,n,r,l,a,i=!1,o=null,c=null)=>{if(!ee.current)return;"function"==typeof n?(a=n,n=null,r=null,l=null):"function"==typeof r?(a=r,r=null,l=null):"function"==typeof l&&(a=l,l=null);let d="string"==typeof o?o:o?.id||null;ee.current.emit("createSession",{name:e,shellId:n,workspaceId:r,cwd:l,nameIsAuto:i,agent:d,replaces:c},i=>{if(i?.success){if(i.sessionId){d&&h.B.getState().setSessionAgent(i.sessionId,d);let a=s.find(e=>e.id===r)?.path||null,o={id:i.sessionId,name:i.name||e||"Terminal",createdAt:Date.now(),cwd:i.cwd||l||null,workspaceId:r||null,groupId:r||null,workspacePath:a,shellId:i.shellId||n||null,shellLabel:i.shellLabel||null,agent:d||null},c=e=>[...e.filter(e=>e.id!==i.sessionId&&e.id!==i.replaced),o];t(c);let u=M.rh.getState(),x=u.hosts[u.currentKey]?.sessions;x&&L({sessions:c(x)})}ec()}a?.(i)})},[ee,ec,s]),eu=(0,r.useCallback)((e,t,s)=>{"function"==typeof t&&(s=t,t=null),ee.current?.emit("createWorkspace",{name:e,path:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),ex=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("renameWorkspace",{workspaceId:e,name:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),em=(0,r.useCallback)((e,t)=>{ee.current?.emit("deleteWorkspace",{workspaceId:e},e=>{e?.success&&ec(),t?.(e)})},[ee,ec]),ep=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("setWorkspaceHiddenRepos",{workspaceId:e,paths:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),ef=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("moveSession",{sessionId:e,workspaceId:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),eh=(0,r.useCallback)((e,t)=>{ee.current?.emit("reorderSession",{orderedIds:e},e=>{e?.success&&ec(),t?.(e)})},[ee,ec]),eb=(0,r.useCallback)(e=>{ee.current&&ee.current.emit("getShells",t=>e?.(t))},[ee]),eg=(0,r.useCallback)((e,t)=>{ee.current&&ee.current.emit("deleteSession",e,e=>{e.success&&ec(),t?.(e)})},[ee,ec]),ev=(0,r.useCallback)((e,t,s)=>{ee.current&&ee.current.emit("renameSession",{sessionId:e,name:t},e=>{e.success&&ec(),s?.(e)})},[ee,ec]);return{bus:Q,busRef:ee,protocolRef:et,disconnect:ea,reconnect:ei,connected:es,connectionMode:en,carrier:er,retryStatus:el,approvalStatus:C,admitted:S,sessions:e,remoteAvailable:b,mobileAvailable:v,platform:w,agentVersion:k,workspaces:s,loadSessions:eo,createSession:ed,getShells:eb,deleteSession:eg,renameSession:ev,createWorkspace:eu,renameWorkspace:ex,deleteWorkspace:em,setWorkspaceHiddenRepos:ep,moveSession:ef,reorderSession:eh}}(),{loadKeys:tA,saveKey:tL,renameKey:tD,removeKey:tB}=(0,nY.u)(),[tF,tK]=(0,r.useState)([]);(0,r.useEffect)(()=>{W&&tK(tA())},[W,tA]),(0,r.useEffect)(()=>{if(!W)return;let e=()=>tK(tA());return window.addEventListener(nY.N,e),()=>window.removeEventListener(nY.N,e)},[W,tA]);let tO=e9?.apiKey?(0,p.Uo)(e9.apiKey):"",tW=ej(tO||null);(0,r.useEffect)(()=>{if(W){if(!tO)return void M.rh.getState().closeAll();M.rh.getState().sync(tF,tO)}},[W,tF,tO]);let t_=(0,M.rh)(e=>e.hosts),tH=t_[tO],tq=(0,r.useMemo)(()=>tH?.sessions||[],[tH]),tU=(0,r.useMemo)(()=>tH?.workspaces||[],[tH]),tV=(0,r.useMemo)(()=>(function(e,t){let s={sessions:[],workspaces:[]};if(!t)return s;for(let n of e){if(n.key===t)continue;let e=`${n.key}:`,r=`${e}_`,l=(n.sessions||[]).some(e=>null==e.workspaceId);for(let t of n.workspaces||[])s.workspaces.push({...t,id:e+t.id,hostKey:n.key});for(let t of(l&&s.workspaces.push({id:r,name:n.label||n.key,hostKey:n.key}),n.sessions||[]))s.sessions.push({...t,workspaceId:null!=t.workspaceId?e+t.workspaceId:r,hostKey:n.key})}return s})(Object.values(t_),tO),[t_,tO]),tX=(0,r.useMemo)(()=>[...tq,...tV.sessions],[tq,tV]),tG=(0,r.useMemo)(()=>[...tU,...tV.workspaces],[tU,tV]),tJ=(0,r.useCallback)((e,t)=>{let s=tA().find(t=>(0,p.Uo)(t.key)===e);s?tD(s.id,t):tL(e,t)},[tA,tD,tL]),[tY,tZ]=(0,r.useState)([]),tQ=function(){let[e,t]=(0,r.useState)(!1),s=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let e=()=>{"visible"===document.visibilityState&&(t(!0),clearTimeout(s.current),s.current=setTimeout(()=>t(!1),4e3))};return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e),clearTimeout(s.current)}},[]),e}(),t0=(0,u.d)(e=>e.bus),t1=(0,u.d)(e=>e.deliberate),t2=(0,u.d)(e=>e.everConnected),t5=!!tH?.updating,t3=(0,r.useRef)({armed:!1,version:null,dropped:!1});(0,r.useEffect)(()=>{if(!tH||!tO)return;let e=t3.current;if(!tH.updating){e.armed=!1,e.dropped=!1;return}if(e.armed||(e.armed=!0,e.version=tH.version||null),tu||(e.dropped=!0),e.dropped&&tu){let t=setTimeout(()=>{let t=M.rh.getState().hosts[tO];t?.version&&e.version&&t.version!==e.version?window.location.reload():M.rh.getState()._patchHost(tO,{updating:!1})},1500);return()=>clearTimeout(t)}},[tH,t5,tu,tO]);let[t4,t6]=(0,r.useState)({isOpen:!1,title:"",message:"",onConfirm:null,confirmText:null});(0,r.useEffect)(()=>{tu&&("win32"===tw?tZ([{id:"cmd",label:"Command Prompt"},{id:"powershell",label:"PowerShell"}]):tZ([]))},[tu,tw]);let t8=es();t=(0,M.rh)(e=>`${e.currentKey}|`+Object.values(e.hosts).filter(e=>"online"===e.status||"full"===e.status).map(e=>e.key).join(",")),(0,r.useEffect)(()=>{let e=M.rh.getState(),s=t.slice(t.indexOf("|")+1),n=[];for(let t of s.split(",").filter(Boolean)){let s=eE(t===e.currentKey?null:t).bus;if(!s)continue;let r=({count:e})=>M.rh.getState()._patchHost(t,{mobileDeviceCount:Number(e)||0});s.on("mobile:devicesChanged",r),s.emit("mobile:deviceCount",{},e=>{e&&"number"==typeof e.count&&r(e)}),n.push(()=>s.off("mobile:devicesChanged",r))}return()=>{for(let e of n)e()}},[t]);let{subscribeToPush:t9,unsubscribeFromPush:t7,notifications:se}=(s=(0,r.useRef)(null),b=ey(e=>e.notifications),(0,h.B)(e=>e.getSelectedSession),(0,h.B)(e=>e.getCurrentView),g=(0,h.B)(e=>e.pushView),v=(0,h.B)(e=>e.addOpenedSession),y=!!window.ReactNativeWebView,w=(0,M.rh)(e=>Object.values(e.hosts).filter(e=>"online"===e.status).map(e=>e.key).join(",")),j=(0,r.useCallback)(e=>{for(let t of(ta?.current&&e(ta.current),Object.values(M.rh.getState().hosts))){if("online"!==t.status)continue;let s=(0,M.eJ)(t.key);s&&e(s)}},[ta]),(0,r.useEffect)(()=>(window.handleNotificationTap=e=>{let t=e?.sessionId;t&&(v(t),g({type:"terminal",sessionId:t}))},()=>{try{delete window.handleNotificationTap}catch(e){window.handleNotificationTap=void 0}}),[g,v]),(0,r.useEffect)(()=>{if(y)return window.handleAppStateChange=e=>{j(t=>t.emit("visibilityChange",!!e))},()=>{try{delete window.handleAppStateChange}catch(e){window.handleAppStateChange=void 0}}},[ta,y,j]),k=(0,r.useCallback)(async()=>{if(ta?.current){if(localStorage.removeItem(eI),y){window.handleExpoPushToken=e=>{j(t=>t.emit("pushSubscribe",{type:"expo",token:e})),s.current={type:"expo",token:e}},window.ReactNativeWebView.postMessage(JSON.stringify({type:"REQUEST_PUSH_TOKEN"}));return}if(!("serviceWorker"in navigator)||!("PushManager"in window))return void console.warn("\uD83D\uDD15 Push not supported");try{let e=await Notification.requestPermission();if("granted"!==e)return;let t=await navigator.serviceWorker.ready;if(!t.pushManager)return;let n=await new Promise(e=>ta.current.emit("getVapidKey",e));if(!n)return;let r=await t.pushManager.getSubscription();r||(r=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n})),j(e=>{e.emit("pushSubscribe",r.toJSON()),e.emit("visibilityChange",document.hidden)}),s.current=r}catch(e){console.error("Push notification setup failed:",e)}}},[ta,y]),(0,r.useEffect)(()=>{let e=ta?.current;if(e&&tu&&"1"!==localStorage.getItem(eI)){if(y){window.handleExpoPushToken=t=>{e.emit("pushSubscribe",{type:"expo",token:t}),s.current={type:"expo",token:t}},window.ReactNativeWebView.postMessage(JSON.stringify({type:"REQUEST_PUSH_TOKEN"}));return}(async()=>{try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return;let t=await navigator.serviceWorker.ready;if(!t.pushManager)return;let s=await t.pushManager.getSubscription();if(!s&&"granted"===Notification.permission){let n=await new Promise(t=>e.emit("getVapidKey",t));n&&(s=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n}))}s&&(e.emit("pushSubscribe",s.toJSON()),e.emit("visibilityChange",document.hidden))}catch(e){}})()}},[ta,tu,y]),(0,r.useEffect)(()=>{s.current&&"1"!==localStorage.getItem(eI)&&j(e=>{let t;return e.emit("pushSubscribe",(t=s.current,t?.type==="expo"?{type:"expo",token:t.token}:t?.toJSON?.()||t))})},[w,j]),(0,r.useEffect)(()=>{let e=ta?.current;if(!e||!tu)return;let t=()=>{e.emit("getStatusState"),e.emit("getNotificationState")},s=()=>M.rh.getState().currentKey,n=e=>M.rh.getState().applyStatusState(s(),e),r=e=>{if(ey.getState().handleStatusChange(e),M.rh.getState().applyStatusChange(s(),e),e&&("done"===e.state||"blocked"===e.state)){let t="done"===e.state,s=e.tool?e.tool.charAt(0).toUpperCase()+e.tool.slice(1):"Terminal",n=t?`${s} \xb7 your turn`:`${s} needs input`;window.__9R_DESKTOP__?.showNotification&&window.__9R_DESKTOP__.showNotification(n,t?"The agent finished its turn and is waiting for you":"Action required to proceed")}},l=e=>M.rh.getState().applyStatusCleared(s(),e),a=e=>ey.getState().handleNotificationState(e),i=()=>t(),o=()=>{e.emit("visibilityChange",document.hidden)},c=()=>t();return e.on("notificationState",a),e.on("notificationCleared",i),e.on("statusState",n),e.on("statusChange",r),e.on("statusCleared",l),e.on("connect",c),document.addEventListener("visibilitychange",o),t(),()=>{e.off("notificationState",a),e.off("notificationCleared",i),e.off("statusState",n),e.off("statusChange",r),e.off("statusCleared",l),e.off("connect",c),document.removeEventListener("visibilitychange",o)}},[ta,tu]),N=e$(),C=(0,r.useMemo)(()=>eP(N).total,[N]),(0,r.useEffect)(()=>{window.__9R_DESKTOP__?.setBadge&&window.__9R_DESKTOP__.setBadge(C),"u">typeof navigator&&"setAppBadge"in navigator&&(C>0?navigator.setAppBadge(C).catch(()=>{}):navigator.clearAppBadge().catch(()=>{}))},[C]),{subscribeToPush:k,unsubscribeFromPush:(0,r.useCallback)(async()=>{localStorage.setItem(eI,"1");try{if(s.current?.type==="expo"){j(e=>e.emit("pushUnsubscribe",s.current.token)),s.current=null;return}if(s.current)await s.current.unsubscribe(),j(e=>e.emit("pushUnsubscribe",s.current.endpoint)),s.current=null;else{let e=await navigator.serviceWorker.ready,t=await e.pushManager.getSubscription();t&&(j(e=>e.emit("pushUnsubscribe",t.endpoint)),await t.unsubscribe())}}catch(e){console.error("Push unsubscribe failed:",e)}},[ta,j]),notifications:b}),st=B(e=>e.setKeyboardOpen),[ss,sn]=(0,r.useState)(()=>window.innerWidth>=eV.jK),sr=(S=(0,r.useRef)(null),(0,r.useCallback)(({enabled:e,sessionIds:t,activeSessionId:s,onSwitch:n})=>({onTouchStart:t=>{if(!e||1!==t.touches.length||function(e,t=e=>"function"==typeof getComputedStyle?getComputedStyle(e).overflowX:""){for(let s=e;s&&1===s.nodeType;s=s.parentElement){let e=t(s);if(("auto"===e||"scroll"===e)&&s.scrollWidth>s.clientWidth)return!0}return!1}(t.target))return S.current=null;let s=t.touches[0];S.current={x:s.clientX,y:s.clientY,time:performance.now()}},onTouchEnd:r=>{let l=S.current;if(S.current=null,!l||!e||t.length<2)return;let a=r.changedTouches[0],i=a.clientX-l.x,o=a.clientY-l.y;if(performance.now()-l.time>eV.bl.maxDuration||Math.abs(i)<eV.bl.minDistance||Math.abs(i)<Math.abs(o)*eV.bl.ratio)return;let c=t.indexOf(s);if(-1===c)return;let d=i<0?t[c+1]:t[c-1];d&&d!==s&&n?.(d)}}),[]));(0,r.useEffect)(()=>{let e=0,t=()=>{clearTimeout(e),e=setTimeout(()=>sn(window.innerWidth>=eV.jK),50)};return window.addEventListener("resize",t),()=>{clearTimeout(e),window.removeEventListener("resize",t)}},[]);let sl=H[H.length-1]||{type:"list"},sa=sl?.type==="terminal"||ss&&sl?.type==="list",si=sl?.type==="terminal"?sl.sessionId:sa&&q[q.length-1]||null,so=function({isDesktop:e,isTerminalView:t,activeSessionId:s,currentView:n,openedSessions:l}){let a=(0,r.useRef)({}),i=(0,r.useRef)({}),o=(0,r.useRef)(null),c=(0,r.useRef)(null),d=(0,r.useRef)(!1),u=(0,r.useRef)(null),x=(0,r.useCallback)((t,s)=>{s?(a.current[t]=s,u.current===t&&e&&!d.current&&(u.current=null,setTimeout(()=>s.focus?.(),50))):delete a.current[t]},[e]),m=(0,r.useCallback)((e,t)=>{t?i.current[e]=t:delete i.current[e]},[]),p=(0,r.useCallback)(t=>{c.current=t,t&&u.current&&e&&d.current&&(u.current=null,setTimeout(()=>t.focus?.(),50))},[e]),f=(0,r.useCallback)(t=>{e&&(u.current=t,setTimeout(()=>{u.current===t&&(u.current=null,d.current&&c.current?.focus?c.current.focus():a.current[t]?.focus?.())},60))},[e]),b=(0,r.useCallback)(()=>{c.current?.openTextPanel?.()},[]),g=(0,r.useCallback)(e=>{d.current=e},[]),v=(0,r.useCallback)(e=>a.current[e]?.focus?.(),[]),y=(0,r.useCallback)(()=>{c.current?.focus?.()},[]),w=(0,r.useCallback)(e=>{d.current?a.current[e]?.focus?.():c.current?.focus?.()},[]),j=(0,r.useRef)(0),k=(0,r.useCallback)(t=>{if(!e)return;if(h.B.getState().fullMode){o.current&&(o.current.scrollLeft=0);return}cancelAnimationFrame(j.current),j.current=0;let s=o.current,n=(0,eY.g4)({container:s,pane:i.current[t]});if(null==n){j.current=requestAnimationFrame(()=>{j.current=0;let e=(0,eY.g4)({container:s,pane:i.current[t]});null!=e&&s.scrollTo({left:e,behavior:"smooth"})});return}s.scrollTo({left:n,behavior:"smooth"})},[e]),N=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!e||n?.type!=="terminal"||!n?.sessionId||N.current===n.sessionId)return;N.current=n.sessionId;let t=requestAnimationFrame(()=>k(n.sessionId));return()=>cancelAnimationFrame(t)},[n?.type,n?.sessionId,e,k]),(0,r.useEffect)(()=>{if(!e||!t||!s)return;let n=setTimeout(()=>{d.current?c.current?.focus?.():a.current[s]?.focus?.()},60);return()=>clearTimeout(n)},[s,e,t]),(0,r.useMemo)(()=>({panesContainerRef:o,registerPaneApi:x,registerPaneElement:m,registerKeyboardTextApi:p,handlePasteFallback:b,handleInputFocusChange:g,focusPane:v,focusKeyboardInput:y,toggleInputFocus:w,scrollPaneIntoView:k,requestFocus:f}),[x,m,p,b,g,v,y,w,k,f])}({isDesktop:ss,isTerminalView:sa,activeSessionId:si,currentView:sl,openedSessions:q}),sc=function({sessions:e,currentView:t,viewStack:s,setViewStack:n,pushView:l,storePopView:a,activeWorkspaceId:i,setActiveWorkspaceId:o,activeSessionId:c,addOpenedSession:d,removeOpenedSession:u,touchLivePane:x,createSession:m,deleteSession:p,renameSession:f,busRef:b,isDesktop:g=!1,requestFocus:v=null}){let{t:y}=(0,ec.s)(),w=(0,r.useCallback)(e=>{let t=[...s];t[t.length-1]={type:"terminal",sessionId:e},n(t)},[s,n]),j=(0,r.useCallback)(t=>e.filter(e=>(0,eY.xs)(e)===(t??null)).map(e=>e.id),[e]),k=(0,r.useCallback)(e=>alert(y("workspace.failedCreateSession",{error:e})),[y]),N=(0,r.useCallback)((s,n)=>{let r=e.find(e=>e.id===s);if(!r&&void 0===n)return;let a=r?(0,eY.xs)(r):n;o(a);let i=j(a);i.forEach(e=>d(e)),d(s),x([...i,s]),"terminal"===t.type?w(s):l({type:"terminal",sessionId:s}),r||v?.(s)},[e,j,d,x,o,t,l,w,v]);(0,r.useEffect)(()=>{let t=e=>{if(e.data?.type!=="NOTIFICATION_CLICK")return;let t=new URLSearchParams(new URL(e.data.url||"",location.origin).search).get("t");t&&N(t)},s=()=>{let t=Object.values(ey.getState().notifications||{});if(!t.length)return;let s=t=>{let s=e.find(e=>e.id===t);return s&&(0,eY.xs)(s)===(i??null)},n=t.sort((e,t)=>{let n=s(e.sessionId),r=s(t.sessionId);return n&&!r?-1:!n&&r?1:"blocked"===e.type&&"blocked"!==t.type?-1:"blocked"===t.type&&"blocked"!==e.type?1:(t.timestamp||0)-(e.timestamp||0)})[0];n?.sessionId&&N(n.sessionId)};return window.addEventListener("message",t),window.addEventListener("9remote:dock-click",s),()=>{window.removeEventListener("message",t),window.removeEventListener("9remote:dock-click",s)}},[N,e,i]),(0,r.useEffect)(()=>{let e=e=>{e.detail?.sessionId&&N(e.detail.sessionId)};return window.addEventListener(eV.vP,e),()=>window.removeEventListener(eV.vP,e)},[N]);let C=(0,r.useCallback)(e=>{let t=j(i);if(t.length<2)return;let s=t.indexOf(c);if(-1===s)return;let n="prev"===e?(s-1+t.length)%t.length:(s+1)%t.length;N(t[n])},[j,i,c,N]),S=(0,r.useCallback)(e=>{let t=j(i);e<0||e>=t.length||N(t[e])},[j,i,N]),E=(0,r.useCallback)((e,s=null,n=null,r=null,a=null,i=!1,c=!1)=>{m(e,n,s,r||null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let n=e5(a,i);n&&h.B.getState().queueStartup(e.sessionId,n),a?.id&&h.B.getState().setSessionAgent(e.sessionId,a.id);let r=s??null;o(r);let c=j(r);c.forEach(e=>d(e)),d(e.sessionId),x([...c,e.sessionId]),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},c,a)},[m,j,d,x,k,t,w,l,o,v]),R=(0,r.useCallback)(e=>{if(!e?.resume)return;let s="ui"===e.mode,n=M.rh.getState().currentKey||"main",r=h.B.getState().agentClisBy[n]?.list?.find(t=>t.id===e.agent)||null,a=s?null:e3(r,e.resume);m(null,null,i,e.cwd||null,n=>{if(!n?.success)return k(n?.error);if(!n.sessionId)return;a&&h.B.getState().queueStartup(n.sessionId,a);let r=s?`${e.agent}-ui`:e.agent;r&&h.B.getState().setSessionAgent(n.sessionId,r),b?.current?.emit("claimAgentSession",{sessionId:n.sessionId,agent:r,conversationId:e.sessionId},()=>h.B.getState().invalidateAgentHistory()),d(n.sessionId),x(n.sessionId),"terminal"===t.type?w(n.sessionId):l({type:"terminal",sessionId:n.sessionId}),v?.(n.sessionId)})},[m,i,d,x,k,w,l,t,v,b]),T=(0,r.useCallback)((e,s=null,n=!1,r=null,a=!1)=>{m(r,e,i,null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let r=e5(s,n);r&&h.B.getState().queueStartup(e.sessionId,r),s?.id&&h.B.getState().setSessionAgent(e.sessionId,s.id),d(e.sessionId),x(e.sessionId),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},a,s)},[m,i,d,x,k,w,l,t,v]),$=(0,r.useCallback)((s,n,r=null,a=!1)=>{m(n,null,i,e.find(e=>e.id===s)?.cwd||null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let n=e.replaced||s;r?.id&&h.B.getState().setSessionAgent(e.sessionId,r.id),n?h.B.getState().replaceOpenedSession(n,e.sessionId):d(e.sessionId),x(e.sessionId),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},a,r,s)},[m,i,k,d,x,w,l,t,v,e]),z=(0,r.useCallback)(e=>{m(null,t=>{if(!t.success)return k(t.error);t.sessionId&&(d(t.sessionId),e?.(t.sessionId))})},[m,d,k]),P=(0,r.useCallback)(t=>{o(t);let s=e.filter(e=>(0,eY.xs)(e)===(t??null));s.forEach(e=>d(e.id)),x(s.map(e=>e.id));let n=s[0];n&&w(n.id)},[e,o,d,x,w]),I=(0,r.useCallback)(s=>{let n=e.find(e=>e.id===s),r=(0,eY.xs)(n),l=t?.type==="terminal"&&t.sessionId===s,i=()=>{if(u(s),h.B.getState().closeSession(s),!l)return;let t=e.filter(e=>e.id!==s),n=t.filter(e=>(0,eY.xs)(e)===r)[0]||t[0];n?(w(n.id),x(n.id)):a()},o=n?.hostKey?M.rh.getState().hosts[n.hostKey]:null;if(o){tt(o).deleteSession(s),i();return}p(s,i)},[e,t,p,u,x,a,w]),A=(0,r.useCallback)((t,s)=>{let n=e.find(e=>e.id===t)?.hostKey;if(n){let e=M.rh.getState().hosts[n];e&&tt(e).renameSession(t,s);return}f(t,s,e=>{e.success||alert(y("workspace.failedRenameSession",{error:e.error}))})},[e,f,y]);return(0,r.useMemo)(()=>({handleSelectSession:N,handleSelectWorkspace:P,handleCreateSession:E,handleQuickCreateSession:T,handleReplaceSession:$,handleResumeAgentSession:R,handleCreateSessionInline:z,handleDeleteSession:I,handleRenameSession:A,switchSession:C,switchToIndex:S}),[N,P,E,T,$,R,z,I,A,C,S])}({sessions:tX,currentView:sl,viewStack:H,setViewStack:X,pushView:U,storePopView:V,activeWorkspaceId:Z,setActiveWorkspaceId:Q,activeSessionId:si,addOpenedSession:G,removeOpenedSession:J,touchLivePane:et,createSession:tE,deleteSession:tR,renameSession:tT,busRef:ta,requestFocus:so.requestFocus}),{systemInfo:sd,mobileEditor:su,setMobileEditor:sx,openFileRef:sm,handleOpenWorkspaceList:sp,handleOpenFiles:sf,handleSelectWorkspace:sh,handleBrowseFolder:sb,handlePathChange:sg,handleOpenFile:sv,handleOpenGit:sy,handleSetWorkspace:sw}=function({pushView:e,viewStack:t,setViewStack:s,currentView:n,cwdBySession:l,sessions:a=[],isDesktop:i,fileBus:o,scope:c=""}){let[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),p=(0,r.useRef)(null),f=(0,r.useCallback)(async()=>{if(!d){let e=await o.getSystemInfo();e.success&&u(e)}e({type:"workspaces"})},[e,o,d]),h=(0,r.useCallback)(async t=>{if(t){ep(t,c),e({type:"files",workspace:t,currentPath:t});return}if("terminal"===n.type){let t=n.sessionId&&(l[n.sessionId]||a.find(e=>e.id===n.sessionId)?.cwd)||null;if(t){ep(t,c),e({type:"files",workspace:t,currentPath:t});return}}let s=em(c);if(s.length>0){let t=s[0];e({type:"files",workspace:t.path,currentPath:t.lastPath||t.path});return}f()},[e,f,n,l,a,c]),b=(0,r.useCallback)(e=>{ep(e,c),s([...t.filter(e=>"workspaces"!==e.type&&"files"!==e.type),{type:"files",workspace:e}])},[t,s]),g=(0,r.useCallback)(t=>{e({type:"browse",path:t})},[e]),v=(0,r.useCallback)((e,t)=>{!function(e,t,s=""){let n=(0,F.kb)(e),r=em(s),l=r.findIndex(e=>e.path===n);-1!==l&&(r[l]={...r[l],lastPath:(0,F.kb)(t)},localStorage.setItem(ed(s),JSON.stringify(r)))}(e,t,c)},[]),y=(0,r.useCallback)((e,t,s={})=>{i?p.current?.(e,s):m({path:e,line:s.line,column:s.column,workspace:n.workspace})},[i,n.workspace]);return{systemInfo:d,mobileEditor:x,setMobileEditor:m,openFileRef:p,handleOpenWorkspaceList:f,handleOpenFiles:h,handleSelectWorkspace:b,handleBrowseFolder:g,handlePathChange:v,handleOpenFile:y,handleOpenGit:(0,r.useCallback)(()=>{let s=t.find(e=>"files"===e.type);s?.workspace&&e({type:"git",workspace:s.workspace})},[e,t]),handleSetWorkspace:(0,r.useCallback)(e=>{ep(e,c),s([...t.filter(e=>"browse"!==e.type&&"workspaces"!==e.type&&"files"!==e.type),{type:"files",workspace:e}])},[t,s])}}({pushView:U,viewStack:H,setViewStack:X,currentView:sl,cwdBySession:eo,sessions:tq,isDesktop:ss,fileBus:t8,scope:tW}),[sj,sk]=(0,r.useState)(null),sN=eb(e=>e.open),sC=(0,r.useMemo)(()=>W?em(tW):[],[W,tU,tW]),sS=(0,r.useCallback)(e=>{sk(null),e&&t$(e.split("/").filter(Boolean).pop()||e,e,t=>{let s=t?.workspace||t?.group;t?.success&&s?.id&&(ep(e,tW),Q(s.id),sc.handleCreateSession(null,s.id,null,e))})},[t$,Q,sc]),sE=(0,r.useCallback)(e=>{if(e)return sS(e);sk({initialPath:null})},[sS]),sR=(0,r.useCallback)((e,t,s,n,r,l,a)=>{let i=tG.find(e=>e.id===t)?.hostKey||Object.values(t_).find(e=>"string"==typeof t&&t.startsWith(`${e.key}:`))?.key;if(i){let o=M.rh.getState().hosts[i];if(!o)return;tt(o,{onSelectSession:sc.handleSelectSession}).createSession(e,ek(t,i),s,n,r,l,a);return}sc.handleCreateSession(e,t,s,n,r,l,a)},[tG,t_,sc]),sT=(0,r.useCallback)(e=>{let t=tX.find(e=>e.id===si)?.hostKey||tG.find(e=>e.id===Z)?.hostKey;if(!t||!e?.resume)return;let s=M.rh.getState().hosts[t];if(!s)return;let n="ui"===e.mode,r=h.B.getState().agentClisBy[t]?.list?.find(t=>t.id===e.agent)||null,l=n?null:e3(r,e.resume),a=n?`${e.agent}-ui`:e.agent,i=ek(Z,t);tt(s,{onSelectSession:sc.handleSelectSession}).createSession(null,i&&"_"!==i?i:null,null,e.cwd||null,null,!1,!1,s=>{s?.success&&s.sessionId&&(l&&h.B.getState().queueStartup(s.sessionId,l),a&&h.B.getState().setSessionAgent(s.sessionId,a),(0,M.Nw)(t,t=>t.emit("claimAgentSession",{sessionId:s.sessionId,agent:a,conversationId:e.sessionId},()=>h.B.getState().invalidateAgentHistory())))})},[tX,tG,si,Z,sc]),s$=(0,r.useCallback)(e=>{sR(null,Z,null,e)},[sR,Z]),sM=tG.find(e=>e.id===Z)?.hostKey||null,sz=sM||tO||"main",sP=th(eE(sM).busRef,sz),sI=tf(e=>e.open),sA=tf(e=>e.isOpen),sL=tf(e=>e.close),[sB,sF]=(0,r.useState)(!1),sK=tU.find(e=>e.id===Z)?.path||tq.find(e=>e.id===si)?.workspacePath||null,sO=(0,r.useCallback)(()=>{let{agentId:e,shellId:t,yolo:s}=te(),n=(sP||[]).flatMap(e=>{let t=tb.H8.find(t=>t.aiEngine===e.id);return t?[e,t]:e}),r=e&&n.find(t=>t.id===e)||null,l=tX.filter(e=>(0,eY.xs)(e)===(Z??null)).length+1;sR(r?`${r.short||r.label} ${l}`:null,Z,r?null:t,null,r,s,!0)},[sP,tX,Z,sR]),sW=(0,r.useCallback)(e=>{let t=tU.map(e=>e.id);if(tq.some(e=>null===(0,eY.xs)(e))&&t.push(null),t.length<2)return;let s=t.indexOf(Z??null),n=-1===s?0:s,r="prev"===e?(n-1+t.length)%t.length:(n+1)%t.length;sc.handleSelectWorkspace(t[r])},[tU,tq,Z,sc]);!function(e,t=!0){let s=(0,r.useRef)(e);(0,r.useEffect)(()=>{s.current=e}),(0,r.useEffect)(()=>{if(!t)return;let e=e=>{if(document.querySelector('[role="dialog"], [aria-modal="true"], .modal-overlay'))return;let t=function(e){let t=ti();if(t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){let t=tl.exec(e.code)||(/^[1-9]$/.test(e.key)?[null,e.key]:null);return t?{id:tn.id,index:Number(t[1])-1}:"ArrowLeft"===e.key?{id:"sessionPrev"}:"ArrowRight"===e.key?{id:"sessionNext"}:"ArrowUp"===e.key?{id:"workspacePrev"}:"ArrowDown"===e.key?{id:"workspaceNext"}:tx(e.target)?null:"Backquote"===e.code||"`"===e.key?{id:"toggleFocus"}:"Equal"===e.code||"="===e.key||"≠"===e.key||"+"===e.key?{id:"fitPanes"}:"KeyW"===e.code||"∑"===e.key||e.key?.toLowerCase()==="w"?{id:"closeTerminal"}:null}if(t&&e.altKey&&e.shiftKey&&!e.ctrlKey&&!e.metaKey){if(tx(e.target))return null;let t=tm(e.target);return"Enter"===e.key||"Enter"===e.code?{id:"newTerminal"}:t?null:"KeyP"===e.code||"π"===e.key||"∏"===e.key||e.key?.toLowerCase()==="p"?{id:"palette"}:"KeyB"===e.code||"ı"===e.key||"∫"===e.key||e.key?.toLowerCase()==="b"?{id:"toggleSidebar"}:"KeyJ"===e.code||"\xd4"===e.key||"∆"===e.key||e.key?.toLowerCase()==="j"?{id:"toggleRightPanel"}:"Slash"===e.code||"?"===e.key||"\xbf"===e.key||"/"===e.key?{id:"help"}:null}if(e.ctrlKey&&!e.shiftKey&&!e.metaKey&&!e.altKey&&("Backquote"===e.code||"`"===e.key)&&!tx(e.target))return{id:"toggleFocus"};if(!t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){if(tx(e.target))return null;if("Equal"===e.code||"="===e.key||"+"===e.key)return{id:"fitPanes"};if("KeyW"===e.code||e.key?.toLowerCase()==="w")return{id:"closeTerminal"}}if(!t&&e.ctrlKey&&e.shiftKey&&!e.altKey&&!e.metaKey){let t=tl.exec(e.code);if(t)return{id:tn.id,index:Number(t[1])-1};if("ArrowLeft"===e.key)return{id:"sessionPrev"};if("ArrowRight"===e.key)return{id:"sessionNext"};if("ArrowUp"===e.key)return{id:"workspacePrev"};if("ArrowDown"===e.key)return{id:"workspaceNext"};if("Equal"===e.code||"="===e.key||"+"===e.key)return{id:"fitPanes"};let s=tm(e.target);if("Enter"===e.key||"Enter"===e.code)return{id:"newTerminal"};if(s)return null;if("KeyP"===e.code||e.key?.toLowerCase()==="p")return{id:"palette"};if("KeyB"===e.code||e.key?.toLowerCase()==="b")return{id:"toggleSidebar"};if("KeyJ"===e.code||e.key?.toLowerCase()==="j")return{id:"toggleRightPanel"};if("Slash"===e.code||"/"===e.key||"?"===e.key)return{id:"help"}}return null}(e);if(!t)return;let n=s.current?.[t.id];n&&(e.preventDefault(),e.stopPropagation(),n(t.index))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[t])}({sessionPrev:()=>sc.switchSession("prev"),sessionNext:()=>sc.switchSession("next"),workspacePrev:()=>sW("prev"),workspaceNext:()=>sW("next"),sessionIndex:e=>sc.switchToIndex(e),closeTerminal:(0,r.useCallback)(()=>{if(sl?.type!=="terminal"||!sl.sessionId)return;let e=tq.find(e=>e.id===sl.sessionId);e&&t6({isOpen:!0,title:O("sessions.deleteTitle"),message:O("sessions.deleteMessage",{name:e.name||O("terminal.defaultName")}),confirmText:O("common.delete"),onConfirm:()=>sc.handleDeleteSession(e.id)})},[sl,tq,sc,O]),toggleFocus:()=>so.toggleInputFocus(si),fitPanes:()=>window.dispatchEvent(new CustomEvent("terminal:fitPanes")),newTerminal:sO,toggleSidebar:ex,toggleRightPanel:eR,palette:()=>{sK&&sF(!0)},help:sI},ss&&sa);let s_=(0,r.useCallback)(e=>{let t=tU.find(e=>e.id===Z)?.path||tq.find(e=>e.id===sl.sessionId)?.workspacePath||null;eB(),U({type:"editor",path:e,workspace:t})},[tU,Z,tq,sl,U,eB]),sH=(0,r.useCallback)((e,t={})=>{if((0,F.pA)(e)){let{status:t,repoPath:s,filePath:n}=(0,F.qu)(e);sx({path:s?`${s}/${n}`:n,workspace:s||void 0,diffStatus:t});return}sx({path:e,workspace:tU.find(e=>e.id===Z)?.path,preview:!!t.preview,artifactSessionId:t.artifactSessionId||null})},[tU,Z,sx]),sq=(0,r.useCallback)((e,t)=>{if(!t?.path)return;let s=t.title||t.path.split("/").pop();ss?eD(t.path,{preview:!0,artifactTitle:s,artifactSessionId:e}):sH(t.path,{preview:!0,artifactSessionId:e})},[ss,eD,sH]);(0,r.useEffect)(()=>{let e=ta.current;if(!e)return;let t=({path:e,title:t,sessionId:s}={})=>{if(!e)return;let n={path:e,title:t||e.split("/").pop(),at:Date.now()};s&&e0(s,n),s&&s!==si||sq(s,n)};return e.on("artifactOpen",t),()=>e.off("artifactOpen",t)},[ta,tu,si,e0,sq]),(0,r.useEffect)(()=>{sa&&void 0!==Z&&er(Z)},[sa,Z,er]);let sU=si?tX.find(e=>e.id===si):null,sV=sU?sU.name||O("terminal.defaultName"):null;(0,r.useEffect)(()=>(eq(Object.keys(se).length,sV),()=>eq(0)),[se,sV]);let[sX,sG]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if("terminal"!==sl.type)return sG(!1);let e=requestAnimationFrame(()=>sG(!0));return()=>cancelAnimationFrame(e)},[sl.type]);let sJ=(0,r.useRef)(null),[sY,sZ]=(0,r.useState)("");(0,r.useEffect)(()=>{let e="terminal"===sl.type?sl.sessionId:null,t=sJ.current;if(sJ.current=e,!sX||!e||!t||e===t)return sZ("");sZ(q.indexOf(e)>q.indexOf(t)?"term-slide-right":"term-slide-left")},[sl,sX,q]);let sQ=(0,r.useCallback)(()=>{if(!ss&&su){su.artifactSessionId&&e1(su.artifactSessionId,su.path),sx(null);return}let e=Array.isArray(H)?H:[],t=e.length>1?e[e.length-2]:{type:"list"};V(),e2.replace((0,dw.O5)(t))},[e2,V,ss,su,sx,e1,H]),s0=(0,r.useCallback)(()=>{if("terminal"!==sl.type)return sQ();X([{type:"list"}])},[sl,sQ,X]);(0,r.useEffect)(()=>{tr&&tS()},[tr,tS]),(0,r.useEffect)(()=>{if(0===tX.length||0===q.length)return;let e=setTimeout(()=>{let e=tX.map(e=>e.id);q.filter(t=>!e.includes(t)).forEach(e=>J(e))},500);return()=>clearTimeout(e)},[tX,q,J]),function({setKeyboardOpen:e}){(0,r.useEffect)(()=>{let t=!1,s=()=>{let s=window.visualViewport,n=s?.height||window.innerHeight,r=s?.offsetTop||0,l=n<window.innerHeight-100;t!==l&&(t=l,e(l)),document.documentElement.style.setProperty("--app-height",`${n}px`),!l&&r>0?document.documentElement.style.transform=`translateY(${-r}px)`:document.documentElement.style.transform="",window.scrollTo(0,0)};document.documentElement.classList.add("terminal-page");let n=0,r=()=>{clearTimeout(n),n=setTimeout(s,100)};return window.visualViewport&&(window.visualViewport.addEventListener("resize",r),window.visualViewport.addEventListener("scroll",r)),window.addEventListener("resize",r),r(),()=>{clearTimeout(n),document.documentElement.classList.remove("terminal-page"),document.documentElement.style.transform="",window.visualViewport&&(window.visualViewport.removeEventListener("resize",r),window.visualViewport.removeEventListener("scroll",r)),window.removeEventListener("resize",r)}},[e]),(0,r.useEffect)(()=>{let e=e=>{e.target.closest(".xterm-viewport,.xterm-screen,.terminal-scroll,.cm-scroller,.cm-content,.overflow-auto,.overflow-x-auto,.overflow-y-auto,.modal-scrollable,.brand-range")||e.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>document.removeEventListener("touchmove",e)},[]),(0,r.useEffect)(()=>{let e=e=>{e.target.matches("input, textarea")&&requestAnimationFrame(()=>window.scrollTo(0,0))};return document.addEventListener("focusin",e),()=>document.removeEventListener("focusin",e)},[])}({setKeyboardOpen:st});let[s1,s2]=(0,r.useState)(null),[s5,s3]=(0,r.useState)(null),s4=eE(s1||tO||null),s6=eE(s5||tO||null),s8=t_[s1||tO],s9=t_[s5||tO],s7=e=>e?.status==="online"||e?.status==="full",ne=(0,r.useCallback)((e=null)=>{s2(e),U({type:"remote"})},[U]),nt=(0,r.useCallback)((e=null)=>{if(!ss){s3(e),U({type:"mobile"});return}if(!eK){s3(e),e_(!0);return}s6.busRef.current?.emit("mobile:stop"),eZ(null),e_(!1),s3(null)},[ss,eK,e_,eZ,s6,U]),ns=(0,r.useCallback)(e=>{eU(e,{startWidth:eW,axis:-1,onWidth:eX})},[eW,eX]),nn=(0,r.useCallback)(()=>{to.current?.retryNow()},[to]),nr=(0,r.useCallback)(()=>{M.rh.getState().closeAll(),el(),e8(),sessionStorage.setItem("9remote_manual_disconnect","1"),window.location.replace("/login")},[el,e8]),nl=(0,r.useCallback)(()=>{t6({isOpen:!0,title:O("workspace.logoutTitle"),message:O("workspace.logoutMessage"),onConfirm:nr})},[nr,O]),na=(0,r.useCallback)(e=>{let t=tA().find(t=>(0,p.Uo)(t.key)===e);t&&tB(t.id),e===tO&&nr()},[tA,tB,tO,nr]),ni=(0,r.useCallback)(()=>{M.rh.getState().disconnectHost(tO),tc()},[tO,tc]),no=(0,r.useCallback)(()=>{M.rh.getState()._patchHost(tO,{status:"connecting"}),td()},[tO,td]),nc=(0,r.useCallback)(()=>{t6({isOpen:!1,title:"",message:"",onConfirm:null})},[]),nd=(0,r.useCallback)(e=>{Y(e),tI(e)},[Y,tI]),nu=(0,r.useCallback)(e=>{Z&&ew(Z,e)},[Z,ew]),nx=(0,r.useMemo)(()=>({open:eN,tabs:eC,width:eS,onTabChange:eT,onResize:eM,onToggle:eR,onNewTerminal:s$}),[eN,eC,eS,eT,eM,eR,s$]),nm=(0,r.useMemo)(()=>({filePath:ez,previewSeq:eF,artifactTitle:eQ,width:eA,onResize:eL,onOpen:ss?eD:sH,onClose:eB,onOpenFull:s_}),[ez,eF,eQ,eA,eL,ss,eD,sH,eB,s_]),np=(0,r.useMemo)(()=>({open:eK,mode:eO,width:eW,busRef:s6.busRef,protocolRef:s6.pmRef,connected:s5?s7(s9):tu,onResizeStart:ns}),[eK,eO,eW,s6,s5,s9,tu,ns]);if(!W||!t0&&!t1)return(0,n.jsx)(o$,{label:O("workspace.loading")});let nf=tu&&tv?ne:null,nh=tu&&ty?nt:null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(oM.A,{}),(0,n.jsx)(r.Suspense,{fallback:null,children:(0,n.jsx)(dk,{hydrated:W,apiKey:e9?.apiKey})}),(0,n.jsxs)("div",{className:"terminal-container h-[var(--app-height,100vh)] fixed inset-0 overflow-hidden overscroll-none",children:[!ss&&(0,n.jsx)("div",{className:`absolute inset-0 transition-opacity duration-150 ease-out ${"list"===sl.type?"opacity-100 z-10":"opacity-0 z-0 pointer-events-none"}`,children:(0,n.jsx)(oz,{sessions:tq,cwdBySession:eo,connected:tu,onSelect:sc.handleSelectSession,onCreate:sc.handleCreateSession,onDelete:sc.handleDeleteSession,onRename:sc.handleRenameSession,onResumeAgentSession:sc.handleResumeAgentSession,onLogout:nl,onOpenRemote:nf,onOpenRemoteHost:ne,tunnelUrl:e9?.tunnelUrl,apiKey:e9?.apiKey,connectionMode:tp,isActive:"list"===sl.type,busRef:ta,subscribeToPush:t9,unsubscribeFromPush:t7,agentVersion:tj,carrier:tg,workspaces:tU,onAddWorkspace:sE,homeDir:sd?.homedir,onRenameWorkspace:tM,onDeleteWorkspace:tz,onReorderSession:nd,recentWorkspaces:sC,shells:tY,onRenameHost:tJ,onDeleteHost:na,onMainDisconnect:ni,onMainReconnect:no})}),(ss||q.length>0)&&(0,n.jsx)(oR,{platform:tw,agentVersion:tj,sessions:tX,workspaces:tG,onCreateAnyHost:sR,onQuickCreateHostAware:sO,onResumeAgentSessionForeign:sT,activeSessionId:si,activeSession:sU,activeWorkspaceId:Z,openedSessions:q,livePanes:ee,mountedWorkspaces:en,cwdBySession:eo,isDesktop:ss,isTerminalView:sa,slideClass:sY,shells:tY,sidebarCollapsed:eu,sidebarWidth:eh,setSidebarWidth:eg,paneWidth:Z?ev[Z]??null:null,setPaneWidth:Z?nu:void 0,toggleSidebar:ex,paneRegistry:so,bindSwipeTab:sr,nav:sc,onBack:s0,atStackBottom:ss&&"list"===sl.type,onOpenRemote:nf,onOpenMobile:nh,onOpenRemoteHost:ne,onOpenMobileHost:nt,onOpenFiles:sf,onLogout:nl,onDeleteWorkspace:tz,onReorderSession:tI,onAddWorkspace:sE,onSetHiddenRepos:tP,onOpenSettings:sN,onRenameHost:tJ,onDeleteHost:na,onMainDisconnect:ni,onMainReconnect:no,homeDir:sd?.homedir,recentWorkspaces:sC,onOpenArtifact:sq,rightPanel:nx,editorPanel:nm,mobilePanel:np,fileBus:t8,tunnelUrl:e9?.tunnelUrl,apiKey:e9?.apiKey,connectionMode:tp,subscribeToPush:t9,unsubscribeFromPush:t7}),sj&&(0,n.jsx)(sD,{fileBus:t8,scope:tW,initialPath:sj.initialPath,onSelect:sS,onClose:()=>sk(null)}),"remote"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(o7,{onClose:()=>{s2(null),sQ()},busRef:s4.busRef,protocolRef:s4.pmRef,connected:s1?s7(s8):tu,carrier:s1?s8?.carrier||"ws":tg,hostPlatform:s8?.platform||tw})}),"mobile"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(rA,{onClose:()=>{s3(null),sQ()},busRef:s6.busRef,protocolRef:s6.pmRef,connected:s5?s7(s9):tu})}),"site"===sl.type&&(0,n.jsx)(ch,{busRef:sl.hostKey?eE(sl.hostKey).busRef:ta,connected:sl.hostKey?s7(t_[sl.hostKey]):tu,initialPort:sl.port,initialPath:sl.path,onBack:V}),"workspaces"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(ef,{onSelect:sh,onBrowse:sb,onBack:sQ,isCodespaces:!!tH?.isCodespaces,systemInfo:sd})}),"browse"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cg,{scope:tW,workspace:sl.path,fileBus:t8,onBack:sQ,onSetWorkspace:sw,isBrowsing:!0})}),ss&&("files"===sl.type||"editor"===sl.type||"git"===sl.type)&&(E="files"===sl.type?sl:[...H].reverse().find(e=>"files"===e.type),R=E?.workspace||sl.workspace,T=em(tW).find(e=>e.path===R),K="editor"===sl.type?sl.path:null,(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cq,{workspace:R,fileBus:t8,onBack:sQ,onSwitchWorkspace:sp,initialOpenedFiles:K?[K]:T?.openedFiles||[],initialActiveFile:K||T?.activeFile||null,onOpenedFilesChange:(e,t)=>(function(e,t,s,n=""){let r=(0,F.kb)(e),l=em(n),a=l.findIndex(e=>e.path===r),i=Array.isArray(t)?t.map(e=>e&&"object"==typeof e?{...e,path:(0,F.kb)(e.path)}:e):t,o="string"==typeof s?(0,F.kb)(s):s;if(-1===a){l.unshift({path:r,lastOpened:Date.now(),openedFiles:i,activeFile:o}),localStorage.setItem(ed(n),JSON.stringify(l));return}l[a]={...l[a],openedFiles:i,activeFile:o??null},localStorage.setItem(ed(n),JSON.stringify(l))})(R,e,t,tW),bus:tr,connected:tu,sessions:tq,onCreateTerminalSession:sc.handleCreateSessionInline,onDeleteTerminalSession:sc.handleDeleteSession,onRenameTerminalSession:sc.handleRenameSession,viewType:sl.type,openFileRef:sm},R)})),!ss&&"files"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cg,{scope:tW,workspace:sl.workspace,initialPath:sl.currentPath,fileBus:t8,onBack:sQ,onOpenFile:sv,onOpenGit:sy,onSwitchWorkspace:sp,onPathChange:e=>sg(sl.workspace,e),hideSwitchWorkspace:sl.fromTerminal})}),!ss&&"git"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-30 transition-all duration-300 ease-out",children:(0,n.jsx)(cN,{workspace:sl.workspace,fileBus:t8,onBack:sQ,onOpenFile:sv})}),!ss&&su&&(0,n.jsx)("div",{className:"absolute inset-0 z-40 transition-all duration-300 ease-out",children:(0,n.jsx)(cj,{filePath:su.path,line:su.line,column:su.column,diffStatus:su.diffStatus,preview:su.preview,fileBus:t8,onBack:()=>{su.artifactSessionId&&e1(su.artifactSessionId,su.path),sx(null)},workspace:su.workspace||sl.workspace})}),(!tu||!tC)&&!t5&&!t1&&(0,n.jsx)(o$,{}),!t5&&(0,n.jsx)(cV,{retryStatus:tk,approvalStatus:tN,connected:tu,suppress:tQ,firstConnect:!t2,onLogout:nr,onRetryNow:nn}),(0,n.jsx)(dy,{}),sB&&sK&&(0,n.jsx)(c_,{mode:"files",workspace:sK,fileBus:t8,onClose:()=>sF(!1),onOpenFile:e=>eD(e)}),(0,n.jsx)(cU,{isOpen:sA,onClose:sL}),(0,n.jsx)(ei.A,{isOpen:t4.isOpen,onClose:nc,onConfirm:t4.onConfirm,title:t4.title,message:t4.message,confirmText:t4.confirmText})]}),(0,n.jsx)("div",{hidden:!0,children:(0,n.jsx)(r.Suspense,{fallback:null,children:e})}),(0,n.jsx)(ea,{})]})}}},e=>{e.O(0,[476,6189,6391,6669,8669,3348,4136,9958,5788,6552,2347,5158,7358],()=>e(e.s=36416)),_N_E=e.O()}]);
14
+ `;return await e.writeFile(r,d)}let lp="application/x-file-paths",lf=()=>"u">typeof document&&"webkitdirectory"in document.createElement("input"),lh=e=>{let t=e.dataTransfer.getData(lp);if(!t)return null;try{return JSON.parse(t)}catch{return null}},lb=e=>[...e.dataTransfer?.types||[]].includes("Files");function lg({workspace:e,fileBus:t,onOpenFile:s,activeFile:l,onSwitchWorkspace:a,onNewTerminal:i,onSearchFolder:o,compact:c=!1,onlyChanged:d=!1,onActions:u}){let{t:x}=(0,ec.s)(),[m,p]=(0,r.useState)(null),f=(0,r.useRef)(null),h=sq(f,m?.x??0,m?.y??0),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(""),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(""),[C,S]=(0,r.useState)(null),[E,R]=(0,r.useState)(null),[T,$]=(0,r.useState)(()=>new Set),M=(0,r.useRef)(T);(0,r.useEffect)(()=>{M.current=T},[T]);let z=(0,r.useRef)(v);(0,r.useEffect)(()=>{z.current=v},[v]);let P=(0,r.useRef)(b);(0,r.useEffect)(()=>{P.current=b},[b]);let[I,A]=(0,r.useState)(null),[L,D]=(0,r.useState)(!1),[B,K]=(0,r.useState)(null),[O,W]=(0,r.useState)(null),[_,H]=(0,r.useState)(null),[q,U]=(0,r.useState)(null),V=(0,r.useRef)(null),X=(0,r.useRef)(null),G=(0,r.useRef)(null),J=(0,r.useRef)(null),[Y]=(0,r.useState)(lf),Z=(0,r.useRef)(null),Q=(0,r.useRef)(null),ee=(0,r.useRef)(null),et=(0,r.useCallback)(t=>t&&e?t.replace(`${e}/`,""):t,[e]),{tree:es,expanded:er,loading:el,truncatedDirs:ea,gitStatusMap:ed,showHidden:eu,setShowHidden:ex,loadDir:em,loadGitStatus:ep,toggleFolder:ef,expandDir:eh,collapseAll:eb,refreshAll:eg}=function({workspace:e,fileBus:t}){let[s,n]=(0,r.useState)(()=>new Map),[l,a]=(0,r.useState)(()=>new Set),[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(()=>new Set),[u,x]=(0,r.useState)(()=>new Set),[m,p]=(0,r.useState)({}),[f,h]=(0,r.useState)(rX),b=(0,r.useCallback)(async e=>{d(t=>{let s=new Set(t);return s.add(e),s});let s=await t.getFiles(e,f);return(d(t=>{let s=new Set(t);return s.delete(e),s}),s?.success)?(n(t=>{let n=new Map(t);return n.set(e,s.files||[]),n}),x(t=>{let n=!!s.truncated;if(n===t.has(e))return t;let r=new Set(t);return n?r.add(e):r.delete(e),r}),s.files||[]):[]},[t,f]),g=(0,r.useRef)(0),v=(0,r.useCallback)(async()=>{if(!e)return;let s=++g.current,{map:n}=await rU(t,e);s===g.current&&p(n)},[t,e]);(0,r.useEffect)(()=>{if(!e)return;let t=!0;return(async()=>{let s,n,r=Array.isArray(n=(s=rV())[e])?n:Array.isArray(s.legacy)?s.legacy:[],l=new Set([e]),i=r.filter(t=>"string"==typeof t&&t.startsWith(e));for(let e of i)l.add(e);await Promise.all([b(e),...i.map(e=>b(e))]),t&&(a(l),o(e),v())})(),()=>{t=!1}},[e]),(0,r.useEffect)(()=>{let e=null,t=()=>{clearTimeout(e),e=setTimeout(v,300)},s=["fileExplorer:fileSaved","fileExplorer:fileCreated","fileExplorer:fileDeleted","fileExplorer:fileRenamed",F.GW];return s.forEach(e=>window.addEventListener(e,t)),()=>{clearTimeout(e),s.forEach(e=>window.removeEventListener(e,t))}},[v]),(0,r.useEffect)(()=>{if(i===e&&e)try{let t=rV();delete t.legacy,t[e]=[...l],window.localStorage.setItem(F.d5.expandedFolders,JSON.stringify(t))}catch{}},[e,i,l]),(0,r.useEffect)(()=>{window.localStorage.setItem(F.d5.showHidden,JSON.stringify(f)),s.size>0&&Promise.all([...s.keys()].map(e=>b(e))).catch(()=>{})},[f]);let y=(0,r.useCallback)(async e=>{(0,eo.e)();let t=e.path;l.has(t)?a(e=>{let s=new Set(e);return s.delete(t),s}):(s.has(t)||await b(t),a(e=>{let s=new Set(e);return s.add(t),s}))},[l,s,b]),w=(0,r.useCallback)(e=>{a(t=>{let s=new Set(t);return s.add(e),s})},[]),j=(0,r.useCallback)(()=>{(0,eo.e)(),a(new Set)},[]),k=rH(),N=(0,r.useMemo)(()=>[...s.keys()].filter(t=>t===e||l.has(t)),[s,l,e]),C=(0,r.useCallback)(e=>{Promise.all(e.map(e=>b(e))).catch(()=>{}),v()},[b,v]);r_({dirs:N,fileBus:t,onDirsChanged:C,enabled:k});let S=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=k&&!S.current;S.current=k,e&&s.size&&C([...s.keys()])},[k]);let E=(0,r.useCallback)(async()=>{(0,eo.e)();let e=[...s.keys()];await Promise.all(e.map(e=>b(e))),v()},[s,b,v]);return{tree:s,expanded:l,loading:c,truncatedDirs:u,gitStatusMap:m,showHidden:f,setShowHidden:h,loadDir:b,loadGitStatus:v,toggleFolder:y,expandDir:w,collapseAll:j,refreshAll:E}}({workspace:e,fileBus:t}),{createItem:ev,renameItem:ey,deleteItem:ew,deleteMany:ej,duplicateItem:ek,moveTo:eN,pasteInto:eC}=function({fileBus:e,loadDir:t,loadGitStatus:s,expandDir:n,onOpenFile:l,onMoved:a}){let i=(0,r.useCallback)(async(s,r,a)=>{let i=rK(s,r),o=await e.createItem(i,a);o?.success&&(rJ("created"),await t(s),"folder"===a?n(s):l?.(i))},[e,t,n,l]),o=(0,r.useCallback)(async(s,n)=>{let r=rO(s.path),l=rK(r,n),a=await e.renameItem(s.path,l);a?.success&&(rJ("renamed"),await t(r))},[e,t]),c=(0,r.useCallback)(async s=>{let n=rO(s.path),r=await e.deleteItem(s.path);r?.success&&(rJ("deleted"),await t(n))},[e,t]),d=(0,r.useCallback)(async n=>{if(!n?.length)return;let r=new Set;for(let t of n){let s=await e.deleteItem(t.path);s?.success&&r.add(rO(t.path))}if(r.size){for(let e of(rJ("deleted"),r))await t(e);s(),a?.()}},[e,t,s,a]),u=(0,r.useCallback)(async(t,s)=>{let n=rW(t),r=new Set(((await e.getFiles(s,!0))?.files||[]).map(e=>e.name)),l=n;if(r.has(l)){let e=n.lastIndexOf("."),t=e>0?n.slice(0,e):n,s=e>0?n.slice(e):"";l=`${t} copy${s}`;for(let e=2;r.has(l);e++)l=`${t} copy ${e}${s}`}return e.copyItem(t,rK(s,l))},[e]),x=(0,r.useCallback)(async e=>{let n=rO(e.path),r=await u(e.path,n);r?.success&&(rJ("created"),await t(n),s())},[u,t,s]),m=(0,r.useCallback)(async(n,r)=>{if(n?.length&&r){for(let t of n){let s=rK(r,t.split("/").pop());t===s||s.startsWith(t+"/")||await e.renameItem(t,s)}for(let e of new Set([r,...n.map(e=>rO(e))]))await t(e);rJ("renamed"),s(),a?.()}},[e,t,s,a]),p=(0,r.useCallback)(async(e,r,l)=>{if(!e?.length||!r)return;if("cut"===l)return m(e,r);let a=0;for(let t of e){if(r===t||r.startsWith(t+"/"))continue;let e=await u(t,r);e?.success&&a++}a&&(rJ("created"),await t(r),n(r),s())},[u,m,t,n,s]);return{createItem:i,renameItem:o,deleteItem:c,deleteMany:d,duplicateItem:x,moveTo:m,pasteInto:p}}({fileBus:t,loadDir:em,loadGitStatus:ep,expandDir:eh,onOpenFile:s,onMoved:()=>$(new Set)});(0,r.useEffect)(()=>{if(!m)return;let e=()=>p(null);return window.addEventListener("click",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("click",e),window.removeEventListener("scroll",e,!0)}},[m]),(0,r.useEffect)(()=>{if(b&&Q.current){Q.current.focus();let e=Q.current.value.length;Q.current.setSelectionRange(e,e)}},[b]),(0,r.useEffect)(()=>{w&&ee.current&&ee.current.focus()},[w]);let eS=(0,r.useCallback)(()=>E&&es.has(E)?E:e,[E,es,e]),eE=(0,r.useCallback)(async e=>{let t=k.trim();if(!t)return;let s=w?.dir||eS();await ev(s,t,e),j(null),N("")},[k,w,eS,ev]),eR=(0,r.useCallback)(async()=>{let e=P.current;if(!e)return;let t=z.current.trim();t&&t!==e.name&&await ey(e,t),g(null)},[ey]),eT=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),e$=(0,r.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),(0,eo.e)(),$(e=>e.has(t.path)?e:new Set([t.path])),U(t.path),p({file:t,x:e.clientX,y:e.clientY})},[]),eM=(0,r.useCallback)((e,t)=>{let s=e.touches?.[0];if(!s)return;let n=s.clientX,r=s.clientY;Z.current=setTimeout(()=>{(0,eo.e)(),p({file:t,x:n,y:r})},500)},[]),ez=(0,r.useCallback)(()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)},[]),eP=(0,r.useMemo)(()=>{if(!l)return null;if(!(0,F.pA)(l))return l;let{repoPath:t,filePath:s}=(0,F.qu)(l);return s?`${t||e}/${s}`:null},[l,e]),eI=e=>!d||!!ed[et(e.path)],eA=(0,r.useMemo)(()=>{let t=[],s=(e,n)=>{for(let r of es.get(e)||[])(!d||ed[et(r.path)])&&(t.push({file:r,depth:n}),"folder"===r.type&&er.has(r.path)&&s(r.path,n+1))};return s(e,0),t},[es,er,ed,d,e,et]),eL=(0,r.useCallback)(e=>eA.find(t=>t.file.path===e)?.file||null,[eA]),eD=(0,r.useCallback)(e=>{let t=eA.filter(e=>T.has(e.file.path)).map(e=>e.file);return t.length?t:e?[e]:[]},[eA,T]),eB=(0,r.useCallback)((e,t)=>{let s=eA.findIndex(t=>t.file.path===e),n=eA.findIndex(e=>e.file.path===t);if(-1===s||-1===n)return new Set([t]);let[r,l]=s<=n?[s,n]:[n,s];return new Set(eA.slice(r,l+1).map(e=>e.file.path))},[eA]),eF=(0,r.useCallback)((e,t)=>{if((0,eo.e)(),V.current?.focus({preventScroll:!0}),t?.metaKey||t?.ctrlKey){$(t=>{let s=new Set(t);return s.has(e.path)?s.delete(e.path):s.add(e.path),s}),U(e.path),X.current=e.path;return}if(t?.shiftKey&&X.current){$(eB(X.current,e.path)),U(e.path);return}$(new Set([e.path])),U(e.path),X.current=e.path,"folder"===e.type?(R(e.path),ef(e)):s?.(e.path)},[ef,s,eB]),eK=(0,r.useCallback)(t=>t?"folder"===t.type?t.path:rO(t.path):e,[e]),eO=(0,r.useCallback)(e=>{let t=eD(e);t.length&&S({files:t})},[eD]),eW=(0,r.useCallback)(async()=>{let e=C?.files||[];S(null),1===e.length?await ew(e[0]):await ej(e),$(new Set)},[C,ew,ej]),e_=(0,r.useCallback)((e,t)=>{let s=eD(e).map(e=>e.path);s.length&&K({paths:s,mode:t})},[eD]),eH=(0,r.useCallback)(async e=>{B?.paths?.length&&(await eC(B.paths,eK(e),B.mode),"cut"===B.mode&&K(null))},[B,eC,eK]),eq=(0,r.useCallback)(async(e,s)=>{if(!e.length)return;let n=0;W({total:e.length,done:0,failed:0}),await t.uploadFiles(s,e,{onConflict:(e,t)=>new Promise(s=>H({name:t||e?.name,resolve:s})),onFileDone:()=>W(e=>e?{...e,done:e.done+1}:e),onError:()=>{n+=1,W(e=>e?{...e,done:e.done+1,failed:n}:e)}}),W(e=>e&&n?e:null),H(null),await em(s),eh(s),ep()},[t,em,eh,ep]),eU=(0,r.useCallback)(async(e,t)=>{eq(await ln(e),t)},[eq]),eV=(0,r.useCallback)(()=>g(null),[]),eX=(0,r.useCallback)((e,t)=>{let s=M.current,n=s.has(t.path)?[...s]:[t.path];e.dataTransfer.setData(lp,JSON.stringify(n)),e.dataTransfer.effectAllowed="move"},[]),eG=(0,r.useCallback)((e,t)=>{let s=lb(e);("folder"===t.type||s)&&(e.preventDefault(),e.dataTransfer.dropEffect=s?"copy":"move","folder"===t.type&&A(t.path))},[]),eJ=(0,r.useCallback)(e=>{A(t=>t===e.path?null:t)},[]),eY=(0,r.useCallback)((e,t)=>{let s=lb(e);if("folder"!==t.type&&!s)return;if(e.preventDefault(),e.stopPropagation(),A(null),D(!1),s)return void eU(e.dataTransfer,eK(t));let n=lh(e);n&&eN(n,t.path)},[eU,eK,eN]),eZ=(0,r.useCallback)(e=>{let t=w?.dir||eS(),s=[...e.target.files].map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}));e.target.value="",j(null),eq(s,t)},[w,eS,eq]),eQ=(0,r.useCallback)((e,t)=>{if(!eA.length)return;let s=eA.findIndex(e=>e.file.path===q),n=eA[Math.min(eA.length-1,Math.max(0,-1===s?0:s+e))];if(!n)return;let r=n.file.path;t&&X.current?$(eB(X.current,r)):($(new Set([r])),X.current=r),U(r),V.current?.querySelector(`[data-path="${CSS.escape(r)}"]`)?.scrollIntoView({block:"nearest"})},[eA,q,eB]),e0=(0,r.useCallback)(e=>{if(b||w||C)return;let t=eL(q),n=e.metaKey||e.ctrlKey;if(n&&"a"===e.key.toLowerCase()){e.preventDefault(),$(new Set(eA.map(e=>e.file.path))),X.current=eA[0]?.file.path||null;return}if(n&&"c"===e.key.toLowerCase()){e.preventDefault(),e_(t,"copy");return}if(n&&"x"===e.key.toLowerCase()){e.preventDefault(),e_(t,"cut");return}if(n&&"v"===e.key.toLowerCase()){e.preventDefault(),eH(t);return}switch(e.key){case"ArrowDown":e.preventDefault(),eQ(1,e.shiftKey);return;case"ArrowUp":e.preventDefault(),eQ(-1,e.shiftKey);return;case"ArrowRight":if(!t)return;e.preventDefault(),"folder"!==t.type||er.has(t.path)?eQ(1,!1):ef(t);return;case"ArrowLeft":if(!t)return;e.preventDefault(),"folder"===t.type&&er.has(t.path)?ef(t):eQ(-1,!1);return;case"Enter":if(!t)return;e.preventDefault(),ti()?(g(t),y(t.name)):"folder"===t.type?ef(t):s?.(t.path);return;case"F2":if(!t)return;e.preventDefault(),g(t),y(t.name);return;case"Delete":case"Backspace":if(!t)return;e.preventDefault(),eO(t);return;case"Escape":$(new Set),K(null);return}},[b,w,C,q,eL,eA,er,ef,s,eQ,e_,eH,eO]),e1=(e,t)=>{if(!eI(e))return null;let s="folder"===e.type,r=s&&er.has(e.path),l=T.has(e.path);return(0,n.jsx)(lt,{file:e,depth:t,isFolder:s,isExpanded:r,isLoading:s&&el.has(e.path),isActive:eP===e.path,isSelected:l,isRenaming:b?.path===e.path,isDragOver:I===e.path&&s,isCut:B?.mode==="cut"&&B.paths.includes(e.path),gitStatus:ed[et(e.path)],renameValue:b?.path===e.path?v:"",renameInputRef:Q,onRenameChange:y,onRenameSubmit:eR,onRenameCancel:eV,onToggleFolder:ef,onClick:eF,onContextMenu:e$,onTouchStart:eM,onTouchEnd:ez,onDragStart:eX,onDragOver:eG,onDragLeave:eJ,onDrop:eY,compact:c,children:s&&r&&(0,n.jsxs)("div",{children:[(es.get(e.path)||[]).map(e=>e1(e,t+1)),ea.has(e.path)&&(0,n.jsx)(le,{depth:t+1,compact:c})]})},e.path)},e2=(0,r.useMemo)(()=>es.get(e)||[],[es,e]);(0,r.useEffect)(()=>{if(!d)return;let t=!0;return(async()=>{for(let s of Object.keys(ed)){if("folder-changed"!==ed[s])continue;let n=`${e}/${s}`;if(!es.has(n)&&(await em(n),!t))return;eh(n)}})(),()=>{t=!1}},[d,ed,e]),(0,r.useEffect)(()=>{if(!eP||!V.current)return;let e=setTimeout(()=>{let e=V.current?.querySelector(`[data-path="${CSS.escape(eP)}"]`);e?.scrollIntoView({block:"nearest"})},0);return()=>clearTimeout(e)},[eP,es]);let e5=(0,r.useMemo)(()=>rW(e),[e]),e3=(e,t)=>{(0,eo.e)(),j({type:e,dir:t}),N("")};(0,r.useEffect)(()=>{if(u)return u({newFile:()=>e3("file",eS()),newFolder:()=>e3("folder",eS()),refresh:eg,collapseAll:eb,hasExpanded:er.size>0,showHidden:eu,toggleHidden:()=>ex(e=>!e)}),()=>u(null)},[u,eu,eg,eb,er.size,e]);let e4=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=et(s.path),r=await lm(t,e,n,"folder"===s.type);r?.success&&(ep(),window.dispatchEvent(new CustomEvent(F.GW)))},[e,t,et,ep]),e6="text-text-muted hover:text-text p-1 rounded hover:bg-surface-2";return(0,n.jsxs)("div",{className:"relative flex flex-col flex-1 min-h-0 text-text overflow-hidden",children:[!c&&(0,n.jsxs)("div",{style:{height:32},className:"bg-surface border-b border-border flex items-center gap-2 sticky top-0 z-10 flex-shrink-0 px-3",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),a?.()},className:"flex items-center gap-1 flex-1 min-w-0 hover:text-text",children:[(0,n.jsx)("span",{className:"text-xs uppercase tracking-wider text-text-muted font-medium truncate",children:e5||"No Workspace"}),(0,n.jsx)(en.Ay,{name:"ChevronDown",size:12,className:"text-text-muted shrink-0"})]}),(0,n.jsx)("button",{onClick:()=>e3("file",eS()),className:e6,title:"New File",children:(0,n.jsx)(en.Ay,{name:"Plus",size:14})}),(0,n.jsx)("button",{onClick:()=>e3("folder",eS()),className:e6,title:"New Folder",children:(0,n.jsx)(en.Ay,{name:"FolderOpen",size:14})}),(0,n.jsx)("button",{onClick:eg,className:e6,title:"Refresh",children:(0,n.jsx)(en.Ay,{name:"RefreshCw",size:14})}),er.size>0&&(0,n.jsx)("button",{onClick:eb,className:e6,title:x("fileExplorer.collapseAll"),children:(0,n.jsx)(en.Ay,{name:"ChevronsDownUp",size:14})}),(0,n.jsx)("button",{onClick:()=>ex(e=>!e),className:`p-1 rounded hover:bg-surface-2 ${eu?"text-text":"text-text-muted hover:text-text"}`,title:eu?"Hide hidden files":"Show hidden files",children:(0,n.jsx)(en.Ay,{name:eu?"Eye":"EyeOff",size:14})})]}),(0,n.jsx)("div",{ref:V,tabIndex:0,onKeyDown:e0,className:`flex-1 overflow-auto py-1 outline-none ${L?"ring-2 ring-inset ring-brand-500/40 bg-brand-500/5":""}`,onDragOver:e=>{e.preventDefault();let t=lb(e);e.dataTransfer.dropEffect=t?"copy":"move",t&&D(!0)},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||D(!1)},onClick:e=>{e.target===e.currentTarget&&($(new Set),R(null))},onDrop:t=>{if(t.preventDefault(),D(!1),lb(t))return void eU(t.dataTransfer,e);let s=lh(t);s&&eN(s,e)},children:d&&!e2.some(eI)?(0,n.jsx)("div",{className:"text-text-subtle text-xs px-3 py-4 text-center",children:x("git.noChanges")}):0!==e2.length||el.has(e)?(0,n.jsxs)(n.Fragment,{children:[e2.map(e=>e1(e,0)),ea.has(e)&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted italic py-0.5 px-3",children:"Showing first 300 entries — use search for the rest."})]}):(0,n.jsx)("div",{className:"text-text-subtle text-xs px-3 py-4 text-center",children:"Empty workspace"})}),m&&(0,n.jsx)("div",{ref:f,className:"fixed z-50 menu-popover p-1 min-w-[150px] animate-in fade-in zoom-in-95 duration-100",style:{left:h.left,top:h.top},onClick:e=>e.stopPropagation(),children:(e=>{if(!e)return[];let n="folder"===e.type,r=eD(e),l=r.length>1,a=[];return!l&&n?(i&&a.push({label:x("workspaces.openHere"),icon:"Terminal",action:()=>i(e.path)}),o&&a.push({label:"Search in Folder",icon:"Search",action:()=>o(e.path)}),a.push({label:"New File",icon:"Plus",action:()=>e3("file",e.path)}),a.push({label:"New Folder",icon:"FolderOpen",action:()=>e3("folder",e.path)})):!l&&(a.push({label:"Open",icon:"File",action:()=>s?.(e.path)}),(0,F.YO)(e.path)&&a.push({label:x("editor.preview"),icon:"Eye",action:()=>s?.(e.path,{preview:!0})})),a.push({label:"Cut",icon:"Scissors",action:()=>e_(e,"cut")}),a.push({label:"Copy",icon:"Copy",action:()=>e_(e,"copy")}),B?.paths?.length&&a.push({label:"Paste",icon:"ClipboardPaste",action:()=>eH(e)}),l||(a.push({label:"Reveal in OS",icon:"FolderOpen",action:()=>t.revealInOS(e.path)}),a.push({label:"Rename",icon:"Pencil",action:()=>{g(e),y(e.name)}}),a.push({label:"Duplicate",icon:"Copy",action:()=>ek(e)}),a.push({label:"Copy Path",icon:"Copy",action:()=>eT(e.path)}),a.push({label:"Copy Relative Path",icon:"Copy",action:()=>eT(et(e.path))}),a.push({label:x("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:"EyeOff",action:()=>e4(e)})),a.push({label:l?`Delete ${r.length} items`:"Delete",icon:"Trash2",danger:!0,action:()=>eO(e)}),a})(m.file).map((e,t)=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),e.action(),p(null)},className:`w-full flex items-center gap-1.5 px-2 py-1.5 text-xs text-left hover:bg-surface-2/80 rounded-[6px] transition-colors ${e.danger?"text-red-400":"text-text"}`,children:[(0,n.jsx)(en.Ay,{name:e.icon,size:13,className:"shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.label})]},t))}),w&&(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[4px] animate-in fade-in duration-150",onClick:()=>j(null)}),(0,n.jsxs)("div",{className:"relative card-elev p-4 w-full max-w-sm animate-in zoom-in-95 duration-150",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text mb-2",children:"folder"===w.type?"New Folder":"New File"}),(0,n.jsxs)("p",{className:"text-xs text-text-muted mb-2 truncate",children:["in ",et(w.dir)||e5||"/"]}),(0,n.jsx)("input",{ref:ee,value:k,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key?eE(w.type):"Escape"===e.key&&j(null)},placeholder:"folder"===w.type?"folder name":"file name",className:"w-full bg-surface-3 text-text text-sm px-2 py-1.5 rounded outline-none border border-border focus:border-brand-500"}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-3",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),("folder"===w.type&&Y?J:G).current?.click()},className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-text-muted hover:text-text rounded-brand hover:bg-surface-3",title:"folder"===w.type&&Y?"Upload a folder from this computer":"Upload files from this computer",children:[(0,n.jsx)(en.Ay,{name:"Upload",size:13}),"Upload"]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),j(null)},className:"px-3 py-1.5 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand",children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),eE(w.type)},className:"px-3 py-1.5 text-sm bg-brand-500 hover:bg-brand-500/80 text-white rounded-brand",children:"Create"})]})]}),(0,n.jsx)("input",{ref:G,type:"file",multiple:!0,className:"hidden",onChange:eZ}),(0,n.jsx)("input",{ref:J,type:"file",webkitdirectory:"",className:"hidden",onChange:eZ})]}),O&&(0,n.jsx)("div",{className:"absolute bottom-0 inset-x-0 bg-surface-2 border-t border-border px-3 py-1.5 pb-safe text-[11px] text-text-muted flex items-center gap-2",children:O.failed?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-danger",children:x("fileExplorer.uploadFailedCount",{n:O.failed,total:O.total})}),(0,n.jsx)("button",{type:"button",onClick:()=>W(null),className:"ml-auto underline hover:text-text",children:x("common.close")})]}):(0,n.jsx)("span",{children:x("fileExplorer.uploadingCount",{n:Math.min(O.done+1,O.total),total:O.total})})}),_&&(0,n.jsx)(lx,{name:_.name,onResolve:e=>{_.resolve(e),H(null)}}),(0,n.jsx)(ei.A,{isOpen:!!C,onClose:()=>S(null),onConfirm:eW,title:"Delete",message:(C?.files?.length||0)>1?`Are you sure you want to delete these ${C.files.length} items?`:`Are you sure you want to delete "${C?.files?.[0]?.name}"?`,confirmText:"Delete",cancelText:"Cancel"})]})}function lv({x:e,y:t,items:s,onClose:l}){let a=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!a.current)return;let s=a.current.getBoundingClientRect(),n=Math.min(e,window.innerWidth-s.width-8),r=Math.min(t,window.innerHeight-s.height-8);a.current.style.left=`${Math.max(8,n)}px`,a.current.style.top=`${Math.max(8,r)}px`},[e,t]),(0,r.useEffect)(()=>{let e=e=>{a.current&&!a.current.contains(e.target)&&l()},t=e=>{"Escape"===e.key&&l()},s=setTimeout(()=>{document.addEventListener("mousedown",e),document.addEventListener("contextmenu",e,!0),document.addEventListener("keydown",t)},0);return()=>{clearTimeout(s),document.removeEventListener("mousedown",e),document.removeEventListener("contextmenu",e,!0),document.removeEventListener("keydown",t)}},[l]),(0,n.jsx)("div",{ref:a,className:"fixed z-50 min-w-[180px] py-1 rounded-lg border border-border bg-surface shadow-elev animate-in fade-in",style:{left:e,top:t},onContextMenu:e=>e.preventDefault(),children:s.filter(Boolean).map((e,t)=>(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:t=>{t.stopPropagation(),e.onClick?.(),l()},className:`w-full flex items-center gap-2.5 px-3 py-1.5 text-sm text-left transition-colors ${e.disabled?"text-text-subtle cursor-not-allowed":e.danger?"text-danger hover:bg-[rgba(var(--danger-rgb),0.12)]":"text-text hover:bg-surface-2"}`,children:[e.icon&&(0,n.jsx)(e.icon,{size:14,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 truncate",children:e.label})]},e.key+t))})}let ly={Copy:en.QR,FileText:en.iU,ExternalLink:en.Gr,Undo2:en.bE,X:en.X,EyeOff:en.X_};function lw(){let[e,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=window.matchMedia("(hover: none), (pointer: coarse)"),s=()=>t(e.matches);return s(),e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[]),e}let lj=(e,t)=>(e||"").split("\n").map(e=>e.trim()).find(t)||"",lk=(e,t)=>{let s=lj(t,e=>/files? changed/.test(e));return e("git.commitSuccess")+(s?` \xb7 ${s}`:"")},lN=(e,t)=>{if(/up.to.date/i.test(t||""))return e("git.upToDate");let s=lj(t,e=>e.includes("->"));return e("git.pushSuccess")+(s?` \xb7 ${s}`:"")},lC="changes",lS="untracked";function lE(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}function lR(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(0,t):""}function lT(e,t){if(!e)return t;let s=e.endsWith("/")||e.endsWith("\\")?"":"/";return`${e}${s}${t}`}let l$=(0,r.memo)(function({file:e,workspace:t,isUntracked:s,t:r,isTouch:l,openDiff:a,onCtxMenu:i,onDiscard:o,onStage:c}){let d=F.vs[e.status]||"text-text-muted";return lT(t,e.path),(0,n.jsxs)("div",{className:"group relative flex items-center gap-1.5 px-2 py-1 hover:bg-surface-2 cursor-pointer",onContextMenu:t=>i(e,t),onClick:()=>{(0,eo.e)(),a(e)},children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:r6({name:lE(e.path),path:e.path,type:"file"},16)}),(0,n.jsx)("span",{className:"truncate text-xs text-text",title:e.path,children:lE(e.path)}),(0,n.jsx)("span",{className:"truncate text-[11px] text-text-muted flex-1",title:lR(e.path),children:lR(e.path)}),(0,n.jsxs)("div",{className:`absolute right-[22px] top-1/2 -translate-y-1/2 flex items-center gap-0.5 pl-2 pr-1 bg-surface-2 transition-opacity ${l?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:[(0,n.jsx)("button",{type:"button",title:r(s?"common.delete":"git.discard"),onClick:t=>{t.stopPropagation(),(0,eo.e)(),o(e)},className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(en.X,{size:12})}),(0,n.jsx)("button",{type:"button",title:r("git.stage"),onClick:t=>{t.stopPropagation(),(0,eo.e)(),c(e)},className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(en.FW,{size:12})})]}),(0,n.jsx)("span",{className:`flex-shrink-0 w-4 h-4 flex items-center justify-center text-[10px] font-mono rounded bg-surface-2 ${d}`,children:e.status})]})});function lM({workspace:e,fileBus:t,onOpenFile:s,tagDiffWithRepo:l=!1}){let{t:a}=(0,ec.s)(),i=lw(),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),[p,f]=(0,r.useState)([]),[h,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(new Set([lC,lS])),[N,C]=(0,r.useState)(!1),[S,E]=(0,r.useState)(!1),[R,T]=(0,r.useState)(null),[$,M]=(0,r.useState)(!1),[z,P]=(0,r.useState)(null),[I,A]=(0,r.useState)(null),L=(0,r.useCallback)(async()=>{if(!e||!t)return;v(!0);let[s,n]=await Promise.all([t.gitStatus?.(e),t.gitBranch?.(e)]);v(!1),s?.success&&f(s.files||[]),n?.success&&(c(n.branch||""),u(n.ahead??null),m(n.behind??null))},[e,t]);(0,r.useEffect)(()=>{L()},[L]),(0,r.useEffect)(()=>{let e=()=>L(),t=["fileExplorer:fileSaved","fileExplorer:fileCreated","fileExplorer:fileDeleted","fileExplorer:fileRenamed",F.GW];return t.forEach(t=>window.addEventListener(t,e)),()=>t.forEach(t=>window.removeEventListener(t,e))},[L]);let{changes:D,untracked:B}=(0,r.useMemo)(()=>{let e=[],t=[];for(let s of p)"?"===s.status?t.push(s):e.push(s);return{changes:e,untracked:t}},[p]),K=(0,r.useCallback)(e=>{k(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),O=(0,r.useCallback)(async s=>{e&&(await t.gitAdd?.(e,[s.path]),L())},[e,t,L]),W=(0,r.useCallback)(async()=>{e&&(await t.gitAdd?.(e,["."]),L())},[e,t,L]),_=(0,r.useCallback)(async s=>{e&&(await t.gitDiscard?.(e,s.path,s.status),L())},[e,t,L]),H=(0,r.useCallback)(e=>{T(e),E(!0)},[]),q=(0,r.useCallback)(t=>{s?.(l?(0,F.n2)(t.status,e,t.path):(0,F.Dk)(t.status,t.path))},[s,l,e]),U=(0,r.useCallback)((e=!1)=>{!h.trim()||p.length&&(M(e),C(!0))},[h,p]),V=(0,r.useCallback)(async()=>{if(!e)return;w(null);let s=await t.gitAdd?.(e,["."]);if(s&&!s.success)return void w({ok:!1,text:s.error||a("git.stageFailed")});let n=await t.gitCommit?.(e,h.trim());if(!n?.success){w({ok:!1,text:n?.output||n?.error||a("git.commitFailed")}),L();return}if(b(""),!$){w({ok:!0,text:lk(a,n.output)}),L();return}let r=await t.gitPush?.(e);w(r?.success?{ok:!0,text:`${lk(a,n.output)} \xb7 ${lN(a,r.output)}`}:{ok:!1,text:r?.output||r?.error||a("git.pushFailed")}),L()},[e,t,h,$,L,a]),X=(0,r.useCallback)(async()=>{if(!e)return;v(!0),w(null);let s=await t.gitPush?.(e);v(!1),w(s?.success?{ok:!0,text:lN(a,s.output)}:{ok:!1,text:s?.output||s?.error||a("git.pushFailed")}),L()},[e,t,L,a]),G=(0,r.useCallback)(async()=>{if(!e)return;v(!0),w(null);let s=await t.gitPull?.(e);v(!1),w(s?.success?{ok:!0,text:((e,t)=>{if(/already up to date|up.to.date/i.test(t||""))return e("git.upToDate");let s=lj(t,e=>/files? changed|fast-forward/i.test(e));return e("git.pullSuccess")+(s?` \xb7 ${s}`:"")})(a,s.output)}:{ok:!1,text:s?.output||s?.error||a("git.pullFailed")}),L()},[e,t,L,a]),J=(0,r.useCallback)((e,t)=>{e.stopPropagation(),(0,eo.e)();let s=e.currentTarget.getBoundingClientRect();t({x:s.right,y:s.bottom+4})},[]),[Y,Z]=(0,r.useState)(null),Q=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),ee=(0,r.useCallback)((e,t)=>{t.preventDefault(),t.stopPropagation(),(0,eo.e)(),Z({file:e,x:t.clientX,y:t.clientY})},[]),et=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=await lm(t,e,s.path);n?.success&&(window.dispatchEvent(new CustomEvent(F.GW)),L())},[e,t,L]),es=(0,r.useCallback)(t=>{let n=lT(e,t.path);return[{key:"open",label:a("git.openFile"),icon:en.Gr,disabled:"D"===t.status,onClick:()=>s?.(n)},{key:"copyPath",label:a("files.copyPath",{defaultValue:"Copy Path"}),icon:en.Gr,onClick:()=>Q(n)},{key:"copyRel",label:a("files.copyRelPath",{defaultValue:"Copy Relative Path"}),icon:en.Gr,onClick:()=>Q(t.path)},{key:"copyName",label:a("files.copyName",{defaultValue:"Copy Filename"}),icon:en.Gr,onClick:()=>Q(lE(t.path))},{key:"addToGitignore",label:a("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:en.X_,onClick:()=>et(t)}]},[e,s,Q,et,a]),er=(t,s,r,l)=>{let o=j.has(t);return(0,n.jsxs)("div",{className:"border-t border-border",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),K(t)},className:"w-full flex items-center gap-1 px-2 py-1 hover:bg-surface-2 text-left",children:[o?(0,n.jsx)(en.yQ,{size:12,className:"text-text-subtle"}):(0,n.jsx)(en.c_,{size:12,className:"text-text-subtle"}),(0,n.jsx)("span",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:s}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 ml-auto rounded-brand bg-surface-3 text-text-muted",children:r.length})]}),o&&r.map(t=>(0,n.jsx)(l$,{file:t,workspace:e,isUntracked:l,t:a,isTouch:i,openDiff:q,onCtxMenu:ee,onDiscard:H,onStage:O},`${t.status}-${t.path}`))]})};return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text",children:[(0,n.jsxs)("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(en.Zr,{size:14,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-xs text-text truncate flex-1",children:o||"—"}),d>0&&(0,n.jsxs)("span",{className:"text-[10px] font-medium px-1.5 rounded-brand bg-brand-500/15 text-brand-500",children:["↑",d]}),x>0&&(0,n.jsxs)("span",{className:"text-[10px] font-medium px-1.5 rounded-brand bg-surface-3 text-text-muted",children:["↓",x]}),(0,n.jsx)("button",{type:"button",title:a("common.refresh"),onClick:()=>{(0,eo.e)(),L()},className:"p-1 text-text-muted hover:text-text",children:(0,n.jsx)(en.e9,{size:12,className:g?"animate-spin":""})}),(0,n.jsx)("button",{type:"button",title:a("git.gitActions"),onClick:e=>J(e,A),className:"p-1 text-text-muted hover:text-text",children:(0,n.jsx)(en.a4,{size:12})})]}),(0,n.jsx)("textarea",{value:h,onChange:e=>b(e.target.value),rows:2,placeholder:a("git.commitPlaceholder"),className:"w-full bg-surface-2 border border-border rounded-brand px-2 py-1 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500 resize-none"}),(0,n.jsxs)("div",{className:`flex items-stretch h-7 rounded-brand overflow-hidden bg-brand-500 text-white transition-opacity ${!h.trim()||!p.length?"opacity-40":""}`,children:[(0,n.jsx)("button",{type:"button",disabled:!h.trim()||!p.length,onClick:()=>{(0,eo.e)(),U(!1)},className:"flex-1 text-xs hover:bg-black/10 disabled:cursor-not-allowed transition-colors",children:a("git.commit")}),(0,n.jsx)("span",{className:"w-px my-1.5 bg-white/25"}),(0,n.jsx)("button",{type:"button",title:a("git.gitActions"),disabled:!h.trim()||!p.length,onClick:e=>J(e,P),className:"px-1.5 flex items-center hover:bg-black/10 disabled:cursor-not-allowed transition-colors",children:(0,n.jsx)(en.yQ,{size:12})})]}),y&&(0,n.jsx)("div",{className:`text-[11px] leading-snug break-words rounded-brand px-2 py-1 ${y.ok?"text-[var(--success)] bg-[rgba(var(--success-rgb),0.1)]":"text-[var(--danger)] bg-[rgba(var(--danger-rgb),0.1)]"}`,children:y.text})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[er(lC,a("git.changes"),D,!1),er(lS,a("git.untracked"),B,!0)]}),(0,n.jsx)(ei.A,{isOpen:N,onClose:()=>C(!1),onConfirm:V,title:a("git.stageAllConfirmTitle"),message:a("git.stageAllConfirmMessage"),confirmText:a("git.stageAndCommit"),cancelText:a("common.cancel")}),(0,n.jsx)(ei.A,{isOpen:S,onClose:()=>{E(!1),T(null)},onConfirm:()=>{R&&_(R),T(null)},title:a("git.discardConfirmTitle"),message:R?"?"===R.status?a("git.discardConfirmDelete",{name:lE(R.path)}):a("git.discardConfirmDiscard",{name:lE(R.path)}):"",confirmText:a("git.discard"),cancelText:a("common.cancel")}),Y&&(0,n.jsx)(lv,{x:Y.x,y:Y.y,items:es(Y.file),onClose:()=>Z(null)}),z&&(0,n.jsx)(lv,{x:z.x,y:z.y,items:[{key:"commitPush",label:a("git.commitAndPush"),icon:en.Do,disabled:!h.trim()||!p.length,onClick:()=>U(!0)}],onClose:()=>P(null)}),I&&(0,n.jsx)(lv,{x:I.x,y:I.y,items:[{key:"push",label:a("git.push"),icon:en.Do,onClick:X},{key:"pull",label:a("git.pull"),icon:en.yd,onClick:G},{key:"stageAll",label:a("git.stageAll"),icon:en.FW,disabled:!p.length,onClick:W}],onClose:()=>A(null)})]})}let lz=[{key:"files",icon:en.sv,labelKey:"workspaces.tabFiles"},{key:"git",icon:en.Zr,labelKey:"workspaces.tabGit"},{key:"trees",icon:en.dx,labelKey:"workspaces.tabTrees"}].filter(e=>"trees"!==e.key);function lP({results:e,loading:t,query:s,searchDir:r,workspace:l,onOpen:a}){let{t:i}=(0,ec.s)();if(!s||s.length<2){let e=r?r.split("/").pop():"";return(0,n.jsxs)("div",{className:"p-6 text-xs text-text-subtle text-center flex flex-col items-center gap-2",children:[(0,n.jsx)(en.vj,{size:20,className:"opacity-40"}),(0,n.jsx)("span",{children:e?`Type at least 2 characters to search in ${e}`:i("files.searchPlaceholder")})]})}return t?(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle text-center",children:i("files.searching")}):e.length?(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:e.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),a(e.path)},className:"w-full px-2 py-1.5 flex items-center gap-2 border-b border-border-subtle hover:bg-surface-2 transition-colors text-left",title:e.path,children:["binary"===e.type?(0,n.jsx)(en.lP,{size:14,className:"text-red-500/70 flex-shrink-0"}):(0,n.jsx)(en.ZH,{size:14,className:"text-text-subtle flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate text-xs text-text flex-1",children:e.name}),(0,n.jsx)("span",{className:"truncate text-[10px] text-text-subtle max-w-[45%]",children:e.path.replace(l,"").replace(/^\//,"")})]},e.path))}):(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle text-center",children:i("files.noFilesFound")})}function lI({root:e,multiple:t,isOpen:s,onToggle:r,onRemove:l=null,removeLabel:a="",children:i}){return t?(0,n.jsxs)("div",{className:`flex flex-col min-h-0 ${s?"flex-1":"flex-shrink-0"}`,children:[(0,n.jsxs)("div",{className:"group px-2 py-1 flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-text-muted bg-surface-2/40 hover:bg-surface-2 border-b border-border-subtle transition-colors",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),r()},className:"flex-1 min-w-0 flex items-center gap-1.5 hover:text-text transition-colors",title:e.path,children:[(0,n.jsx)(en.c_,{size:11,className:`flex-shrink-0 transition-transform duration-150 ${s?"rotate-90":""}`}),(0,n.jsx)("span",{className:"truncate flex-1 text-left",children:e.branch||e.name||e.path.split("/").pop()}),!e.isMain&&(0,n.jsx)(en.dx,{size:10,className:"flex-shrink-0 opacity-60"})]}),l&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),l()},title:a,className:"p-0.5 shrink-0 hover:text-red-500 transition-colors",children:(0,n.jsx)(en.TB,{size:11})})]}),s&&(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:i})]}):(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:i})}function lA({icon:e,label:t,onClick:s,active:r,disabled:l,spinning:a}){return(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),s?.()},disabled:l,title:t,className:`p-2 sm:p-1 rounded-[3px] hover:bg-surface-2 transition-colors disabled:opacity-40 ${r?"text-brand-500":"text-text-muted hover:text-text"}`,children:(0,n.jsx)(e,{size:16,className:`sm:w-[13px] sm:h-[13px] ${a?"animate-spin":""}`})})}function lL({onClick:e,children:t}){return(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),e()},className:"w-full px-3 py-1.5 text-[11px] text-text-subtle hover:text-text hover:bg-surface-2 transition-colors text-left",children:t})}function lD({repo:e,changedCount:t=0,isOpen:s,onToggle:r,onHide:l,children:a}){let{t:i}=(0,ec.s)();return(0,n.jsxs)("div",{className:"border-b border-border-subtle last:border-0",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),r()},className:"group/repo w-full sticky top-0 z-10 px-2 py-1 flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-text-muted hover:text-text bg-surface-3 border-b border-border-subtle transition-colors",children:[(0,n.jsx)(en.c_,{size:11,className:`flex-shrink-0 transition-transform duration-150 ${s?"rotate-90":""}`}),(0,n.jsx)("span",{className:"truncate flex-1 text-left",title:e.relPath||e.name,children:e.relPath||e.name}),e.branch&&(0,n.jsx)("span",{className:"text-text-subtle normal-case tracking-normal truncate max-w-[45%]",title:e.branch,children:e.branch}),t>0&&(0,n.jsx)("span",{className:"px-1 rounded-[2px] bg-brand-500/15 text-brand-500 normal-case tracking-normal flex-shrink-0",children:t}),l&&(0,n.jsx)("span",{role:"button",tabIndex:-1,onClick:e=>{e.stopPropagation(),(0,eo.e)(),l()},className:"p-0.5 text-text-subtle hover:text-text flex-shrink-0 opacity-100 sm:opacity-0 sm:group-hover/repo:opacity-100 transition-opacity",title:i("workspaces.hideRepo"),children:(0,n.jsx)(en.X_,{size:11})})]}),s&&a]})}let lB=(0,r.memo)(function({workspacePath:e,filesRoot:t=null,cwdHint:s=null,fileBus:l,activeFile:a,tab:i,onTabChange:o,width:c,onResize:d,onClose:u,onOpenFile:x,onNewTerminal:m,onAddWorkspace:p,onOpenFiles:f,homeDir:h,changedPerRepo:b={},hiddenRepos:g=[],onHiddenReposChange:v,isDesktop:y=!0}){let{t:w}=(0,ec.s)(),j=l||et.getState(),k="trees"===i?"git":i,{repos:N,refresh:C,scanning:S,deep:E,scanDeeper:R}=function(e,t){let[s,n]=(0,r.useState)([]),[l,a]=(0,r.useState)(!1),i=t||et.getState(),[o,c]=(0,r.useState)(!1),d=(0,r.useCallback)(async(t,s)=>{if(!e||!i?.gitScanRepos)return;a(!0),t&&await i.gitRefreshRepos?.(e);let r=s?eV.Tk.deepMaxDepth:eV.Tk.maxDepth,l=await i.gitScanRepos(e,r);a(!1),n(l?.success&&l.repos||[])},[e,i]);return(0,r.useEffect)(()=>{let e=setTimeout(()=>void d(!1,o),0);return()=>clearTimeout(e)},[d,o]),{repos:s,refresh:(0,r.useCallback)(()=>d(!0,o),[d,o]),scanning:l,deep:o,scanDeeper:(0,r.useCallback)(()=>c(!0),[])}}(e,j),T=t||e,{roots:$,refresh:M}=function(e,t){let[s,n]=(0,r.useState)([]),l=t||et.getState(),a=(0,r.useCallback)(async()=>{if(!e||!l?.gitWorktreeList)return n([]);let t=await l.gitWorktreeList(e);if(!t?.success||!t.worktrees?.length)return n([{path:e,branch:null,name:rF(e)}]);n(t.worktrees.map(e=>({path:e.path,branch:e.branch,name:rF(e.path),isMain:e.isMain})))},[e,l]);return(0,r.useEffect)(()=>{let e=setTimeout(()=>void a(),0);return()=>clearTimeout(e)},[a]),{roots:s,refresh:a}}(T,j),z=()=>{C(),M()},{branch:P}=n8(e,j),I=(0,r.useRef)({path:null,branch:null});(0,r.useEffect)(()=>{let t=I.current;I.current={path:e,branch:P},t.path===e&&null!==t.branch&&t.branch!==P&&(C(),M(),window.dispatchEvent(new Event(F.GW)))},[P,e]);let[A,L]=(0,r.useState)({forWorkspace:e,showClean:!1,openRepo:null}),D=A.forWorkspace===e?A:{showClean:!1,openRepo:null},B=D.showClean,K=D.openRepo,O=new Set(g),W=e=>b[e.path]??e.changedCount??0,_=t=>!t.relPath||t.path===e,H=N.filter(e=>!O.has(e.path)),q=H.filter(e=>W(e)>0).reduce((e,t)=>e+W(t),0),U=B?H:H.filter(e=>W(e)>0||_(e)),V=B?0:H.length-U.length,X=N.length-H.length,G=K??(1===U.length?U[0].path:null),J=!y||c>=eV.Ds.min,[Y,Z]=(0,r.useState)(null),[Q,ee]=(0,r.useState)(null),[es,er]=(0,r.useState)(null),[el,ea]=(0,r.useState)(null),ed=$.find(e=>e.isMain)?.path||e,eu=async e=>{er(null);let t=await j.gitWorktreeRemove(ed,e.path,{probe:!0,deleteBranch:e.branch||void 0});if(!t?.success)return er(t?.error||"Probe failed");ee({root:e,sessions:t.sessions||[],branchMerged:t.branchMerged})},ex=async(e,t=!1)=>{er(null),ea(null);let s=await j.gitWorktreeRemove(ed,e.path,{confirmed:!0,force:t,deleteBranch:e.branch||void 0});return!s?.success&&/use --force/i.test(s?.error||"")?ee({root:e,dirty:!0}):(ee(null),s?.success)?void(s.branchKept&&ea(e.branch),z()):er(s?.error||"Remove failed")},em=s||T,ep=(0,r.useMemo)(()=>{let e=$.filter(e=>em===e.path||em?.startsWith(`${e.path}/`));return e.length?e.sort((e,t)=>t.path.length-e.path.length)[0].path:($.find(e=>e.isMain)||$[0])?.path||T},[$,em,T]),[ef,eh]=(0,r.useState)({forProbe:null,path:null}),eb=ef.forProbe===em?ef.path:ep,[eg,ev]=(0,r.useState)({forRoot:null,searchDir:null,show:!1,query:"",results:[],loading:!1}),ey=eg.forRoot===T?eg:{show:!1,searchDir:null,query:"",results:[],loading:!1},ew=(0,r.useRef)(null),ej=(0,r.useCallback)(()=>{ev({forRoot:null,searchDir:null,show:!1,query:"",results:[],loading:!1})},[]),ek=(0,r.useCallback)(e=>{ev({forRoot:T,searchDir:e,show:!0,query:"",results:[],loading:!1})},[T]),eN=(0,r.useCallback)(()=>{ev(e=>{let t={...e,searchDir:null};return e.query&&e.query.length>=2&&(t.loading=!0,j.searchFiles(T,e.query).then(e=>{ev(t=>t.loading?{...t,results:e.success?e.files:[],loading:!1}:t)})),t})},[j,T]),eC=(0,r.useCallback)(e=>{if(ev(t=>({...t,query:e})),ew.current&&clearTimeout(ew.current),!e||e.length<2)return void ev(e=>({...e,results:[],loading:!1}));ev(e=>({...e,loading:!0}));let t=ey.searchDir||T;ew.current=setTimeout(async()=>{let s=await j.searchFiles(t,e);ev(t=>t.query===e&&t.loading?{...t,results:s.success?s.files:[],loading:!1}:t)},300)},[j,T,ey.searchDir]);return(0,r.useEffect)(()=>()=>{ew.current&&clearTimeout(ew.current)},[]),(0,n.jsxs)("div",{className:`h-full flex flex-col terminal-sidebar-bg border-l border-border-subtle relative shrink ${y?"":"pb-safe"}`,style:y?{width:c,flexBasis:c,minWidth:eV.Ds.min}:void 0,children:[(0,n.jsxs)("div",{className:`h-11 ${s1} pl-1 pr-0.5 flex items-stretch gap-0 border-b border-border-subtle flex-shrink-0`,children:[lz.map(({key:e,icon:t,labelKey:s})=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),o(e)},className:`px-3 sm:px-2 flex items-center justify-center gap-1 text-[11px] border-b-2 -mb-px transition-colors ${k===e?"text-text border-brand-500":"text-text-muted border-transparent hover:text-text"}`,title:w(s),children:[(0,n.jsx)(t,{size:18,className:"sm:w-[15px] sm:h-[15px]"}),J&&(0,n.jsx)("span",{children:w(s)}),"git"===e&&q>0&&(0,n.jsx)("span",{className:"min-w-[14px] h-[14px] px-[4px] rounded-full bg-brand-500 text-white text-[9px] font-semibold flex items-center justify-center leading-none",children:q>99?"99+":q})]},e)),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 sm:gap-0.5",children:[(0,n.jsx)(lA,{icon:en.e9,label:w("workspaces.refreshRepos"),onClick:()=>{z(),Y?.refresh?.()},disabled:S,spinning:S}),u&&(0,n.jsx)(lA,{icon:en.X,label:w("common.close"),onClick:u})]})]}),"files"===k&&e&&(0,n.jsx)("div",{className:`h-11 ${s1} px-2 flex items-center gap-1.5 border-b border-border-subtle flex-shrink-0`,children:ey.show?(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[(0,n.jsx)(en.vj,{size:14,className:"text-text-subtle shrink-0"}),(0,n.jsx)("input",{type:"text",value:ey.query,onChange:e=>eC(e.target.value),onKeyDown:e=>{"Escape"===e.key&&ej()},placeholder:ey.searchDir?`Search in ${ey.searchDir.split("/").pop()}…`:w("files.searchPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs text-text placeholder-text-subtle focus:outline-none",autoFocus:!0}),ey.loading?(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-brand-500 shrink-0"}):ey.query?(0,n.jsx)("button",{type:"button",onClick:()=>eC(""),className:"p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(en.X,{size:12})}):null,(0,n.jsx)(lA,{icon:en.X,label:w("common.close"),onClick:ej})]}):(0,n.jsxs)(n.Fragment,{children:[Y&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(lA,{icon:en.FW,label:w("files.newFile"),onClick:Y.newFile}),(0,n.jsx)(lA,{icon:en.JU,label:w("files.newFolder"),onClick:Y.newFolder})]}),(0,n.jsx)(lA,{icon:en.vj,label:w("files.searchFiles"),onClick:()=>{if(ey.show)return ej();ev({forRoot:T,searchDir:null,show:!0,query:"",results:[],loading:!1})},active:ey.show}),(0,n.jsx)("div",{className:"flex-1"}),Y?.hasExpanded&&(0,n.jsx)(lA,{icon:en.WE,label:w("fileExplorer.collapseAll"),onClick:Y.collapseAll}),Y&&(0,n.jsx)(lA,{icon:Y.showHidden?en.kU:en.X_,label:w("files.toggleHidden"),onClick:Y.toggleHidden,active:Y.showHidden}),f&&(0,n.jsx)(lA,{icon:en.Gr,label:w("workspaces.openFullFiles"),onClick:f})]})}),"files"===k&&e&&ey.show&&ey.searchDir&&(0,n.jsxs)("div",{className:"px-3 py-1 bg-surface-3/40 border-b border-border-subtle flex items-center justify-between text-[11px] text-text-muted flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)(en.vd,{size:12,className:"text-yellow-500/80 shrink-0"}),(0,n.jsx)("span",{className:"text-text-subtle shrink-0",children:"Folder:"}),(0,n.jsx)("span",{className:"font-medium text-text truncate max-w-[150px]",title:ey.searchDir,children:ey.searchDir.split("/").pop()})]}),(0,n.jsx)("button",{type:"button",onClick:eN,className:"text-brand-500 hover:text-brand-400 hover:underline shrink-0 text-[11px] ml-2",children:"Search all"})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:e?"files"===k?ey.show?(0,n.jsx)(lP,{results:ey.results,loading:ey.loading,query:ey.query,searchDir:ey.searchDir,workspace:T,onOpen:e=>{x?.(e),ej()}}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(es||el)&&(0,n.jsxs)("div",{className:"px-3 py-1.5 border-b border-border-subtle text-[11px]",children:[es&&(0,n.jsx)("p",{className:"text-red-500 break-words whitespace-pre-wrap",children:es}),el&&(0,n.jsx)("p",{className:"text-text-muted break-words",children:w("workspaces.worktreeBranchKept",{branch:el})})]}),$.map(e=>(0,n.jsx)(lI,{root:e,multiple:$.length>1,isOpen:1===$.length||eb===e.path,onToggle:()=>eh({forProbe:em,path:eb===e.path?null:e.path}),onRemove:e.isMain?null:()=>{(0,eo.e)(),eu(e)},removeLabel:w("workspaces.removeWorktree"),children:(0,n.jsx)(lg,{workspace:e.path,fileBus:j,activeFile:a,onOpenFile:x,onNewTerminal:m,onSearchFolder:ek,compact:!0,onActions:e.path===eb||1===$.length?Z:void 0})},e.path))]}):"git"===k?(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[U.map(t=>(0,n.jsx)(lD,{repo:t,changedCount:W(t),isOpen:G===t.path,onToggle:()=>{let s;return s=G===t.path?"":t.path,L({...D,forWorkspace:e,openRepo:s})},onHide:v&&!_(t)?()=>{let e;return e=t.path,v?.([...g,e])}:null,children:(0,n.jsx)(lM,{workspace:t.path,fileBus:j,onOpenFile:x,tagDiffWithRepo:!0})},t.path)),!U.length&&!S&&(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle italic",children:B?w("workspaces.emptyWorkspace"):w("git.noChanges")}),(V>0||X>0||!E)&&(0,n.jsxs)("div",{className:"border-t border-border-subtle mt-1",children:[V>0&&(0,n.jsx)(lL,{onClick:()=>L({...D,forWorkspace:e,showClean:!0}),children:w("workspaces.showCleanRepos",{count:V})}),X>0&&(0,n.jsx)(lL,{onClick:()=>v?.([]),children:w("workspaces.showHiddenRepos",{count:X})}),!E&&(0,n.jsx)(lL,{onClick:R,children:w("workspaces.scanDeeper")})]})]}):null:(0,n.jsxs)("div",{className:"p-4 flex flex-col items-center gap-2 text-center",children:[(0,n.jsx)(en.vd,{size:22,className:"text-text-subtle"}),(0,n.jsx)("p",{className:"text-xs text-text-subtle",children:w("workspaces.emptyWorkspace")}),p&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),p()},className:"mt-1 px-2 py-1 text-[11px] text-brand-500 bg-brand-500/10 hover:bg-brand-500/20 rounded-[3px] transition-colors",children:w("workspaces.selectFolder")})]})}),(0,n.jsx)(ei.A,{isOpen:!!Q,onClose:()=>ee(null),onConfirm:()=>{(0,eo.e)(),ex(Q.root,!!Q.dirty)},title:w("workspaces.removeWorktree"),message:Q?Q.dirty?w("workspaces.worktreeDirty"):[w("workspaces.removeWorktreeFolder",{path:Q.root.path}),Q.root.branch&&w(!0===Q.branchMerged?"workspaces.removeWorktreeBranchDelete":!1===Q.branchMerged?"workspaces.removeWorktreeBranchKeep":"workspaces.removeWorktreeBranch",{branch:Q.root.branch}),Q.sessions?.length?w("workspaces.removeWorktreeSessions",{count:Q.sessions.length,names:Q.sessions.map(e=>e.name).join(", ")}):null].filter(Boolean).join("\n"):""}),y&&(0,n.jsx)("div",{onPointerDown:e=>eU(e,{startWidth:c,axis:-1,onWidth:e=>d?.(e)}),className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})]})});function lF(e){return e?e<1024?`${e}B`:e<1048576?`${(e/1024).toFixed(1)}KB`:`${(e/1048576).toFixed(1)}MB`:""}function lK({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!0),[x,m]=(0,r.useState)(1),[p,f]=(0,r.useState)({x:0,y:0}),[h,b]=(0,r.useState)(0),g=(0,r.useRef)(null),v=(0,r.useRef)(null),y=(0,r.useRef)(null),w=(0,r.useRef)(null),j=(0,r.useRef)(null),k=(0,r.useRef)(null),N=(0,r.useRef)(0);(0,r.useEffect)(()=>{let s=!1,n=[],r="";u(!0),c(""),l(""),i(null),m(1),f({x:0,y:0}),b(0),y.current=null,w.current&&(URL.revokeObjectURL(w.current),w.current=null);let a=e.toLowerCase();if(a.endsWith(".tif")||a.endsWith(".tiff"))return t.readMedia(e).then(e=>{s||(e.success?(l(e.dataUrl),i({size:e.originalSize||e.size,width:e.width,height:e.height,scaled:e.scaled,originalWidth:e.originalWidth,originalHeight:e.originalHeight})):c(e.error||"Failed to load image"),u(!1))}),()=>{s=!0};let o=t.streamMedia(e,{onMeta:e=>{s||(r=e.mime||"image/*",i({size:e.size,width:e.width,height:e.height,scaled:e.scaled,originalWidth:e.originalWidth,originalHeight:e.originalHeight}))},onChunk:e=>{s||n.push(e)},onDone:()=>{if(s)return;let e=new Blob(n,{type:r});if(e.size>F.W5){y.current=e,b(e.size),u(!1);return}w.current=URL.createObjectURL(e),l(w.current),u(!1)},onError:e=>{s||(c(e.message||"Failed to load image"),u(!1))}});return()=>{s=!0,o?.()}},[e,t]),(0,r.useEffect)(()=>()=>{w.current&&URL.revokeObjectURL(w.current)},[]);let C=(0,r.useCallback)((e,t,s)=>{let n=v.current,r=g.current;if(!n||!r)return{x:e,y:t};let l=r.clientWidth,a=r.clientHeight,i=n.clientWidth*s,o=n.clientHeight*s,c=Math.max(0,(i-l)/2),d=Math.max(0,(o-a)/2);return{x:Math.max(-c,Math.min(c,e)),y:Math.max(-d,Math.min(d,t))}},[]),S=(0,r.useCallback)(()=>{m(1),f({x:0,y:0})},[]),E=(0,r.useCallback)((e,t,s)=>{m(n=>{let r=Math.max(.2,Math.min(8,n*e));if(r===n)return n;if(null!=t&&null!=s){let e=g.current;if(e){let l=e.clientWidth/2,a=e.clientHeight/2,i=t-l,o=s-a;f(e=>C((e.x-i)*(r/n)+i,(e.y-o)*(r/n)+o,r))}}else f(e=>C(e.x,e.y,r));return r})},[C]),R=(e,t)=>Math.hypot(e.clientX-t.clientX,e.clientY-t.clientY),T=(0,r.useCallback)(e=>{if(2===e.touches.length)k.current=null,j.current={dist:R(e.touches[0],e.touches[1]),scale:x,pos:p};else if(1===e.touches.length){let t=Date.now();if(t-N.current<300){x>1.01?S():(m(2),f({x:0,y:0})),N.current=0,k.current=null;return}N.current=t,x>1.01&&(k.current={x:e.touches[0].clientX,y:e.touches[0].clientY,pos:p})}},[x,p,S]),$=(0,r.useCallback)(e=>{if(2===e.touches.length&&j.current){e.preventDefault();let t=R(e.touches[0],e.touches[1]),s=Math.max(.2,Math.min(8,j.current.scale*(t/j.current.dist)));m(s),f(e=>C(e.x,e.y,s))}else if(1===e.touches.length&&k.current){e.preventDefault();let t=e.touches[0],s=t.clientX-k.current.x,n=t.clientY-k.current.y;f(C(k.current.pos.x+s,k.current.pos.y+n,x))}},[x,C]),M=(0,r.useCallback)(e=>{e.touches.length<2&&(j.current=null),0===e.touches.length&&(k.current=null)},[]),z=(0,r.useCallback)(e=>{e.preventDefault();let t=e.deltaY<0?1.1:1/1.1,s=g.current?.getBoundingClientRect();E(t,s?e.clientX-s.left:null,s?e.clientY-s.top:null)},[E]);if(d)return(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(en.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading image..."})]});if(o)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:o});if(h)return(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-text-muted px-6 text-center",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-text truncate max-w-full",title:e,children:e.split("/").pop()}),(0,n.jsxs)("span",{className:"text-xs",children:[lF(h)," — decoding an image this large can crash mobile Safari."]}),(0,n.jsx)("button",{onClick:()=>{let e=y.current;e&&(w.current=URL.createObjectURL(e),l(w.current),b(0))},className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-surface-3 text-text text-sm",children:"Open anyway"})]});let P=a?.width&&a?.height?`${a.width}\xd7${a.height}`:"",I=a?.scaled&&a?.originalWidth&&a?.originalWidth!==a?.width;return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-3 py-1.5 flex items-center gap-2 text-xs text-text-muted",children:[(0,n.jsx)("span",{className:"truncate flex-1",title:e,children:e.split("/").pop()}),a?.size?(0,n.jsx)("span",{className:"text-text-subtle",children:lF(a.size)}):null,P?(0,n.jsxs)("span",{className:"text-text-subtle",children:[P,I?" ↓":""]}):null,(0,n.jsx)("button",{onClick:()=>E(1/1.2),className:"px-2 hover:bg-surface-2 rounded",children:"−"}),(0,n.jsxs)("span",{className:"w-12 text-center",children:[Math.round(100*x),"%"]}),(0,n.jsx)("button",{onClick:()=>E(1.2),className:"px-2 hover:bg-surface-2 rounded",children:"+"}),(0,n.jsx)("button",{onClick:S,className:"px-2 hover:bg-surface-2 rounded",children:"Reset"})]}),(0,n.jsx)("div",{ref:g,className:"flex-1 min-h-0 overflow-hidden flex items-center justify-center bg-[repeating-conic-gradient(#0001_0%_25%,transparent_0%_50%)] bg-[length:20px_20px] touch-none",onTouchStart:T,onTouchMove:$,onTouchEnd:M,onWheel:z,children:(0,n.jsx)("img",{ref:v,src:s,alt:e,draggable:!1,onLoad:e=>i(t=>({...t,width:e.target.naturalWidth,height:e.target.naturalHeight})),style:{transform:`translate(${p.x}px, ${p.y}px) scale(${x})`,transformOrigin:"center",willChange:"transform"},className:"max-w-full max-h-full object-contain select-none"})})]})}function lO({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(""),[o,c]=(0,r.useState)(0),[d,u]=(0,r.useState)(""),[x,m]=(0,r.useState)(!0);if((0,r.useEffect)(()=>{let s=!1,n=null,r=null,a=null,o=null,d=[],x=!1;m(!0),u(""),l(""),i(""),c(0);let p=!1,f="",h=()=>{if(!s&&!p&&o&&!o.updating){if(d.length)return void o.appendBuffer(d.shift());if(x&&r&&"open"===r.readyState)try{r.endOfStream()}catch{}}};return n=t.streamMedia(e,{onMeta:({mime:e,size:t})=>{if(!s){if(i(e),c(t),!("u">typeof MediaSource&&MediaSource.isTypeSupported(e))){p=!0,f=e;return}r=new MediaSource,l(a=URL.createObjectURL(r)),m(!1),r.addEventListener("sourceopen",()=>{s||((o=r.addSourceBuffer(e)).addEventListener("updateend",h),h())})}},onChunk:e=>{!s&&(d.push(e),p||h())},onDone:()=>{if(!s)if(p){let e=new Blob(d,{type:f||"application/octet-stream"});l(a=URL.createObjectURL(e)),m(!1)}else x=!0,h()},onError:e=>{s||(u(e.message||"Stream error"),m(!1))}}),()=>{s=!0,n?.(),a&&URL.revokeObjectURL(a);try{r&&"open"===r.readyState&&r.endOfStream()}catch{}}},[e,t]),x)return(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(en.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading media..."})]});if(d)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:d});let p=a.startsWith("video/"),f=e.split("/").pop();return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-3 py-1.5 flex items-center gap-2 text-xs text-text-muted",children:[(0,n.jsx)("span",{className:"truncate flex-1",title:e,children:f}),o?(0,n.jsx)("span",{className:"text-text-subtle",children:o?o<1024?`${o}B`:o<1048576?`${(o/1024).toFixed(1)}KB`:`${(o/1048576).toFixed(1)}MB`:""}):null]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto flex items-center justify-center bg-black/30",children:p?(0,n.jsx)("video",{src:s,controls:!0,className:"max-h-full max-w-full"}):(0,n.jsx)("audio",{src:s,controls:!0,className:"w-full max-w-md"})})]})}function lW({filePath:e,fileBus:t}){let[l,a]=(0,r.useState)(!0),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)([]),[u,x]=(0,r.useState)(0),[m,p]=(0,r.useState)([]),f=(0,r.useRef)(null),h=(0,r.useRef)(null),b=(0,r.useRef)(null);if((0,r.useEffect)(()=>{let n=!1,r=null,l=[],i=(0,F.$b)(e);a(!0),o(""),d([]),x(0),p([]),h.current=null,f.current&&(f.current.innerHTML="");let c=async e=>{try{if(i){let{renderAsync:t}=await s.e(910).then(s.bind(s,80910));if(n||!f.current){n||a(!1);return}for(let s of(await t(new Blob([e]),f.current,void 0,{inWrapper:!0,renderAltChunks:!1}),f.current.querySelectorAll("a[href]"))){let e=s.getAttribute("href")||"";/^(https?:|mailto:|#)/i.test(e.trim())||s.removeAttribute("href")}n||a(!1)}else{let t=await Promise.all([s.e(8874),s.e(4930)]).then(s.bind(s,19819));if(n)return;b.current=t,h.current=t.read(e,{type:"array"}),d(h.current.SheetNames),x(0),(()=>{let e=h.current,t=b.current;if(!e||!t)return;let s=e.SheetNames[0];s&&(p(t.utils.sheet_to_json(e.Sheets[s],{header:1,defval:"",raw:!1})),a(!1))})()}}catch(e){n||(o(e.message||"Failed to render"),a(!1))}};return r=t.streamMedia(e,{onChunk:e=>{n||l.push(e)},onDone:()=>{if(n)return;let e=new Uint8Array(l.reduce((e,t)=>e+t.byteLength,0)),t=0;for(let s of l)e.set(s,t),t+=s.byteLength;c(e)},onError:e=>{n||(o(e.message||"Failed to load"),a(!1))}}),()=>{n=!0,r?.()}},[e,t]),(0,r.useEffect)(()=>{let e=h.current,t=b.current;if(!e||!t)return;let s=e.SheetNames[u];s&&p(t.utils.sheet_to_json(e.Sheets[s],{header:1,defval:"",raw:!1}))},[u]),i)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:i});let g=(0,F.$b)(e);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[l&&(0,n.jsxs)("div",{className:"absolute inset-0 z-10 flex items-center justify-center gap-2 bg-surface text-text-muted",children:[(0,n.jsx)(en.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading document..."})]}),!g&&c.length>1&&(0,n.jsx)("div",{className:"flex gap-1 overflow-x-auto bg-surface border-b border-border px-2 py-1 flex-shrink-0",children:c.map((e,t)=>(0,n.jsx)("button",{onClick:()=>x(t),className:`px-2 py-1 text-xs rounded whitespace-nowrap transition-colors ${t===u?"bg-brand-500 text-white":"bg-surface-2 text-text-muted hover:text-text"}`,children:e},t))}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto bg-white text-black",children:g?(0,n.jsx)("div",{ref:f,className:"p-4"}):(0,n.jsx)("div",{className:"p-2",children:(0,n.jsx)("table",{className:"border-collapse",children:(0,n.jsx)("tbody",{children:m.map((e,t)=>(0,n.jsx)("tr",{children:e.map((e,t)=>(0,n.jsx)("td",{className:"border border-gray-300 px-2 py-1 whitespace-pre-wrap align-top",children:e},t))},t))})})})})]})}function l_({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(""),[o,c]=(0,r.useState)(!0);return((0,r.useEffect)(()=>{let s=!1,n=null,r=[],a="application/pdf";c(!0),i(""),l("");let o=t.streamMedia(e,{onMeta:({mime:e})=>{!s&&e&&(a=e)},onChunk:e=>{s||r.push(e)},onDone:()=>{if(s)return;let e=new Blob(r,{type:a}),t=URL.createObjectURL(e);n=t,l(t),c(!1)},onError:e=>{s||(i(e.message||"Failed to load PDF"),c(!1))}});return()=>{s=!0,o(),n&&URL.revokeObjectURL(n)}},[e,t]),o)?(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(en.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading PDF..."})]}):a?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:a}):(0,n.jsx)("iframe",{src:s,title:"PDF preview",className:"h-full w-full bg-bg"})}let lH=e=>(0,F.u)(e)||(0,F.AE)(e)||(0,F.L8)(e)||(0,F.ZH)(e)||(0,F.$b)(e)||(0,F.iB)(e);function lq({filePath:e,fileBus:t}){return(0,F.ZH)(e)?(0,n.jsx)(l_,{filePath:e,fileBus:t},e):(0,F.$b)(e)||(0,F.iB)(e)?(0,n.jsx)(lW,{filePath:e,fileBus:t},e):(0,F.AE)(e)||(0,F.L8)(e)?(0,n.jsx)(lO,{filePath:e,fileBus:t},e):(0,n.jsx)(lK,{filePath:e,fileBus:t},e)}function lU({filePath:e,fileBus:t}){let[s,n]=(0,r.useState)(!0),[l,a]=(0,r.useState)(null),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),f=(0,r.useRef)(""),h=(0,r.useRef)(null),b=(0,r.useRef)(null),[g,v]=(0,r.useState)(!1),y=(0,r.useCallback)(e=>{h.current=e},[]),w=(0,r.useCallback)(async(s=()=>!1)=>{n(!0),o(""),d(!1),v(!1);let r=await t.readFile(e);if(s())return;if(!r?.success){o(r?.error||""),n(!1);return}let l=r.content;if(r.streamInstead)try{let n=[];if(await new Promise((s,r)=>{t.streamMedia(e,{onMeta:()=>{},onChunk:e=>n.push(e),onDone:s,onError:r})}),s())return;l=await new Blob(n).text()}catch(e){if(s())return;o(e?.message||""),n(!1);return}f.current=l,a(l),n(!1)},[e,t]);(0,r.useEffect)(()=>{let t=!1;if(!e){n(!1),a(null),d(!1),o(""),v(!1);return}return w(()=>t),()=>{t=!0}},[e,w]);let j=(0,r.useCallback)(()=>{c?v(!0):w()},[c,w]);(0,r.useEffect)(()=>()=>clearTimeout(b.current),[]);let k=(0,r.useCallback)(e=>{d(e!==f.current)},[]),N=(0,r.useCallback)(async()=>{let s=h.current?.();if(null==s||u||s===f.current)return!0;x(!0);let n=await t.writeFile(e,s);return(x(!1),n?.success)?(f.current=s,d(!1),o(""),p(!0),clearTimeout(b.current),b.current=setTimeout(()=>p(!1),2e3),window.dispatchEvent(new CustomEvent("fileExplorer:fileSaved",{detail:{filePath:e}})),!0):(o(n?.error||""),!1)},[e,t,u]);return{loading:s,content:l,error:i,dirty:c,saving:u,justSaved:m,staleOnDisk:g,register:y,onTextChanged:k,save:N,discard:(0,r.useCallback)(()=>{d(!1),a(f.current)},[]),setError:o,reload:w,onChangedOnDisk:j}}function lV({dirty:e,onSave:t}){let[s,n]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!e)return;let t=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[e]);let l=(0,r.useCallback)(t=>{if(!e)return t();n(()=>t)},[e]),a=(0,r.useCallback)(async()=>{await t()&&(n(null),s?.())},[t,s]),i=(0,r.useCallback)(()=>{n(null),s?.()},[s]);return{guard:l,asking:!!s,saveThenLeave:a,discardAndLeave:i,cancel:(0,r.useCallback)(()=>n(null),[])}}function lX({isOpen:e,fileName:t,onSave:s,onDiscard:l,onCancel:a}){let{t:i}=(0,ec.s)(),o=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{o.current?.focus()});return()=>cancelAnimationFrame(t)},[e]),(0,r.useEffect)(()=>{if(!e)return;let t=e=>{if("Escape"===e.key)e.preventDefault(),e.stopPropagation(),a?.();else if("Enter"===e.key){if(document.activeElement?.tagName==="BUTTON"&&document.activeElement!==o.current)return;e.preventDefault(),e.stopPropagation(),(0,eo.e)(),s?.()}else"d"!==e.key&&"D"!==e.key||e.metaKey||e.ctrlKey||e.altKey||(e.preventDefault(),e.stopPropagation(),(0,eo.e)(),l?.())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e,a,s,l]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[90] flex items-center justify-center px-4",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},onClick:a,children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60"}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:"relative card-elev w-full max-w-sm p-5",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-[15px] font-semibold text-text mb-1.5",children:i("editor.unsavedTitle",{name:t||""})}),(0,n.jsx)("p",{className:"text-[13px] text-text-muted leading-snug mb-5",children:i("editor.unsavedBody")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),l?.()},className:"px-3 py-2 text-[13px] text-text-muted hover:text-red-500 transition-colors flex items-center gap-1",children:[(0,n.jsx)("span",{children:i("editor.discard")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"D"})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{onClick:a,className:"px-4 py-2 text-[13px] text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)("span",{children:i("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{ref:o,onClick:()=>{(0,eo.e)(),s?.()},autoFocus:!0,className:"px-4 py-2 text-[13px] font-semibold text-white bg-brand-500 hover:bg-brand-600 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)("span",{children:i("editor.save")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(en.Lt,{size:10,strokeWidth:2.5})})]})]})]})]}):null}var lG=s(70256),lJ=s(39821),lY=s(48907),lZ=s(74447),lQ=s(15332),l0=s(9722),l1=s(97320),l2=s(99833),l5=s(50807),l3=s(57378),l4=s(41554),l6=s(42760);let l8={javascript:(0,lZ.Q2)(),html:(0,lQ.qy)(),css:(0,l0.AH)(),json:(0,l1.Pq)(),markdown:(0,l2.wD)()};function l9({filePath:e,content:t,onTextChanged:s,onRegisterView:l,onSave:a,onCursorChange:i,line:o,column:c,compact:d=!1,className:u=""}){let x,m,{theme:p}=(0,n_.D)(),f=(0,r.useRef)(null),h=(0,r.useRef)(null),b=(0,r.useRef)(s),g=(0,r.useRef)(i),v=(0,r.useRef)(a);(0,r.useEffect)(()=>{b.current=s},[s]),(0,r.useEffect)(()=>{g.current=i},[i]),(0,r.useEffect)(()=>{v.current=a},[a]);let[y]=tK(F.d5.editorFontSize,F.A0),[w]=tK(F.d5.wordWrap,!0),j=window.innerWidth<eV.jK,k=d?Math.max(F.rL,y-F.xl):y+ +!!j,{extension:N}=(x="."+e.split(".").pop()?.toLowerCase(),{lang:m=F.so[x]||"plaintext",extension:l8[m]||[]});return(0,r.useEffect)(()=>{if(null==t||!f.current)return;let e=lY.$t.create({doc:t,extensions:[lG.oQ,..."dark"===p?[l5.bM]:[],N,...w?[lJ.Lz.lineWrapping]:[],(0,l3.$P)(),(0,l4.yU)(),(0,l4.wm)(),lJ.w4.of([{key:"Mod-s",preventDefault:!0,run:()=>(v.current?.(),!0)},...l4.Bc,...l4.OO,l6.Yc]),lJ.Lz.updateListener.of(e=>{if(e.docChanged&&b.current?.(e.state.doc.toString()),e.selectionSet||e.docChanged){let t=e.state.selection.main.head,s=e.state.doc.lineAt(t);g.current?.({line:s.number,column:t-s.from+1})}}),lJ.Lz.theme({"&":{height:"100%",fontSize:`${k}px`},".cm-scroller":{overflow:"auto",lineHeight:d?"1.35":""},".cm-content":{minHeight:"100%"},".cm-gutters":d?{fontSize:`${Math.max(8,k-1)}px`}:{}})]});return h.current?.destroy(),h.current=new lJ.Lz({state:e,parent:f.current}),l?.(()=>h.current?.state.doc.toString()??null,h.current),()=>{h.current?.destroy(),h.current=null}},[t,e,p,w,k,d]),(0,r.useEffect)(()=>{let e=h.current;if(!e||!o)return;let t=e.state.doc,s=Math.max(1,Math.min(o,t.lines)),n=t.line(s),r=Math.min(n.from+Math.max(0,(c||1)-1),n.to);e.dispatch({selection:{anchor:r},effects:lJ.Lz.scrollIntoView(r,{y:"center"})}),e.focus()},[o,c,t]),(0,n.jsx)("div",{ref:f,className:`h-full w-full overflow-hidden ${u}`})}function l7(e,t){return decodeURIComponent((t&&e.startsWith(t)?e.slice(t.length):e)||"/").replace(/^\//,"")||"/"}function ae({filePath:e,fileBus:t,reloadKey:s=0}){let{t:l}=(0,ec.s)(),{getAuth:i}=(0,a.Fo)(),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(""),[x,m]=(0,r.useState)(0),[p,f]=(0,r.useState)(e),[h,b]=(0,r.useState)({entries:[],index:-1}),g=(0,r.useRef)(null),v=(0,r.useRef)(!1);p!==e&&(f(e),c(null),u(""),b({entries:[],index:-1})),(0,r.useEffect)(()=>{let s=!1;return t.previewStart(e).then(e=>{var n;if(s){e.success&&t.previewEnd(e.sessionId);return}if(!e.success)return void u(e.error||l("editor.previewFailed"));let r=(n=i(),n?.localIp&&"https:"!==window.location.protocol?`http://${n.localIp}`:n?.tunnelUrl||null);if(!r){t.previewEnd(e.sessionId),u(l("editor.previewNoRoute"));return}let a=`/preview/${e.sessionId}`;g.current=e.sessionId,c({origin:r,root:a}),b({entries:[`${a}/${encodeURIComponent(e.entry)}`],index:0})}),()=>{s=!0,g.current&&t.previewEnd(g.current),g.current=null}},[e,t]);let y=o?.root;(0,r.useEffect)(()=>{if(!y)return;let e=e=>{if(e.data?.source!==F.fQ||"string"!=typeof e.data.path)return;let t=e.data.path;if(t.startsWith(y+"/")||t===y){if(v.current){v.current=!1;return}b(e=>{if(e.index>=0&&e.entries[e.index]===t)return e;let s=[...e.entries.slice(0,e.index+1),t];return{entries:s,index:s.length-1}})}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[y]);let w=(0,r.useCallback)(e=>{(0,eo.e)(),v.current=!0,b(t=>{let s=Math.max(0,Math.min(t.entries.length-1,t.index+e));return s===t.index?t:{...t,index:s}})},[]);if(d)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm px-6 text-center",children:d});if(!o)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:l("common.loading")});let j=h.entries[h.index]||o.root,k=`${o.origin}${j}`,N=h.index>0,C=h.index<h.entries.length-1,S="p-1 rounded-[3px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors disabled:opacity-30 disabled:hover:bg-transparent";return(0,n.jsxs)("div",{className:"h-full w-full flex flex-col bg-white",children:[(0,n.jsxs)("div",{className:"h-8 flex items-center gap-0.5 px-1.5 shrink-0 border-b border-border-subtle bg-surface",children:[(0,n.jsx)("button",{onClick:()=>w(-1),disabled:!N,title:l("editor.previewBack"),className:S,children:(0,n.jsx)(en.JG,{size:14})}),(0,n.jsx)("button",{onClick:()=>w(1),disabled:!C,title:l("editor.previewForward"),className:S,children:(0,n.jsx)(en.c_,{size:14})}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),m(e=>e+1)},title:l("editor.reload"),className:S,children:(0,n.jsx)(en.e9,{size:13})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate px-2 py-0.5 mx-1 rounded-[3px] bg-surface-2 text-[11px] text-text-muted",title:l7(j,o.root),children:l7(j,o.root)}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),window.open(k,"_blank","noopener")},title:l("editor.previewOpenTab"),className:S,children:(0,n.jsx)(en.Gr,{size:13})})]}),(0,n.jsx)("iframe",{src:k,sandbox:"allow-scripts allow-forms allow-popups",className:"flex-1 min-h-0 w-full border-0",title:"HTML preview"},`${k}|${h.index}|${s}|${x}`)]})}let at=null,as=0;function an({content:e,reloadKey:t=0}){let l,a,{t:i}=(0,ec.s)(),{theme:o}=(0,n_.D)(),[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(""),m=(0,r.useRef)(null),p=(a=(l=String(e||"").trim()).match(/^```(?:mermaid)?\s*([\s\S]*?)\s*```$/i))?a[1].trim():l,[f,h]=(0,r.useState)(p);return(f!==p&&(h(p),d(""),x("")),(0,r.useEffect)(()=>{let e=!1;if(p)return(!at&&(at=Promise.all([s.e(3755),s.e(7162),s.e(3606)]).then(s.bind(s,86492)).then(e=>e.default)),at).then(async t=>{if(!e){t.initialize({startOnLoad:!1,theme:"dark"===o?"dark":"default",securityLevel:z.Ic});try{let{svg:s}=await t.render(`mmd-${++as}`,p);if(e)return;d(s),x("")}catch(t){if(e)return;d(""),x(t?.message||String(t))}}}).catch(t=>{e||x(t?.message||String(t))}),()=>{e=!0}},[p,o,t]),u)?(0,n.jsxs)("div",{className:"h-full overflow-auto p-3",children:[(0,n.jsx)("p",{className:"text-[11px] text-red-500 mb-2 break-words",children:u}),(0,n.jsx)("pre",{className:"text-[11px] text-text-muted whitespace-pre-wrap break-words",children:p})]}):p?c?(0,n.jsx)("div",{ref:m,className:"h-full overflow-auto p-3 flex items-start justify-center [&_svg]:max-w-full [&_svg]:h-auto",dangerouslySetInnerHTML:{__html:c}}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:i("common.loading")}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:i("editor.mermaidEmpty")})}var ar=s(49430),al=s(93473);let aa=(e,t)=>function({children:s,className:r,node:l,...a}){return(0,n.jsx)(e,{className:r?`${t} ${r}`:t,...a,children:s})},ai={h1:aa("h1","text-xl sm:text-2xl font-bold border-b border-border-subtle pb-2 mt-5 mb-3 text-text first:mt-0"),h2:aa("h2","text-lg sm:text-xl font-bold border-b border-border-subtle pb-1.5 mt-4 mb-2.5 text-text first:mt-0"),h3:aa("h3","text-base sm:text-lg font-semibold mt-3.5 mb-2 text-text"),h4:aa("h4","text-sm sm:text-base font-semibold mt-3 mb-1.5 text-text"),h5:aa("h5","text-xs sm:text-sm font-semibold mt-2.5 mb-1 text-text"),h6:aa("h6","text-xs font-semibold mt-2 mb-1 text-text-muted"),p:aa("p","my-2 leading-relaxed text-text text-sm"),ul:aa("ul","list-disc pl-5 my-2 space-y-1 text-sm text-text"),ol:aa("ol","list-decimal pl-5 my-2 space-y-1 text-sm text-text"),li:aa("li","leading-relaxed"),blockquote:aa("blockquote","border-l-4 border-brand-500/40 pl-3.5 my-2.5 text-text-muted italic text-sm"),th:aa("th","border border-border-subtle bg-surface-2 px-3 py-1.5 font-semibold text-left text-text align-top whitespace-normal break-words"),td:aa("td","border border-border-subtle px-3 py-1.5 text-text align-top whitespace-normal break-words"),hr:aa("hr","border-t border-border-subtle my-4"),img:({alt:e="",node:t,...s})=>(0,n.jsx)("img",{className:"max-w-full h-auto rounded my-2",alt:e,...s}),a:({children:e,className:t,node:s,...r})=>(0,n.jsx)("a",{className:`text-brand-500 hover:underline wrap-anywhere${t?` ${t}`:""}`,target:"_blank",rel:"noopener noreferrer",...r,children:e}),table:({children:e,node:t,...s})=>(0,n.jsx)("table",{className:"w-full table-fixed border-collapse border border-border-subtle text-xs my-3",...s,children:e}),pre:function({children:e,node:t,...s}){let[l,a]=(0,r.useState)(!1),i=(0,r.useRef)(null);return(0,n.jsxs)("div",{className:"relative group/code my-2.5",children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)();let t=i.current?.innerText||"";try{navigator.clipboard.writeText(t)}catch{}a(!0),setTimeout(()=>a(!1),2e3)},className:"absolute top-2 right-2 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-100 sm:opacity-0 sm:group-hover/code:opacity-100 transition-opacity z-10",title:"Copy code",children:l?(0,n.jsx)(en.aJ,{size:13,className:"text-brand-500"}):(0,n.jsx)(en.QR,{size:13})}),(0,n.jsx)("pre",{ref:i,className:"p-3 rounded bg-surface-2 whitespace-pre-wrap break-words text-[12px] font-mono border border-border-subtle text-text [&_code]:bg-transparent [&_code]:p-0 [&_code]:border-0 [&_code]:text-text",...s,children:e})]})},code:({children:e,className:t,node:s,...r})=>{let l=/language-/.test(t||"");return(0,n.jsx)("code",{className:`${l?"font-mono text-[12px] text-text":"font-mono text-[0.9em] text-accent wrap-anywhere"}${t?` ${t}`:""}`,...r,children:e})},input:({type:e,checked:t,node:s,...r})=>"checkbox"===e?(0,n.jsx)("input",{type:"checkbox",checked:t,readOnly:!0,className:"mr-2 rounded accent-brand-500 cursor-default",...r}):(0,n.jsx)("input",{type:e,...r})},ao=(0,r.memo)(function({content:e,components:t}){return(0,n.jsx)(ar.oz,{remarkPlugins:[al.A],components:t?{...ai,...t}:ai,children:e})},(e,t)=>e.content===t.content);function ac({content:e}){let{t}=(0,ec.s)();return e?.trim()?(0,n.jsx)("div",{className:"h-full overflow-auto p-4 sm:p-6 bg-bg select-text",children:(0,n.jsx)("div",{className:"max-w-4xl mx-auto",children:(0,n.jsx)(ao,{content:e})})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:t("common.empty",{defaultValue:"Empty file"})})}function ad({kind:e,filePath:t,fileBus:s,content:r,reloadKey:l=0}){return"html"===e?(0,n.jsx)(ae,{filePath:t,fileBus:s,reloadKey:l}):"mermaid"===e?(0,n.jsx)(an,{content:r,reloadKey:l}):"markdown"===e?(0,n.jsx)(ac,{content:r}):null}var au=s(23910);s(14876);let ax=["diff --git","index ","new file","deleted file","--- ","+++ "];function am({diff:e,compact:t=!1,className:s=""}){let[l,a]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(t)return;let e=window.matchMedia(`(min-width: ${F.gh}px)`),s=()=>a(e.matches);return s(),e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[t]);let i=!t&&l,o=(0,r.useCallback)(t=>{if(t&&e&&i)try{new au.LU(t,e,{drawFileList:!1,matching:"words",outputFormat:"side-by-side",renderNothingWhenEmpty:!1}).draw()}catch{t.replaceChildren(Object.assign(document.createElement("pre"),{className:"text-text-muted p-4",textContent:e}))}},[e,i]),c=(0,r.useMemo)(()=>i||!e?[]:function(e){let t=[],s=0,n=0;for(let r of e.split("\n")){if(ax.some(e=>r.startsWith(e))){r.startsWith("diff --git")&&t.push({type:"file",text:r.replace("diff --git a/","").split(" b/")[0]});continue}if(r.startsWith("@@")){let e=r.match(/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);e&&(s=parseInt(e[1],10),n=parseInt(e[2],10)),t.push({type:"hunk",text:r});continue}r.startsWith("+")?t.push({type:"add",text:r.slice(1),newLn:n++}):r.startsWith("-")?t.push({type:"del",text:r.slice(1),oldLn:s++}):t.push({type:"ctx",text:r.slice(1),oldLn:s++,newLn:n++})}return t}(e),[i,e]);return i?(0,n.jsx)("div",{ref:o,className:`diff-themed ${t?"diff-themed-compact":"bg-surface rounded"} overflow-hidden text-sm ${s}`}):(0,n.jsx)("div",{className:`w-full max-w-full overflow-hidden font-mono leading-[1.6] ${t?"text-[10px] leading-[1.45]":"rounded-lg border border-border bg-surface text-[12.5px]"} ${s}`,children:c.map((e,t)=>{if("file"===e.type)return(0,n.jsx)("div",{className:"px-3 py-2 bg-surface-2 text-text font-semibold break-all",children:e.text},t);if("hunk"===e.type)return(0,n.jsx)("div",{className:"px-3 py-1 bg-surface-2/60 text-text-muted select-none break-all",children:e.text},t);let s="add"===e.type?e.newLn:"del"===e.type?e.oldLn:e.newLn,r="add"===e.type?"bg-[rgba(var(--success-rgb),0.14)]":"del"===e.type?"bg-[rgba(var(--danger-rgb),0.14)]":"",l="add"===e.type?"text-[var(--success)]":"del"===e.type?"text-[var(--danger)]":"text-text-subtle",a="add"===e.type?"+":"del"===e.type?"-":" ";return(0,n.jsxs)("div",{className:`flex ${r}`,children:[(0,n.jsx)("span",{className:"shrink-0 w-9 px-1 text-right text-text-subtle bg-black/5 select-none",children:s}),(0,n.jsx)("span",{className:`shrink-0 w-4 text-center font-bold ${l} select-none`,children:a}),(0,n.jsx)("span",{className:"flex-1 min-w-0 pr-2 whitespace-pre-wrap break-words text-text",children:e.text||"\xa0"})]},t)})})}function ap({title:e,badge:t,badgeColor:s,img:r,loading:l,error:a,t:i}){var o;let c,d,u=[(c=r?.originalWidth||r?.width,d=r?.originalHeight||r?.height,c&&d?`${c} \xd7 ${d}`:""),!(o=r?.size||r?.originalSize)?"":o<1024?`${o} B`:o<1048576?`${(o/1024).toFixed(1)} KB`:`${(o/1048576).toFixed(1)} MB`].filter(Boolean).join(" \xb7 ");return(0,n.jsxs)("div",{className:"flex-1 flex flex-col rounded-brand border border-border-subtle bg-surface overflow-hidden min-h-[220px]",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border-subtle flex items-center justify-between bg-surface-2/60 shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-text",children:e}),t&&(0,n.jsx)("span",{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded-[3px] ${s}`,children:t})]}),u&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted font-mono",children:u})]}),(0,n.jsx)("div",{className:"flex-1 p-3 flex items-center justify-center bg-surface-2/20 min-h-[160px] overflow-hidden relative",children:l?(0,n.jsxs)("div",{className:"flex items-center gap-2 text-text-muted text-xs",children:[(0,n.jsx)(en.kr,{size:16,className:"animate-spin"}),(0,n.jsx)("span",{children:i("common.loading")})]}):a?(0,n.jsx)("div",{className:"text-xs text-text-muted text-center px-4 py-6",children:a}):r?.dataUrl?(0,n.jsx)("img",{src:r.dataUrl,alt:e,className:"max-h-[320px] max-w-full object-contain rounded drop-shadow-sm select-none"}):(0,n.jsx)("div",{className:"text-xs text-text-muted",children:i("git.noChanges")})})]})}function af({filePath:e,status:t,workspace:s,fileBus:l,compact:a=!1}){let{t:i}=(0,ec.s)(),o="A"===t||"?"===t,c="D"===t,d=!o,u=!c,[x,m]=(0,r.useState)(null),[p,f]=(0,r.useState)(d),[h,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)(u),[j,k]=(0,r.useState)(""),[N,C]=(0,r.useState)(e);N!==e&&(C(e),m(null),f(d),b(""),v(null),w(u),k("")),(0,r.useEffect)(()=>{let t=!1;if(!e||!l)return;let n=s&&!e.startsWith("/")?`${s}/${e}`:e,r=s&&e.startsWith(s)?e.slice(s.length).replace(/^\//,""):e,a=setTimeout(()=>{d&&(f(!0),b(""),l.gitShowMedia?.(s,r,"HEAD").then(e=>{t||(f(!1),e?.success?m(e):b(e?.error||i("git.noOldVersion",{defaultValue:"No previous version in HEAD"})))}).catch(e=>{t||(f(!1),b(e?.message||"Failed to load old version"))})),u&&(w(!0),k(""),l.readMedia?.(n).then(e=>{t||(w(!1),e?.success?v(e):k(e?.error||i("git.noNewVersion",{defaultValue:"Failed to load working image"})))}).catch(e=>{t||(w(!1),k(e?.message||"Failed to load new version"))}))},0);return()=>{t=!0,clearTimeout(a)}},[e,s,l,d,u,i]);let S=e?e.split("/").pop():"",E=c||d&&!h&&(p||!!x?.dataUrl),R=E&&u;return(0,n.jsx)("div",{className:"h-full overflow-y-auto p-2 sm:p-3 flex flex-col gap-3",children:(0,n.jsxs)("div",{className:`flex-1 ${!a&&R?"grid grid-cols-1 md:grid-cols-2 gap-3":"flex flex-col gap-3"}`,children:[E&&(0,n.jsx)(ap,{title:c?`${S} (Deleted)`:"Old (HEAD)",badge:c?"DELETED":"ORIGINAL",badgeColor:"bg-red-500/15 text-red-400",img:x,loading:p,error:h,t:i}),u&&(0,n.jsx)(ap,{title:o?`${S} (Added)`:"New (Working Tree)",badge:o?"NEW":"MODIFIED",badgeColor:"bg-green-500/15 text-green-400",img:g,loading:y,error:j,t:i})]})})}function ah({diffPath:e,workspace:t,fileBus:s,compact:l=!1}){let{t:a}=(0,ec.s)(),{status:i,repoPath:o,filePath:c}=(0,F.qu)(e),d=o||t,u=(0,F.u)(c),[x,m]=(0,r.useState)(!u),[p,f]=(0,r.useState)(""),[h,b]=(0,r.useState)("");return((0,r.useEffect)(()=>{if(u)return;let e=!1,t=setTimeout(async()=>{m(!0),b("");let t=await s.gitDiff?.(d,c,i);e||(t?.success?f(t.diff||""):b(t?.error||""),m(!1))},0);return()=>{e=!0,clearTimeout(t)}},[d,c,i,s,u]),u)?(0,n.jsx)(af,{filePath:c,status:i,workspace:d,fileBus:s,compact:l}):(0,n.jsxs)("div",{className:`h-full overflow-auto ${l?"p-0":"p-2 sm:p-3"}`,children:[h&&(0,n.jsx)("div",{className:"bg-red-500/20 border border-red-500/50 rounded px-4 py-2 text-red-400 text-sm mb-3",children:h}),x?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted text-sm",children:a("common.loading")}):p?(0,n.jsx)(am,{diff:p,compact:l}):(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted text-sm",children:a("git.noChanges")})]})}function ab({filePath:e,workspace:t,fileBus:s,width:l,onResize:a,onClose:i,onOpenFull:o,onOpenFile:c,isDesktop:d=!0,previewSeq:u=0,artifactTitle:x=null}){let{t:m}=(0,ec.s)(),p=(0,F.pA)(e),f=p?(0,F.qu)(e):null,h=f?.repoPath||t,b=p?f.filePath:e,g=f?f.repoPath?`${f.repoPath.replace(/\/$/,"")}/${f.filePath}`:f.filePath.startsWith("/")?f.filePath:`${t?.replace(/\/$/,"")||""}/${f.filePath}`:"",v=!!e&&!p&&!lH(e),y=lU({filePath:v?e:"",fileBus:s}),w=(0,r.useRef)(y);(0,r.useEffect)(()=>{w.current=y},[y]);let j=lV({dirty:v&&y.dirty,onSave:y.save}),k=v?(0,F.YO)(e):null,N=u>0,[C,S]=(0,r.useState)(N),[E,R]=(0,r.useState)(0),[T,$]=(0,r.useState)(e),[M,z]=(0,r.useState)(!1),[P,I]=(0,r.useState)(u);(T!==e||P!==u)&&($(e),I(u),S(N)),y.justSaved!==M&&(z(y.justSaved),y.justSaved&&R(e=>e+1)),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&j.guard(i)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[j,i]);let A=e&&!p?e.slice(0,e.lastIndexOf("/")):"",L=(0,r.useMemo)(()=>A?[A]:[],[A]),D=rH(),B=(0,r.useCallback)(()=>{R(e=>e+1),w.current?.onChangedOnDisk()},[]);if(r_({dirs:L,fileBus:s,enabled:!!A&&D,debounceMs:F.Jl.PREVIEW_DEBOUNCE_MS,onDirsChanged:B}),!e)return null;let K=b.split("/").pop(),O=t&&b.startsWith(t)?b.slice(t.length).replace(/^\//,""):b;return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg border-l border-border-subtle relative shrink min-w-0",style:d?{width:l,flexBasis:l,minWidth:eV.Ao.min}:void 0,children:[(0,n.jsxs)("div",{style:{height:32},className:"px-2 flex items-center gap-1.5 border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:r6({name:K,type:"file"},14)}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-[12px] text-text",title:O,children:K}),x&&(0,n.jsx)("span",{className:"flex-shrink-0 px-1.5 py-px rounded-[3px] text-[9px] font-medium uppercase tracking-wide bg-brand-500/15 text-brand-500",children:m("editor.artifact")}),p&&(0,n.jsx)("span",{className:`text-[10px] font-bold flex-shrink-0 ${F.vs[f.status]||"text-text-muted"}`,children:f.status}),k&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),S(e=>!e)},title:m(C?"editor.editCode":"editor.preview"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:C?(0,n.jsx)(en.GD,{size:13}):(0,n.jsx)(en.kU,{size:13})}),v&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),y.save()},disabled:!y.dirty||y.saving,title:m("editor.save"),className:`p-1 rounded-[3px] transition-colors disabled:opacity-30 ${y.dirty?"text-brand-500 hover:bg-surface-2":"text-text-muted"}`,children:(0,n.jsx)(en.eM,{size:13})}),(p?!!c:o&&d)&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),p?c(g):o(e)},title:m(p?"git.openFile":"editor.openFull"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:p?(0,n.jsx)(en.GD,{size:13}):(0,n.jsx)(en.Gr,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),j.guard(i)},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:(0,n.jsx)(en.X,{size:13})})]}),y.error&&v&&(0,n.jsx)("div",{className:"px-3 py-1.5 text-[11px] text-red-500 bg-red-500/10 border-b border-border-subtle break-words",children:y.error}),y.staleOnDisk&&(0,n.jsxs)("div",{className:"px-3 py-1.5 flex items-center gap-2 text-[11px] text-amber-500 bg-amber-500/10 border-b border-border-subtle",children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:m("editor.changedOnDisk")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),y.reload()},className:"shrink-0 px-1.5 py-0.5 rounded-[3px] hover:bg-amber-500/20 font-medium transition-colors",children:m("editor.reloadFromDisk")})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:p?(0,n.jsx)(ah,{diffPath:(0,F.Dk)(f.status,f.filePath),workspace:h,fileBus:s,compact:!0}):lH(e)?(0,n.jsx)(lq,{filePath:e,fileBus:s}):C&&k?(0,n.jsx)(ad,{kind:k,filePath:e,fileBus:s,content:y.content,reloadKey:E}):y.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:m("common.loading")}):(0,n.jsx)(l9,{filePath:e,content:y.content,onTextChanged:y.onTextChanged,onRegisterView:y.register,onSave:y.save,compact:!0})}),(0,n.jsx)(lX,{isOpen:j.asking,fileName:K,onSave:j.saveThenLeave,onDiscard:j.discardAndLeave,onCancel:j.cancel}),d&&(0,n.jsx)("div",{onPointerDown:e=>eU(e,{startWidth:l,axis:-1,onWidth:e=>a?.(e)}),className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})]})}function ag(){let[e,t]=(0,r.useState)(null),s="mouse"!==tF();return((0,r.useEffect)(()=>{if(s)return;let e=null,n=null,r=()=>{clearTimeout(e),n=null,t(null)},l=s=>{let r=s.target?.closest?.("[data-tip]");if(r!==n){if(clearTimeout(e),n=r,!r)return t(null);e=setTimeout(()=>{let e;(e=r.getAttribute("data-tip"))&&function(e){let t=e.getBoundingClientRect();if(e.scrollHeight>e.clientHeight+eV.de.SLACK_PX)return!0;let s=document.createRange();s.selectNodeContents(e);let n=s.getBoundingClientRect().width;s.detach();let r=getComputedStyle(e),l=parseFloat(r.paddingLeft)+parseFloat(r.paddingRight);return n>t.width-l+eV.de.SLACK_PX}(r)&&t({text:e,...function(e){let{GAP_PX:t,EDGE_PX:s,MAX_WIDTH_PX:n,EST_HEIGHT_PX:r}=eV.de,l=e.bottom+t,a=l+r>window.innerHeight-s;return{left:Math.min(Math.max(e.left,s),Math.max(s,window.innerWidth-n-s)),top:a?void 0:l,bottom:a?window.innerHeight-e.top+t:void 0}}(r.getBoundingClientRect())})},"focusin"===s.type?0:eV.de.DELAY_MS)}},a=e=>{"Escape"===e.key&&r()};return document.addEventListener("mouseover",l,!0),document.addEventListener("focusin",l,!0),document.addEventListener("focusout",r,!0),document.documentElement.addEventListener("mouseleave",r),document.addEventListener("mousedown",r,!0),document.addEventListener("keydown",a,!0),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{clearTimeout(e),document.removeEventListener("mouseover",l,!0),document.removeEventListener("focusin",l,!0),document.removeEventListener("focusout",r,!0),document.documentElement.removeEventListener("mouseleave",r),document.removeEventListener("mousedown",r,!0),document.removeEventListener("keydown",a,!0),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[s]),e)?(0,sU.createPortal)((0,n.jsx)("div",{role:"tooltip",className:"fixed z-[90] pointer-events-none px-2 py-1 rounded-[3px] bg-surface-2 border border-border-subtle shadow-lg text-[11px] text-text break-words animate-in fade-in duration-100",style:{left:e.left,top:e.top,bottom:e.bottom,maxWidth:eV.de.MAX_WIDTH_PX},children:e.text}),document.body):null}let av=(0,r.memo)(function({height:e=1,className:t=""}){let s=(0,r.useRef)(null),[l,a]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=s.current;if(!e)return;let t=new ResizeObserver(([t])=>{let s=t?.contentRect?.width||e.offsetWidth;s>0&&a(Math.round(s))});return t.observe(e),()=>t.disconnect()},[]);let i=l||600,o=Math.max(1.8,(i+140)/250);return(0,n.jsx)("div",{ref:s,"aria-hidden":"true",className:`absolute inset-x-0 top-0 overflow-hidden pointer-events-none ${t}`,style:{height:e,"--pane-w":`${i}px`,"--beam-w":"140px","--beam-dur":`${o.toFixed(2)}s`,"--beam-delay":`${(o/2).toFixed(2)}s`},children:(0,n.jsxs)("div",{className:"relative w-full h-full bg-blue-500/10",children:[(0,n.jsx)("div",{className:"pane-light-beam"}),(0,n.jsx)("div",{className:"pane-light-beam pane-light-beam-2"})]})})}),ay=["newTerminal","palette","help"];function aw({onAddWorkspace:e,onOpenRemote:t,recent:s=[],homeDir:r,onOpenRecent:l}){let{t:a}=(0,ec.s)(),i=[...ay.map(e=>ts.find(t=>t.id===e)).filter(Boolean),tn];return(0,n.jsxs)("div",{className:"h-full w-full empty-stage empty-stage-h",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),e?.()},disabled:!e,className:"empty-half text-left transition-all duration-150 enabled:hover:opacity-90 enabled:active:scale-[0.99] disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",a("workspaces.emptyTagWorkspace")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordTerminal")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaWorkspace")}}),(0,n.jsxs)("span",{className:"empty-go",children:[a("workspaces.selectFolder"),(0,n.jsx)(en.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]}),!!s.length&&(0,n.jsx)("span",{className:"flex flex-wrap gap-1.5 mt-4 max-w-full",children:s.slice(0,4).map(e=>(0,n.jsx)("span",{role:"button",title:e.path,onClick:t=>{t.stopPropagation(),(0,eo.e)(),l?.(e.path)},className:"welcome-chip path-tail px-2 py-1 text-[11px] font-mono text-text-muted rounded-full truncate max-w-[180px]",children:sf(e.path,r)},e.path))})]}),!!t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"empty-hairline","aria-hidden":!0}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),t?.()},className:"empty-half text-left transition-all duration-150 enabled:hover:opacity-90 enabled:active:scale-[0.99] disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"02"})," / ",a("workspaces.emptyTagRemote")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordRemote")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaRemote")}}),(0,n.jsxs)("span",{className:"empty-go",children:[a("menu.remoteDesktop"),(0,n.jsx)(en.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]})]})]}),(0,n.jsx)("div",{className:"hidden lg:flex absolute bottom-0 inset-x-0 z-[2] flex-wrap items-center justify-center gap-x-5 gap-y-1.5 px-8 pb-6 font-mono text-[11px] text-text-subtle",children:i.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[a(`shortcuts.${e.id}`),(0,n.jsx)("kbd",{className:"px-1.5 py-0.5 rounded-[4px] bg-surface-2/60 text-text-muted whitespace-nowrap",children:to(e)})]},e.id))})]})}let aj=new Set(["Agent","Task","Workflow","task","browser_subagent","invoke_subagent","spawn_agent"]),ak=e=>e?.input?.subagent_type||e?.input?.agent||e?.input?.description||"agent",aN=e=>e?.input?.description||e?.input?.command||"shell";function aC(e=[],t=""){if(!t)return null;let s=null,n=e=>{for(let r of e||[]){if(r?.id===t)return s=r,!0;if(r?.children?.length&&n(r.children))return!0}return!1};for(let t=e.length-1;t>=0&&!s;t--)n(e[t]?.tools);return s}function aS(e=[],t=""){let s=aC(e,t);if(!s)return null;let n=s;for(;"running"===n.status;){let e=n.children||[],t=e.filter(e=>e?.status==="running").pop()||e[e.length-1];if(!t||t===n)break;n=t}return n}function aE(e){return(e||[]).map(e=>{let t=e.children?aE(e.children):null;return"running"!==e.status||e.async?t?{...e,children:t}:e:{...e,status:"done",...t?{children:t}:null}})}function aR(e,t,s){let n=!1,r=(e||[]).map(e=>{if(t(e))return n=!0,s(e);let r=aR(e.children,t,s);return r?(n=!0,{...e,children:r}):e});return n?r:null}var aT=s(91524);function a$(e,t="claude"){if(!e?.name)return"";let{name:s,input:n={}}=e,r=az(n.file_path||n.path);switch((0,aT.$Z)(t,s)){case"bash":return aI(n.description||n.command||"shell",aM);case"file":return aI(`${/^(list|list_dir|ls)$/i.test(s)?"Listing":"Reading"} ${r}`,aM);case"search":return aI([n.pattern?`"${n.pattern}"`:n.query||n.url||"",r?`in ${r}`:""].filter(Boolean).join(" "),aM);case"diff":return aI(`${/^(Write|write_to_file)$/i.test(s)?"Writing":"Editing"} ${az(n.file_path||n.filePath||n.file||n.path)||aL(n)}`,aM);case"agent":return aI(n.description||aL(n)||"sub-agent",aM);case"plan":return aI(az(n.path)||s,aM);default:return aI([aA(s),aL(n)].filter(Boolean).join(" "),aM)}}let aM=60,az=e=>"string"==typeof e&&e.replace(/\\/g,"/").split("/").filter(Boolean).pop()||"",aP=e=>{if("string"!=typeof e)return"";let t=e.slice(-512).split("\n");for(let e=t.length-1;e>=0;e--){let s=t[e].trim();if(s)return s}return""},aI=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,aA=(e="")=>{let t=/^mcp__[^_]+(?:_[^_]+)*__(.+)$/.exec(e);return t?t[1]:e},aL=(e={})=>e.url||e.query||e.pattern||e.name||az(e.path)||az(e.file_path)||"";function aD(e){let t=Number(e)||0,s=t>=1e6?[1e6,"M"]:t>=1e3?[1e3,"k"]:null;if(!s)return String(t);let n=t/s[0];return`${n>=100?Math.round(n):n.toFixed(1).replace(/\.0$/,"")}${s[1]}`}let aB=new Set(["Edit","Write","MultiEdit","NotebookEdit","edit","write","patch","apply","write_to_file","replace_file_content","multi_replace_file_content","sed_file","file_change"]),aF=e=>"string"==typeof e&&e?e.split("\n").length:0;function aK(e=[]){let t=0,s=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if("user"===r.role)break;let l=r.diffs||[];for(let e of l)for(let n of(e.patch||e.diff||"").split("\n"))n.startsWith("+")&&!n.startsWith("+++")?t++:n.startsWith("-")&&!n.startsWith("---")&&s++;let a=new Set(l.map(e=>e.file).filter(Boolean));for(let e of r.tools||[]){if(!aB.has(e?.name))continue;let n=e.input?.file_path||e.input?.path||e.input?.file||"";if(n&&a.has(n))continue;let r=function(e){let t=e.input;if(!t||"string"==typeof t)return null;let s=t.file_path||t.path||t.file||"",n=Array.isArray(t.edits)?t.edits:Array.isArray(t.replacement_chunks)?t.replacement_chunks:Array.isArray(t.replacements)?t.replacements:null;if(n){let e=0,t=0;for(let s of n)t+=aF(s.old_string??s.oldString??s.old??s.target_content),e+=aF(s.new_string??s.newString??s.new??s.replacement_content);return{file:s,added:e,removed:t}}if("string"==typeof t.content&&t.content)return{file:s,added:aF(t.content),removed:0};let r=t.old_string??t.oldString??t.old_str??t.target_content??t.TargetContent,l=t.new_string??t.newString??t.new_str??t.replacement_content??t.ReplacementContent;return void 0===r&&void 0===l?null:{file:s,added:aF(l),removed:aF(r)}}(e);r&&(t+=r.added,s+=r.removed)}}return{added:t,removed:s}}let aO=/^\s*<(task-notification|environment_context|turn_aborted|persisted-output)>/,aW=e=>aO.test(String(e||""));function a_(e){let t=String(e||"").trim();if(!t)return"";if(!t.startsWith("<persisted-output>"))return t;let s=/saved to: (\S+)/.exec(t);return s?`saved to: ${s[1]}`:""}let aH=new Set(["completed","failed","killed","stopped"]),aq=(e,t=Date.now())=>e?.usage?.duration_ms>0?e.usage.duration_ms:e?.endedAt&&e?.startedAt?Math.max(0,e.endedAt-e.startedAt):e?.startedAt?Math.max(0,t-e.startedAt):0,aU=(e,t)=>t?.startedAt?null:{startedAt:Date.now()-(Number.isFinite(e)?Math.max(0,e):0)},aV=(e=[])=>{for(let t=e.length-1;t>=0;t--)if(e[t]?.compacting)return t;return -1},aX=new Set(["compacting"]);function aG(e,t,s,n,r){if("system"!==t)return e;let l=Number.isFinite(r)?r:n?.ageMs;switch(s){case"task_started":if(!n?.task_id)return e;return aJ(e,n.task_id,{taskId:n.task_id,status:"running",background:!!n.is_backgrounded,...n.tool_use_id?{toolUseId:n.tool_use_id}:null,...n.description?{description:n.description}:null,...n.subagent_type?{subagentType:n.subagent_type}:null,...n.task_type?{taskType:n.task_type}:null,...aU(l,e.find(e=>e.taskId===n.task_id))});case"task_updated":{let t=e.findIndex(e=>e.taskId===n?.task_id);if(-1===t)return e;let s=n.patch||{},r=e.slice(),a=s.status&&!aH.has(s.status),i={...r[t],...s.status?{status:s.status}:null,...s.description?{description:s.description}:null,...s.end_time?{endedAt:s.end_time}:null};return a&&delete i.endedAt,a&&r[t].endedAt&&Object.assign(i,aU(l,null)),r[t]=i,r}case"task_notification":{let t=e.findIndex(e=>e.taskId===n?.task_id);if(-1===t)return e;let s=e.slice();return s[t]={...s[t],status:n.status||"completed",endedAt:s[t].endedAt||Date.now(),...n.output_file?{outputFile:n.output_file}:null,...n.summary?{summary:n.summary}:null,...n.usage?{usage:n.usage}:null},s}case"background_tasks_changed":{let t=new Set((n?.tasks||[]).map(e=>e.task_id)),s=e;for(let e of(s.some(e=>e.background&&!aH.has(e.status)&&!t.has(e.taskId))&&(s=s.map(e=>!e.background||aH.has(e.status)||t.has(e.taskId)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()})),n?.tasks||[]))s=aJ(s,e.task_id,{background:!0,status:"running",...e.description?{description:e.description}:null,...e.task_type?{taskType:e.task_type}:null,...aU(l,s.find(t=>t.taskId===e.task_id))});return s}default:return e}}function aJ(e,t,s){let n=e.findIndex(e=>e.taskId===t);if(-1===n)return[...e,{taskId:t,toolUseId:"",...s}];let r={...e[n],...s};if(aY(r,e[n]))return e;let l=e.slice();return l[n]=r,l}let aY=(e,t)=>{let s=Object.keys(e);return s.length===Object.keys(t).length&&s.every(s=>e[s]===t[s])};function aZ(e,t){let s=[];for(let t of e||[])t&&(s=aG(s,t.type||"system",t.subtype||"",t.record||null,t.ageMs));let n=new Map(s.map(e=>[e.taskId,e]));for(let e of t||[])e?.taskId&&n.set(e.taskId,{...n.get(e.taskId),...e});return[...n.values()]}function aQ(e,t){if(!t)return null;if(e.startsWith("session.next."))return"session.next.retried"===e?{subtype:e,level:"warning",content:`Retrying (attempt ${t.attempt??"?"}): ${t.error?.message||""}`.trim()}:"session.next.compaction.started"===e?{subtype:e,level:"info",content:"Compacting…",compacting:!0}:"session.next.compaction.ended"===e?{subtype:e,level:"info",content:"Compacted",compactSettled:!0}:"session.next.revert.staged"===e?{subtype:e,level:"info",content:"Rewind staged"}:"session.next.revert.committed"===e?{subtype:e,level:"info",content:"Rewound the conversation"}:"session.next.agent.switched"===e?{subtype:e,level:"info",content:`Agent: ${t.agent||""}`}:null;if("warning"===e||"guardianWarning"===e||"configWarning"===e||"deprecationNotice"===e)return null;let s="error"===e?String(t.error?.message||"").trim():"warning"===e||"guardianWarning"===e?String(t.message||"").trim():"configWarning"===e||"deprecationNotice"===e?[t.summary,t.details].filter(Boolean).join(" — ").trim():"model/rerouted"===e?`Model rerouted: ${t.fromModel} → ${t.toModel}`:"";if(s){let n="error"!==e||t.willRetry?"warning":"error";return{subtype:e,level:n,content:s}}if("thread/compacted"===e)return{subtype:e,level:"info",content:"Compacted",compactSettled:!0};if("system"===e&&"compact_boundary"===t.subtype){let e=function(e){let t=e.compact_metadata||e.compactMetadata;if(!t||"object"!=typeof t)return null;let s=e=>Number.isFinite(e)?e:null,n=s(t.pre_tokens??t.preTokens),r=s(t.post_tokens??t.postTokens),l=null!=n&&null!=r?`${aD(n)} → ${aD(r)} tokens`:"";return{trigger:t.trigger||"auto",preTokens:n,postTokens:r,durationMs:s(t.duration_ms??t.durationMs),...l?{detail:l}:null}}(t),s="string"==typeof t.content?t.content.trim():"";return e||s?{subtype:"compact_boundary",level:t.level||"info",content:s||"Compacted",compactSettled:!0,...e?{compact:e}:null}:null}if("system"===e&&"status"===t.subtype){if(aX.has(t.status))return{subtype:"status",level:"info",content:"Compacting…",compacting:!0};if(null!=t.status&&!t.compact_result)return null;let e="failed"===t.compact_result;return{subtype:"status",level:e?"error":"info",content:e?String(t.compact_error||"").trim()||"Compaction failed":"",compactSettled:!0}}if("attachment"===e){let e=t.attachment||t,s=e.type||"";if("edited_text_file"===s)return null;if("hook_success"===s){if("SessionStart"!==e.hookEvent)return null;let t=a_(e.content);return t?{subtype:s,level:"info",content:t}:null}let n="queued_command"===s?e.prompt:"";if("string"!=typeof n||!n.trim()||aW(n))return null;let r=a_(n);return r?{subtype:s,level:"info",content:r}:null}if("system"!==e||aW(t.content))return null;let n="string"==typeof t.content&&t.content.trim()?t.content.trim():"string"==typeof t.error?.formatted&&t.error.formatted.trim()?t.error.formatted.trim():"string"==typeof t.error?.message&&t.error.message.trim()?t.error.message.trim():"";return n?{subtype:t.subtype||"",level:t.level||"info",content:n}:null}function a0(e=[],t){if(!t)return e||[];if(t.replaceAll)return t.todos||[];let s=e||[],n=t.taskId?String(t.taskId):"",r=t.id?String(t.id):"",l=s.findIndex(e=>n&&String(e.taskId)===n||r&&e.id&&String(e.id)===r);if("deleted"===t.status)return -1===l?s:[...s.slice(0,l),...s.slice(l+1)];if(-1===l)return t.subject?[...s,t]:s;let a=s.slice();return a[l]={...a[l],...t},a}let a1=(0,tg.KU)(()=>window.localStorage),a2=null,a5=a1&&{...a1,setItem:(e,t)=>{t!==a2&&(a2=t,a1.setItem(e,t))}},a3=0,a4=e=>`${e}-${Date.now()}-${++a3}`,a6={messages:[],isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null,gateError:!1,activeBlocked:null,permissionMode:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0},metadata:{model:"",skills:[],mcpServers:[]},tasks:[],harnessTasks:[],queue:[]},a8=(e,t)=>({...a6,...e.bySession[t]});function a9(e,t){if(!t?.length)return null;let s=e.filter(e=>e.toolUseId&&aH.has(e.status));if(!s.length)return null;let n=t;for(let e of s){let t="failed"===e.status?"error":"done",s=n.map(s=>{if(!s.tools)return s;let n=aR(s.tools,t=>t.id===e.toolUseId&&"running"===t.status,e=>({...e,status:t}));return n?{...s,tools:n}:s});s.some((e,t)=>e!==n[t])&&(n=s)}return n===t?null:n}let a7=(0,b.v)((0,tg.Zr)((e,t)=>({bySession:{},initSession:s=>{s&&!t().bySession[s]&&e(e=>({bySession:{...e.bySession,[s]:{...a6}}}))},setTaskRecords:(t,s)=>{t&&Array.isArray(s)&&e(e=>{let n=a8(e,t),r=aZ(s,[]),l=a9(r,n.messages);return r!==n.harnessTasks||l?{bySession:{...e.bySession,[t]:{...n,harnessTasks:r,...l?{messages:l}:null}}}:e})},applyTaskRecords:(t,s)=>{t&&s?.length&&e(e=>{let n=a8(e,t),r=n.harnessTasks||[],l=r;for(let[e,t,n,r]of s)l=aG(l,e,t,n,r);let a=a9(l,n.messages);return l!==r||a?{bySession:{...e.bySession,[t]:{...n,harnessTasks:l,...a?{messages:a}:null}}}:e})},addNotice:(t,s)=>{let n="string"==typeof s?.content?s.content.trim():"";!t||(n||s?.compactSettled)&&e(e=>{let r=a8(e,t);if(s?.compacting&&-1!==aV(r.messages))return e;if(-1!==(s?.compactSettled?aV(r.messages):-1)){let l=r.messages.findIndex(e=>e?.compacting),a=r.messages.filter(e=>!e?.compacting);return n&&a.splice(l,0,{id:a4("n"),role:"notice",subtype:s.subtype||"",level:s.level||"info",content:n,...s.compact?{compact:s.compact}:null}),{bySession:{...e.bySession,[t]:{...r,messages:a}}}}if(!n)return e;let l={id:a4("n"),role:"notice",subtype:s.subtype||"",level:s.level||"info",content:n,...s.file?{file:s.file}:null,...s.compact?{compact:s.compact}:null,...s.compacting?{compacting:!0}:null},a=r.messages[r.messages.length-1],i=!a||"assistant"!==a.role||a.content||a.thinking||(a.tools||[]).length?[...r.messages,l]:[...r.messages.slice(0,-1),l];return{bySession:{...e.bySession,[t]:{...r,messages:i}}}})},setPermissionMode:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,permissionMode:s}}}})},setTurnRunning:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,isTurnRunning:s}}}})},setQueue:(t,s)=>{t&&e(e=>{let n=a8(e,t),r=Array.isArray(s)?s:[];return{bySession:{...e.bySession,[t]:{...n,queue:r}}}})},setMetadata:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,metadata:{...n.metadata,...s}}}}})},setStats:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,stats:{...n.stats,...s}}}}})},addUserMessage:(t,s,n=null,r=!1)=>{e(e=>{let l=a8(e,t),a={id:a4("u"),role:"user",content:s,attachments:n||[]},i={id:a4("a"),role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0};return{bySession:{...e.bySession,[t]:{...l,...r?null:{isTurnRunning:!0,turnStartedAt:Date.now(),lastTurnMs:0,turnBaseline:{inputTokens:l.stats.inputTokens||0,outputTokens:l.stats.outputTokens||0},activeBlocked:null},messages:[...l.messages,a,i]}}}})},appendDelta:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages],l=r[r.length-1];return l&&"assistant"===l.role&&l.isLive?r[r.length-1]={...l,content:(l.content||"")+(s||"")}:r.push({id:a4("msg"),role:"assistant",content:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendThinking:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages],l=r[r.length-1];return l&&"assistant"===l.role&&l.isLive?r[r.length-1]={...l,thinking:(l.thinking||"")+(s||"")}:r.push({id:a4("msg"),role:"assistant",content:"",thinking:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendStream:(t,s,n)=>{e(e=>{let r=a8(e,t),l=[...r.messages],a=l[l.length-1];return a&&"assistant"===a.role&&a.isLive?l[l.length-1]={...a,...s?{content:(a.content||"")+s}:null,...n?{thinking:(a.thinking||"")+n}:null}:l.push({id:a4("msg"),role:"assistant",content:s||"",thinking:n||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...r,messages:l}}}})},appendDiff:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages],l=r[r.length-1];l&&"assistant"===l.role?(l={...l},r[r.length-1]=l):(l={id:a4("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},r.push(l));let a=[...l.diffs||[]],i=a.findIndex(e=>e.file===s.file);return -1!==i?a[i]=s:a.push(s),l.diffs=a,{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendTool:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages],l=r[r.length-1];if(l&&"assistant"===l.role&&l.isLive&&(l.content||l.thinking||"").length>0)r[r.length-1]={...l,isLive:!1},r.push({id:a4("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...s,status:s.status||"running"}]});else if(l&&"assistant"===l.role){let e=[...l.tools||[]],t=e.findIndex(e=>e.id===s.id);-1!==t?e[t]={...e[t],...s}:e.push({...s,status:s.status||"running"}),r[r.length-1]={...l,tools:e}}else r.push({id:a4("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...s,status:s.status||"running"}]});return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},updateToolResult:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e];if(!t?.tools)continue;let n=t.tools.findIndex(e=>e.id===s.id);if(-1!==n){let l=[...t.tools];l[n]={...l[n],...s,status:s.status||"done"},r[e]={...t,tools:l};break}}return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},nestTool:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e],n=aR(t?.tools,e=>e.id===s.parentToolUseId,e=>{let t=[...e.children||[]],n=t.findIndex(e=>e.id===s.id);return -1!==n?t[n]={...t[n],...s}:t.push({...s,status:s.status||"running"}),{...e,children:t}});if(n){r[e]={...t,tools:n};break}}return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},nestToolResult:(t,s)=>{e(e=>{let n=a8(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e],n=aR(t?.tools,e=>(e.children||[]).some(e=>e.id===s.id),e=>({...e,children:e.children.map(e=>e.id===s.id?{...e,...s,status:s.status||"done"}:e)}));if(n){r[e]={...t,tools:n};break}}return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},setPermission:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,activePermission:s,gateError:!1}}}})},clearPermission:t=>{e(e=>{let s=a8(e,t);return{bySession:{...e.bySession,[t]:{...s,activePermission:null}}}})},setBlocked:(t,s)=>{e(e=>{let n=a8(e,t);return{bySession:{...e.bySession,[t]:{...n,activeBlocked:s}}}})},clearBlocked:t=>{e(e=>{let s=a8(e,t);return{bySession:{...e.bySession,[t]:{...s,activeBlocked:null}}}})},setGateError:(t,s,n=!0)=>{e(e=>{let r=a8(e,t);return r.activePermission?.requestId!==s?e:{bySession:{...e.bySession,[t]:{...r,gateError:n}}}})},finishTurn:(t,s,n=0,r=!1)=>{e(e=>{let l=a8(e,t),a=l.messages.map((e,t)=>({...e,...t===l.messages.length-1?{isLive:!1}:null,...e.tools?{tools:aE(e.tools)}:null}));return{bySession:{...e.bySession,[t]:{...l,...r?{activePermission:null}:{isTurnRunning:!1,lastTurnMs:n||(l.turnStartedAt?Date.now()-l.turnStartedAt:l.lastTurnMs),activePermission:null,stats:s?{...l.stats,...s}:l.stats},messages:a}}}})},clearMessages:t=>{e(e=>{let s=a8(e,t);return{bySession:{...e.bySession,[t]:{...s,messages:[],tasks:[],turnStartedAt:0,lastTurnMs:0,activePermission:null,activeBlocked:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0}}}}})},rewindToMessage:(t,s,n)=>{e(e=>{let r=a8(e,t),l=r.messages.findIndex(e=>e.id===s);if(-1===l)return e;let a=r.messages.slice(0,l+1);return n&&(a[l]={...a[l],content:n}),{bySession:{...e.bySession,[t]:{...r,messages:a,isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null}}}})},upsertTask:(t,s)=>{e(e=>{let n=a8(e,t),r=a0(n.tasks,s);return r===n.tasks?e:{bySession:{...e.bySession,[t]:{...n,tasks:r}}}})},hydrateSession:(t,{messages:s=[],tasks:n=[],isTurnRunning:r=!1,metadata:l={},stats:a=null,permissionMode:i=null,activeBlocked:o=null,elapsedMs:c=0,lastTurnMs:d=0,harnessTasks:u=null,queue:x=null})=>{e(e=>{let m=a8(e,t),p=u?a9(u,s):null;return{bySession:{...e.bySession,[t]:{...m,activePermission:null,messages:p||s,tasks:n,isTurnRunning:r,...Array.isArray(x)?{queue:x}:{},turnStartedAt:r?Date.now()-(c||0):0,lastTurnMs:r?0:d||0,turnBaseline:r?{inputTokens:0,outputTokens:0}:{inputTokens:a?.inputTokens||0,outputTokens:a?.outputTokens||0},metadata:{...m.metadata,...l},stats:a?{...m.stats,...a}:m.stats,activeBlocked:o,...i?{permissionMode:i}:{},...u?{harnessTasks:u}:{}}}}})},prependMessages:(t,s)=>{s?.length&&e(e=>{let n=a8(e,t),r=a9(n.harnessTasks||[],s)||s,l=new Set(n.messages.map(e=>e.id)),a=r.map(e=>l.has(e.id)?{...e,id:a4(e.id.split("-")[0])}:(l.add(e.id),e));return{bySession:{...e.bySession,[t]:{...n,messages:[...a,...n.messages]}}}})},restoreTurnState:(t,s={})=>{if(void 0===s.isTurnRunning)return;let{isTurnRunning:n,lastTurnMs:r=0,elapsedMs:l=0}=s;(n||r)&&e(e=>{let s=a8(e,t);return{bySession:{...e.bySession,[t]:{...s,isTurnRunning:n,lastTurnMs:r,turnStartedAt:n?Date.now()-(l||0):0}}}})},removeSession:t=>{e(e=>{let{[t]:s,...n}=e.bySession;return{bySession:n}})}}),{name:"9remote-ai-store",storage:a5,partialize:e=>({bySession:Object.fromEntries(Object.entries(e?.bySession||{}).map(([e,t])=>[e,{permissionMode:t?.permissionMode??null,metadata:{model:t?.metadata?.model||"",effort:t?.metadata?.effort||""}}]))})}));function ie(e){if(!e)return 0;let t=(e.content?.length||0)+(e.thinking?.length||0);if(Array.isArray(e.tools))for(let s of e.tools)t+=(s.command?.length||0)+(s.output?.length||0)+120;if(Array.isArray(e.diffs))for(let s of e.diffs)t+=(s.diff?.length||0)+(s.file?.length||0)+80;return Math.max(t,100)}function it(e,t,s,n=2){if(!Array.isArray(e)||0===e.length)return 0;let r=Math.min(s??e.length,e.length),l=0,a=0;for(let s=r-1;s>=0&&(l+=ie(e[s]),a++,!(l>=t)||!(a>=n));s--);return r-a}async function is({startSeq:e,fetchChunk:t,reduceChunk:s,maxChunks:n=8,pageBudget:r=131072,estimateBytes:l=()=>0}){let a=e,i=[],o=0,c=!0,d=0,u=!1;for(;d<n;){let e=await t(a);if(d++,null==e)break;if(!e.success||!e.events?.length){c=!1;break}u=!0;let n=s(e.events,i.length);if(i=[...n,...i],o+=n.reduce((e,t)=>e+l(t),0),a=e.events[0].seq,!(c=!!e.hasMore)||o>=r)break}return{messages:i,before:a,hasMore:c,answered:u,chunks:d}}let ir=[1200,3e3,6e3],il=e=>Array.isArray(e)?e.map(e=>"string"==typeof e?{id:e,name:e,description:""}:e):[];function ia(e,t){let s=String(t||"").trim();if(!s)return!1;let n=e[e.length-1];return!!(n&&"assistant"===n.role&&String(n.content||"").trim().endsWith(s))}let ii=e=>e?.text?`Not sent — ${e.reason||"the turn is still running"}: ${e.text}`:e?.reason||"Not sent";function io(e=[],t="claude",s=0){let n=[],r=[],l=[],a={model:"",skills:[],mcpServers:[]},i={inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},o=!1,c=null,d=null,u=null,x=!1,m=s;for(let s of e){let e=s?.event,p=s?.data;if(e)switch(e){case"user_message":o=!0,d=null,n.push({id:`u-${++m}`,role:"user",content:p?.text||"",attachments:p?.attachments||[]}),n.push({id:`a-${++m}`,role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0});break;case"init":{let e=il(p?.skills),t=e.length>0?e:a.skills,{model:s,...n}=p||{};a={...a,...n,skills:t,...s?{model:s}:{}};break}case"goal":a={...a,goal:p?.goal||null};break;case"delta":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++m}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.content=(e.content||"")+(p?.text||"");break}case"thinking":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++m}`,role:"assistant",content:"",thinking:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.thinking=(e.thinking||"")+(p?.text||"");break}case"diff":{if(!p)break;let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++m}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e));let t=e.diffs||(e.diffs=[]),s=t.findIndex(e=>e.file===p.file);-1!==s?t[s]=p:t.push(p);break}case"tool_child":if(!p)break;for(let e=n.length-1;e>=0;e--){let t=aR(n[e]?.tools,e=>e.id===p.parentToolUseId,e=>{let t=[...e.children||[]],s=t.findIndex(e=>e.id===p.id);return -1!==s?t[s]={...t[s],...p}:t.push({...p,status:p.status||"running"}),{...e,children:t}});if(t){n[e].tools=t;break}}break;case"tool_result_child":if(!p?.id)break;for(let e=n.length-1;e>=0;e--){let t=aR(n[e]?.tools,e=>(e.children||[]).some(e=>e.id===p.id),e=>({...e,children:e.children.map(e=>e.id===p.id?{...e,...p,status:p.status||"done"}:e)}));if(t){n[e].tools=t;break}}break;case"tool_start":{if(!p)break;let e=n[n.length-1];if(e&&"assistant"===e.role&&e.isLive&&(e.content||e.thinking||"").length>0)e.isLive=!1,e={id:`msg-${++m}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...p,status:p.status||"running"}]},n.push(e);else if(e&&"assistant"===e.role){let t=e.tools||(e.tools=[]),s=t.findIndex(e=>e.id===p.id);-1!==s?t[s]={...t[s],...p}:t.push({...p,status:p.status||"running"})}else e={id:`msg-${++m}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...p,status:p.status||"running"}]},n.push(e);if(p.name){let e=(0,aT.Zm)(t,p.name,p.input,p.id,r);e&&(r=a0(r,e))}break}case"tool_result":{if(!p?.id)break;for(let e=n.length-1;e>=0;e--){let t=n[e],s=t?.tools?.find(e=>e.id===p.id);if(s){Object.assign(s,p,{status:p.status||"done"});break}}let e=(0,aT.in)(t,p.name||"",p.output||"",p.id);e&&(r=a0(r,e));break}case"permission_request":c=p;break;case"permission_resolved":c=null;break;case"blocked":d=p;break;case"options_changed":p?.permissionMode&&(u=p.permissionMode),p?.model&&(a.model=p.model),p?.effort&&(a.effort=p.effort);break;case"turn_complete":x=!0,o=!1,c=null,p?.stats&&(i={...i,...p.stats}),n.length>0&&(n[n.length-1].isLive=!1),p?.isError&&!ia(n,p.result)&&n.push({id:`n-${++m}`,role:"notice",subtype:p.subtype||"",level:"error",content:p.result||"The turn ended in an error."});break;case"stats":p?.stats&&(i={...i,...p.stats});break;case"stopped":x=!0,o=!1,c=null;break;case"stall":for(let e of(x=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);break;case"exit":for(let e of(x=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);(p?.error||p?.code!=null&&0!==p.code)&&n.push({id:`n-${++m}`,role:"notice",subtype:"exit",level:"error",content:p.error||`The AI process exited (code ${p.code}).`});break;case"error":for(let e of(x=!0,o=!1,n))e.isLive&&(e.isLive=!1);n.push({id:`n-${++m}`,role:"notice",subtype:"error",level:"error",content:p?.message||"AI process failed"});break;case"prompt_refused":n.push({id:`n-${++m}`,role:"notice",subtype:"prompt_refused",level:"error",content:ii(p)});break;case"conversation_reset":n.length=0,r.length=0,l.length=0,o=!1,c=null,d=null;break;case"cli_event":{let e=p?.type||"",t=p?.record||null;l.push([e,p?.subtype||"",t,p?.ageMs]);let s=aQ(e,t);if(!s)break;let{compactSettled:r,...a}=s,i=r?aV(n):-1;if(-1!==i){a.content?.trim()?n[i]={id:`n-${++m}`,role:"notice",...a}:n.splice(i,1);break}if(!a.content?.trim())break;let o=n[n.length-1];!o||"assistant"!==o.role||o.content||o.thinking||(o.tools||[]).length||n.pop(),n.push({id:`n-${++m}`,role:"notice",...a})}}}if(x)for(let e of n)e.tools&&(e.tools=aE(e.tools));let p=[];for(let[e,t,s]of l)p=aG(p,e,t,s);return{messages:n,tasks:r,metadata:a,stats:i,isTurnRunning:o,activePermission:c,activeBlocked:d,permissionMode:u,harnessRecords:l,harnessTasks:p}}let ic=(0,r.memo)(function({message:e,engine:t="claude",workspacePath:s="",onResolvePermission:l,onRewind:a,onPreviewRewind:i,onCutLocal:o,rewindIndex:c=null,canRewind:d=!1}){let[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),[f,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(null);(0,h.B)(e=>e.openEditorFile);let{id:N,role:C,content:S,thinking:E,diffs:R=[],tools:T=[],permission:$=null,isLive:M=!1,attachments:z=[]}=e;if("user"===C){let e=async e=>{w(!0),k("preview");let t=await i?.(null,{index:c});(w(!1),k(null),t?.ok)?v({files:t.files||[],text:e}):v({error:t?.error||"The host could not preview this rewind.",text:e})},t=async()=>{let e=g?.text;v(null),w(!0),k("apply"),o?.(N,e);let t=await a?.(null,e,{index:c});(w(!1),k(null),t&&!t.ok)?v({error:t.error||"The rewind did not go through.",text:e}):p(!1)},s=(0,n.jsx)(ei.A,{isOpen:!!g,onClose:()=>v(null),onConfirm:g?.error?()=>v(null):t,title:g?.error?"Cannot rewind":"Rewind to this prompt?",message:g?.error?g.error:["This discards every turn after this prompt and re-sends your edited text.",g?.files?.length?`These ${g.files.length} file${1===g.files.length?"":"s"} go back to how they were:`:"No file changes to restore — this rewinds the conversation only.",...g?.files?.slice(0,8).map(e=>`\xb7 ${e.file}${e.status?` (${e.status})`:""}`)||[],g?.files?.length>8?`… and ${g.files.length-8} more`:"","Edits made by hand, or by shell commands, are NOT restored."].filter(Boolean).join("\n"),confirmText:g?.error?"OK":"Rewind"});if(m)return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex justify-end my-3",children:(0,n.jsxs)("div",{className:"max-w-[85%] sm:max-w-[75%] w-full",children:[(0,n.jsx)("textarea",{value:f,onChange:e=>b(e.target.value),onBlur:()=>{y||g||p(!1)},onKeyDown:t=>{if("Enter"===t.key&&!t.shiftKey){if(t.nativeEvent.isComposing||229===t.keyCode||(t.preventDefault(),y||g))return;f.trim()&&e(f.trim())}"Escape"===t.key&&p(!1)},rows:Math.min(10,f.split("\n").length+1),className:"w-full resize-none overflow-hidden rounded-brand-lg bg-surface-2 px-4 py-2.5 text-sm text-text focus:outline-none focus:ring-1 focus:ring-brand-500 leading-relaxed",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex justify-end items-center gap-1.5 mt-1.5 text-[11px] text-text-muted",children:[y&&(0,n.jsx)(en.kr,{size:11,className:"animate-spin"}),(0,n.jsx)("span",{children:"apply"===j?"Rewinding...":"preview"===j?"Checking what this would change...":"Enter to rewind, Esc to cancel"})]})]})}),s]});let r=d&&!!a,l=()=>{(0,eo.e)(),b(S||""),p(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"group/msg flex flex-col items-end my-3",children:[(0,n.jsxs)("div",{className:"max-w-[85%] sm:max-w-[75%] flex flex-col items-end gap-1.5",children:[z.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap justify-end gap-1.5",children:z.map((e,t)=>(0,n.jsxs)("span",{className:`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] ${e.isImage?"border-brand-500/40 bg-brand-500/10 text-brand-500":"border-border-subtle bg-surface-2 text-text-muted"}`,children:[e.isImage?(0,n.jsx)(en._V,{size:10}):(0,n.jsx)(en.xv,{size:10}),(0,n.jsx)("span",{className:"max-w-[160px] truncate",children:e.filename})]},`${e.filename}-${t}`))}),S&&(0,n.jsx)("div",{onClick:r?e=>{let t=window.getSelection();t&&!t.isCollapsed&&t.containsNode(e.currentTarget,!0)||l()}:void 0,className:`px-4 py-2.5 rounded-brand-lg bg-brand-500/15 border border-brand-500/25 text-text text-sm whitespace-pre-wrap wrap-anywhere ${r?"cursor-pointer":""}`,children:S})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),S&&(navigator.clipboard.writeText(S),x(!0),setTimeout(()=>x(!1),2e3))},className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors",title:"Copy this prompt",children:u?(0,n.jsx)(en.aJ,{size:11,className:"text-success"}):(0,n.jsx)(en.QR,{size:11})}),r&&(0,n.jsx)("button",{type:"button",disabled:y,onClick:l,className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors disabled:opacity-40",title:"Edit & rewind to here",children:y&&"preview"===j?(0,n.jsx)(en.kr,{size:11,className:"animate-spin"}):(0,n.jsx)(en.gH,{size:11})})]})]}),s]})}return null},(e,t)=>e.message===t.message&&e.onResolvePermission===t.onResolvePermission&&e.rewindIndex===t.rewindIndex||!e.message.isLive&&!t.message.isLive&&e.message.id===t.message.id&&e.message.content===t.message.content&&e.message.thinking===t.message.thinking&&e.message.permission===t.message.permission&&e.message.tools===t.message.tools&&e.message.diffs===t.message.diffs&&e.canRewind===t.canRewind&&e.rewindIndex===t.rewindIndex&&e.onResolvePermission===t.onResolvePermission);function id(e,t){if("string"!=typeof e||!e)return{dir:"",name:""};let s=e.replace(/\\/g,"/"),n=t?t.replace(/\\/g,"/").replace(/\/+$/,""):"",r=!!n&&s.startsWith(`${n}/`),l=r?5:4,a=(r?s.slice(n.length+1):s).split("/").filter(Boolean);a.length>l&&(a=["…",...a.slice(-l)]);let i=a.pop()||"";return{dir:a.join("/"),name:i}}let iu={file:en.kU},ix=(0,r.memo)(function e({id:t="",name:s="tool",command:l="",input:a=null,output:i="",error:o="",status:c="done",children:d=[],engine:u="claude",workspacePath:x="",deferred:m=!1}){let p=!!(o||"error"===c),[f,b]=(0,r.useState)(p&&!m),[g,v]=(0,r.useState)(!1),y=(0,h.B)(e=>e.openEditorFile);(0,r.useEffect)(()=>{p&&!m&&b(!0)},[p,m]);let w=!!l||"string"!=typeof a&&!!a?.command,j="string"==typeof a?"":a?.file_path||a?.notebook_path||a?.path||a?.file||"",k=l||j||("string"==typeof a?a:a?.command||a?.pattern||a?.query||""),N=!w&&j&&k===j?function(e,t){let{dir:s,name:n}=id(e,t);return s?`${s}/${n}`:n}(k,x):k,C=a?.file_path||a?.path||a?.file||"",S=iu[(0,aT.$Z)(u,s)]||en.Jl;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>b(!f),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:"running"===c?(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-accent"}):p?(0,n.jsx)(en.RI,{size:13,className:"text-danger"}):(0,n.jsx)(S,{size:13,className:"text-success"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1 font-mono text-[11px] leading-relaxed line-clamp-2",children:[(0,n.jsx)("span",{className:"text-[10px] font-semibold text-text uppercase tracking-wider break-all px-1 py-0.5 rounded bg-surface-2/80 [box-decoration-break:clone]",title:s,children:s}),N&&(0,n.jsxs)(n.Fragment,{children:[" ",(0,n.jsx)("span",{className:"text-text-muted break-all",title:N,children:N})]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 self-center",children:f?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0 ml-2 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:[C&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)(),C&&y(C)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1",title:"Open file in editor",children:(0,n.jsx)(en.Gr,{size:11})}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)();let t=i||o||N;t&&(navigator.clipboard.writeText("string"==typeof t?t:JSON.stringify(t,null,2)),v(!0),setTimeout(()=>v(!1),2e3))},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors",title:"Copy output",children:g?(0,n.jsx)(en.aJ,{size:11,className:"text-success"}):(0,n.jsx)(en.QR,{size:11})})]})]}),f&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text",children:[o&&(0,n.jsx)("div",{className:"text-danger mb-1.5 whitespace-pre-wrap",children:o}),i?(0,n.jsx)("div",{className:"text-text whitespace-pre-wrap leading-relaxed",children:"string"==typeof i?i:JSON.stringify(i,null,2)}):o?null:(0,n.jsx)("div",{className:"text-text-muted italic",children:"Running or no output returned..."})]}),f&&d.length>0&&(0,n.jsx)("div",{className:"ml-3.5 pl-3 border-l-2 border-border-subtle/80",children:d.map(t=>(0,n.jsx)(e,{...t,engine:u,workspacePath:x},t.id))})]})}),im=new Set(["TaskCreate","TaskUpdate","TodoWrite","todowrite"]),ip=new Set(["claude","omp","devin","opencode"]),ih=new Set(["Edit","Write","MultiEdit","NotebookEdit","file_change","edit","write","write_to_file","replace_file_content"]),ib=e=>"thought"===e.kind||"tool"===e.kind||"diff"===e.kind;function ig({total:e,windowSize:t=3,children:s}){let[l,a]=(0,r.useState)(0),i=function(e,t,s=0){let n=e-Math.max(0,s);return n>t+1?n-t:0}(e,t,l);return(0,n.jsxs)(n.Fragment,{children:[l>0?(0,n.jsx)("button",{type:"button",onClick:()=>a(e=>e-Math.min(12,Math.max(0,e))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:"▼ show less"}):i>0?(0,n.jsxs)("button",{type:"button",onClick:()=>a(e=>e+Math.min(12,Math.max(0,i))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:["▲ ",i," more ",1===i?"step":"steps"]}):null,s(i)]})}let iv=(0,r.memo)(function({file:e="",patch:t="",diff:s="",content:l="",workspacePath:a=""}){let[i,o]=(0,r.useState)(!1),c=(0,h.B)(e=>e.openEditorFile),d=lw(),u=t||s||(t||s||!l?"":String(l).split("\n").map(e=>`+${e}`).join("\n")),x=u?u.split("\n"):[],m=id(e,a),p=x.filter(e=>e.startsWith("+")&&!e.startsWith("+++")).length,f=x.filter(e=>e.startsWith("-")&&!e.startsWith("---")).length;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>o(!i),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(en.GD,{size:13,className:"text-success shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 font-mono font-medium text-text text-[11px] break-all",title:e,children:m.dir?`${m.dir}/${m.name}`:m.name||"diff"}),(p>0||f>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 font-mono text-[10px] shrink-0 text-text-muted",children:[p>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",p]}),f>0&&(0,n.jsxs)("span",{className:"text-danger",children:["-",f]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:i?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]}),(0,n.jsx)("div",{className:`flex items-center gap-1 shrink-0 ml-2 transition-opacity ${d?"opacity-100":"opacity-0 group-hover/tool:opacity-100"}`,children:e&&(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),(0,eo.e)(),e&&c(e)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1 text-[10px]",title:"Open file in editor",children:(0,n.jsx)(en.Gr,{size:11})})})]}),i&&(0,n.jsx)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[300px] overflow-y-auto font-mono text-[11px] leading-relaxed select-text",children:0===x.length?(0,n.jsx)("div",{className:"text-text-muted italic py-1 px-2",children:"No changes"}):x.map((e,t)=>{let s=e.startsWith("+")&&!e.startsWith("+++"),r=e.startsWith("-")&&!e.startsWith("---"),l=e.startsWith("@@"),a="text-text",i="";return s?(a="text-success",i="bg-success/10"):r?(a="text-danger",i="bg-danger/10"):l&&(a="text-text-muted",i="bg-surface-2/40"),(0,n.jsx)("div",{className:`px-2 py-0.5 rounded-sm whitespace-pre ${a} ${i}`,children:e},t)})})]})});var iy=s(6552);let iw=(0,r.memo)(function({text:e="",isLive:t=!1,defaultOpen:s=!1}){let[l,a]=(0,r.useState)(s);return e?.trim()?(0,n.jsxs)("div",{className:"my-1.5 text-xs select-none",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>a(e=>!e),className:"inline-flex items-center gap-1.5 text-[11px] text-text-muted hover:text-text py-0.5 transition-colors cursor-pointer group",children:[(0,n.jsx)(en.sU,{size:12,className:t?"animate-pulse text-success":"text-success"}),(0,n.jsx)("span",{className:"italic",children:t?"Thinking...":"Thought process"}),(0,n.jsx)("span",{className:"text-text-muted/50 group-hover:text-text-muted",children:l?(0,n.jsx)(en.yQ,{size:12}):(0,n.jsx)(en.c_,{size:12})})]}),l&&(0,n.jsx)("div",{className:"mt-1 pl-3.5 border-l-2 border-border-subtle/80 font-mono text-[11px] text-text-muted leading-relaxed whitespace-pre-wrap max-h-[260px] overflow-y-auto custom-scrollbar select-text py-1",children:e})]}):null}),ij=/Command running in background with ID:\s*([^\s.]+)/;var ik=s(14890);let iN=(0,r.memo)(function({id:e="",name:t="Bash",input:s=null,output:l="",error:a="",status:i="done",deferred:o=!1}){let c,{sessionId:d}=(0,ik.OO)(),u=!!(a||"error"===i),[x,m]=(0,r.useState)(u&&!o),[p,f]=(0,r.useState)(!1),[h,b]=(0,r.useState)(!1);(0,r.useEffect)(()=>{u&&!o&&m(!0)},[u,o]);let g=s?.command||"",v=s?.description||"",y=a||l||"",w="string"==typeof y?y:y?JSON.stringify(y,null,2):"",j=(c=ij.exec("string"==typeof l?l:""))?c[1]:"",k=!!(s?.run_in_background||j);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:(0,ik.xo)(d,"shell",e),children:[(0,n.jsxs)("div",{onClick:()=>m(!x),className:"flex items-start justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:"running"===i?(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-accent"}):u?(0,n.jsx)(en.RI,{size:13,className:"text-danger"}):(0,n.jsx)(en.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:"text-text-muted select-none shrink-0 font-mono text-[11px] leading-relaxed",children:"$"}),(0,n.jsx)("span",{className:"font-mono text-[11px] leading-relaxed text-text line-clamp-2 min-w-0",title:g,children:g||t}),k&&(0,n.jsxs)("span",{className:"font-mono text-[10px] font-semibold text-warning shrink-0 px-1 py-0.5 rounded bg-warning/10",title:j?`Background shell ${j}`:"Running in the background",children:["BG",j?` ${j}`:""]}),w&&(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:x?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 shrink-0 ml-2 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:g&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)(),navigator.clipboard.writeText(g),f(!0),setTimeout(()=>f(!1),2e3)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors text-[10px] flex items-center gap-0.5",title:"Copy command",children:p?(0,n.jsx)(en.aJ,{size:11,className:"text-success"}):(0,n.jsx)(en.QR,{size:11})})})]}),v&&!x&&(0,n.jsxs)("div",{className:"ml-7 text-[10px] text-text-muted/70 italic truncate",children:["# ",v]}),x&&w&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text relative group/out",children:[v&&(0,n.jsxs)("div",{className:"px-2 pt-1.5 text-[10px] text-text-muted/70 italic",children:["# ",v]}),(0,n.jsx)("pre",{className:`p-2 whitespace-pre-wrap leading-relaxed ${u?"text-danger":"text-text"}`,children:w}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)(),navigator.clipboard.writeText(w),b(!0),setTimeout(()=>b(!1),2e3)},className:"absolute top-1.5 right-1.5 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-0 group-hover/out:opacity-100 transition-opacity text-[10px]",title:"Copy output",children:h?(0,n.jsx)(en.aJ,{size:10,className:"text-success"}):(0,n.jsx)(en.QR,{size:10})})]})]})});function iC(e){let t=String(e||"").split("\n")[0].trim();return t.length>140?`${t.slice(0,140)}…`:t}let iS=(0,r.memo)(function({id:e="",name:t="Agent",input:s=null,output:l="",error:a="",status:i="done",children:o=[],engine:c="claude",workspacePath:d=""}){let{sessionId:u}=(0,ik.OO)(),x="running"===i,m=!!(a||"error"===i),p=o.filter(e=>"running"===e.status).length,[f,h]=(0,r.useState)(m);(0,r.useEffect)(()=>{m&&h(!0)},[m]);let b=aj.has(t),g=b?ak({input:s}):t||"agent",v=b?iC(s?.prompt??s?.description??s?.message):iC(s?.message??s?.prompt??s?.query);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:(0,ik.xo)(u,"agent",e),children:[(0,n.jsxs)("div",{onClick:()=>h(!f),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0",children:x?(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-accent"}):m?(0,n.jsx)(en.RI,{size:13,className:"text-danger"}):(0,n.jsx)(en.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:"AGENT"}),(0,n.jsx)("span",{className:"font-mono text-[11px] font-semibold text-brand-500 shrink-0",children:g}),v&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",title:v,children:v})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 shrink-0 ml-2",children:[o.length>0&&(0,n.jsxs)("span",{className:"font-mono text-[10px] text-text-subtle",title:`${o.length} sub-agent tool calls`,children:[x&&p>0?`${p}/${o.length}`:o.length," tools"]}),(0,n.jsx)("span",{className:"text-text-muted/50",children:f?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]})]}),f&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 py-1 space-y-0.5",children:[o.length>0?(0,n.jsx)(ig,{total:o.length,children:e=>(e>0?o.slice(e):o).map(e=>iM(c,e,{workspacePath:d})||(0,n.jsx)(ix,{...e,engine:c,workspacePath:d},e.id))}):(0,n.jsx)("div",{className:"text-text-muted italic py-0.5",children:x?"Sub-agent started…":"No tool calls reported."}),!x&&(l||a)&&(0,n.jsx)("div",{className:"mt-1 pl-3 border-l-2 border-border-subtle/60 font-mono text-[11px] max-h-[240px] overflow-y-auto select-text",children:(0,n.jsx)("div",{className:`whitespace-pre-wrap leading-relaxed ${m?"text-danger":"text-text-muted"}`,children:"string"==typeof(a||l)?a||l:JSON.stringify(a||l,null,2)})})]})]})}),iE=(0,r.memo)(function({toolName:e="EnterPlanMode",input:t={}}){let s="string"==typeof t?.plan?t.plan.trim():"";if(s)return(0,n.jsx)(iR,{plan:s,explanation:t?.explanation||""});let r="EnterPlanMode"===e,l=t?.reason||(r?"Exploring codebase and designing implementation approach":"Implementation plan finalized");return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${r?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between font-semibold",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[r?(0,n.jsx)(en.y8,{size:16,className:"text-brand-500"}):(0,n.jsx)(en.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:r?"Plan Mode Activated":"Plan Mode Completed"})]}),(0,n.jsx)("span",{className:"font-mono text-[10px] px-2 py-0.5 rounded bg-surface-2 text-text-muted",children:e})]}),(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reason: "}),l]}),r&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted/80 italic pl-6 select-none",children:"Plan mode reads files and drafts an approach — nothing is applied without your review, in whichever CLI this chat is running."})]})}),iR=(0,r.memo)(function({plan:e,explanation:t=""}){return(0,n.jsxs)("div",{className:"p-3.5 rounded-brand-lg border border-brand-500/30 bg-brand-500/10 text-text my-2 text-xs flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[(0,n.jsx)(en.y8,{size:16,className:"text-brand-500"}),(0,n.jsx)("span",{children:"Plan"})]}),(0,n.jsx)("pre",{className:"font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-words pl-6 max-h-[320px] overflow-y-auto",children:e}),t&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted pl-6 italic",children:t})]})}),iT=(0,r.memo)(function({toolName:e="enteredReviewMode",input:t={}}){let s="enteredReviewMode"===e,r=String(t?.review||"").trim();return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${s?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[s?(0,n.jsx)(en.kU,{size:16,className:"text-brand-500"}):(0,n.jsx)(en.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:s?"Code review started":"Code review finished"})]}),r&&(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reviewing: "}),r]})]})}),i$={bash:(e,t)=>(0,n.jsx)(iN,{...e,deferred:t},e.id),agent:(e,t,{engine:s,workspacePath:r})=>(0,n.jsx)(iS,{...e,engine:s,workspacePath:r},e.id),plan:e=>(0,n.jsx)(iE,{toolName:e.name,input:e.input},e.id),review:e=>(0,n.jsx)(iT,{toolName:e.name,input:e.input},e.id),question:(e,t,s)=>{if("running"===e.status||!e.output&&!e.error)return null;let r=s?.engine==="antigravity"&&/user skipped/i.test(String(e.output||""));return(0,n.jsx)(iy.J,{engine:s?.engine,questions:e.input?.questions||[],answers:r||e.error?null:e.output||"",declined:r||!!e.error||"error"===e.status},e.id)}};function iM(e,t,s={}){let n=i$[(0,aT.$Z)(e,t.name)];return n?n(t,s.deferred,{...s,engine:e}):null}function iz({row:e,engine:t,workspacePath:s,deferred:r}){if("thought"===e.kind)return(0,n.jsx)(iw,{text:e.text,isLive:e.isLive});if("diff"===e.kind){let t=e.diff;return(0,n.jsx)(iv,{file:t.file,patch:t.patch,diff:t.diff,content:t.content,workspacePath:s})}let l=e.tool;return iM(t,l,{workspacePath:s,deferred:r})||(0,n.jsx)(ix,{...l,engine:t,workspacePath:s,deferred:r})}let iP={info:"text-text-muted",suggestion:"text-text-muted",warning:"text-warning",error:"text-danger"};function iI({notice:e}){if(!e?.content)return null;let t=`text-xs leading-relaxed py-1 px-2 my-0.5 rounded border-l-2 border-current/30 bg-surface-2/40 wrap-anywhere ${iP[e.level]||iP.info}`;return e.compacting?(0,n.jsxs)("div",{className:`${t} flex items-center gap-2`,children:[(0,n.jsx)(en.kr,{size:12,className:"animate-spin text-brand-500 shrink-0"}),(0,n.jsx)("span",{children:e.content}),(0,n.jsx)(iL,{})]}):(0,n.jsxs)("div",{className:t,children:[e.content,e.compact?.detail&&(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",e.compact.detail]}),e.compact?.durationMs?(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",iA(e.compact.durationMs)]}):null]})}function iA(e){let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`}function iL(){let[e]=(0,r.useState)(()=>Date.now()),[t,s]=(0,r.useState)(e);return(0,r.useEffect)(()=>{let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[]),(0,n.jsx)("span",{className:"text-text-muted/70 tabular-nums",children:iA(t-e)})}function iD({content:e,isLive:t}){let s=function(e,t){let[s,n]=(0,r.useState)(e),l=(0,r.useRef)(e);return(0,r.useEffect)(()=>{l.current=e},[e]),(0,r.useEffect)(()=>{if(!t)return;let e=setInterval(()=>{n(e=>e===l.current?e:l.current)},80);return()=>clearInterval(e)},[t]),t?s:e}(e,t);return(0,n.jsxs)("div",{className:"text-sm leading-relaxed text-text py-1.5 wrap-anywhere",children:[(0,n.jsx)(ao,{content:s}),t&&(0,n.jsx)("span",{className:"inline-block w-1.5 h-3.5 bg-brand-500 animate-pulse ml-1 align-middle"})]})}let iB=(0,r.memo)(function({messages:e=[],engine:t="claude",workspacePath:s="",onResolvePermission:l,isLive:a=!0}){let i=(0,r.useMemo)(()=>(function(e=[],t="claude"){let s=[],n=new Set;for(let r of e){if("notice"===r.role){s.push({kind:"notice",id:r.id,notice:{subtype:r.subtype,level:r.level,content:r.content,...r.compact?{compact:r.compact}:null,...r.compacting?{compacting:!0}:null}});continue}if("assistant"!==r.role)continue;r.thinking?.trim()&&s.push({kind:"thought",id:`${r.id}-th`,text:r.thinking});let e=function(e,t,s){return(t||[]).filter(t=>!(!t||!t.name||(s||[]).some(e=>{let s;return e.file&&(s=e.file,ih.has(t?.name)&&s&&((t.input?.paths||[]).includes(s)||((e={})=>e.file_path||e.notebook_path||e.path||e.filePath||e.file||"")(t.input)===s))})||"task"===(0,aT.$Z)(e,t.name)&&im.has(t.name)))}(t,r.tools,r.diffs);for(let l=0;l<e.length;l++){let a=e[l];if("question"===(0,aT.$Z)(t,a.name)&&"running"===a.status&&ip.has(t))continue;let i=a.id||`${r.id}-t${l}`;n.has(i)||(n.add(i),s.push({kind:"tool",id:i,tool:a,engine:t}))}for(let e=0;e<(r.diffs?.length||0);e++){let t=r.diffs[e];s.push({kind:"diff",id:`${r.id}-d${e}`,diff:t})}r.content&&s.push({kind:"prose",id:`${r.id}-p`,content:r.content,isLive:r.isLive}),r.permission&&s.push({kind:"permission",id:`${r.id}-perm`,permission:r.permission})}return s})(e,t),[e,t]),o=(0,r.useMemo)(()=>(function(e=[],t=6,{deferred:s=!1}={}){let n=[];for(let t of e)if(ib(t)){let e=n[n.length-1];e?.type==="steps"?e.rows.push(t):n.push({type:"steps",rows:[t]})}else n.push({type:"row",row:t});return n.map((e,n)=>{if("steps"!==e.type)return{...e,key:`r${n}`,deferred:s};let r=e.rows.length>t+1?e.rows.length-t:0;return{type:"steps",key:`s${n}`,rows:e.rows,hidden:r,deferred:s}})})(i,3,{deferred:!a}),[i,a]);return(0,n.jsx)("div",{className:"my-1",children:o.map(e=>{if("steps"!==e.type){if("prose"===e.row.kind)return(0,n.jsx)(iD,{content:e.row.content,isLive:e.row.isLive},e.key);if("notice"===e.row.kind)return(0,n.jsx)(iI,{notice:e.row.notice},e.key);if("permission"===e.row.kind){let t=e.row.permission;return(0,n.jsx)(iy.J,{requestId:t.requestId,questions:t.input?.questions||[],onResolve:l},e.key)}return null}return(0,n.jsx)("div",{className:"relative pl-2.5 border-l-2 border-border-subtle/50 my-1",children:(0,n.jsx)(ig,{total:e.rows.length,children:r=>(r>0?e.rows.slice(r):e.rows).map(e=>(0,n.jsx)(iz,{row:e,engine:t,workspacePath:s,deferred:!a},e.id))})},e.key)})})},(e,t)=>{if(e.messages.length!==t.messages.length)return!1;for(let s=0;s<e.messages.length;s++)if(e.messages[s]!==t.messages[s])return!1;return e.engine===t.engine&&e.workspacePath===t.workspacePath&&e.isLive===t.isLive&&e.onResolvePermission===t.onResolvePermission}),iF=[],iK=(e,t)=>{if(!e||!t)return null;let s=e.getBoundingClientRect();return{scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight,nodeTop:t.getBoundingClientRect().top-s.top+e.scrollTop}},iO=e=>String(e).padStart(2,"0");function iW(e){let t=Math.max(0,Math.floor(e/1e3)),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}h ${n}m ${iO(r)}s`:n>0?`${n}m ${iO(r)}s`:`${r}s`}function i_(e){return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),aD(e)," tokens"]}):null}let iH=(0,r.memo)(function({engine:e="claude",failed:t=!1,onRetry:s}){let r=tb.UB[e]||tb.UB.claude;return t?(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-center p-6 select-none",children:[(0,n.jsx)("span",{className:"font-mono text-[12px] text-danger",children:"Couldn't load this conversation"}),(0,n.jsx)("span",{className:"text-[11px] font-mono text-text-muted/70",children:r.label}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),s?.()},className:"px-3 py-1.5 rounded-brand text-[11px] font-mono text-text bg-surface-2 hover:bg-surface-3 transition-colors",children:"Retry"})]}):(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-center p-6 select-none",children:[(0,n.jsx)(en.kr,{size:20,className:"animate-spin text-brand-500"}),(0,n.jsx)("span",{className:"ai-sheen-text font-mono text-[12px] text-text-muted",children:"Syncing…"}),(0,n.jsx)("span",{className:"text-[11px] font-mono text-text-muted/70",children:r.label})]})}),iq=(0,r.memo)(function({sessionId:e,engine:t="",hydrating:s=!1}){let l=a7(t=>t.bySession[e]?.isTurnRunning),a=a7(t=>t.bySession[e]?.turnStartedAt),i=a7(t=>t.bySession[e]?.lastTurnMs),o=a7(t=>t.bySession[e]?.stats),c=a7(t=>t.bySession[e]?.turnBaseline),d=(0,u.d)(e=>e.connected),x=(0,u.d)(e=>e.retryStatus),m=a7(t=>t.bySession[e]?.messages)||iF,p=m[m.length-1]||null,f=Math.max(0,(o?.outputTokens||0)-(c?.outputTokens||0)),[h,b]=(0,r.useState)(Date.now());(0,r.useEffect)(()=>{if(!l)return;b(Date.now());let e=setInterval(()=>b(Date.now()),1e3);return()=>clearInterval(e)},[l]);let[g,v]=(0,r.useState)(null),y=(0,r.useRef)(l);(0,r.useEffect)(()=>{y.current&&!l&&a&&v({ms:i||Date.now()-a,outputTokens:f,changes:aK(m)}),l&&v(null),y.current=l},[l,a,i,f,m]);let w=(0,r.useMemo)(()=>g||l||!i?null:{ms:i,outputTokens:0,changes:aK(m)},[g,l,i,m]),j=g||w;if(!l&&!j)return null;if(!l)return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 select-none text-xs text-text-muted",children:[(0,n.jsx)(en.aJ,{size:14,className:"text-emerald-400 shrink-0"}),(0,n.jsxs)("span",{className:"flex items-center min-w-0 font-mono text-[11px]",children:[(0,n.jsxs)("span",{className:"truncate",children:["Worked for ",(0,n.jsx)("span",{className:"text-text",children:iW(j.ms)})]}),(0,n.jsxs)("span",{className:"shrink-0",children:[function({added:e,removed:t}){return e||t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),e>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",e]}),e>0&&t>0&&" ",t>0&&(0,n.jsxs)("span",{className:"text-danger",children:["−",t]})]}):null}(j.changes),i_(j.outputTokens)]})]})]});let k=p?.tools?.find(e=>"running"===e.status),N=f+function(e=[]){let t=0;for(let s=e.length-1;s>=0;s--){let n=e[s];if("user"===n.role)break;t+=(n.content?.length||0)+(n.thinking?.length||0)}return Math.round(t/4)}(m),C=function({connected:e=!0,hydrating:t=!1,retryStatus:s=null,activeTool:n=null,engine:r="",lastMsg:l=null}={}){if(!e){let e=s||{};return{verb:"Reconnecting",detail:e.isRetrying?`attempt ${e.attempt}/${e.maxAttempts}${e.failed?" \xb7 gave up":""}`:"",tone:"alert"}}if(t)return{verb:"Syncing",detail:"from host",tone:"wait"};if(n?.name){let{name:e,input:t={}}=n,s=(0,aT.$Z)(r,e),l=az(t.file_path||t.path);switch(s){case"bash":return{verb:"Running",detail:aI(t.command||"",aM),tone:"wait"};case"file":{let s=/^(list|list_dir|ls)$/i.test(e),n=t.offset?`:L${t.offset}`:"";return{verb:s?"Listing":"Reading",detail:aI(`${l}${n}`,aM),tone:"wait"}}case"search":{let e=t.pattern?`"${t.pattern}"`:t.query||t.url||"",s=az(t.path);return{verb:"Searching",detail:aI([e,s?`in ${s}`:""].filter(Boolean).join(" "),aM),tone:"wait"}}case"diff":return{verb:/^(Write|write_to_file)$/i.test(e)?"Writing":"Editing",detail:aI(az(t.file_path||t.filePath||t.file||t.path)||aL(t),aM),tone:"wait"};case"agent":{let e=n.children?.length||0;return{verb:"Delegating",detail:aI([t.description||aL(t),e?`${e} steps`:""].filter(Boolean).join(" \xb7 "),aM),tone:"wait"}}case"task":return{verb:"Updating tasks",detail:aI(t.activeForm||t.subject||"",aM),tone:"wait"};case"plan":return{verb:"Planning",detail:aI(az(t.path)||e,aM),tone:"wait"};default:return{verb:"Calling",detail:aI([aA(e),aL(t)].filter(Boolean).join(" "),aM),tone:"wait"}}}return l?.thinking?{verb:"Thinking",detail:aI(aP(l.thinking),aM),tone:"wait"}:l?.content?{verb:"Writing",detail:aI(aP(l.content),aM),tone:"wait"}:{verb:"Working",detail:"",tone:"wait"}}({connected:d,hydrating:s,retryStatus:x,activeTool:k,engine:t,lastMsg:p});return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 select-none text-xs text-text-muted",children:["alert"===C.tone?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-danger animate-pulse shrink-0"}):(0,n.jsx)(en.kr,{size:13,className:"animate-spin text-brand-500 shrink-0"}),(0,n.jsxs)("span",{className:"flex items-center min-w-0 font-mono text-[11px]",children:[(0,n.jsxs)("span",{className:"truncate",children:[(0,n.jsxs)("span",{className:`ai-sheen-text${"alert"===C.tone?" !text-danger":""}`,children:[C.verb,"…"]}),C.detail&&(0,n.jsxs)("span",{className:"text-text-subtle",children:[" ",C.detail]}),(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),iW(h-(a||h))]}),(0,n.jsx)("span",{className:"shrink-0",children:i_(N)})]})]})}),iU=(0,r.memo)(function({engine:e,engineMeta:t,workspacePath:s,bus:l=null,fileBus:a,onSendPrompt:i,onOpenResume:o}){let{t:c}=(0,ec.s)(),[d,u]=(0,r.useState)([]),[x,m]=(0,r.useState)(null),p=n8(s,a,{enabled:!!s});(0,r.useEffect)(()=>{if(!s)return;let e=!0;return a?.getSystemInfo?.().then(t=>{e&&t?.success&&m(t.homedir||null)}).catch(()=>{}),()=>{e=!1}},[a,s]),(0,r.useEffect)(()=>{if(!s)return;let t=!0;if(l?.emit)return l.emit("getAgentSessions",{cwd:s},s=>{t&&u((Array.isArray(s?.sessions)?s.sessions:[]).filter(t=>!e||t.agent===e).slice(0,8))}),()=>{t=!1}},[s,e]);let f=s?sf(s,x):"";return(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-center p-6 select-none overflow-y-auto custom-scrollbar",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-2xl flex items-center justify-center mb-3 shadow-md border border-border-subtle/40 backdrop-blur-sm shrink-0",style:{backgroundColor:`${t.color}15`},children:(0,n.jsx)("img",{src:e1(`${e}-ui`),alt:t.label,className:`w-7 h-7 object-contain ${e0}`})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-text mb-1",children:t.label}),f&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-3 text-[11px] font-mono text-text-muted",title:s,children:[(0,n.jsx)("span",{className:"truncate max-w-[220px]",children:f}),p.branch&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/50",children:"\xb7"}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:p.branch}),p.dirty&&(0,n.jsxs)("span",{className:"text-amber-400",title:`${p.changedCount} changed`,children:["●",p.changedCount]})]})]}),d.length>0&&(0,n.jsxs)("div",{className:"w-full max-w-md mb-4 text-left",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1.5 px-1 text-[10px] uppercase tracking-wide text-text-muted",children:[(0,n.jsx)(en.BZ,{size:11}),(0,n.jsx)("span",{children:"Recent in this project"})]}),(0,n.jsx)("div",{className:"max-h-[38vh] overflow-y-auto custom-scrollbar rounded-brand border border-border-subtle bg-surface-2/30",children:d.map(e=>{let t=!!e.openSessionId;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),t?window.dispatchEvent(new CustomEvent(eV.vP,{detail:{sessionId:e.openSessionId}})):o?.(e)},className:"w-full flex items-center gap-2 px-2.5 py-1.5 text-left border-b border-border-subtle/50 last:border-b-0 hover:bg-surface-2 transition-colors",title:t?c("agentHistory.openNow"):void 0,children:[(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-[11px] ${t?"text-text font-medium":"text-text-muted"}`,children:e.title||"Untitled conversation"}),(0,n.jsx)("span",{className:"shrink-0 text-[10px] font-mono text-text-muted",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m`;let s=Math.round(t/60);return s<24?`${s}h`:`${Math.round(s/24)}d`}(e.updatedAt)})]},`${e.agent}:${e.sessionId}`)})}),d.length>=8&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),o?.()},className:"mt-1.5 px-1 text-[10px] font-mono text-text-muted hover:text-text transition-colors",children:"All conversations →"})]}),(0,n.jsx)("div",{className:"flex flex-wrap items-center justify-center gap-2 max-w-md shrink-0",children:tb.y2.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>i?.(e),className:"px-2.5 py-1 rounded-full bg-surface-2 hover:bg-surface-3 text-[11px] text-text font-mono border border-border-subtle transition-colors",children:e},e))})]})}),iV=(0,r.memo)(function({sessionId:e,engine:t="claude",workspacePath:s="",bus:l=null,fileBus:a=null,onSendPrompt:i,onResolvePermission:o,hasOlder:c=!1,onLoadOlder:d,onRewind:u,onPreviewRewind:x,onCutLocal:m,onListRewindPoints:p,onOpenResume:f,hydrating:h=!1,synced:b=!0,hydrateFailed:g=!1,onReload:v}){let y=(0,r.useRef)(null),w=(0,r.useRef)(null),j=(0,r.useRef)(!0),k=(0,r.useRef)(null),N=(0,r.useRef)(null),C=(0,r.useRef)(null),S=(0,r.useRef)(null),E=(0,r.useRef)(0),[R,T]=(0,r.useState)(!1),[$,M]=(0,r.useState)(131072),[z,P]=(0,r.useState)(null),I=(0,r.useRef)({sessionId:null,n:0}),L=a7(t=>t.bySession[e]?.messages)||iF,D=tb.UB[t]||tb.UB.claude;(0,r.useEffect)(()=>{M(131072),P(null),S.current=null},[e]);let{id:B,index:F}=(0,r.useMemo)(()=>(function(e,t,s){if(!t?.length)return{id:null,index:0};let n=it(t,s,void 0),r=null!=e?t.findIndex(t=>t.id===e):-1,l=it(t,Math.max(524288,s),void 0),a=r<0?n:Math.max(r,l);return{id:t[a].id,index:a}})(z,L,$),[z,L,$]);(0,r.useEffect)(()=>{P(B)},[B]);let K=F>0?L.slice(F):L,[O,W]=(0,r.useState)(null),_=(0,r.useRef)(0),H=(0,r.useMemo)(()=>L.filter(e=>"user"===e.role).length,[L]);(0,r.useEffect)(()=>{if(O?.ok||O?.supported===!1||_.current>=6)return;_.current+=1;let e=!0;return p?.().then(t=>{e&&W(t)}).catch(()=>{}),()=>{e=!1}},[p,t,e,H,O?.ok,O?.supported]);let q=!!O?.ok,U=(0,r.useMemo)(()=>{let e=new Map,t=0;for(let s=L.length-1;s>=0;s--)"user"===L[s].role&&e.set(L[s].id,t++);return e},[L]),V=(0,r.useMemo)(()=>{let e=[];for(let t of K)"user"===t.role||0===e.length?e.push({key:t.id,messages:[t]}):e[e.length-1].messages.push(t);return e},[K]),X=(0,r.useCallback)(async({auto:e=!1}={})=>{let t=y.current,s=Date.now();if(!e&&s-E.current<300)return;E.current=s;let n=C.current,r=n?function({scrollTop:e=0,scrollHeight:t=0,clientHeight:s=0,nodeTop:n=0}={}){return{nodeTop:n,scrollTop:e,atBottom:t-e-s<8}}(iK(t,n)):null,l=r?{...r,atBottom:e&&j.current,node:n}:null,a={hiddenCount:F,hasOlder:c,scrollTop:t?.scrollTop??0,scrollHeight:t?.scrollHeight??0},i=null;0===F&&c&&(i=await d?.()),(0,A.Lq)("ai-page","loadMore",{...a,fetched:i}),S.current=l,P(null),M(e=>e+131072)},[F,c,d]);(0,r.useLayoutEffect)(()=>{let e=y.current,t=S.current;if(!e||!t)return;S.current=null;let s=function(e,{scrollHeight:t=0,clientHeight:s=0,nodeTop:n=0}={}){return e?e.atBottom?t:n<=e.nodeTop?null:Math.max(0,n-(e.nodeTop-e.scrollTop)):null}(t,iK(e,t.node)||{});null!=s&&(e.scrollTop=s);let n=e.scrollHeight-e.scrollTop-e.clientHeight;j.current=n<8,T(n>140)},[$,z]),(0,r.useEffect)(()=>{let t=I.current;t.sessionId!==e&&(t.sessionId=e,t.n=0),!(t.n>=40)&&!h&&b&&j.current&&c&&L?.length&&L[F]?.role!=="user"&&(t.n+=1,X({auto:!0}))},[e,L,F,c,h,b,X]);let G=(0,r.useCallback)(()=>{k.current||(k.current=requestAnimationFrame(()=>{k.current=null;let e=y.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight,s=t<80;j.current=s,T(!s&&t>140),e.scrollTop<120&&(F>0||c)&&X()}))},[X,F,c]);(0,r.useEffect)(()=>{let e=y.current,t=w.current;if(!e||!t)return;let s=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&!j.current&&X()},{root:e,rootMargin:"120px"});return s.observe(t),()=>s.disconnect()},[X]);let J=(0,r.useMemo)(()=>L.map(e=>`${e.id}:${+!!e.thinking}:${+!!e.content}:${e.tools?.length||0}:${e.diffs?.length||0}:${+!!e.permission}`).join("|"),[L]),Y=(0,r.useCallback)(e=>{C.current=e},[]);(0,r.useEffect)(()=>{let e=y.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},[J]);let Z=(0,r.useMemo)(()=>L.reduce((e,t)=>e+(t.content?.length||0),0),[L]);(0,r.useEffect)(()=>{!j.current||N.current||(N.current=setTimeout(()=>{N.current=null;let e=y.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},150))},[Z]),(0,r.useEffect)(()=>()=>{N.current&&clearTimeout(N.current)},[]),(0,r.useEffect)(()=>{let e=y.current;if(!e)return;let t=new ResizeObserver(()=>{j.current&&(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>t.disconnect()},[]);let Q=(0,r.useCallback)(()=>{(0,eo.e)();let e=y.current;e&&(e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),j.current=!0,T(!1))},[]),ee=(0,r.useCallback)(e=>e.messages.some(e=>e.isLive),[]);return(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{ref:y,onScroll:G,className:"ai-conversation flex-1 min-h-0 overflow-y-auto px-4 sm:px-6 py-4 space-y-4 custom-scrollbar relative",children:[(F>0||c)&&(0,n.jsx)("div",{ref:w,"aria-hidden":"true",className:"h-px"}),0===L.length?b?(0,n.jsx)(iU,{engine:t,engineMeta:D,workspacePath:s,bus:l,fileBus:a,onSendPrompt:i,onOpenResume:f}):(0,n.jsx)(iH,{engine:t,failed:g,onRetry:v}):(0,n.jsxs)(n.Fragment,{children:[(F>0||c)&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),X()},className:"w-full py-1.5 text-[11px] font-mono text-text-muted hover:text-text bg-surface-2/50 hover:bg-surface-2 border border-border-subtle/60 rounded-brand transition-colors",children:F>0?`Load older \xb7 ${F} more`:"Load older turns"}),V.map((e,r)=>{let[l,...a]=e.messages;return"user"!==l.role?(0,n.jsx)("div",{ref:0===r?Y:void 0,children:(0,n.jsx)(iB,{messages:e.messages,engine:t,workspacePath:s,onResolvePermission:o,isLive:ee(e)})},e.key):(0,n.jsxs)("div",{ref:0===r?Y:void 0,children:[(0,n.jsx)(ic,{message:l,engine:t,workspacePath:s,onResolvePermission:o,onRewind:u,onPreviewRewind:x,onCutLocal:m,rewindIndex:U.get(l.id),canRewind:q}),(0,n.jsx)(iB,{messages:a,engine:t,workspacePath:s,onResolvePermission:o,isLive:ee(e)})]},e.key)}),(0,n.jsx)(iq,{sessionId:e,engine:t,hydrating:h})]})]}),R&&(0,n.jsx)("button",{type:"button",onClick:Q,className:"absolute bottom-4 right-6 p-2 rounded-full bg-surface-2 border border-border-subtle shadow-lg hover:bg-surface-3 text-text transition-all duration-150 z-30",title:"Scroll to bottom",children:(0,n.jsx)(en.yd,{size:16})})]})});function iX(e){return e.provider?e.provider:e.id&&e.id.includes("/")?e.id.split("/")[0]:""}function iG(e,t,s,n){let r=n?t:e,l=[],a=r.filter(e=>e.recent||e.id===s).sort((e,t)=>(e.recentRank??999)-(t.recentRank??999));a.length>0&&l.push({key:"recent",title:"Recent",items:a});let i=new Set(a.map(e=>e.id)),o=r.filter(e=>!i.has(e.id)),c=new Map;for(let e of o){let t=iX(e)||"other";c.has(t)||c.set(t,[]),c.get(t).push(e)}for(let e of[...c.keys()].sort((e,t)=>"opencode-go"===e?-1:"opencode-go"===t?1:"opencode"===e?-1:"opencode"===t?1:e.localeCompare(t))){let t=c.get(e)||[];0!==t.length&&(t.sort((e,t)=>(e.label||e.id).localeCompare(t.label||t.id)),l.push({key:e,title:e?"opencode-go"===e?"OpenCode Go":"opencode"===e?"OpenCode Zen":"9router"===e?"9Router":"google-antigravity"===e?"Google Antigravity":"ollama-cloud"===e?"Ollama Cloud":"anthropic"===e?"Anthropic":"openai"===e?"OpenAI":"google"===e?"Google":e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):"Other Models",items:t}))}return l}let iJ=[],iY=(0,r.memo)(function({sessionId:e="",engine:t="claude",bus:s=null,isTurnRunning:l=!1,isFocused:a=!1,onSend:i,onRemoveQueueItem:o,onClearQueue:c,onStop:d,onRunShell:u,onResolvePermission:x,onSelectModel:m,onModeChange:p,onOpenModal:f,onOptionChange:h,onActivate:b,fileBus:g=null,workspacePath:v="",model:y="",modalOpen:w=!1}){let{t:j,locale:k}=(0,ec.s)(),N="mouse"===tF(),C=ti()?"Opt ←/→ \xb7 Opt 1…9 to switch tab":"Ctrl+Shift+←/→ \xb7 1…9 to switch tab",S=(0,aT.Tw)(t),E=S.permissionModes,R=S.slashCommands,T=a7(t=>t.bySession[e]?.isTurnRunning),$=a7(t=>t.bySession[e]?.metadata?.model),M=a7(t=>t.bySession[e]?.metadata?.modelOptions),z=M?.length?M:S.models,P=a7(t=>t.bySession[e]?.metadata?.skills)||iJ,I=a7(t=>t.bySession[e]?.metadata?.commands)||iJ,A=a7(t=>t.bySession[e]?.permissionMode),L=a7(t=>t.bySession[e]?.metadata?.effort||t.bySession[e]?.metadata?.variant),D=A||S.defaultMode,B=void 0!==T?T:l,F=void 0!==$?$:y,[K,O]=(0,r.useState)(""),W=a7(t=>t.bySession[e]?.queue)||iJ,[_,H]=(0,r.useState)(-1),q=(0,r.useRef)(""),[U,V]=(0,r.useState)(!1),[X,G]=(0,r.useState)(null),[J,Y]=(0,r.useState)(""),[Z,Q]=(0,r.useState)([]),[ee,et]=(0,r.useState)(0),[es,er]=(0,r.useState)(null),[el,ea]=(0,r.useState)(-1),ei=tk(e=>e.addCommand),ed=tk(e=>e.resolveAlias),eu=tk(e=>e.history),ex=tk(e=>e.pinned),em=(0,r.useMemo)(()=>U?[]:tT(K,eu,ex,[],!N),[K,eu,ex,N,U]),[ep,ef]=(0,r.useState)(!1),[eh,eb]=(0,r.useState)(""),[eg,ev]=(0,r.useState)(()=>new Set),[ey,ew]=(0,r.useState)(!1),[ej,ek]=(0,r.useState)(!1),eN=(0,r.useRef)(null),{attachments:eC,setAttachments:eS,removeAttachment:eE,handleFileUpload:eR,handleAttachPaste:eT}=tV({bus:s,sessionId:e}),[e$]=tI(k),eM=tD({lang:tz(e$),onText:e=>{O(e),eL.current&&(eL.current.value=e,eL.current.style.height="auto",eL.current.style.height=`${Math.min(eL.current.scrollHeight,120)}px`,eL.current.focus())}}),ez=(0,r.useCallback)(()=>{(0,eo.e)(),eM.stop()},[eM]),eP=(0,r.useCallback)(()=>{eM.cancel()},[eM]),eI=(0,r.useCallback)(()=>{eM.listening?eM.stop():(document.activeElement?.blur(),eM.start(K))},[eM,K]),eA=(0,r.useCallback)(()=>{(0,eo.e)(),O(""),eL.current&&(eL.current.value="",eL.current.style.height="26px");try{localStorage.removeItem(`9remote_draft_${e}`)}catch{}eL.current?.focus()},[e]),eL=(0,r.useRef)(null),eD=(0,r.useRef)(eC);(0,r.useEffect)(()=>{eD.current=eC},[eC]);let eB=(0,r.useRef)(null),eF=(0,r.useRef)(!1),eK=(0,r.useRef)(0),eO=(0,r.useRef)(0),eW=(0,r.useRef)(0);tb.UB[t]||tb.UB.claude,(0,r.useEffect)(()=>{a&&!w&&N&&eL.current?.focus({preventScroll:!0})},[a,w,N]),(0,r.useEffect)(()=>{let e=e=>{eN.current&&!eN.current.contains(e.target)&&(ef(!1),ew(!1))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,r.useEffect)(()=>{B&&(ef(!1),ew(!1))},[B]),(0,r.useEffect)(()=>{let e=eL.current;if(!e)return;e.style.height="auto";let t=Math.min(e.scrollHeight,140);e.style.height=`${Math.max(t,26)}px`},[K]),(0,r.useEffect)(()=>{if(!U||!eB.current)return;let e=eB.current.querySelectorAll("[data-menu-item]")[ee];e&&e.scrollIntoView({block:"nearest"})},[ee,U]),(0,r.useEffect)(()=>{if(e){eS([]);try{O(localStorage.getItem(`9remote_draft_${e}`)||"")}catch{}}},[e,eS]),(0,r.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{try{K?localStorage.setItem(`9remote_draft_${e}`,K):localStorage.removeItem(`9remote_draft_${e}`)}catch{}},300);return()=>clearTimeout(t)},[K,e]),(0,r.useEffect)(()=>{if(es){let e=es.name.replace(/[/@]/g,"\\$&");if(RegExp(`(?:^|\\s)${e}\\s*$`).test(K))return;er(null)}let e=/(?:^|\s)([/@][\w\d_.-]*)$/.exec(K);if(!e){V(!1),G(null),Y("");return}let t=e[1],n=t[0],r=t.slice(1).toLowerCase();if(G(n),Y(r),et(0),"/"===n){let e=function({staticCommands:e=[],liveCommands:t=[],skills:s=[],filter:n=""}={}){let r=(t||[]).map(e=>({name:`/${e.name}`,description:e.description||"",isCommand:!0})),l=(s||[]).map(e=>({name:`/${e.name||e.id}`,description:e.description||`Skill: ${e.name||e.id}`,isSkill:!0})),a=new Set,i=String(n||"").toLowerCase();return[...e||[],...r,...l].filter(e=>!a.has(e.name)&&!!e.name.toLowerCase().includes(i)&&(a.add(e.name),!0))}({staticCommands:R,liveCommands:I,skills:P,filter:r});Q(e),V(e.length>0)}else"@"===n&&(s?.emit?s.emit("ai:files",{workspace:v,query:r},e=>{e?.ok&&Array.isArray(e.files)&&(Q(e.files.map(e=>({name:e.path||e,description:e.isModified?`${e.dir?e.dir+" \xb7 ":""}modified`:e.dir||""}))),V(e.files.length>0))}):g?.searchFiles&&v?g.searchFiles(v,r).then(e=>{e?.success&&Array.isArray(e.files)&&(Q(e.files.slice(0,10).map(e=>({name:e.path||e,description:e.relPath||e}))),V(e.files.length>0))}):(Q([]),V(!1)))},[K,g,v,P,I,R,es]);let e_=(0,r.useCallback)(t=>{let s=ed((("string"==typeof t?t:eL.current?eL.current.value:K)||K).trim()),n=eD.current;if(!s&&0===n.length)return;let r=Date.now();if(r-eO.current<250)return;eO.current=r,eW.current=r,(0,eo.e)(),s&&!s.startsWith("!")&&ei(s),H(-1),O(""),eL.current&&(eL.current.value="",eL.current.style.height="26px");try{localStorage.removeItem(`9remote_draft_${e}`)}catch{}if(s.startsWith("!")){n.length||u?.(s.slice(1).trim());return}let l=a7.getState().bySession[e]?.activePermission;l&&x?.(l.requestId,tb.x6,tb.mX),n.length&&eS([]),i?.(s,{attachments:n.map(({name:e,type:t,content:s})=>({filename:e,type:t,content:s}))})},[K,e,i,u,x,eS,ei,ed]),eH=(0,r.useCallback)(()=>{(0,eo.e)(),d?.()},[d]),eq=(0,r.useCallback)(e=>{let t=e.action||"send",[s,n]=t.split(":");if("modal"===s){eL.current?.blur(),f?.(n);return}if("clear"===s){i?.("/clear",{force:!0}),O("");return}if("setMode"===s){p?.(e.mode),O("");return}if("send"===s||"send"===t){i?.(e.name),O("");return}eL.current?.focus()},[f,i,p]),eU=(0,r.useCallback)(e=>{(0,eo.e)();let t=/(?:^|\s)([/@][\w\d_.-]*)$/.exec(K);if(!t)return;let s=t[1],n=K.slice(0,K.length-s.length),r="/"===X&&e.action?.startsWith("modal:"),l="@"===X?`@${e.name} `:`${e.name} `;(O(r?n:`${n}${l}`),V(!1),"/"!==X)?eL.current?.focus():"submenu"===e.action&&Array.isArray(e.subOptions)&&e.subOptions.length>0?B&&("effort"===e.optionKey||"variant"===e.optionKey)?O(""):(er(e),et(0),V(!0)):eq(e)},[K,X,eq,B]),eV=(0,r.useCallback)(e=>{(0,eo.e)(),es&&(h?.(es.optionKey,e.value),er(null),V(!1),O(""),eL.current?.focus())},[es,h]),eX=(0,r.useCallback)(e=>{(0,eo.e)();let t=/(?:^|\s)(\S*)$/.exec(K),s=t?t[1]:"";O(K.slice(0,K.length-s.length)+e),ea(-1),eL.current?.focus()},[K]),eG=e=>String(e||"").toLowerCase().replace(/\[[^\]]*\]$/,""),eJ=(0,r.useMemo)(()=>{if(!F)return null;let e=z||[],t=eG(F);return e.find(e=>e.id===F)||e.find(e=>eG(e.id)===t)||e.find(e=>eG(e.id).split("/").pop()===t.split("/").pop())||null},[F,z]),eY=eJ?.short||eJ?.label||F||"Model",eZ=L||S.defaultEffort||"",eQ=(0,r.useMemo)(()=>{let e=[...z||[]];return F&&!e.some(e=>e.id===F)&&e.unshift({id:F,label:F,short:F}),e},[z,F]),e2=(0,r.useMemo)(()=>{if(eQ.length<=20)return eQ;let e=eh.trim().toLowerCase();return e?eQ.filter(t=>{let s=(t.id||"").toLowerCase();return(t.label||"").toLowerCase().includes(e)||s.includes(e)||(t.provider||"").toLowerCase().includes(e)}):eQ},[eQ,eh]),e5=(0,r.useMemo)(()=>eQ.length<=20?[{key:"all",title:"",items:eQ}]:iG(eQ,e2,F,eh.trim()),[eQ,e2,F,eh]),e3=(0,r.useMemo)(()=>(R||[]).find(e=>"submenu"===e.action&&("effort"===e.optionKey||"variant"===e.optionKey)),[R]),e4=(0,r.useMemo)(()=>{let e=(eJ?.efforts||[]).map(e=>({value:e,label:e}));return e.length>0?e:e3?.subOptions||[]},[e3,eJ]);return(0,n.jsxs)("div",{className:"relative px-3 py-1.5 bg-transparent border-t border-border-subtle/40 select-none",children:[U&&es&&(0,n.jsxs)("div",{ref:eB,className:"absolute left-3 right-3 bottom-[calc(100%+6px)] max-h-52 bg-surface border border-border-subtle rounded-brand shadow-lg overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsxs)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1 flex items-center justify-between",children:[(0,n.jsxs)("span",{children:[es.name," — ",es.optionKey]}),(0,n.jsx)("button",{type:"button",onClick:()=>{er(null),V(!1),O("")},className:"text-text-muted hover:text-text",children:(0,n.jsx)(en.X,{size:11})})]}),(es.subOptions||[]).map((e,t)=>(0,n.jsxs)("div",{"data-menu-item":"true",onClick:()=>eV(e),onMouseEnter:()=>et(t),className:`px-2 py-1 rounded-brand flex items-center justify-between text-xs cursor-pointer ${t===ee?"bg-surface-2 text-text font-medium":"text-text-muted hover:text-text"}`,children:[(0,n.jsx)("span",{className:"font-mono text-xs text-text",children:e.label}),e.desc&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted truncate ml-2 max-w-[55%]",children:e.desc})]},e.value))]}),U&&!es&&Z.length>0&&(0,n.jsxs)("div",{ref:eB,className:"absolute left-3 right-3 bottom-[calc(100%+6px)] max-h-52 bg-surface border border-border-subtle rounded-brand shadow-lg overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"/"===X?"Slash Commands & Skills":"Files in repo (@)"}),Z.map((e,t)=>{let s=B&&("/model"===e.name||"submenu"===e.action&&("effort"===e.optionKey||"variant"===e.optionKey));return(0,n.jsxs)("div",{"data-menu-item":"true",onClick:s?void 0:()=>eU(e),onMouseEnter:()=>et(t),className:`px-2 py-1 rounded-brand flex items-center justify-between text-xs ${s?"opacity-40 cursor-not-allowed":t===ee?"bg-surface-2 text-text font-medium cursor-pointer":"text-text-muted hover:text-text cursor-pointer"}`,title:s?"Cannot change while turn is running":void 0,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 truncate",children:[e.isSkill?(0,n.jsx)(en.Kq,{size:12,className:"text-warning shrink-0"}):"/"===X?(0,n.jsx)(en.BK,{size:12,className:"text-accent shrink-0"}):(0,n.jsx)(en.GD,{size:12,className:"text-accent shrink-0"}),(0,n.jsx)("span",{className:"font-mono text-xs text-text",children:e.name}),e.isSkill&&(0,n.jsx)("span",{className:"text-[9px] px-1 rounded bg-warning/15 text-warning font-mono",children:"skill"}),"submenu"===e.action&&(0,n.jsx)(en.rX,{size:11,className:"text-text-muted shrink-0 rotate-90"})]}),e.description&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted truncate ml-2 max-w-[50%]",children:e.description})]},e.name)})]}),W.length>0&&(0,n.jsx)("div",{className:"mb-1 space-y-0.5",children:W.map((e,t)=>(0,n.jsxs)("div",{className:"px-2 py-0.5 rounded bg-brand-500/10 border border-brand-500/30 flex items-center justify-between text-xs animate-in fade-in duration-100",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-mono text-[9px] uppercase tracking-wider font-semibold px-1 rounded bg-brand-500/20 text-brand-400 shrink-0",children:0===t?"Next":`Queued ${t+1}`}),(0,n.jsx)("span",{className:"truncate text-text font-mono text-[11px]",children:e.text}),e.attachments?.length>0&&(0,n.jsxs)("span",{className:"shrink-0 text-text-muted flex items-center gap-0.5 font-mono text-[10px]",children:[(0,n.jsx)(en.xv,{size:10}),e.attachments.length]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0 ml-2",children:[0===t&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),eH()},className:"text-text-muted hover:text-brand-400 p-1 rounded hover:bg-surface-2 transition-colors cursor-pointer",title:"Send now (stops the current turn)",children:(0,n.jsx)(en.Vn,{size:13})}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),o?.(e.id)},className:"text-text-muted hover:text-text p-1 rounded hover:bg-surface-2 transition-colors cursor-pointer",title:"Remove from queue",children:(0,n.jsx)(en.X,{size:14})})]})]},e.id))}),(0,n.jsx)(t5,{voice:eM,onDone:ez,onCancel:eP,className:"mb-1.5"}),(0,n.jsxs)("div",{className:"relative rounded-brand border border-border-subtle/80 bg-transparent focus-within:border-brand-500 transition-colors px-2.5 py-1 flex flex-col gap-1",children:[eC.length>0&&(0,n.jsx)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x pt-0.5",children:eC.map(e=>(0,n.jsxs)("div",{className:"relative flex-shrink-0 group",children:[e.isImage?(0,n.jsx)("img",{src:`data:${e.type};base64,${e.content}`,alt:e.name,className:"w-10 h-10 object-cover rounded border border-border-subtle"}):(0,n.jsxs)("div",{className:"w-10 h-10 flex flex-col items-center justify-center rounded border border-border-subtle bg-surface-2 px-1",children:[(0,n.jsx)(en.xv,{size:12,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-[8px] text-text-muted truncate w-full text-center",children:e.name})]}),(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>eE(e.id),className:"absolute -top-1.5 -right-1.5 w-4 h-4 flex items-center justify-center bg-surface-3 rounded-full text-text-muted hover:text-text border border-border-subtle","aria-label":"Remove attachment",children:(0,n.jsx)(en.X,{size:10})})]},e.id))}),(0,n.jsx)(t$,{value:K,store:tk,isMobile:!N,activeIndex:el,onSelect:eX}),(0,n.jsxs)("div",{className:"flex items-start gap-1",children:[(0,n.jsx)("textarea",{ref:eL,value:K,onPaste:eT,onChange:e=>{if(Date.now()-eW.current<200){eL.current&&(eL.current.value="");return}O(e.target.value),ea(-1)},onFocus:()=>b?.(),onKeyDown:t=>{if(w||t.nativeEvent?.isComposing||229===t.keyCode)return;if(t.shiftKey&&"Tab"===t.key){t.preventDefault(),t.stopPropagation(),(0,eo.e)();let e=E||[];if(e.length>0){let t=e.findIndex(e=>e.id===D),s=-1===t?0:(t+1)%e.length,n=e[s]?.id;n&&p?.(n)}return}if("Escape"===t.key){if(es){t.preventDefault(),er(null),V(!1),O("");return}if(U){t.preventDefault(),V(!1);return}if(B){t.preventDefault(),console.log("[TEMP DIAGNOSTIC] Esc → stop",{sessionId:e}),eH();return}if(W.length>0){t.preventDefault(),c?.();return}}if(es){let e=es.subOptions||[];if("ArrowDown"===t.key){t.preventDefault(),et(t=>(t+1)%e.length);return}if("ArrowUp"===t.key){t.preventDefault(),et(t=>(t-1+e.length)%e.length);return}if("Enter"===t.key||"Tab"===t.key){t.preventDefault(),eV(e[ee]);return}}if(U&&Z.length>0){if("ArrowDown"===t.key){t.preventDefault(),et(e=>(e+1)%Z.length);return}if("ArrowUp"===t.key){t.preventDefault(),et(e=>(e-1+Z.length)%Z.length);return}if("Enter"===t.key||"Tab"===t.key){t.preventDefault(),eU(Z[ee]);return}}if(em.length>0){let e=el<0?-1:(el%em.length+em.length)%em.length;if("Tab"===t.key&&!t.shiftKey){t.preventDefault(),ea(-1===e?0:(e+1)%em.length);return}if(("Enter"===t.key||"Tab"===t.key)&&-1!==e){t.preventDefault(),eX(em[e].cmd);return}}let s=eL.current,n=s?.selectionStart??0,r=s?.value??"",l=-1===r.lastIndexOf("\n",n-1),a=-1===r.indexOf("\n",n);if("ArrowUp"===t.key&&!es&&!U&&l&&eu.length>0){t.preventDefault(),-1===_&&(q.current=K);let e=Math.min(_+1,eu.length-1);if(e===_)return;H(e),O(eu[e]);return}if("ArrowDown"===t.key&&!es&&!U&&a&&-1!==_){t.preventDefault();let e=_-1;e<0?(H(-1),O(q.current)):(H(e),O(eu[e]));return}if("Enter"===t.key&&(t.metaKey||t.ctrlKey)){t.preventDefault(),e_();return}"Enter"===t.key&&!t.shiftKey&&N&&(t.preventDefault(),e_())},onCompositionStart:()=>{eF.current=!0},onCompositionEnd:()=>{eF.current=!1,eK.current=Date.now(),Date.now()-eW.current<200&&(eL.current&&(eL.current.value=""),O(""))},placeholder:B?N?"Type command \xb7 Enter to queue \xb7 Esc to stop":"Type command \xb7 Send to queue":N?`Type command \xb7 ${C}`:"Type command",rows:1,className:"ai-conversation ai-composer-input flex-1 min-w-0 bg-transparent resize-none text-xs text-text placeholder-text-muted focus:outline-none custom-scrollbar leading-snug min-h-[24px]"}),K.trim().length>0?(0,n.jsx)("button",{type:"button",onClick:eA,className:"shrink-0 mt-0.5 p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center justify-center",title:"Clear input",children:(0,n.jsx)(en.X,{size:16})}):(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),ek(!0)},className:"shrink-0 mt-0.5 p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center justify-center",title:j("history.title"),children:(0,n.jsx)(en.BZ,{size:16})})]}),(0,n.jsxs)("div",{className:"relative flex items-center justify-between text-xs pt-0.5 border-t border-border-subtle/30",children:[(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:(0,n.jsxs)("div",{ref:eN,className:"relative min-w-0 flex items-center gap-1",children:[(0,n.jsxs)("button",{type:"button",disabled:B,onClick:()=>{ef(!ep),ep||eb(""),ew(!1)},className:"min-w-0 px-1.5 py-0.5 rounded text-[11px] font-medium flex items-center gap-1 font-mono text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",title:B?"Cannot change model while turn is running":"Select model (/model)",children:[(0,n.jsx)("img",{src:e1(`${t}-ui`),alt:"",className:`w-3.5 h-3.5 object-contain shrink-0 ${e0}`}),(0,n.jsx)("span",{dir:"rtl",className:"truncate min-w-0",children:(0,n.jsx)("bdi",{children:eY})}),(0,n.jsx)(en.rX,{size:11,className:`text-text-muted shrink-0 transition-transform ${ep?"":"rotate-180"}`})]}),ep&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[260px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"Select Model"}),eQ.length>20&&(0,n.jsxs)("div",{className:"px-1.5 pb-1.5 mb-1 border-b border-border-subtle flex items-center gap-1.5 text-text-muted",children:[(0,n.jsx)(en.vj,{size:12,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:eh,onChange:e=>eb(e.target.value),placeholder:"Search models...",autoFocus:!0,className:"w-full bg-transparent text-[11px] text-text placeholder-text-muted/70 focus:outline-none py-0.5"})]}),0===e2.length&&(0,n.jsxs)("div",{className:"px-2 py-2 text-[11px] text-text-muted",children:['No models match "',eh,'"']}),e5.map(e=>(0,n.jsxs)("div",{children:[e5.length>1&&(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.key,void ev(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},"aria-expanded":!eg.has(e.key),className:"w-full px-2 py-0.5 text-[10px] font-mono uppercase tracking-wider font-semibold text-text flex items-center justify-between select-none border-b border-border-subtle mb-1 mt-1 first:mt-0",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-[8px]",children:eg.has(e.key)?"▶":"▼"}),e.title]}),(0,n.jsx)("span",{className:"text-[9px] text-text-subtle",children:e.items.length})]}),!eg.has(e.key)&&e.items.map(e=>{let t=F===e.id;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),m?.(e.id),ef(!1)},title:e.id,className:`w-full pl-4 pr-2 py-1.5 rounded text-left text-xs flex flex-col gap-0.5 transition-colors ${t?"bg-surface-2 text-text font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsxs)("span",{className:"w-full flex items-center justify-between",children:[(0,n.jsx)("span",{className:"truncate",children:e.label}),t&&(0,n.jsx)(en.aJ,{size:12,className:"text-text shrink-0 ml-1"})]}),e.label!==e.id&&(0,n.jsx)("span",{className:"truncate font-mono text-[10px] text-text-subtle",children:e.id})]},e.id)})]},e.key))]}),e4.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:B,onClick:()=>{ew(e=>!e),ef(!1)},className:"shrink-0 px-1 py-0.5 rounded text-[10px] uppercase tracking-wide font-mono text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",title:B?`Cannot change ${e3?.optionKey||"effort"} while turn is running`:`Select ${e3?.optionKey||"effort"}`,children:eZ||"—"}),ey&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[220px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:e3?.optionKey==="variant"?"Variant":"Reasoning effort"}),e4.map(e=>{let t=eZ===e.value;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),h?.(e3?.optionKey||"effort",e.value),ew(!1)},className:`w-full px-2 py-1.5 rounded text-left text-xs flex items-center justify-between gap-2 transition-colors ${t?"bg-brand-500/15 text-brand-400 font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),t&&(0,n.jsx)(en.aJ,{size:12,className:"text-brand-400 shrink-0"}),!t&&e.desc&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle truncate max-w-[55%]",children:e.desc})]},e.value)})]})]})]})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 pl-1.5",children:[(0,n.jsxs)("label",{className:"p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer flex items-center justify-center",title:"Attach file or image",children:[(0,n.jsx)(en.xv,{size:15}),(0,n.jsx)("input",{type:"file",multiple:!0,onChange:eR,className:"hidden",accept:"*/*"})]}),eM.active&&(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:eI,title:j("not-allowed"===eM.error||"service-not-allowed"===eM.error?"voice.denied":"voice.dictate"),"aria-label":j("voice.dictate"),className:`p-1.5 rounded flex items-center justify-center transition-colors ${eM.listening?"bg-red-500/90 text-white animate-pulse":eM.error?"text-red-400":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:eM.listening?(0,n.jsx)(en.jj,{size:15}):(0,n.jsx)(en.GO,{size:15})}),B?(0,n.jsxs)(n.Fragment,{children:[(K.trim()||eC.length>0)&&(0,n.jsxs)("button",{type:"button",onClick:e_,className:"px-2 py-0.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 text-[11px] font-medium transition-colors shadow-sm cursor-pointer",title:N?"Queue message (Enter)":"Queue message",children:[(0,n.jsx)(en.Vn,{size:13}),(0,n.jsx)("span",{children:"Queue"})]}),(0,n.jsx)("button",{type:"button",onClick:eH,className:"px-2 py-0.5 rounded bg-danger/20 hover:bg-danger/30 text-danger flex items-center gap-1 text-[11px] font-medium transition-colors cursor-pointer",title:W.length?"Stop & run the next queued message (Esc)":"Stop generation (Esc)",children:(0,n.jsx)(en.M6,{size:13,className:"fill-current"})})]}):(0,n.jsx)("button",{type:"button",onClick:e_,disabled:!K.trim()&&0===eC.length,className:`px-2 py-1 rounded transition-colors flex items-center justify-center ${K.trim()||eC.length>0?"bg-brand-500 hover:bg-brand-600 text-white shadow-sm cursor-pointer":"text-text-muted bg-surface-2 cursor-not-allowed opacity-40"}`,title:"Send (Enter)",children:(0,n.jsx)(en.Vn,{size:14})})]})]})]}),(0,n.jsx)(tC,{isOpen:ej,store:tk,onSelect:eX,onClose:()=>ek(!1)})]})}),iZ={Shield:"text-text-muted",Pencil:"text-accent",Eye:"text-accent",Sparkles:"text-warning"},iQ=(0,r.memo)(function({sessionId:e="",sessionName:t="",engine:s="claude",workspacePath:l="",fileBus:a=null,isTurnRunning:i=!1,isDesktop:o=!0,onModeChange:c,onNewChat:d}){let u=a7(t=>t.bySession[e]?.isTurnRunning),x=a7(t=>t.bySession[e]?.metadata),m=x?.goal,p=(0,aT.Tw)(s).permissionModes||[],f=a7(t=>t.bySession[e]?.permissionMode)||(0,aT.Tw)(s).defaultMode,{branch:h,dirty:b}=n8(l,a,{enabled:!!a&&!!l}),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=e=>{y.current&&!y.current.contains(e.target)&&v(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let w=p.find(e=>e.id===f)||p[0];return(0,n.jsxs)("div",{className:`relative min-h-6 px-3 bg-surface/50 border-t border-border-subtle/50 flex items-center text-[11px] font-mono text-text-muted select-none flex-shrink-0 z-20 gap-3${o?"":" safe-area-bottom"}`,children:[(void 0!==u?u:i)&&(0,n.jsx)(av,{className:"hidden sm:block"}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[w&&p.length>0&&(0,n.jsxs)("div",{ref:y,className:"relative",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),v(e=>!e)},className:"hover:text-text flex items-center gap-1 transition-colors",title:"Change permission mode (Shift+Tab)",children:[(0,n.jsx)(en.Ay,{name:w.icon||"Shield",size:11,className:`${iZ[w.icon]||"text-text-muted"} shrink-0`}),(0,n.jsx)("span",{children:w.label}),(0,n.jsx)(en.rX,{size:11,className:`text-text-muted transition-transform ${g?"":"rotate-180"}`})]}),g&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[220px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"Permission Mode"}),p.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),c?.(e.id),v(!1)},className:`w-full px-2 py-1.5 rounded text-left text-xs flex flex-col gap-0.5 transition-colors cursor-pointer ${f===e.id?"bg-brand-500/15 text-brand-400 font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(en.Ay,{name:e.icon||"Shield",size:12,className:`${iZ[e.icon]||"text-text-muted"} shrink-0`}),(0,n.jsx)("span",{children:e.label})]}),f===e.id&&(0,n.jsx)(en.aJ,{size:12,className:"text-brand-400 shrink-0"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted/70 font-normal font-sans leading-tight",children:e.desc})]},e.id))]})]}),m?.objective&&(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",title:`Goal (${m.status}): ${m.objective}`,children:[(0,n.jsx)(en.We,{size:11,className:`shrink-0 ${"active"===m.status?"text-danger":"text-text-muted"}`}),(0,n.jsx)("span",{className:"truncate max-w-[22ch]",children:m.objective})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 shrink-0",children:[h&&!(0,eV.ok)(h)&&(0,n.jsx)(n9,{branch:h,dirty:b,size:11,className:"text-text font-medium",iconClassName:"text-brand-500 opacity-100"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),d?.()},className:"hover:text-text flex items-center transition-colors p-0.5 rounded hover:bg-surface-2",title:"New chat",children:(0,n.jsx)(en.J4,{size:12})})]})]})}),i0=(0,r.memo)(function({skills:e=[],onClose:t,onSelectSkill:s}){let[l,a]=(0,r.useState)(""),i=e.filter(e=>{let t=l.toLowerCase();return(e.name||e.id||"").toLowerCase().includes(t)||(e.description||"").toLowerCase().includes(t)});return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.Kq,{size:14}),title:`Agent Skills (${e.length})`,subtitle:"Skills loaded from ~/.claude/skills and project directory",onClose:t,children:[(0,n.jsx)("div",{className:"p-3 border-b border-border-subtle bg-bg",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-brand bg-surface border border-border-subtle focus-within:border-brand-500",children:[(0,n.jsx)(en.vj,{size:14,className:"text-text-muted shrink-0"}),(0,n.jsx)("input",{type:"text",value:l,onChange:e=>a(e.target.value),placeholder:"Search skills (e.g. cloudflare, review, deploy)...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted focus:outline-none",autoFocus:!0})]})}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.Kq,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:0===e.length?"No skills discovered on host agent.":`No skills matching "${l}".`})]}):i.map(e=>(0,n.jsxs)("div",{onClick:()=>{(0,eo.e)(),s?.(e.name||e.id),t?.()},className:"modal-row items-start",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1 flex flex-col gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 font-mono text-xs font-semibold text-text",children:[(0,n.jsxs)("span",{children:["/",e.name||e.id]}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-3 text-text-muted font-normal",children:"skill"})]}),e.description&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted leading-relaxed line-clamp-2",children:e.description})]}),(0,n.jsxs)("span",{className:"modal-row-acts text-[11px] text-brand-500 items-center gap-1",children:[(0,n.jsx)("span",{children:"Use"}),(0,n.jsx)(en.Lt,{size:11})]})]},e.id||e.name))})]})}),i1=(0,r.memo)(function({mcpServers:e=[],onClose:t}){return(0,n.jsx)(nl,{icon:(0,n.jsx)(en.lP,{size:14}),iconClass:"bg-sky-500/15 text-sky-400",title:`MCP Servers (${e.length})`,subtitle:"Model Context Protocol tools and integrations",onClose:t,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===e.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.lP,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:"No MCP servers configured yet."})]}):e.map((e,t)=>(0,n.jsxs)("div",{className:"modal-row",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"text-xs font-semibold text-text flex items-center gap-2",children:[(0,n.jsx)(en.Jl,{size:13,className:"text-emerald-400 shrink-0"}),(0,n.jsx)("span",{className:"font-mono",children:e.name||e.id})]}),e.command&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted font-mono break-all mt-1",children:e.command})]}),(0,n.jsx)("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-emerald-500/15 text-emerald-300 border border-emerald-500/30 uppercase shrink-0 ml-2",children:e.status||"active"})]},e.id||t))})})}),i2=(0,r.memo)(function({currentModel:e="",currentEffort:t="",models:s=[],onClose:l,onSelectModel:a,onSelectEffort:i,isTurnRunning:o=!1}){let[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(e),[m,p]=(0,r.useState)(()=>new Set),f=(0,r.useMemo)(()=>{let t=[...s||[]];return e&&!t.some(t=>t.id===e)&&t.unshift({id:e,label:e,desc:"Active CLI model",recent:!0}),t},[s,e]),h=f.find(e=>e.id===u),b=h?.efforts||[],g=(0,r.useMemo)(()=>{let e=c.trim().toLowerCase();return e?f.filter(t=>{let s=(t.label||"").toLowerCase(),n=(t.id||"").toLowerCase(),r=(t.desc||"").toLowerCase(),l=iX(t).toLowerCase();return s.includes(e)||n.includes(e)||r.includes(e)||l.includes(e)}):f},[f,c]),v=(0,r.useMemo)(()=>iG(f,g,e,c.trim()),[f,g,e,c]);return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.cC,{size:14}),title:"Switch AI Model",subtitle:"Select an active model for this session",maxWidth:"max-w-md",onClose:l,children:[(0,n.jsx)("div",{className:"px-4 py-2.5 border-b border-border-subtle shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 focus-within:text-text text-text-muted",children:[(0,n.jsx)(en.vj,{size:14,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Search models...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted/70 focus:outline-none",autoFocus:!0}),c&&(0,n.jsx)("button",{type:"button",onClick:()=>d(""),className:"text-text-muted hover:text-text shrink-0 text-xs px-1","aria-label":"Clear search",children:"✕"})]})}),b.length>0&&(0,n.jsxs)("div",{className:"px-3 pt-3 shrink-0",children:[(0,n.jsx)("div",{className:"text-[10px] font-mono uppercase tracking-wider text-text-muted mb-1.5",children:"Reasoning effort"}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:b.map(e=>(0,n.jsx)("button",{type:"button",disabled:o,onClick:()=>{(0,eo.e)(),i?.(e)},className:`px-2.5 py-1 rounded-brand text-[11px] font-mono border transition-colors ${t===e?"border-brand-500 bg-brand-500/10 text-brand-400":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"} disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent`,title:o?"Cannot change effort while turn is running":void 0,children:e},e))})]}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===g.length?(0,n.jsxs)("div",{className:"py-8 text-center text-xs text-text-muted",children:['No models found matching "',c,'"']}):v.map(e=>(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 mb-2",children:[v.length>1&&(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.key,void p(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},"aria-expanded":!m.has(e.key),className:"w-full text-left text-[10px] font-mono uppercase tracking-wider font-semibold text-text px-2 pt-2 pb-1 select-none flex items-center justify-between border-b border-border-subtle",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-[8px]",children:m.has(e.key)?"▶":"▼"}),e.title]}),(0,n.jsx)("span",{className:"text-text-subtle text-[9px]",children:e.items.length})]}),!m.has(e.key)&&e.items.map(s=>{var r;let l=u===s.id,c=iX(s),d=(r=s.contextWindow)&&!(r<=0)?r>=1e6?`${Math.round(r/1e5)/10}M`:r>=1e3?`${Math.round(r/1e3)}k`:`${r}`:null;return(0,n.jsxs)("div",{onClick:o?void 0:()=>(e=>{(0,eo.e)(),a?.(e),x(e);let s=f.find(t=>t.id===e),n=s?.efforts||[];if(n.length>0&&!n.includes(t)){let e=s?.defaultEffort||n[0];e&&i?.(e)}})(s.id),"data-selected":l,className:`modal-row ml-2 ${o?"opacity-40 cursor-not-allowed pointer-events-none":""}`,title:o?"Cannot change model while turn is running":s.id,children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:`text-xs flex items-center gap-1.5 flex-wrap ${l?"text-text font-semibold":"text-text-muted"}`,children:[(0,n.jsx)("span",{className:"truncate",children:s.label||s.id}),"opencode"===c&&(0,n.jsx)("span",{className:"text-[9px] px-1.5 py-0.2 rounded bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 font-mono shrink-0",children:"Free"}),d&&(0,n.jsx)("span",{className:"text-[9px] px-1 py-0.2 rounded bg-surface-2/60 text-text-subtle font-mono shrink-0",children:d}),s.efforts?.length>0&&(0,n.jsx)("span",{className:"text-[9px] px-1 py-0.2 rounded bg-brand-500/10 text-brand-400 font-mono shrink-0",children:"reasoning"})]}),(s.desc||s.label!==s.id&&s.id)&&(0,n.jsx)("div",{className:"text-[10px] font-mono text-text-subtle truncate mt-0.5",children:s.desc||s.id})]}),l&&(0,n.jsx)(en.aJ,{size:14,className:"text-text shrink-0"})]},`${e.key}-${s.id}`)})]},e.key))})]})}),i5=(0,r.memo)(function({engine:e="claude",workspacePath:t="",bus:s=null,onClose:l,onResume:a}){let[i,o]=(0,r.useState)([]),[c,d]=(0,r.useState)(!0),[u,x]=(0,r.useState)(""),m=(0,r.useCallback)(()=>{if(!s?.emit||!t){o([]),d(!1);return}d(!0),s.emit("getAgentSessions",{cwd:t},e=>{o(Array.isArray(e?.sessions)?e.sessions:[]),d(!1)})},[t]);(0,r.useEffect)(()=>{m()},[m]);let p=(0,r.useMemo)(()=>{let t=u.toLowerCase();return i.filter(t=>!e||t.agent===e).filter(e=>!t||(e.title||"").toLowerCase().includes(t)||(e.sessionId||"").toLowerCase().includes(t))},[i,e,u]);return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.BZ,{size:14}),iconClass:"bg-sky-500/15 text-sky-400",title:"Resume a session",subtitle:`Past ${e} conversations in this project`,maxWidth:"max-w-xl",onClose:l,children:[(0,n.jsx)("div",{className:"px-4 py-2.5 border-b border-border-subtle shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 focus-within:text-text text-text-muted",children:[(0,n.jsx)(en.vj,{size:14,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:u,onChange:e=>x(e.target.value),placeholder:"Search sessions...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted/70 focus:outline-none",autoFocus:!0}),(0,n.jsx)("button",{type:"button",onClick:m,className:"hover:text-text shrink-0",title:"Refresh",children:(0,n.jsx)(en.e9,{size:13,className:c?"animate-spin":""})})]})}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:c?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-text-muted",children:[(0,n.jsx)(en.kr,{size:14,className:"animate-spin"}),(0,n.jsx)("span",{children:"Scanning conversations..."})]}):0===p.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.BZ,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:0===i.length?"No past conversations found for this project.":`No sessions matching "${u}".`})]}):p.map(e=>{let t=!!e.openSessionId;return(0,n.jsxs)("div",{onClick:()=>{if((0,eo.e)(),t){window.dispatchEvent(new CustomEvent(eV.vP,{detail:{sessionId:e.openSessionId}})),l?.();return}(0,eo.e)(),a?.(e),l?.()},className:"modal-row",title:e.sessionId,children:[(0,n.jsx)("img",{src:e1("ui"===e.mode?`${e.agent}-ui`:e.agent),alt:e.agent,className:`shrink-0 ${e0} ${t?"":"opacity-50"}`,style:{width:14,height:14}}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-xs ${t?"text-text font-medium":"text-text-muted"}`,children:e.title||"Untitled conversation"}),e.updatedAt?(0,n.jsx)("span",{className:"shrink-0 text-[10px] font-mono text-text-subtle tabular-nums",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m ago`;let s=Math.round(t/60);return s<24?`${s}h ago`:`${Math.round(s/24)}d ago`}(e.updatedAt)}):null]},`${e.agent}:${e.sessionId}`)})})]})}),i3={claude:{shape:"flat",items:[]},codex:{shape:"flat",items:[{key:"personality",kind:"menu",label:"Personality",desc:"Communication style codex is instructed to use",choices:[{value:"",label:"Default"},...aT.Mm],default:""},{key:"networkAccess",kind:"bool",label:"Network access",desc:"Let sandboxed commands reach the network",default:!1},{key:"planEffort",kind:"menu",label:"Plan mode reasoning",desc:"Reasoning tier used while in plan mode",choices:[{value:"",label:"Default"},{value:"low",label:"low"},{value:"medium",label:"medium"},{value:"high",label:"high"},{value:"xhigh",label:"xhigh"}],default:""},{key:"addDirs",kind:"list",label:"Extra writable directories",desc:"Absolute paths, comma-separated",default:[]},{key:"enable",kind:"list",label:"Enable features",desc:"Feature names, comma-separated (see `codex features list`)",default:[]},{key:"disable",kind:"list",label:"Disable features",desc:"Feature names, comma-separated",default:[]},{key:"skipGitRepoCheck",kind:"bool",label:"Allow outside a git repo",desc:"Run in a directory without a repository",default:!1},{key:"ephemeral",kind:"bool",label:"Ephemeral run",desc:"Do not persist the session to disk",default:!1}]},opencode:{shape:"flags",items:[{key:"pure",kind:"bool",label:"Pure mode",desc:"Run without external plugins",default:!1},{key:"printLogs",kind:"bool",label:"Print logs",desc:"Show CLI logs on stderr",default:!1}]}};function i4(e){return i3[e]||{shape:"flat",items:[]}}let i6=(0,r.memo)(function({engine:e="claude",options:t,onClose:s,onApply:l}){let{shape:a,items:i}=i4(e),[o,c]=(0,r.useState)(()=>{let s,n;return s=i4(e).items,n=t||{},Object.fromEntries(s.map(e=>[e.key,void 0!==n[e.key]?n[e.key]:e.default]))}),d=(e,t)=>c(s=>({...s,[e]:t}));return(0,n.jsx)(nl,{icon:(0,n.jsx)(en.wB,{size:14}),iconClass:"bg-surface-3 text-text-muted",title:"Configuration",subtitle:`Runtime flags for ${e}`,maxWidth:"max-w-md",onClose:s,footer:i.length>0?(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border-subtle flex justify-end gap-2 shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"px-3 py-1.5 rounded-brand text-xs text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)();let e={};for(let t of i){let s=o[t.key];"list"===t.kind?e[t.key]=String(s||"").split(",").map(e=>e.trim()).filter(Boolean):e[t.key]=s}l?.("flags"===a?{flags:e}:e),s?.()},className:"px-3 py-1.5 rounded-brand text-xs bg-brand-500 hover:bg-brand-600 text-white font-medium transition-colors",children:"Apply"})]}):null,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-2 custom-scrollbar",children:0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.wB,{size:32,className:"opacity-50"}),(0,n.jsxs)("span",{className:"text-sm",children:["No runtime flags are configurable for ",e,"."]})]}):i.map(e=>(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-surface-2/50",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text",children:e.label}),(0,n.jsx)("div",{className:"text-[11px] text-text-muted",children:e.desc})]}),"bool"===e.kind&&(0,n.jsx)("input",{type:"checkbox",checked:!!o[e.key],onChange:()=>d(e.key,!o[e.key]),className:"w-4 h-4 accent-brand-500 rounded shrink-0"})]}),"menu"===e.kind&&(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-2",children:e.choices.map(t=>(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),d(e.key,t.value)},className:`px-2.5 py-1 rounded-brand text-[11px] border transition-colors ${o[e.key]===t.value?"border-brand-500 bg-brand-500/10 text-brand-400":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"}`,children:t.label},t.value))}),"list"===e.kind&&(0,n.jsx)("input",{type:"text",value:Array.isArray(o[e.key])?o[e.key].join(", "):o[e.key]||"",onChange:t=>d(e.key,t.target.value),placeholder:"/path/one, /path/two",className:"mt-2 w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs font-mono text-text placeholder-text-muted focus:outline-none focus:border-brand-500"})]},e.key))})})}),i8={Shield:"text-text-muted",Pencil:"text-accent",Eye:"text-accent",Sparkles:"text-warning"},i9=(0,r.memo)(function({modes:e=[],currentMode:t="",onClose:s,onSelectMode:r}){return(0,n.jsx)(nl,{icon:(0,n.jsx)(en.Ay,{name:"Shield",size:14}),title:"Permissions",subtitle:"What the agent may do without asking",maxWidth:"max-w-md",onClose:s,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:e.map(e=>{let l=t===e.id;return(0,n.jsxs)("div",{onClick:()=>{var t;return t=e.id,void((0,eo.e)(),r?.(t),s?.())},"data-selected":l,className:"modal-row",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[(0,n.jsx)(en.Ay,{name:e.icon||"Shield",size:14,className:`${i8[e.icon]||"text-text-muted"} shrink-0`}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text",children:e.label}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle",children:e.desc})]})]}),l&&(0,n.jsx)(en.aJ,{size:14,className:"text-brand-500 shrink-0"})]},e.id)})})})}),i7=(0,r.memo)(function({engine:e="claude",workspacePath:t="",bus:s=null,onClose:l}){let[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!0),d=(0,r.useCallback)(()=>{if(!s?.emit){i({error:"Not connected to the host agent."}),c(!1);return}c(!0),s.emit("ai:doctor",{engine:e,cwd:t},e=>{i(e?.ok?{output:e.output||"",version:e.version||""}:{error:e?.error||"Doctor check failed."}),c(!1)})},[e,t]);return(0,r.useEffect)(()=>{d()},[d]),(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.mN,{size:14}),iconClass:"bg-emerald-500/15 text-emerald-400",title:"Diagnostics",subtitle:`Health check for the ${e} CLI`,onClose:l,children:[(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto custom-scrollbar",children:o?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-8 text-xs text-text-muted",children:[(0,n.jsx)(en.kr,{size:14,className:"animate-spin"}),(0,n.jsxs)("span",{children:["Running ",e," doctor..."]})]}):a?.error?(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-danger/10 border border-danger/30 text-danger text-xs flex items-start gap-2",children:[(0,n.jsx)(en.RI,{size:14,className:"shrink-0 mt-0.5"}),(0,n.jsx)("span",{children:a.error})]}):(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-emerald-500/10 border border-emerald-500/30 text-emerald-300 text-xs flex items-center gap-2",children:[(0,n.jsx)(en.Jl,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"font-medium",children:a?.version?`${e} ${a.version}`:`${e} environment report`})]}),(0,n.jsx)("pre",{className:"p-3 rounded-brand bg-bg border border-border-subtle text-[11px] font-mono text-text-muted whitespace-pre-wrap break-words leading-relaxed",children:a?.output||"No output."})]})}),(0,n.jsx)("div",{className:"px-4 py-3 border-t border-border-subtle flex justify-end shrink-0",children:(0,n.jsxs)("button",{type:"button",onClick:d,disabled:o,className:"px-3 py-1.5 rounded-brand text-xs text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-1.5 disabled:opacity-50",children:[(0,n.jsx)(en.e9,{size:12,className:o?"animate-spin":""}),(0,n.jsx)("span",{children:"Re-run"})]})})]})}),oe={completed:{icon:en.Jl,cls:"text-emerald-400",line:"line-through text-text-muted"},in_progress:{icon:en.kr,cls:"text-sky-400 animate-spin",line:"text-sky-300 font-semibold"},pending:{icon:en.jl,cls:"text-text-muted",line:"text-text"}},ot=(0,r.memo)(function({tasks:e=[],onClose:t}){let s=e.length,r=e.filter(e=>"completed"===e.status).length,l=e.filter(e=>"in_progress"===e.status).length,a=s-r-l;return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.y8,{size:14}),iconClass:"bg-brand-500/15 text-brand-500",title:`Tasks (${s})`,subtitle:"Checklist the agent is working through",onClose:t,children:[(0,n.jsx)("div",{className:"grid grid-cols-4 gap-2 px-4 py-3 border-b border-border-subtle bg-bg text-center shrink-0",children:[{label:"TOTAL",value:s,cls:"text-text"},{label:"RUNNING",value:l,cls:"text-sky-400"},{label:"DONE",value:r,cls:"text-emerald-400"},{label:"PENDING",value:a,cls:"text-text-muted"}].map(e=>(0,n.jsxs)("div",{className:"p-2 rounded-brand bg-surface-2/40",children:[(0,n.jsx)("div",{className:"text-[10px] text-text-muted font-mono",children:e.label}),(0,n.jsx)("div",{className:`text-base font-bold ${e.cls}`,children:e.value})]},e.label))}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===s?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.y8,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:"No tasks in this session yet."})]}):e.map((e,t)=>{let s=oe[e.status]||oe.pending,r=s.icon;return(0,n.jsxs)("div",{className:"modal-row items-start",children:[(0,n.jsx)(r,{size:14,className:`${s.cls} shrink-0 mt-0.5`}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:`text-xs ${s.line}`,children:e.subject||e.activeForm||"(untitled task)"}),e.activeForm&&"in_progress"===e.status&&(0,n.jsx)("div",{className:"text-[11px] text-sky-400/80 font-mono mt-0.5 truncate",children:e.activeForm})]}),e.taskId&&(0,n.jsxs)("span",{className:"text-[10px] font-mono text-text-muted shrink-0",children:["#",e.taskId]})]},e.id||t)})})]})}),os=(0,r.memo)(function({sessionId:e="",onListPoints:t,onPreview:s,onApply:l,onClose:a}){let[i,o]=(0,r.useState)([]),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(!0),[m,p]=(0,r.useState)(null),[f,h]=(0,r.useState)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)("");(0,r.useEffect)(()=>{let e=!0;return t?.().then(t=>{e&&(t||y("The host did not answer. Try again."),o(t?.points||[]),d(t?.support||null),x(!1))}).catch(()=>{e&&(y("Could not read this conversation."),x(!1))}),()=>{e=!1}},[t]);let w=(0,r.useCallback)(async e=>{(0,eo.e)(),p(e),h(null),y("");let t=await s?.(e.messageId);t?.ok?h(t):y(t?.error||"The host could not preview this rewind.")},[s]),j=(0,r.useCallback)(async()=>{if(!m)return;(0,eo.e)(),g(!0),y("");let e=await l?.(m.messageId);(g(!1),e?.ok)?a?.():y(e?.error||"The rewind did not go through.")},[m,l,a]),k=c&&!c.conversation;return(0,n.jsx)(nl,{icon:(0,n.jsx)(en.BZ,{size:14}),iconClass:"bg-amber-500/15 text-amber-400",title:"Rewind",subtitle:"Go back to an earlier prompt. Turns after it are discarded.",maxWidth:"max-w-xl",onClose:a,children:u?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-text-muted",children:[(0,n.jsx)(en.kr,{size:14,className:"animate-spin"}),(0,n.jsx)("span",{children:"Reading this conversation..."})]}):k?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 py-12 px-6 text-center text-text-muted",children:[(0,n.jsx)(en.RI,{size:28,className:"opacity-60"}),(0,n.jsx)("span",{className:"text-sm",children:c.how||"This engine cannot rewind a conversation."})]}):0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(en.BZ,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:v||"Nothing to rewind to yet."})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar max-h-[45vh]",children:[...i].reverse().map(e=>(0,n.jsxs)("div",{onClick:()=>w(e),className:`modal-row ${m?.messageId===e.messageId?"modal-row-active":""}`,children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-xs text-text truncate",children:e.text||"Untitled prompt"}),e.createdAt&&(0,n.jsx)("div",{className:"mt-1 text-[10px] font-mono text-text-subtle",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m ago`;let s=Math.round(t/60);return s<24?`${s}h ago`:`${Math.round(s/24)}d ago`}(Date.parse(e.createdAt))})]}),(0,n.jsxs)("span",{className:"modal-row-acts text-[11px] text-brand-500 items-center gap-1",children:[(0,n.jsx)("span",{children:m?.messageId===e.messageId?"Selected":"Pick"}),(0,n.jsx)(en.Lt,{size:11})]})]},e.messageId))}),v&&(0,n.jsx)("div",{className:"px-3 py-2 border-t border-border-subtle text-[11px] text-danger bg-danger/5",children:v}),(0,n.jsxs)("div",{className:"p-3 border-t border-border-subtle bg-bg shrink-0 flex flex-col gap-2",children:[m&&(0,n.jsx)("div",{className:"text-[11px] leading-relaxed text-text-muted",children:f?.files?.length>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text",children:f.files.length})," file",1===f.files.length?"":"s"," will be restored.",(0,n.jsxs)("ul",{className:"mt-1 flex flex-col gap-0.5",children:[f.files.slice(0,8).map(e=>(0,n.jsxs)("li",{className:"truncate font-mono text-[10px]",title:e.file,children:["\xb7 ",e.file,e.status?` (${e.status})`:""]},e.file)),f.files.length>8&&(0,n.jsxs)("li",{className:"text-[10px]",children:["… and ",f.files.length-8," more"]})]}),f.note&&(0,n.jsx)("span",{className:"block mt-1 text-text-subtle",children:f.note})]}):f?(0,n.jsx)("span",{className:"block text-text-subtle",children:f.note}):(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(en.kr,{size:11,className:"animate-spin"}),"Checking what this would change..."]})}),(0,n.jsxs)("button",{type:"button",onClick:j,disabled:!m||b||!f?.ok,className:`px-3 py-1.5 rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors ${m&&!b&&f?.ok?"bg-brand-500 hover:bg-brand-600 text-white cursor-pointer":"bg-surface-2 text-text-muted cursor-not-allowed opacity-50"}`,children:[b?(0,n.jsx)(en.kr,{size:13,className:"animate-spin"}):(0,n.jsx)(en.aJ,{size:13}),(0,n.jsx)("span",{children:b?"Rewinding...":"Rewind to this prompt"})]})]})]})})}),on=(0,r.memo)(function({requestId:e="",tool:t="",input:s={},failed:l=!1,onResolve:a}){let[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),u=function(e){if(e?.kind!=="permission_grant")return"";let t=[],s=String(e.reason||"").trim();return s&&t.push(s),t.push(...function(e={}){let t=[];e?.network?.enabled&&t.push("• network access");let s=e?.fileSystem||{};for(let e of s.read||[])t.push(`• read ${e}`);for(let e of s.write||[])t.push(`• write ${e}`);for(let e of s.entries||[]){var n;let s="string"==typeof(n=e?.path)?n:n?.path||n?.pattern||n?.value||"";s&&t.push(`• ${e.access||"access"} ${s}`)}return t}(e.permissions)),t.join("\n")}(s)||s?.command||s?.path||JSON.stringify(s||{});return(0,n.jsxs)("div",{className:"my-3 p-3 rounded-brand-lg border border-warning/30 bg-surface shadow-sm text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-warning font-medium",children:[(0,n.jsx)(en.ek,{size:16}),(0,n.jsx)("span",{children:"Permission Request"}),(0,n.jsx)("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-warning/15 text-warning uppercase min-w-0 break-all",title:t,children:t||"Action"})]}),(0,n.jsx)("div",{className:"p-2.5 rounded bg-bg font-mono text-[11px] text-text break-all border border-border-subtle mb-3 max-h-[140px] overflow-y-auto",children:u}),c&&(0,n.jsx)("div",{className:"mb-3",children:(0,n.jsx)("input",{type:"text",value:i,onChange:e=>o(e.target.value),placeholder:"Reason for denial or alternative instructions...",className:"w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs text-text placeholder-text-muted focus:outline-none focus:border-brand-500",autoFocus:!0})}),l&&(0,n.jsx)("div",{className:"mb-3 text-[11px] text-danger leading-snug",children:"Not sent — the host did not answer. Try again."}),(0,n.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[c?(0,n.jsx)("button",{type:"button",onClick:()=>d(!1),className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Hide note"}):(0,n.jsx)("button",{type:"button",onClick:()=>d(!0),className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Add note"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),a?.(e,"deny",i||"User denied")},className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-danger/20 text-danger flex items-center gap-1 font-medium transition-colors",children:[(0,n.jsx)(en.X,{size:14}),(0,n.jsx)("span",{children:"Deny"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),a?.(e,"allow")},className:"px-3.5 py-1.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 font-medium transition-colors shadow-sm",children:[(0,n.jsx)(en.aJ,{size:14}),(0,n.jsx)("span",{children:"Allow"})]})]})]})}),or=(0,r.memo)(function({engine:e="",message:t="",reason:s="",escalate:r=null,onEscalate:l,onDismiss:a}){return(0,n.jsxs)("div",{className:"my-3 p-3 rounded-brand-lg border border-danger/40 bg-surface shadow-sm text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-danger font-medium",children:[(0,n.jsx)(en.ek,{size:16}),(0,n.jsx)("span",{children:"Action blocked"}),e&&(0,n.jsx)("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-danger/15 text-danger uppercase",children:e})]}),(0,n.jsx)("div",{className:"p-2.5 rounded bg-bg text-[11px] text-text border border-border-subtle mb-3 whitespace-pre-wrap break-words max-h-[160px] overflow-y-auto",children:t||s||"The CLI refused this action under the current permission mode."}),(0,n.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),a?.()},className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-1",children:[(0,n.jsx)(en.X,{size:13}),(0,n.jsx)("span",{children:"Dismiss"})]}),r?.mode&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),l?.(r?.mode)},className:"px-3.5 py-1.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 font-medium transition-colors shadow-sm",children:[(0,n.jsx)(en.sU,{size:14}),(0,n.jsxs)("span",{children:["Switch to ",r.label||r.mode]})]})]})]})}),ol=[],oa=(0,r.memo)(function({sessionId:e=""}){let[t,s]=(0,r.useState)(!1),l=a7(t=>t.bySession[e]?.tasks),a=(0,r.useMemo)(()=>Array.isArray(l)?l.filter(e=>!!(e&&e.subject&&String(e.subject).trim().length>0)):ol,[l]);if(0===a.length)return null;let i=a.filter(e=>"completed"===e.status).length,o=a.find(e=>"in_progress"===e.status),c=i===a.length;return(0,n.jsxs)("div",{className:"px-4 sm:px-6 py-1 border-b border-border-subtle/40 bg-surface-2/20 shrink-0 text-xs select-none",children:[(0,n.jsx)("div",{onClick:()=>s(!t),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control transition-colors group",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[c?(0,n.jsx)(en.Jl,{size:13,className:"text-success shrink-0"}):o?(0,n.jsx)(en.y8,{size:13,className:"text-brand-500 shrink-0"}):(0,n.jsx)(en.y8,{size:13,className:"text-text-muted shrink-0"}),(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:"TASKS"}),(0,n.jsxs)("span",{className:"font-mono text-[11px] text-text-muted shrink-0",children:[i,"/",a.length]}),o&&(0,n.jsx)("span",{className:"text-[11px] text-brand-500 truncate min-w-0 font-medium",children:o.activeForm||o.subject}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 ml-auto",children:t?(0,n.jsx)(en.yQ,{size:11}):(0,n.jsx)(en.c_,{size:11})})]})}),t&&(0,n.jsx)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 py-1 space-y-0.5 animate-in fade-in duration-100",children:a.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-2 py-0.5",children:["completed"===e.status?(0,n.jsx)(en.Jl,{size:12,className:"text-success shrink-0"}):"in_progress"===e.status?(0,n.jsx)(en.jG,{size:10,className:"text-brand-500 fill-brand-500 shrink-0"}):(0,n.jsx)(en.jl,{size:12,className:"text-text-muted/50 shrink-0"}),(0,n.jsx)("span",{className:`text-[11px] truncate ${"completed"===e.status?"line-through text-text-muted/60":"in_progress"===e.status?"text-text font-medium":"text-text-muted"}`,children:e.subject})]},e.id||t))})]})}),oi=e=>String(e).padStart(2,"0");function oo(e){let t=Math.max(0,Math.floor((Number(e)||0)/1e3)),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}h ${oi(n)}m`:n>0?`${n}m ${oi(r)}s`:`${r}s`}let oc=e=>Number(e?.duration_ms)||0,od={agent:{label:"Sub-agent",icon:en.cC,cls:"bg-accent/15 text-accent"},shell:{label:"Background task",icon:en.BK,cls:"bg-warning/15 text-warning"}},ou={running:"bg-sky-500/15 text-sky-400",completed:"bg-emerald-500/15 text-emerald-400",failed:"bg-danger/15 text-danger",killed:"bg-danger/15 text-danger",stopped:"bg-surface-2 text-text-muted",paused:"bg-warning/15 text-warning"},ox=(0,r.memo)(function({tasks:e=[],messages:t=[],engine:s="claude",sessionId:l="",onStopTask:a,onClose:i}){let[o,c]=(0,r.useState)(()=>Date.now()),[d,u]=(0,r.useState)(null),x=a7(e=>e.bySession[l]?.harnessTasks);(0,r.useEffect)(()=>{let e=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(e)},[]);let m=(0,r.useMemo)(()=>e.map(e=>x?.find(t=>t.taskId===e.taskId)||e),[e,x]),p=m.find(e=>e.taskId===d)||m[0];if(!p)return null;let f=aq(p,o),h=!p.endedAt&&("running"===p.status||"paused"===p.status),b=ou[p.status]||(h?ou.running:ou.stopped);return(0,n.jsxs)(nl,{icon:(0,n.jsx)(en.BZ,{size:14}),iconClass:"bg-brand-500/15 text-brand-500",title:h?`Running for ${oo(f)}`:`Ended \xb7 ${oo(f)}`,subtitle:`${m.length} task${m.length>1?"s":""} handed off`,onClose:i,children:[m.length>1&&(0,n.jsx)("div",{className:"flex gap-1 px-3 py-2 border-b border-border-subtle overflow-x-auto custom-scrollbar shrink-0",children:m.map(e=>{let t=od[e.background?"shell":"agent"].icon,s=e.taskId===p.taskId;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),u(e.taskId)},className:`flex items-center gap-1.5 shrink-0 px-2 py-1 rounded-full text-[11px] transition-colors ${s?"bg-brand-500/15 text-brand-400 font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(t,{size:11,className:"shrink-0"}),(0,n.jsx)("span",{className:"max-w-[18ch] truncate",children:e.description||e.subagentType||e.taskId})]},e.taskId)})}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[(0,n.jsx)(om,{task:p,elapsed:f,statusCls:b}),(0,n.jsxs)("div",{className:"p-3",children:[(0,n.jsx)(op,{task:p,messages:t,engine:s}),(0,n.jsx)(of,{task:p,messages:t,engine:s,sessionId:l}),p.usage&&(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 mt-3",children:[(0,n.jsx)(oh,{label:"TOKENS",value:aD(p.usage.total_tokens)}),(0,n.jsx)(oh,{label:"TOOLS",value:p.usage.tool_uses??0}),oc(p.usage)>0&&(0,n.jsx)(oh,{label:"TOOK",value:oo(oc(p.usage))})]}),p.summary&&(0,n.jsx)("p",{className:"mt-3 text-[11px] text-text-muted leading-relaxed border-l-2 border-border-subtle pl-3",children:p.summary}),p.outputFile&&(0,n.jsxs)("p",{className:"mt-3 font-mono text-[10px] text-text-subtle truncate",title:p.outputFile,children:["output \xb7 ",p.outputFile]})]})]}),h&&p.taskId&&a&&(0,n.jsx)("div",{className:"px-3 py-2.5 border-t border-border-subtle bg-bg shrink-0",children:(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),a(p.taskId)},className:"w-full flex items-center justify-center gap-1.5 py-2 rounded-brand text-xs font-semibold text-danger bg-danger/10 hover:bg-danger/20 transition-colors",children:[(0,n.jsx)(en.M6,{size:11}),"Stop this task"]})})]})});function om({task:e,elapsed:t,statusCls:s}){let r=od[e.background?"shell":"agent"],l=r.icon;return(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border-subtle flex items-start gap-3",children:[(0,n.jsx)("div",{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${r.cls}`,children:(0,n.jsx)(l,{size:15})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,n.jsx)("span",{className:"text-sm font-semibold text-text truncate",children:e.description||e.subagentType||"task"}),(0,n.jsx)("span",{className:`text-[10px] font-mono uppercase tracking-wider px-1.5 py-0.5 rounded ${s}`,children:e.status})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1 text-[11px] text-text-muted font-mono flex-wrap",children:[(0,n.jsx)("span",{children:r.label}),e.subagentType&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ob,{}),(0,n.jsx)("span",{className:"text-brand-500",children:e.subagentType})]}),e.taskType&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ob,{}),(0,n.jsx)("span",{children:e.taskType})]}),(0,n.jsx)(ob,{}),(0,n.jsxs)("span",{className:"text-text tabular-nums",title:"since the agent logged the task's start",children:["running ",oo(t)]}),(0,n.jsx)(ob,{}),(0,n.jsx)("span",{className:"text-text-subtle",children:e.taskId})]})]})]})}function op({task:e,messages:t,engine:s}){let r=aS(t,e.toolUseId),l=a$(r,s);if(!l||!r)return null;let a="error"===r.status;return(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-brand bg-surface-2/40 border border-border-subtle/60",children:["running"===e.status?(0,n.jsx)(en.kr,{size:12,className:"animate-spin text-brand-500 shrink-0"}):a?(0,n.jsx)(en.RI,{size:12,className:"text-danger shrink-0"}):(0,n.jsx)(en.Jl,{size:12,className:"text-success shrink-0"}),(0,n.jsx)("span",{className:"font-mono text-[10px] uppercase tracking-wider text-text-muted shrink-0",children:"now"}),(0,n.jsx)("span",{className:"text-[11px] text-text truncate min-w-0",title:l,children:l})]})}function of({task:e,messages:t,engine:s,sessionId:r}){let l=aC(t,e.toolUseId);if(!l)return null;let a=l.children?.length?l.children:[l];return(0,n.jsxs)("div",{className:"mt-3",id:(0,ik.xo)(r,"calls",l.id),children:[(0,n.jsx)("div",{className:"text-[10px] font-mono uppercase tracking-wider text-text-muted mb-1",children:l.children?.length?`${l.children.length} call${l.children.length>1?"s":""}`:"command"}),a.map(e=>iM(s,e,{engine:s})||(0,n.jsx)(ix,{...e,engine:s},e.id))]})}function oh({label:e,value:t}){return(0,n.jsxs)("div",{className:"px-2.5 py-1.5 rounded-brand bg-surface-2/40 min-w-[68px]",children:[(0,n.jsx)("div",{className:"text-[9px] font-mono text-text-muted tracking-wider",children:e}),(0,n.jsx)("div",{className:"text-xs font-semibold text-text tabular-nums",children:t})]})}let ob=()=>(0,n.jsx)("span",{className:"text-text-subtle",children:"\xb7"}),og=[],ov=(0,r.memo)(function({sessionId:e="",engine:t="claude",onStopTask:s}){let l=a7(t=>t.bySession[e]?.messages)||og,a=a7(t=>t.bySession[e]?.harnessTasks)||og,i=(0,r.useMemo)(()=>(function(e=[],t=[]){return t.length>0?t.filter(e=>e?.status==="running").map(e=>({kind:e.background?"shell":"agent",id:e.toolUseId||e.taskId,taskId:e.taskId,label:e.description||e.subagentType||"task",startedAt:e.startedAt,taskType:e.taskType,subagentType:e.subagentType,usage:e.usage,toolUseId:e.toolUseId})):function(e=[]){let t=[],s=e=>{for(let n of e||[]){if(n?.status==="running"){let e=n.startedAt||n.timestamp,s=e?{startedAt:e}:null;aj.has(n?.name)?t.push({kind:"agent",id:n.id,label:ak(n),...s}):n?.async&&t.push({kind:"shell",id:n.id,label:aN(n),...s})}n?.children?.length&&s(n.children)}};for(let n=e.length-1;n>=0&&(!e[n]?.tools?.length||(s(e[n].tools),!(t.length>0)));n--);return t}(e)})(l,a),[l,a]),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(()=>Date.now()),[x,m]=(0,r.useState)(!1),p=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(0===i.length)return;let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[i.length]),(0,r.useEffect)(()=>()=>clearTimeout(p.current),[]);let f=(0,r.useCallback)(()=>{if(!x){m(!0),(0,eo.e)(),clearTimeout(p.current),p.current=setTimeout(()=>m(!1),3e3);return}for(let e of(clearTimeout(p.current),m(!1),(0,eo.e)(),i))e.taskId&&s(e.taskId)},[x,i,s]),h=i.some(e=>e.taskId&&s);if(0===i.length)return null;let b=i.filter(e=>"agent"===e.kind),g=i.filter(e=>"shell"===e.kind);return(0,n.jsxs)("div",{className:"px-4 sm:px-6 py-1 border-b border-border-subtle/40 bg-brand-500/[0.06] shrink-0 text-xs select-none",children:[b.length>0&&(0,n.jsx)(oy,{icon:(0,n.jsx)(en.kr,{size:13,className:"text-brand-500 shrink-0 animate-spin"}),tag:"AGENTS",items:b,messages:l,engine:t,now:d,onOpen:c}),g.length>0&&(0,n.jsx)(oy,{icon:(0,n.jsx)(en.kr,{size:13,className:"text-warning shrink-0 animate-spin"}),tag:"SHELLS",items:g,messages:l,engine:t,now:d,onOpen:c}),h&&i.length>1&&(0,n.jsx)("div",{className:"flex justify-end pb-0.5",children:(0,n.jsx)("button",{type:"button",onClick:f,className:`text-[11px] px-2 py-0.5 rounded transition-colors ${x?"bg-danger/20 text-danger font-semibold":"text-text-muted hover:text-text"}`,children:x?"Press again to stop all":"Stop all"})}),o&&(0,n.jsx)(ox,{tasks:o,messages:l,engine:t,sessionId:e,onStopTask:s,onClose:()=>c(null)})]})});function oy({icon:e,tag:t,items:s,messages:r,engine:l,now:a,onOpen:i}){let o=s.map(e=>e.label).join(", "),c=aq(s.reduce((e,t)=>t.startedAt&&(!e?.startedAt||t.startedAt<e.startedAt)?t:e,null),a),d=s.map(e=>a$(aS(r,e.toolUseId),l)).find(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 min-w-0",children:[e,(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:t}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),i(s)},title:o,className:"flex items-center gap-2 min-w-0 flex-1 text-left hover:bg-surface-2/40 rounded transition-colors px-1",children:[(0,n.jsxs)("span",{className:"font-mono text-[11px] text-brand-500 shrink-0 tabular-nums",children:[s.length," running"]}),c>0&&(0,n.jsx)("span",{className:"font-mono text-[11px] text-text shrink-0 tabular-nums",children:oo(c)}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",children:d||o})]})]})}let ow={model:"",skills:[],mcpServers:[]},oj=[],ok=(0,r.memo)(function({sessionId:e,engine:t="claude",workspacePath:s="",sessionName:l="",bus:a=null,fileBus:i=null,isVisible:o=!0,isFocused:c=!1,isDesktop:d=!0,bgIndex:x=0,onActivate:m=null,onOpenRemote:p=null,onOpenMobile:f=null,onOpenArtifact:b=null,onNewChat:g=null}){let[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(!1),{t:C}=(0,ec.s)(),{sendPrompt:S,removeQueueItem:E,clearQueue:R,resolvePermission:T,stop:$,stopTask:M,runShell:z,rewindToMessage:P,previewRewind:I,listRewindPoints:L,escalateMode:D,dismissBlocked:B,hasOlder:F,loadOlder:K,reload:O,hydrating:W,synced:_,hydrateFailed:H}=function({sessionId:e,engine:t="claude",workspacePath:s="",bus:n=null,isVisible:l=!0}){let a=(0,r.useRef)(n);(0,r.useEffect)(()=>{a.current=n},[n]);let i=a7(e=>e.initSession),o=a7(e=>e.setMetadata),c=a7(e=>e.appendDelta),d=a7(e=>e.appendThinking),x=a7(e=>e.appendDiff),m=a7(e=>e.appendTool),p=a7(e=>e.updateToolResult),f=a7(e=>e.nestTool),h=a7(e=>e.nestToolResult),b=a7(e=>e.upsertTask),g=a7(e=>e.setPermission),v=a7(e=>e.clearPermission),y=a7(e=>e.finishTurn),w=a7(e=>e.setTurnRunning),j=a7(e=>e.addUserMessage),k=(0,u.d)(e=>e.connected),[N,C]=(0,r.useState)(!1),[S,E]=(0,r.useState)(!1),[R,T]=(0,r.useState)(!1),[$,M]=(0,r.useState)(!1),z=(0,r.useRef)(0),P=(0,r.useRef)(!1),I=(0,r.useCallback)((e,s,n)=>{switch(s){case"user_message":j(e,n.text,n.attachments||null,!!n?.replay);break;case"init":{let t=il(a7.getState().bySession[e]?.metadata?.skills),s=new Map(t.map(e=>[e.id||e.name,e])),r=il(n.skills),l=r.length>0?r.map(e=>{let t=s.get(e.id);return t?.description?{...e,description:t.description}:e}):t,{model:a,...i}=n||{};o(e,{...i,skills:l,...a?{model:a}:{}});break}case"goal":o(e,{goal:n?.goal||null});break;case"delta":c(e,n.text);break;case"thinking":d(e,n.text);break;case"diff":x(e,n);break;case"tool_child":f(e,n);break;case"tool_result_child":h(e,n);break;case"tool_start":if(m(e,n),n&&n.name){let s=a7.getState().bySession[e]?.tasks||[],r=(0,aT.Zm)(t,n.name,n.input,n.id,s);r&&b(e,r)}break;case"tool_result":if(p(e,n),n&&n.id){let s=(0,aT.in)(t,n.name||"",n.output||"",n.id);s&&b(e,s)}break;case"permission_request":g(e,n);break;case"permission_resolved":v(e,n.requestId);break;case"blocked":a7.getState().setBlocked(e,n);break;case"options_changed":n?.permissionMode&&a7.getState().setPermissionMode(e,n.permissionMode),n?.model&&o(e,{model:n.model}),n?.effort&&o(e,{effort:n.effort});break;case"queue_update":a7.getState().setQueue(e,n?.queue||[]);break;case"turn_complete":y(e,n.stats,n.turnMs,!!n?.replay),n?.isError&&!ia(a7.getState().bySession[e]?.messages,n.result)&&a7.getState().addNotice(e,{subtype:n.subtype||"",level:"error",content:n.result||"The turn ended in an error."});break;case"stats":n?.stats&&a7.getState().setStats(e,n.stats);break;case"stopped":case"exit":v(e),a7.getState().finishTurn(e,null,n?.turnMs),"exit"===s&&(n?.error||n?.code!=null&&0!==n.code)&&a7.getState().addNotice(e,{subtype:"exit",level:"error",content:n.error||`The AI process exited (code ${n.code}).`});break;case"stall":w(e,!1),y(e,null,n?.turnMs);break;case"error":a7.getState().addNotice(e,{subtype:"error",level:"error",content:n?.message||"AI process failed"}),y(e,null,n?.turnMs);break;case"prompt_refused":a7.getState().addNotice(e,{subtype:"prompt_refused",level:"error",content:ii(n)});break;case"conversation_reset":(0,A.Lq)("ai-status","reset",{sessionId:e,isTurnRunning:n?.isTurnRunning,elapsedMs:n?.elapsedMs,lastTurnMs:n?.lastTurnMs,fromSeq:n?.fromSeq}),a7.getState().clearMessages(e),a7.getState().setTaskRecords(e,n?.taskRecords),a7.getState().restoreTurnState(e,n),Array.isArray(n?.queue)&&a7.getState().setQueue(e,n.queue);break;case"cli_event":{let t=n?.type||"",s=n?.record||null;a7.getState().applyTaskRecords(e,[[t,n?.subtype||"",s,n?.ageMs]]);let r=aQ(t,s);r&&a7.getState().addNotice(e,r)}}},[t,j,o,c,d,x,m,p,f,h,b,g,v,y,w]),L=(0,r.useRef)(I);(0,r.useEffect)(()=>{L.current=I});let D=(0,r.useRef)(i);(0,r.useEffect)(()=>{D.current=i});let B=(0,r.useRef)(0),F=(0,r.useRef)(0),K=(0,r.useRef)(!1),O=(0,r.useRef)([]),W=(0,r.useRef)(0),_=(0,r.useRef)(null);null==_.current&&(_.current=function(e=ir){let t=0,s=!1;return{schedule:n=>s||!n?null:(s=!0,e[Math.min(t++,e.length-1)]),fired(){s=!1},answered(){s=!1,t=0},exhausted:()=>t>=e.length}}());let H=(0,r.useRef)(null),q=(0,r.useRef)(null),U=(0,r.useRef)(null),V=(0,r.useRef)({}),X=(0,r.useRef)(null),G=(0,r.useRef)(l);(0,r.useEffect)(()=>{G.current=l},[l]);let J=(0,r.useRef)(null),Y=(0,r.useRef)(null),Z=(0,r.useRef)(null),Q=(0,r.useCallback)(()=>{H.current&&clearTimeout(H.current),H.current=null,_.current?.answered()},[]),ee=(0,r.useCallback)(()=>{let e=_.current?.schedule(u.d.getState().connected);M(!!_.current?.exhausted()),(0,A.Lq)("ai-hydrate","ladder",{delay:e??null,exhausted:_.current?.exhausted(),connected:u.d.getState().connected,armed:null!=H.current}),null!=e&&(H.current=setTimeout(()=>{H.current=null,_.current?.fired(),V.current.request?.()},e))},[]),et=(0,r.useCallback)(()=>{if(!e||!n)return;if(K.current){(0,A.Lq)("ai-hydrate","blocked (round in flight)",{gen:W.current}),ee();return}let r=++W.current,l=F.current;K.current=!0,E(!0),O.current=[],z.current=0;let a=Date.now();(0,A.Lq)("ai-hydrate","emit ai:create",{gen:r,sessionId:e,engine:t,cwd:s,carrier:u.d.getState().carrier,connected:u.d.getState().connected});let i=()=>{let t=O.current;for(let s of(O.current=[],K.current=!1,E(!1),t)){if("conversation_reset"===s.event){B.current=0,F.current++,z.current=s.data?.fromSeq??0,C(!!s.data?.hasMore),L.current(e,s.event,s.data);continue}if(null!=s.seq){if(s.seq<=B.current)continue;B.current=s.seq}L.current(e,s.event,s.data)}},o=setTimeout(()=>{r===W.current&&K.current&&(i(),ee())},4e3);U.current=o,n.emit("ai:create",{sessionId:e,engine:t,cwd:s,options:{defaultMode:(0,aT.Tw)(t).defaultMode,defaultEffort:(0,aT.Tw)(t).defaultEffort}},s=>{if(!function({isNewest:e,snapshotSeq:t=0,appliedSeq:s=0,sameLog:n=!0}){return!!e||!!n&&(t||0)>(s||0)}({isNewest:r===W.current,snapshotSeq:s?.session?.seq,appliedSeq:B.current,sameLog:l===F.current}))return;let n=null,c=null,d=s?.session?.events;(0,A.Lq)("ai-hydrate","ack",{gen:r,stale:r!==W.current,ms:Date.now()-a,ok:s?.ok??null,error:s?.error??null,events:Array.isArray(d)?d.length:null,hasMore:s?.session?.hasMore??null});try{if(clearTimeout(o),!s?.ok||!Array.isArray(d))return void C(!1);let r=s.session.seq||0;if((0,A.Lq)("ai-status","hydrate ack",{sessionId:e,isTurnRunning:s.session.isTurnRunning,elapsedMs:s.session.elapsedMs,lastTurnMs:s.session.lastTurnMs,events:d.length,hasMore:s.session.hasMore}),z.current=d[0]?.seq??0,C(!!s.session.hasMore&&d.length>0),(0,A.Lq)("ai-page","hydrate",{sessionId:e,replayed:d.length,hasMore:s.session.hasMore,fromSeq:d[0]?.seq??0,lastSeq:r,oldestId:null}),Array.isArray(s?.modelOptions)&&s.modelOptions.length>0&&a7.getState().setMetadata(e,{modelOptions:s.modelOptions}),d.length>0){let n=io(d,t);a7.getState().hydrateSession(e,{messages:n.messages,tasks:n.tasks,metadata:{...a7.getState().bySession[e]?.metadata,...n.metadata,...Array.isArray(s?.modelOptions)?{modelOptions:s.modelOptions}:{},...s.session.effort?{effort:s.session.effort}:{}},stats:{...n.stats,...s.session.stats||{}},isTurnRunning:void 0!==s.session.isTurnRunning?!!s.session.isTurnRunning:n.isTurnRunning,elapsedMs:s.session.elapsedMs||0,lastTurnMs:s.session.lastTurnMs||0,permissionMode:s.session.permissionMode||n.permissionMode,activeBlocked:n.activeBlocked,harnessTasks:aZ(s.session.taskRecords,n.harnessTasks),queue:s.session.queue||[]})}else w(e,!!s.session.isTurnRunning),a7.getState().setTaskRecords(e,s.session.taskRecords),s.session.permissionMode&&a7.getState().setPermissionMode(e,s.session.permissionMode),Array.isArray(s.session.queue)&&a7.getState().setQueue(e,s.session.queue),s.session.stats&&a7.getState().setStats(e,s.session.stats);n=s.session.activePermission||null,c=Array.isArray(s.session.queue)?s.session.queue:null,B.current=r}finally{clearTimeout(o),r===W.current&&i(),n&&r===W.current&&a7.getState().setPermission(e,n),c&&r===W.current&&a7.getState().setQueue(e,c),s?.ok&&void 0!==s.session.isTurnRunning&&(a7.getState().restoreTurnState(e,{isTurnRunning:!!s.session.isTurnRunning,elapsedMs:s.session.elapsedMs||0,lastTurnMs:s.session.isTurnRunning?0:s.session.lastTurnMs||0}),(0,A.Lq)("ai-status","restate",{sessionId:e,isTurnRunning:!!s.session.isTurnRunning,elapsedMs:s.session.elapsedMs||0,lastTurnMs:s.session.lastTurnMs||0})),s?.ok?(T(!0),M(!1),Q()):ee(),(0,A.Lq)("ai-hydrate","settled",{gen:r,stale:r!==W.current,ok:s?.ok??null,hydrating:K.current,synced:!!s?.ok})}})},[e,t,s,n,w,ee,Q]),es=(0,r.useCallback)(()=>{!u.d.getState().connected||q.current||(q.current=setTimeout(()=>{q.current=null,et()},eV.qw))},[et]),en=(0,r.useCallback)(()=>{if(n&&e){if(!G.current){J.current="visible";return}!u.d.getState().connected||K.current||Y.current||(Y.current=setTimeout(()=>{if(Y.current=null,!G.current||K.current)return;let t=!1,s=setTimeout(()=>{t||((0,A.Lq)("ai-hydrate","peekSeq: no ack → full hydrate"),es())},eV.zm);Z.current=s,n.emit("ai:peekSeq",{sessionId:e},n=>{if(t=!0,clearTimeout(s),Z.current=null,!n?.ok||"number"!=typeof n.seq)return void es();let r=B.current,l=!!a7.getState().bySession[e]?.isTurnRunning,a=a7.getState().bySession[e]?.queue?.length||0,i="number"==typeof n.queueLength?n.queueLength:a;n.seq===r&&!!n.isTurnRunning===l&&i===a?(0,A.Lq)("ai-hydrate","peekSeq: nothing missed",{seq:r}):((0,A.Lq)("ai-hydrate","peekSeq: state changed",{fromSeq:r,toSeq:n.seq,turn:n.isTurnRunning}),es())})},eV.qw))}},[n,e,es]),er=(0,r.useCallback)(()=>{Q(),et()},[Q,et]);(0,r.useEffect)(()=>{V.current={request:es}},[es]),(0,r.useEffect)(()=>()=>{q.current&&clearTimeout(q.current),Y.current&&clearTimeout(Y.current),Z.current&&clearTimeout(Z.current),H.current&&clearTimeout(H.current),U.current&&clearTimeout(U.current),q.current=Y.current=Z.current=H.current=U.current=null,K.current=!1,O.current=[]},[]),(0,r.useEffect)(()=>{if(e)return X.current!==e&&(X.current=e,K.current=!1,Q(),T(!1),M(!1)),D.current(e),et()},[e,et,Q]),(0,r.useEffect)(()=>{if(!l)return;let e=J.current;e&&(J.current=null,"reconnect"===e?es():en())},[l,es,en]),(0,r.useEffect)(()=>{if(!n||!e)return;let t=()=>{document.hidden||en()},s=()=>{if(!G.current){J.current="reconnect";return}es()};return n.on("connect",s),document.addEventListener("visibilitychange",t),document.addEventListener("resume",t),()=>{n.off("connect",s),document.removeEventListener("visibilitychange",t),document.removeEventListener("resume",t)}},[n,e,en,es]);let el=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=el.current;if(el.current=k,k&&!e){if(!G.current){J.current="reconnect";return}es()}},[k,es]),(0,r.useEffect)(()=>{if(!n||!e)return;let t="",s="",r=null,l=[],a=!1,i=()=>{null!=r&&cancelAnimationFrame(r),r=null;let n=t,l=s;t="",s="",(n||l)&&a7.getState().appendStream(e,n,l)},o=()=>{a=!1;let t=l;l=[];let s=L.current;for(let n of t)n.stream?a7.getState().appendStream(e,n.data.text,n.data.thinking):s(e,n.event,n.data)},c=(e,n)=>{if("cli_event"!==e&&(t||s)){let e={stream:!0,data:{text:t,thinking:s}};t="",s="",null!=r&&(cancelAnimationFrame(r),r=null),l.push(e)}l.push({event:e,data:n}),a||(a=!0,queueMicrotask(o))},d=n=>{var l,a,o,d;if(!n||n.sessionId!==e)return;if(K.current)return void O.current.push(n);let u="delta"===n.event||"thinking"===n.event;if("conversation_reset"===n.event){B.current=0,F.current++,z.current=n.data?.fromSeq??0,C(!!n.data?.hasMore),c(n.event,n.data);return}if(l=n.seq,a=B.current,null==l||!(l<=(a||0))){if(null!=n.seq&&(B.current=n.seq),u)return void(o=n.event,(d=n.data?.text)&&("delta"===o?t+=d:s+=d,null==r&&(r=requestAnimationFrame(i))));c(n.event,n.data)}};return n.on("ai:event",d),()=>{n.off("ai:event",d),i()}},[n,e,I]);let ea=(0,r.useCallback)((t,{attachments:n=null}={})=>{if(!t&&!n?.length)return;let r=a.current;ey.getState().clearNotification(e),r?.emit("ai:prompt",{sessionId:e,message:t,cwd:s,...n?.length?{attachments:n}:{}})},[e,s]),ei=(0,r.useCallback)(t=>{let s=a7.getState().bySession[e]?.queue||[];a7.getState().setQueue(e,s.filter(e=>e.id!==t));let n=a.current;n?.emit("ai:queueRemove",{sessionId:e,id:t})},[e]),eo=(0,r.useCallback)(()=>{a7.getState().setQueue(e,[]);let t=a.current;t?.emit("ai:queueClear",{sessionId:e})},[e]),ec=(0,r.useCallback)((t,s,n="",r=null)=>{let l=a.current;if(!l)return;let i=!1,o=null,c=n=>{if(!i){if(i=!0,clearTimeout(o),n?.ok||n?.reason==="stale")return void v(e,t);(0,A.Lq)("ai-gate","resolve failed",{requestId:t,behavior:s,res:n??"timeout"}),a7.getState().setGateError(e,t)}};r?l.emit("ai:question",{sessionId:e,requestId:t,answers:r},c):l.emit("ai:permission",{sessionId:e,requestId:t,behavior:s,message:n},c),o=setTimeout(()=>c(null),tb.GX)},[e,v]),ed=(0,r.useCallback)(()=>{let t=a.current;t?.emit("ai:stop",{sessionId:e})},[e]),eu=(0,r.useCallback)(t=>{if(!t)return;let s=a.current;s?.emit("ai:stopTask",{sessionId:e,taskId:t})},[e]),ex=(0,r.useCallback)(e=>{ea(`! ${e}`)},[ea]),em=(0,r.useCallback)(async()=>{let t=a.current;if(!t)return null;let s=await new Promise(s=>{let n=!1,r=e=>{n||(n=!0,clearTimeout(l),s(e))},l=setTimeout(()=>r(null),4e3);t.emit("ai:rewind",{sessionId:e,action:"list"},r)});return s?s.support?.conversation?s.ok?{supported:!0,ok:!0,points:s.points||[],support:s.support}:{supported:!0,ok:!1,points:[],support:s.support}:{supported:!1,ok:!1,points:[],support:s.support}:null},[e]),ep=(0,r.useCallback)(async(t,n,{files:r=!0,preview:l=!1,index:i=null}={})=>{let o=a.current;if(!o)return{ok:!1,error:"Not connected to the host."};let c=await new Promise(s=>{let n=!1,a=e=>{n||(n=!0,clearTimeout(c),s(e))},c=setTimeout(()=>a(null),l?4e3:13e4);o.emit("ai:rewind",{sessionId:e,action:l?"preview":"apply",messageId:t,index:i,files:r},a)});return(l||c&&c.ok||er(),c)?(c.ok&&!l&&n&&o.emit("ai:prompt",{sessionId:e,message:n,cwd:s}),c):{ok:!1,error:"The host did not answer in time."}},[e,s,er]),ef=(0,r.useCallback)((e,{files:t=!0,index:s=null}={})=>ep(e,null,{files:t,preview:!0,index:s}),[ep]),eh=(0,r.useCallback)(t=>{if(!t)return;a7.getState().setPermissionMode(e,t),a7.getState().clearBlocked(e);let s=a.current;s?.emit("ai:options",{sessionId:e,options:{mode:t}})},[e]),eb=(0,r.useCallback)(()=>{a7.getState().clearBlocked(e)},[e]);return{hydrating:S,synced:R,hydrateFailed:$,hasOlder:N,loadOlder:(0,r.useCallback)(async()=>{if(P.current)return!1;let s=a.current;if(!s)return!1;P.current=!0;let n=z.current;try{let r=Date.now(),{messages:l,before:a,hasMore:i,answered:o,chunks:c}=await is({startSeq:n,estimateBytes:ie,fetchChunk:t=>new Promise(n=>{let r=!1,l=e=>{r||(r=!0,clearTimeout(a),n(e))},a=setTimeout(()=>l(null),4e3);s.emit("aiHistory",{sessionId:e,before:t},l)}),reduceChunk:(s,n)=>{let r=a7.getState().bySession[e];return io(s,t,(r?.messages?.length||0)+n+1).messages}});if((0,A.Lq)("ai-page","loadOlder",{sessionId:e,before:n,ms:Date.now()-r,transport:s.transport||s.carrier||"?",chunks:c,messages:l.length,bytes:Math.round(l.reduce((e,t)=>e+ie(t),0)/1024)+"KB",hasMore:i}),z.current!==n||!o||(z.current=a,C(i),!l.length))return!1;return a7.getState().prependMessages(e,l),!0}finally{P.current=!1}},[e,t]),reload:er,sendPrompt:ea,removeQueueItem:ei,clearQueue:eo,resolvePermission:ec,stop:ed,stopTask:eu,runShell:ex,rewindToMessage:ep,previewRewind:ef,listRewindPoints:em,escalateMode:eh,dismissBlocked:eb}}({sessionId:e,engine:t,workspacePath:s,bus:a,isVisible:o}),q=(0,r.useCallback)(()=>{(0,eo.e)(),j(!0),O(),setTimeout(()=>j(!1),700)},[O]),U=a7(t=>t.bySession[e]?.activePermission),V=!!a7(t=>t.bySession[e]?.isTurnRunning),X=a7(t=>t.bySession[e]?.gateError),G=a7(t=>t.bySession[e]?.activeBlocked),J=a7(t=>t.bySession[e]?.metadata)||ow,Y=a7(t=>t.bySession[e]?.tasks)||oj,Z=a7(e=>e.setPermissionMode),Q=eT(e),ee=(0,h.B)(e=>e.terminalBackgroundOpacity),et=(0,h.B)(e=>e.customBackgrounds),es=(0,h.B)(e=>e.terminalBackgrounds),er=(0,h.B)(t=>t.backgroundBySession[e]),el=(0,h.B)(e=>e.terminalTheme),ea=(0,h.B)(e=>e.fontSize),ei=(0,h.B)(e=>e.showFolderButton),ed=(0,h.B)(e=>e.showNoteButton),eu=(0,h.B)(e=>e.setRightPanelRoot),ex=(0,h.B)(e=>e.setRightPanelTab),em=(0,h.B)(e=>e.openRightPanel),ep=(0,h.B)(t=>t.artifactsBySession[e]),ef=nj(s,i,{enabled:c&&ei}),{theme:eh}=(0,n_.D)(),eb=(0,r.useMemo)(()=>(0,nT.In)(eh,el),[eh,el]),eg=(0,r.useMemo)(()=>(0,eV.ar)(ea)+(d?tb.TQ:tb.wM),[ea,d]),ev=(0,r.useMemo)(()=>{let{alpha:e,size:t}=tb.ii,s=`radial-gradient(color-mix(in srgb, ${eb.foreground} ${e}%, transparent) 1px, transparent 1px) 0 0 / ${t}px ${t}px`,n=(0,eV.$Z)(er,es,et,x),r="dark"===eh?(0,eV.RS)(n,et):null;if(r){let e=`rgba(${eV.c},${ee??eV._z})`,t=`rgba(${eV.pZ},${eV.B$})`;return{background:`${s}, linear-gradient(${e},${e}), linear-gradient(${t},${t}), center / cover no-repeat url("${r}")`,backgroundBlendMode:"luminosity, normal, screen, normal"}}return{background:`${s}, ${eb.background}`}},[es,er,et,ee,eb,eh,x]),ew=J.skills||[],ej=J.mcpServers||[],ek=(0,r.useCallback)(e=>{S(`/${e}`)},[S]),eN=(0,r.useCallback)(t=>{a?.emit?.("ai:options",{sessionId:e,options:t})},[a,e]),eC=(0,r.useCallback)(t=>{a7.getState().setMetadata(e,{model:t}),eN({model:t})},[eN,e]),eS=(0,r.useCallback)(e=>{e?.sessionId&&eN({resume:e.sessionId})},[eN]),eE=(0,r.useCallback)(e=>{if(e)return eS(e);y("sessions")},[eS]),eR=(0,r.useCallback)((t,s)=>{t&&("effort"===t&&a7.getState().setMetadata(e,{effort:s}),eN({[t]:s}))},[eN,e]),e$=(0,aT.Tw)(t),eM=(0,r.useCallback)(t=>{Z(e,t),eN({mode:t})},[eN,e,Z]),ez=(0,r.useCallback)((t,s)=>{a7.getState().rewindToMessage(e,t,s)},[e]),eP=(0,r.useCallback)(t=>{if(!v&&t.shiftKey&&"Tab"===t.key){t.preventDefault(),(0,eo.e)();let s=e$.permissionModes||[],n=a7.getState().bySession[e]?.permissionMode||e$.defaultMode,r=s.findIndex(e=>e.id===n),l=-1===r?0:(r+1)%s.length,a=s[l]?.id;a&&eM(a)}},[e,e$,eM,v]),eI=nH({isFocused:c,onActivate:()=>m?.()}),eA=(0,r.useRef)(m);(0,r.useEffect)(()=>{eA.current=m});let eL=(0,r.useCallback)(()=>eA.current?.(),[]),eD=(0,r.useMemo)(()=>({sessionId:e,isFocused:c,activate:eL}),[e,c,eL]);return(0,n.jsx)(ik.fe.Provider,{value:eD,children:(0,n.jsxs)("div",{...eI,onKeyDown:eP,className:"ai-pane w-full h-full flex flex-col bg-bg overflow-hidden relative select-text",style:{...ev,"--color-text":eb.foreground,"--ai-fs":`${eg}px`},children:[(0,n.jsxs)("div",{style:{height:26},className:"sm:hidden flex items-center gap-2 px-2 border-b border-border-subtle bg-surface/70 backdrop-blur-sm text-[11px] select-none shrink-0 relative z-10",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${t9(Q)}`,style:{background:t8(Q).dot}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",children:l||tb.UB[t]?.label||t}),(0,n.jsx)(nW,{onOpenRemote:p,onOpenMobile:f})]}),c&&(0,n.jsxs)("div",{className:"absolute right-2 z-[2] flex flex-col items-end gap-2 pointer-events-auto touch-none top-9 sm:top-2",children:[(0,n.jsxs)("div",{className:"flex flex-row gap-2",children:[ed&&(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,eo.e)(),N(!0)},className:nq,title:C("terminalPane.note"),children:(0,n.jsx)(en.y8,{size:16,className:nU})}),(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),q()},className:nq,title:C("terminalPane.refresh"),children:(0,n.jsx)(en.e9,{size:16,className:`${nU} ${w?"animate-spin":""}`})})]}),ei&&s&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,eo.e)(),eu(s,s),window.innerWidth>=eV.jK?ex("files",s):em()},className:`relative ${nq}`,title:C("terminalPane.openFolderHere"),children:[(0,n.jsx)(en.vd,{size:16,className:nU}),ef>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:ef>eV.KN?`${eV.KN}+`:ef})]}),b&&ep?.length>0&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:t=>{t.stopPropagation(),(0,eo.e)(),b(e,ep[0])},className:`relative ${nq}`,title:C("terminalPane.artifacts"),children:[(0,n.jsx)(en.sU,{size:16,className:nU}),(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:ep.length})]})]}),(0,n.jsx)(oa,{sessionId:e}),(0,n.jsx)(ov,{sessionId:e,engine:t,onStopTask:M}),(0,n.jsx)(iV,{bus:a,sessionId:e,engine:t,workspacePath:s,fileBus:i,onSendPrompt:S,onResolvePermission:T,onRewind:P,onPreviewRewind:I,onListRewindPoints:L,onCutLocal:ez,hasOlder:F,onLoadOlder:K,onOpenResume:eE,hydrating:W,synced:_,hydrateFailed:H,onReload:O}),G&&!U&&(0,n.jsx)("div",{className:"px-3 pb-2 select-none animate-in fade-in slide-in-from-bottom-2 duration-150 flex-shrink-0 z-30",children:(0,n.jsx)(or,{engine:G.engine||t,message:G.message,escalate:G.escalate,onEscalate:D,onDismiss:B})}),U&&(0,n.jsx)("div",{className:"px-3 pb-2 select-none animate-in fade-in slide-in-from-bottom-2 duration-150 flex-shrink-0 z-30",children:"AskUserQuestion"===U.tool?(0,n.jsx)(iy.J,{requestId:U.requestId,questions:U.input?.questions||[],failed:X,onResolve:T}):(0,n.jsx)(on,{requestId:U.requestId,tool:U.tool,input:U.input,failed:X,onResolve:T})}),(0,n.jsx)(iY,{bus:a,sessionId:e,engine:t,onSend:S,onRemoveQueueItem:E,onClearQueue:R,onStop:$,onRunShell:z,onResolvePermission:T,onSelectModel:eC,onModeChange:eM,onOpenModal:y,onOptionChange:eR,onActivate:m,isFocused:c,fileBus:i,workspacePath:s,modalOpen:null!==v}),(0,n.jsx)(iQ,{sessionId:e,fileBus:i,sessionName:l,engine:t,workspacePath:s,isDesktop:d,onModeChange:eM,onNewChat:g}),"skills"===v&&(0,n.jsx)(i0,{skills:ew,onClose:()=>y(null),onSelectSkill:ek}),"mcp"===v&&(0,n.jsx)(i1,{mcpServers:ej,onClose:()=>y(null)}),"model"===v&&(0,n.jsx)(i2,{currentModel:J.model,currentEffort:J.effort||"",models:J.modelOptions?.length?J.modelOptions:e$.models,isTurnRunning:V,onClose:()=>y(null),onSelectModel:eC,onSelectEffort:e=>eN({effort:e})}),"sessions"===v&&(0,n.jsx)(i5,{bus:a,engine:t,workspacePath:s,onClose:()=>y(null),onResume:eS}),"config"===v&&(0,n.jsx)(i6,{engine:t,options:a7.getState().bySession[e]?.metadata,onClose:()=>y(null),onApply:e=>eN(e)}),"mode"===v&&(0,n.jsx)(i9,{modes:e$.permissionModes||[],currentMode:a7.getState().bySession[e]?.permissionMode||e$.defaultMode,onClose:()=>y(null),onSelectMode:eM}),"doctor"===v&&(0,n.jsx)(i7,{bus:a,engine:t,workspacePath:s,onClose:()=>y(null)}),"tasks"===v&&(0,n.jsx)(ot,{tasks:Y,onClose:()=>y(null)}),"rewind"===v&&(0,n.jsx)(os,{sessionId:e,onListPoints:L,onPreview:I,onApply:e=>P(e),onClose:()=>y(null)}),k&&ed&&(0,n.jsx)(nO,{bus:a,sessionId:e,onClose:()=>N(!1)})]})})});class oN extends r.Component{constructor(e){super(e),this.handleReset=()=>{this.setState({hasError:!1,error:null}),this.props.onReset?.()},this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("[ErrorBoundary caught error]:",e,t)}render(){return this.state.hasError?this.props.fallback?"function"==typeof this.props.fallback?this.props.fallback(this.state.error,this.handleReset):this.props.fallback:(0,n.jsxs)("div",{className:"w-full h-full min-h-[160px] flex flex-col items-center justify-center p-6 text-center select-none bg-surface/50 border border-border-subtle/40 rounded-brand m-2",children:[(0,n.jsx)(en.RI,{size:24,className:"text-danger mb-2"}),(0,n.jsx)("div",{className:"text-sm font-semibold text-text mb-1",children:this.props.title||"Something went wrong in this pane"}),(0,n.jsx)("div",{className:"text-xs text-text-muted font-mono max-w-md truncate mb-4",children:this.state.error?.message||"Render error"}),(0,n.jsxs)("button",{type:"button",onClick:this.handleReset,className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-surface-3 text-text text-xs flex items-center gap-1.5 font-medium transition-colors border border-border-subtle",children:[(0,n.jsx)(en.e9,{size:12}),(0,n.jsx)("span",{children:"Try again"})]})]}):this.props.children}}let oC=(0,r.memo)(function({children:e}){return(0,n.jsx)("div",{className:"absolute inset-x-0 top-0 bottom-[37px] overflow-hidden",children:e})}),oS=(0,r.memo)(function({sessionId:e}){let t=eT(e);return"idle"===t?null:(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 z-20 h-[1px] pointer-events-none hidden sm:block",children:"working"===t?(0,n.jsx)(av,{}):"done"===t?(0,n.jsx)("div",{className:"w-full h-full bg-[#f59e0b]",style:{boxShadow:"0 0 4px rgba(245,158,11,0.6)"}}):"blocked"===t?(0,n.jsx)("div",{className:"w-full h-full bg-[#ef4444] animate-pulse",style:{boxShadow:"0 0 4px rgba(239,68,68,0.7)"}}):null})}),oE=(0,r.memo)(function({sessionId:e,placeholder:t}){let s=(0,h.B)(t=>t.drafts[e]??"").replace(/\s+/g," ").trim();return s?(0,n.jsx)("span",{className:"text-text",children:s}):(0,n.jsx)(n.Fragment,{children:t})}),oR=(0,r.memo)(function({bus:e,busRef:t,connected:s,carrier:l,platform:a,agentVersion:i,sessions:o,workspaces:c,activeSessionId:d,activeSession:x,activeWorkspaceId:m,openedSessions:p,livePanes:f,mountedWorkspaces:b,cwdBySession:g,sessionStatus:v,notifications:y,isDesktop:w,isTerminalView:j,slideClass:k,shells:N,sidebarCollapsed:C,sidebarWidth:S,setSidebarWidth:E,toggleSidebar:R,paneWidth:T=null,setPaneWidth:$,paneRegistry:z,bindSwipeTab:P,nav:I,onBack:A,onOpenRemote:L,onOpenMobile:D,onOpenRemoteHost:B=null,onOpenMobileHost:F=null,onOpenFiles:K,onLogout:O,onRenameHost:W,onDeleteHost:_,onMainDisconnect:H,onDeleteWorkspace:q,onRenameWorkspace:U,onReorderSession:V,onSetHiddenRepos:X,atStackBottom:G=!1,onAddWorkspace:J,onOpenSettings:Y,homeDir:Z,recentWorkspaces:Q,rightPanel:ee,editorPanel:es,mobilePanel:en,onOpenArtifact:er,fileBus:el,onCreateAnyHost:ea,onQuickCreateHostAware:ei,tunnelUrl:ed,apiKey:eu,connectionMode:ex,onResumeAgentSessionForeign:em=null,subscribeToPush:ep,unsubscribeFromPush:ef}){let{t:eh}=(0,ec.s)(),eb="mouse"===tF(),eg=(0,u.d)(e=>e.bus),ev=(0,u.d)(e=>e.busRef),ew=(0,u.d)(e=>e.connected),ej=(0,u.d)(e=>e.carrier),ek=e||eg,eN=t||ev,eC=(0,r.useMemo)(()=>o.filter(e=>!e.hostKey),[o]),eS=(0,r.useMemo)(()=>c.filter(e=>!e.hostKey),[c]),eT=(0,r.useCallback)(e=>{let t=eR(e);return t.head?t.bus:ek},[ek]),e$=s??ew,eM=el||et.getState(),ez=(0,r.useMemo)(()=>x?.hostKey?eE(x.hostKey).fileBus:eM,[x?.hostKey,eM]),{panesContainerRef:eP,registerPaneApi:eI,registerPaneElement:eA,registerKeyboardTextApi:eL,handlePasteFallback:eD,handleInputFocusChange:eB,focusPane:eF,focusKeyboardInput:eK,scrollPaneIntoView:eO}=z,[eW,e_]=(0,r.useState)(null),{workspaceSessionIds:eH,workspaceOpenedSessions:eq,renderedSessions:eX,mountedSet:eG,workspaceIndex:eJ}=(0,r.useMemo)(()=>(0,eY.gk)({sessions:o,openedSessions:p,livePanes:f,mountedWorkspaces:b,activeWorkspaceId:m,isDesktop:w}),[o,p,f,b,m,w]),eZ=(0,r.useMemo)(()=>o.filter(e=>(0,eY.xs)(e)===m),[o,m]),eQ=(0,r.useMemo)(()=>new Map(eZ.map((e,t)=>[e.id,t])),[eZ]),e0=c.find(e=>e.id===m),e1=e0?.path||x?.workspacePath||null,e2=(0,h.B)(e=>e.rightPanelRoots),e5=(0,h.B)(e=>e.agentBySession),e3=(0,h.B)(e=>e.fullModes||{})[m??eY.AD]??!1,e4=(0,h.B)(e=>e.hiddenPaneSessionIds||[]),e6=(0,h.B)(e=>e.setRightPanelRoot),e8=(0,h.B)(e=>e.openRightPanel),e9=(0,h.B)(e=>e.reorderOpenedSessions),e7=(0,r.useCallback)(e=>{e9(e),V?.(e)},[e9,V]),te=(0,r.useCallback)(e=>{I.handleSelectSession(e)},[I]),tt=!!o.find(e=>e.id===d)?.hostKey,ts=e0?.hostKey||null,tn=eE(ts).busRef,[tr,tl]=(0,r.useState)([]),ta=(0,M.rh)(e=>ts&&e.hosts[ts]?.status||null),ti=(0,M.rh)(e=>e.hosts),to=(0,M.rh)(e=>e.currentKey);(0,r.useEffect)(()=>{ts&&eE(ts).bus?.emit("getShells",e=>tl(e?.shells||[]))},[ts,ta]);let tc=(0,r.useCallback)((e,t)=>{let s=o.filter(e=>e.id!==t&&(0,eY.xs)(e)===(m??null)).length+1;I.handleReplaceSession(t,`${e.short||e.label} ${s}`,e,!0)},[I,o,m]),td=e2[e1]||e1,tu=(0,r.useCallback)(e=>ee?.onTabChange(e,e1??""),[ee,e1]),tx=(0,r.useCallback)(()=>K?.(td),[K,td]),tm=(0,r.useMemo)(()=>e0?.hiddenRepos||[],[e0?.hiddenRepos]),tf=(0,r.useCallback)(e=>{e0&&X?.(e0.id,e)},[e0,X]),th=d&&(g[d]||o.find(e=>e.id===d)?.cwd)||null;(0,r.useEffect)(()=>{e6(e1,null)},[d,e1,e6]);let tg=!o.length,tv=(0,M.rh)(e=>Object.keys(e.hosts).length),ty=tg&&!c.length&&tv<=1,[tw,tj]=(0,r.useState)(!1);ee?.open&&!tw&&tj(!0);let[tk,tN]=(0,r.useState)(!1);!ee?.open&&tk&&tN(!1),(0,r.useEffect)(()=>{if(!ee?.open)return;let e=requestAnimationFrame(()=>tN(!0));return()=>cancelAnimationFrame(e)},[ee?.open]);let tC=!!es?.filePath,[tS,tE]=(0,r.useState)(!1);tC&&!tS&&tE(!0);let[tR,tT]=(0,r.useState)(!1);!tC&&tR&&tT(!1);let[t$,tM]=(0,r.useState)(null);tC&&t$?.filePath!==es.filePath&&tM({filePath:es.filePath,artifactTitle:es.artifactTitle,previewSeq:es.previewSeq}),(0,r.useEffect)(()=>{if(!tC)return;let e=requestAnimationFrame(()=>tT(!0));return()=>cancelAnimationFrame(e)},[tC]);let[tz,tP]=(0,r.useState)(0),[tI,tA]=(0,r.useState)(!1),tL=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!w)return;let e=tL.current;if(!e)return;let t=new ResizeObserver(e=>tP(e[0].contentRect.width));return t.observe(e),()=>t.disconnect()},[w]),(0,r.useEffect)(()=>{if(!e$||!ek?.emit)return;let e=!1,t=()=>ek.emit("bg:get",{},t=>{!e&&t?.success&&t.dataUrl&&h.B.getState().setCustomBackgrounds([{id:"custom",dataUrl:t.dataUrl}])}),s=setTimeout(()=>{e||t()},eV._O);return ek.emit("bg:list",{},n=>{e||(clearTimeout(s),n?.success&&Array.isArray(n.items)?h.B.getState().setCustomBackgrounds(n.items):t())}),()=>{e=!0,clearTimeout(s)}},[e$,ek]);let tD=(0,r.useMemo)(()=>eq.filter(e=>!e4.includes(e)),[eq,e4]).length,tB=(ee?.open&&tk?ee.width:0)+(tC&&tR?es.width:0)+(en?.open&&"pin"===en.mode?en.width:0),tK=(0,eY.Jc)({rowWidth:tz,paneCount:tD,sidebarWidth:C?0:S,sidePx:tB,gapPx:eV.pS,paddingPx:eV.Jv,minWidth:eV.k9.min}),tO=T??tK,tW=(0,r.useRef)({editorFile:es?.filePath,rightOpen:ee?.open});(0,r.useEffect)(()=>{if(!w||!d)return;let e=tW.current,t=e.editorFile!==es?.filePath||e.rightOpen!==ee?.open;if(tW.current={editorFile:es?.filePath,rightOpen:ee?.open},!t)return;let s=setTimeout(()=>{eO(d)},260);return()=>clearTimeout(s)},[es?.filePath,ee?.open,d,w,eO]),(0,r.useEffect)(()=>{w&&e3&&eP.current&&(eP.current.scrollLeft=0)},[w,e3,eP]);let t_=e=>{let t=tO??e.currentTarget.parentElement?.offsetWidth??eV.k9.min;tA(!0),eU(e,{startWidth:t,onWidth:e=>$?.(e),onEnd:()=>tA(!1)})},tH=(0,r.useCallback)(()=>$?.(null),[$]),[tq,tU]=(0,r.useState)(null),tV=(0,r.useRef)(null),tX=sq(tV,tq?.x??0,tq?.y??0),tG=(0,r.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),tU({x:e.clientX,y:e.clientY})},[]),tJ=(0,r.useCallback)(e=>{if("auto"===e)tH();else{let t=eP.current?.clientWidth||tz-(C?0:S)-tB;if(t>0){let s=Math.max(eV.k9.min,Math.floor((t-(e-1)*eV.pS)/e));$?.(s)}}tU(null)},[tH,eP,tz,C,S,tB,$]);(0,r.useEffect)(()=>{if(!tq)return;let e=e=>{tV.current&&!tV.current.contains(e.target)&&tU(null)},t=e=>{"Escape"===e.key&&tU(null)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",t)}},[tq]),(0,r.useEffect)(()=>{let e=()=>tH();return window.addEventListener("terminal:fitPanes",e),()=>window.removeEventListener("terminal:fitPanes",e)},[tH]),(0,r.useEffect)(()=>{let e=e=>{e.detail?.fraction&&tJ(e.detail.fraction)};return window.addEventListener("terminal:splitPreset",e),()=>window.removeEventListener("terminal:splitPreset",e)},[tJ]);let tY=(e,t,s,r=0)=>{let l=o.find(t=>t.id===e),a=l?.hostKey?eE(l.hostKey).fileBus:eM,i=e5[e],c=tb.H8.find(e=>e.id===i);return c?(0,n.jsx)(oN,{title:"AI Chat Pane",children:(0,n.jsx)(ok,{sessionId:e,engine:c.aiEngine,workspacePath:l?.cwd||l?.workspacePath||e0?.path,sessionName:l?.name,bus:eT(e),fileBus:a,isVisible:t,isFocused:s,isDesktop:w,bgIndex:r,onActivate:()=>I.handleSelectSession(e),onNewChat:()=>tc(c,e),onOpenRemote:L,onOpenMobile:D,onOpenArtifact:er})},e):(0,n.jsx)(nV,{workspacePath:l?.workspacePath,sessionName:l?.name,bus:eT(e),fileBus:a,connected:e$,sessionId:e,isVisible:t,isFocused:s,onActivate:I.handleSelectSession,onRegisterApi:eI,onPasteFallback:eD,showFocusBorder:!1,mountDelay:(0,eY.Mt)(e,s,eJ),bgIndex:r,onOpenArtifact:er,onOpenRemote:L,onOpenMobile:D})},tZ=e=>(0,n.jsx)(t4,{bus:eT(e),sessionId:e,onExpandChange:()=>{},onRefocus:()=>eF(e),onRegisterTextApi:eL,onInputFocusChange:eB,platform:a,onInput:ey.getState().clearNotification,onSwitchSession:I.switchSession,onSwitchToIndex:I.switchToIndex,isDesktop:w,statusStrip:(0,n.jsx)(rj,{sessionId:e,busRef:eN,onReveal:t=>{let s=o.find(t=>t.id===e)?.workspacePath;e6(s,t||s),e8()}})});return(0,n.jsxs)("div",{className:`absolute inset-0 flex flex-col ${j?"translate-x-0 opacity-100 z-10":"translate-x-full opacity-0 z-0 pointer-events-none"}`,children:[(0,n.jsxs)("div",{ref:tL,className:`flex-1 min-h-0 relative ${w?"flex flex-row":"flex flex-col"}`,children:[w&&(0,n.jsx)("div",{className:"hidden sm:block overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out",style:{width:C?0:S},children:(0,n.jsx)(ri,{allSessions:o,mainSessions:eC,workspaces:eS,activeSessionId:d,activeWorkspaceId:m,onSelectSession:I.handleSelectSession,onSelectWorkspace:I.handleSelectWorkspace,onCreateNamedSession:I.handleCreateSession,onResumeAgentSession:tt?em:I.handleResumeAgentSession,shells:N,onRenameSession:I.handleRenameSession,onDeleteSession:I.handleDeleteSession,onReorderSession:e7,onDeleteWorkspace:q,onAddWorkspace:J,onRenameWorkspace:U,onOpenSettings:Y,onOpenRemoteHost:B,onOpenMobileHost:F,onLogout:O,onRenameHost:W,onMainDisconnect:H,onDeleteHost:_,busRef:eN,homeDir:Z,cwdBySession:g,connected:e$,width:S,onResize:E,onCollapse:R})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 min-h-0 flex flex-col",children:[(!tg||!w)&&(0,n.jsx)(nh,{sessions:eZ,allSessions:o,activeSessionId:d,isActive:j,connected:e$,onSwitchSession:te,onCreateSession:ts?ei:I.handleQuickCreateSession,onRenameSession:I.handleRenameSession,onDeleteSession:I.handleDeleteSession,onCreateNamedSession:ea,modalBusRef:tn,modalHostKey:ts||"main",modalShells:ts?tr:null,onResumeAgentSession:tt?em:I.handleResumeAgentSession,onBack:w||G?null:A,workspaces:c,activeWorkspaceId:m,onSelectWorkspace:I.handleSelectWorkspace,hasUngrouped:o.some(e=>!(0,eY.xs)(e)),onOpenRemote:L,onOpenMobile:D,onOpenRemoteHost:B,onOpenMobileHost:F,hostKey:ts,onOpenFiles:K,onLogout:O,tunnelUrl:ed,apiKey:eu,connectionMode:ex,subscribeToPush:ep,unsubscribeFromPush:ef,agentVersion:i,busRef:eN,carrier:l||ej,shells:N,onToggleSidebar:w?R:null,sidebarCollapsed:C,onReorderSession:e7,onToggleRightPanel:ee?.onToggle,rightPanelOpen:ee?.open,fileBus:eM,homeDir:Z,isDesktop:w}),ty?(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(aw,{onAddWorkspace:J,onOpenRemote:L,recent:Q,homeDir:Z,onOpenRecent:e=>J?.(e)})}):(0,n.jsx)("div",{ref:eP,className:`flex-1 min-h-0 ${w?`flex flex-row ${e3?"overflow-hidden":"overflow-x-auto"} overflow-y-hidden px-0 pb-0 scrollbar-none`:"relative"}`,...P({enabled:!w,sessionIds:eq,activeSessionId:d,onSwitch:I.handleSelectSession}),children:eX.map(e=>{let t=eH.has(e),s=e===d,r=e4.includes(e),l=t&&!r&&(w&&!e3||s),a=!!ti[eR(e).head||to]?.updating,i=eQ.get(e)??0;return(0,n.jsxs)("div",{ref:t=>eA(e,t),className:!t||w&&e3&&!s||w&&r?"hidden":w?`h-full relative bg-bg ${a?"opacity-50 pointer-events-none":""} ${e3?"w-full flex-1":`border-r-2 border-border-subtle last:border-r-0 ${tI?"":"transition-[width] duration-200 ease-out"}`}`:`absolute inset-0 ${a?"opacity-50 pointer-events-none":s?`opacity-100 z-10 ${k}`:"opacity-0 z-0 pointer-events-none"}`,style:t&&w?e3?{width:"100%",flex:"1 1 0"}:null!=tO?{width:tO,flexShrink:0}:{flex:"1 1 0",minWidth:eV.k9.min}:void 0,children:[eG.has(e)?e5[e]?.endsWith("-ui")?(0,n.jsx)("div",{onMouseDown:()=>{s||I.handleSelectSession(e)},onTouchStart:()=>{s||I.handleSelectSession(e)},className:"w-full h-full flex flex-col relative overflow-hidden",children:tY(e,l,s,i)}):w?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(oC,{children:[tY(e,l,s,i),(0,n.jsx)(oS,{sessionId:e})]}),(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 z-20 border-t border-border-subtle bg-surface",children:s?tZ(e):(0,n.jsx)("button",{type:"button",tabIndex:-1,onClick:()=>{I.handleSelectSession(e),setTimeout(eK,60)},className:"group block w-full text-left","aria-label":"Focus this terminal input",children:(0,n.jsx)("span",{className:"block w-full pl-9 pr-16 py-2 text-sm text-text-muted/60 group-hover:bg-surface-2/70 group-hover:text-text-muted transition-colors truncate",children:(0,n.jsx)(oE,{sessionId:e,placeholder:eh("mobileKeyboard.typeCommand")})})})})]}):tY(e,l,s,i):(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center text-text-muted text-xs"}),t&&w&&!e3&&!r&&(0,n.jsx)("div",{onPointerDown:t_,onDoubleClick:tH,onContextMenu:tG,className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-30",title:eb?tp(eh("shortcuts.fitPanes")||"Auto-fit panes","fitPanes"):void 0})]},e)})}),!w&&d&&!e5[d]?.endsWith("-ui")&&tZ(d)]}),(es?.filePath||w&&tS)&&(0,n.jsx)("div",{className:w?"overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out":"absolute inset-0 z-40 animate-in slide-in-from-bottom duration-200",style:w?{width:tC&&tR?es.width:0}:void 0,"aria-hidden":w&&!tC,children:(0,n.jsx)(ab,{filePath:tC?es.filePath:t$?.filePath,artifactTitle:tC?es.artifactTitle:t$?.artifactTitle,previewSeq:tC?es.previewSeq:t$?.previewSeq,workspace:td,fileBus:ez,width:es.width,onResize:es.onResize,onClose:es.onClose,onOpenFull:es.onOpenFull,onOpenFile:es.onOpen,isDesktop:w})}),w&&en?.open&&"pin"===en.mode&&(0,n.jsx)("div",{ref:e_,className:"relative overflow-hidden flex-shrink-0 border-l border-border",style:{width:en.width},children:(0,n.jsx)("div",{onPointerDown:en.onResizeStart,className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})}),w&&en?.open&&(0,n.jsx)(rB,{busRef:en.busRef||eN,protocolRef:en.protocolRef,connected:en.connected??e$,pinSlot:eW}),ee?.open&&!w&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 bg-black/50 animate-in fade-in duration-200",onClick:ee.onToggle}),(ee?.open||w&&tw)&&(0,n.jsx)("div",{className:w?"overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out":"absolute inset-y-0 right-0 z-30 w-[85%] max-w-sm shadow-elev animate-in slide-in-from-right duration-200",style:w?{width:ee?.open&&tk?ee.width:0}:void 0,"aria-hidden":w&&!ee?.open,children:(0,n.jsx)(lB,{workspacePath:e1,filesRoot:td,cwdHint:th,activeFile:es?.filePath,fileBus:ez,tab:ee.tabs?.[e1??""]||"files",onTabChange:tu,width:ee.width,onResize:ee.onResize,onClose:ee.onToggle,onOpenFiles:K?tx:null,onOpenFile:es?.onOpen,onNewTerminal:ee.onNewTerminal,onAddWorkspace:J,homeDir:Z,hiddenRepos:tm,onHiddenReposChange:e0&&X?tf:null,isDesktop:w})})]}),(0,n.jsx)(ag,{}),w&&!tg&&(0,n.jsx)(rk,{cwd:d&&(g[d]||x?.cwd||e0?.path)||"",sessionId:d,hostKey:x?.hostKey||null,sessionName:x?x?.name:"",agentVersion:i,platform:a,homeDir:Z}),tq&&(0,n.jsxs)("div",{ref:tV,className:"fixed z-[70] menu-popover p-1 min-w-[130px] animate-in fade-in zoom-in-95 duration-100 shadow-xl",style:{left:tX.left,top:tX.top},children:[(0,n.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold text-text-subtle uppercase tracking-wider",children:"Split"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),tJ("auto")},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Auto Fit"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"Auto"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),tJ(2)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/2"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"50%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),tJ(3)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/3"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"33%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),tJ(4)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/4"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"25%"})]})]})]})});var oT=s(45111);function o$({label:e,inline:t=!1}){let{t:s}=(0,ec.s)();return(0,n.jsxs)("div",{className:`${t?"absolute inset-0 z-10":"fixed inset-0 z-40"} flex items-center justify-center animate-in fade-in duration-300`,children:[(0,n.jsx)("div",{className:"cine-bg","aria-hidden":!0,children:(0,n.jsx)("div",{className:"cine-grid"})}),(0,n.jsxs)("div",{className:"relative z-10 flex flex-col items-center gap-3 px-6 text-center",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-text animate-pulse-glow"}),(0,n.jsx)("span",{className:"text-[15px] font-semibold text-text tracking-wide",children:"9Remote"})]}),(0,n.jsx)(oT.A,{size:"lg"}),(0,n.jsx)("p",{className:"text-sm text-text-muted",children:e||s("connection.retrying")})]})]})}var oM=s(30240);function oz({sessions:e,cwdBySession:t={},connected:s,onSelect:l,onCreate:a,onDelete:i,onRename:o,onLogout:c,onOpenRemote:d,tunnelUrl:x,apiKey:m,connectionMode:p="tunnel",isActive:f=!0,busRef:b,subscribeToPush:g,unsubscribeFromPush:v,onResumeAgentSession:y=null,notifications:w,sessionStatus:j,agentVersion:k,carrier:N,workspaces:C=[],onRenameWorkspace:S,onDeleteWorkspace:E,onAddWorkspace:R,onOpenRemoteHost:T=null,fileBus:$,homeDir:z,recentWorkspaces:P=[],shells:I=[],onReorderSession:A,onRenameHost:L=null,onDeleteHost:D=null,onMainDisconnect:B=null,onMainReconnect:F=null}){let K,{t:O}=(0,ec.s)(),W=$||et.getState(),_=Object.values((0,M.rh)(e=>e.hosts)),H=(0,M.rh)(e=>e.currentKey),q=_.find(e=>e.key===H),U=(0,u.d)(e=>e.connected),V=(0,u.d)(e=>e.carrier),X=(0,u.d)(e=>e.busRef),G=s??U,J=N||V||"ws",Y=b||X,Z=ey(e=>e.notifications),Q=e$(),ee=w||Z,es=j||Q,er=eb(e=>e.open),el=eb(e=>e.setContext),ea=eb(e=>e.setCallbacks),ei=(0,h.B)(e=>e.hiddenHeaderButtons),[ed,eu]=(0,r.useState)(null),[ex,em]=(0,r.useState)(null),[ep,ef]=(0,r.useState)(!1),[eh,eg]=(0,r.useState)(!1),ev=_.filter(e=>("full"===e.status||"online"===e.status)&&e.remoteAvailable),ew=eN(_,q?.key);(0,r.useEffect)(()=>{if(!f)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.altKey&&!e.shiftKey&&"t"===e.key.toLowerCase()&&(e.preventDefault(),em({workspaceId:null}))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[f]),(0,r.useEffect)(()=>{f&&(el({connected:G,remoteAvailable:!!d,showTheme:!1,theme:"default",busRef:Y,hideActions:["remote","files","sites"],tunnelUrl:x,apiKey:m,connectionMode:p,subscribeToPush:g,unsubscribeFromPush:v,notifications:ee,agentVersion:k,carrier:J}),ea({onRemote:null,onFiles:null,onSelectSite:null,onRefreshSites:null,onLogout:c,onThemeChange:null}))},[f,G,d,c,el,ea,Y,p,g,v,k,J,x,m,ee]);let ej=new Set(e.map(e=>e.id)),ek=!_.some(e=>e.updating)&&!e.length&&!C.length&&_.length<=1;return(0,n.jsxs)("div",{className:"h-full flex flex-col overflow-hidden relative",children:[(0,n.jsxs)("header",{className:`relative z-10 bg-surface/80 backdrop-blur-md px-4 py-3 ${s1} flex items-center justify-between gap-2 flex-shrink-0 border-b border-border-subtle`,style:{paddingTop:"calc(0.75rem + env(safe-area-inset-top, 0px))"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("div",{className:"p-1.5 bg-brand-500/10 rounded-brand flex-shrink-0",children:(0,n.jsx)(en.Kq,{className:"text-brand-500 w-5 h-5"})}),(0,n.jsx)("h1",{className:"text-text text-lg font-semibold truncate",children:O("sessions.headerTitle")}),(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${G?"bg-green-500":"bg-red-500 animate-pulse"}`,title:G?O("sessions.connected"):O("sessions.disconnected")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[!ei.includes("remote")&&ev.length>0&&(0,n.jsx)(oP,{icon:en.VA,label:O("menu.remoteDesktop"),onClick:()=>{((0,eo.e)(),1===ev.length)?T?.(ev[0].key):eg(!0)},disabled:!G}),(0,n.jsx)(oP,{icon:en.kV,label:O("hosts.addHost"),onClick:()=>{(0,eo.e)(),ef(!0)}}),(0,n.jsx)(oP,{icon:en.wB,label:O("menu.title"),onClick:er})]})]}),(0,n.jsx)("div",{className:"relative z-10 flex-1 overflow-auto modal-scrollable pt-2 pb-12",style:{overflowAnchor:"none"},children:ek?(0,n.jsx)("div",{className:"absolute inset-0 z-10",children:(0,n.jsx)(oI,{onAddWorkspace:R,onOpenRemote:d,recent:P,homeDir:z,connected:G})}):(0,n.jsx)(n.Fragment,{children:ew.map((s,r)=>(0,n.jsx)("div",{className:0===r?"pl-1 pr-3":"mt-3 border-t border-border-subtle pt-2 pl-1 pr-3",children:s.key===(q?.key||"main")&&q?(0,n.jsx)(rl,{mobile:!0,host:{...q,workspaces:C,sessions:e,statusMap:es,onDisconnect:B,onConnect:F},busRef:Y,actions:{selectSession:l,createSession:a,renameSession:o,deleteSession:i,backgroundSession:e=>eu(e),reorderSession:A,renameWorkspace:S,deleteWorkspace:E,renameHost:L,deleteHost:D},connected:G,fileBus:W,homeDir:z,cwdBySession:t,onAddWorkspace:R,menuAddWorkspace:R,onOpenRemoteHost:T,treeCls:"pl-5",rowCls:"active:bg-surface-2 active:text-text"}):(0,n.jsx)(rl,{mobile:!0,host:{...s,onDisconnect:()=>M.rh.getState().disconnectHost(s.key)},actions:{...tt(s,{onSelectSession:l}),renameHost:L,deleteHost:D},connected:G,onOpenRemoteHost:T,treeCls:"pl-5",rowCls:"active:bg-surface-2 active:text-text"})},s.key))})}),ed&&(0,n.jsx)(sJ,{sessionId:ed.id,title:ed.name,busRef:Y,onClose:()=>eu(null)}),ex&&(0,n.jsx)(s_,{onClose:()=>em(null),onCreate:(e,t,s,n,r,l)=>{a?.(e,ex.workspaceId,t,r||null,s,n,l),em(null)},shells:I,busRef:Y,onResumeAgentSession:y,onSelectSession:l,liveSessionIds:ej,connected:G,workspacePath:C.find(e=>e.id===ex.workspaceId)?.path||null,workspaceName:C.find(e=>e.id===ex.workspaceId)?.name||"",fileBus:W,homeDir:z,suggestName:`${O("terminal.defaultName")} ${(K=ex.workspaceId,e.filter(e=>(0,eY.xs)(e)===K)).length+1}`}),ep&&(0,n.jsx)(nQ,{onClose:()=>ef(!1)}),eh&&(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50 backdrop-blur-[4px] animate-in fade-in duration-150",onClick:()=>eg(null),children:(0,n.jsx)("div",{className:"card-elev w-full sm:max-w-sm max-h-[60%] overflow-auto modal-scrollable rounded-t-2xl sm:rounded-2xl p-2 animate-in slide-in-from-bottom-4 duration-150",onClick:e=>e.stopPropagation(),children:ev.map(e=>(0,n.jsxs)("button",{onClick:()=>{let t=e.key;eg(!1),T?.(t)},className:"w-full flex items-center gap-2.5 px-3 py-3 text-left rounded-brand hover:bg-surface-2 active:bg-surface-2 transition-colors",children:[(0,n.jsx)(en.VA,{size:16,className:"text-text-muted shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm text-text",children:e.label||O("agentSwitcher.unnamed")})]},e.key))})})]})}function oP({icon:e,label:t,onClick:s,disabled:r,className:l=""}){return(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),s()},disabled:r,title:t,className:`p-2 rounded-brand transition-colors active:scale-[0.96] ${r?"text-text-subtle cursor-not-allowed":`text-text-muted hover:text-text hover:bg-surface-2 ${l}`}`,children:(0,n.jsx)(e,{className:"w-5 h-5"})})}function oI({onAddWorkspace:e,onOpenRemote:t,recent:s,homeDir:r,connected:l}){let{t:a}=(0,ec.s)(),i=l&&!!t;return(0,n.jsxs)("div",{className:"empty-stage w-full h-full",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),e?.()},disabled:!l,className:"empty-half text-left active:opacity-80 enabled:active:scale-[0.99] transition-all duration-150 disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",a("workspaces.emptyTagWorkspace")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordTerminal")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaWorkspace")}}),(0,n.jsxs)("span",{className:"empty-go",children:[a("workspaces.selectFolder"),(0,n.jsx)(en.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]}),!!s.length&&(0,n.jsx)("span",{className:"flex flex-wrap gap-1.5 mt-4 max-w-full",children:s.slice(0,3).map(t=>(0,n.jsx)("span",{role:"button",title:t.path,onClick:s=>{s.stopPropagation(),(0,eo.e)(),e?.(t.path)},className:"welcome-chip path-tail px-2 py-1 text-[11px] font-mono text-text-muted rounded-full truncate max-w-[46%]",children:sf(t.path,r)},t.path))})]}),!!t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"empty-hairline","aria-hidden":!0}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),t?.()},disabled:!i,className:"empty-half text-left active:opacity-80 enabled:active:scale-[0.99] transition-all duration-150 disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"02"})," / ",a("workspaces.emptyTagRemote")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordRemote")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaRemote")}}),i&&(0,n.jsxs)("span",{className:"empty-go",children:[a("menu.remoteDesktop"),(0,n.jsx)(en.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]})]})]})]})}let oA=(e,t,s)=>Math.max(t,Math.min(s,e));function oL({clientX:e,clientY:t,containerRect:s,pan:n,totalScale:r}){return{x:(e-s.left-n.x)/r,y:(t-s.top-n.y)/r}}function oD(e,t){return{x:Math.min(0,e.width-t.width),y:Math.min(0,e.height-t.height)}}function oB(e,t){return{x:oA(e.x,t.x,0),y:oA(e.y,t.y,0)}}function oF({prevZoom:e,prevPan:t,focal:s,nextZoomRaw:n,maxZoom:r,containerSize:l,displaySizeAt:a}){let i=oA(n,1,r),o=i/e,c=oD(l,a(i));return{zoom:i,pan:oB({x:s.x-(s.x-t.x)*o,y:s.y-(s.y-t.y)*o},c)}}function oK({accum:e,delta:t,threshold:s,multiplier:n}){let r=e+t;if(Math.abs(r)<s)return{accum:r,scroll:null};let l=Math.max(1,Math.round(Math.abs(r)*n));return{accum:0,scroll:r>0?l:-l}}let oO=!!window.chrome,oW=e=>new Blob([e]),o_=(e,t)=>()=>{e.current[t]=null},oH=null,oq=0,oU=new Map;async function oV(e){if("u"<typeof createImageBitmap)return null;if(oO)return createImageBitmap(e);let t=new Image,s=URL.createObjectURL(e);t.src=s,await t.decode();let n=await createImageBitmap(t);return URL.revokeObjectURL(s),n}let oX={fps:0,latency:0,tilesPerSec:0,bandwidthMBps:0,webrtcTiles:0,wsTiles:0,webrtcPercent:0};function oG({list:e,activeIndex:t,onSelect:s}){if(!Array.isArray(e)||e.length<=1)return null;let r=e=>e.stopPropagation();return(0,n.jsx)("div",{className:"absolute bottom-1.5 right-1.5 z-40 flex gap-1.5",children:e.map(e=>{let l=e.index===t,a=`${e.index+1}`;return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),s?.(e.index)},onMouseDown:e=>e.preventDefault(),onPointerDown:r,onPointerUp:r,onPointerMove:r,onTouchStart:r,onTouchMove:r,onTouchEnd:r,onWheel:r,className:`px-1.5 py-0.5 rounded-md text-xs font-medium backdrop-blur-md border transition-colors inline-flex items-center gap-1 ${l?"bg-blue-500/70 text-white border-blue-400/70":"bg-black/30 text-white/80 border-white/10 hover:bg-black/50"}`,title:`${e.name} (${e.width}\xd7${e.height})`,children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]}),a]},e.index)})})}function oJ({canvasRef:e,canvasContainerRef:t,canvasZoom:s,canvasPan:l,fitScale:a,streaming:i,hasFrame:o=!0,selectionRect:d,clickIndicator:u,pointerMode:x,selectionMode:m,handMode:p,handHolding:f,scrollLock:h,virtualCursor:b,cursorShape:g,inputMode:v,keyboardOn:y,monitors:w,activeMonitorIndex:j,onSelectMonitor:k,onPointerDown:N,onPointerMove:C,onPointerUp:S,onWheel:E,onContextMenu:R,onDoubleClick:T,onTouchStart:$,onTouchMove:M,onTouchEnd:z,onKeyDown:P,screenLocked:I,unlockReady:A,unlockResult:L,onUnlockSubmit:D}){let B=a*s,F="mouse"===v,{t:K}=(0,ec.s)(),[O,W]=(0,r.useState)(!1),[_,H]=(0,r.useState)(""),[q,U]=(0,r.useState)(!1),[V,X]=(0,r.useState)(!1);(0,r.useEffect)(()=>{I||(H(""),U(!1))},[I]),(0,r.useEffect)(()=>{L&&U(!1)},[L]);let G={ew:"cursor-ew-resize",ns:"cursor-ns-resize",nwse:"cursor-nwse-resize",nesw:"cursor-nesw-resize",all:"cursor-move"},J=m?"cursor-crosshair":p?f?"cursor-grabbing":"cursor-grab":F&&O?"cursor-grabbing":F&&g&&G[g]?G[g]:"trackpad"===x?"cursor-grab active:cursor-grabbing":"cursor-default",Y=(0,r.useRef)(E);return(0,r.useEffect)(()=>{Y.current=E},[E]),(0,r.useEffect)(()=>{let t=e.current;if(!t)return;let s=e=>Y.current?.(e);return t.addEventListener("wheel",s,{passive:!1}),()=>t.removeEventListener("wheel",s)},[e]),(0,r.useEffect)(()=>{F&&i&&e.current?.focus()},[e,F,i]),(0,r.useEffect)(()=>{if(!O)return;let e=()=>W(!1);return window.addEventListener("pointerup",e),window.addEventListener("pointercancel",e),window.addEventListener("blur",e),()=>{window.removeEventListener("pointerup",e),window.removeEventListener("pointercancel",e),window.removeEventListener("blur",e)}},[O]),(0,n.jsxs)("div",{className:"w-full h-full overflow-hidden relative flex-1",children:[(0,n.jsxs)("div",{className:"absolute inset-0",ref:t,style:{touchAction:"none"},onTouchStart:$,onTouchMove:M,onTouchEnd:z,children:[(0,n.jsx)("canvas",{ref:e,className:`block ${J} bg-black outline-none`,style:{touchAction:"none",transformOrigin:"top left",userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent",transform:`translate3d(${l.x}px, ${l.y}px, 0) scale(${B})`,imageRendering:"auto",willChange:"transform"},onPointerDown:t=>{let s=document.activeElement;if(s?.name==="remote-batch-input")if(y){let e=document.querySelector('textarea[name="remote-keyboard-sink"]');e?.focus()}else s.blur();F&&(e.current?.focus(),"mouse"===t.pointerType&&W(!0)),N?.(t)},onPointerMove:C,onPointerUp:e=>{F&&"mouse"===e.pointerType&&W(!1),S?.(e)},onDoubleClick:T,onContextMenu:R,tabIndex:0,onKeyDown:P}),i&&!o&&!I&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 flex items-center justify-center pointer-events-none",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-black/60 text-white/80 text-[11px] font-mono",children:[(0,n.jsx)(en.kr,{size:12,className:"animate-spin"}),K("remote.receivingImage",{defaultValue:"Receiving screen…"})]})}),d&&(0,n.jsx)("div",{className:"absolute border-2 border-blue-400 bg-blue-400/20 z-10",style:{left:`${d.x}px`,top:`${d.y}px`,width:`${d.width}px`,height:`${d.height}px`}}),"trackpad"===x&&b&&(0,n.jsx)("div",{className:"absolute pointer-events-none z-30",style:{left:`${b.x*B+l.x}px`,top:`${b.y*B+l.y}px`,width:`${c.eR.trackpadCursorSize}px`,height:`${c.eR.trackpadCursorSize}px`,transform:g||p||h||m?"translate(-50%, -50%)":"translate(-2px, -2px)"},children:h?(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center text-yellow-400 drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{fontSize:`${c.eR.trackpadCursorSize}px`,lineHeight:1},children:"✥"}):m?(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full text-yellow-400 drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",children:(0,n.jsx)("path",{d:"M12 3 V21 M3 12 H21",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})}):p?(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{fontSize:`${c.eR.trackpadCursorSize}px`,lineHeight:1},children:f?"✊":"✋"}):g?(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{transform:`rotate(${"ns"===g?90:"nwse"===g?45:"nesw"===g?-45:0}deg)`},children:"all"===g?(0,n.jsx)("path",{d:"M12 3 V21 M3 12 H21 M8 6 L12 2 L16 6 M8 18 L12 22 L16 18 M6 8 L2 12 L6 16 M18 8 L22 12 L18 16",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"}):(0,n.jsx)("path",{d:"M3 12 H21 M7 8 L3 12 L7 16 M17 8 L21 12 L17 16",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",children:(0,n.jsx)("path",{d:"M4 2 L4 18 L8.5 14 L11 20 L14 18.5 L11.5 13 L18 12.5 Z",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinejoin:"round"})})}),u&&(0,n.jsxs)("div",{className:"absolute pointer-events-none z-20",style:{left:`${u.x-u.size/2}px`,top:`${u.y-u.size/2}px`,width:`${u.size}px`,height:`${u.size}px`},children:[(0,n.jsx)("div",{className:"w-full h-full rounded-full border-2 border-blue-400 bg-blue-400/30 animate-ping"}),(0,n.jsx)("div",{className:"absolute inset-0 w-full h-full rounded-full border-2 border-blue-400 bg-blue-400/50"})]})]}),(0,n.jsx)(oG,{list:w,activeIndex:j,onSelect:k}),I&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center",style:{background:"radial-gradient(circle at 50% 40%, rgba(40,60,140,0.55) 0%, rgba(10,12,30,0.92) 60%, rgba(0,0,0,0.96) 100%)"},children:(0,n.jsx)("div",{className:"w-full max-w-[300px] mx-4 rounded-2xl p-5 shadow-2xl backdrop-blur-md",style:{background:"rgba(20,22,40,0.85)",border:"1px solid rgba(120,140,220,0.25)"},children:A?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 mb-4",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center",style:{background:"rgba(120,140,220,0.18)"},children:(0,n.jsx)(en.LM,{size:26,color:"#a9b8ff"})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-white",children:K("remote.lockTitle")}),(0,n.jsx)("p",{className:"text-xs text-center",style:{color:"rgba(220,225,245,0.7)"},children:K("remote.lockDesc")})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{type:V?"text":"password",value:_,autoFocus:!0,disabled:q,onChange:e=>H(e.target.value),onKeyDown:e=>{"Enter"===e.key&&_&&!q&&(U(!0),D?.(_))},placeholder:K("remote.lockPlaceholder"),className:"w-full rounded-xl px-4 py-2 pr-11 text-sm text-white focus:outline-none focus:border-blue-400",style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(120,140,220,0.35)"}}),(0,n.jsx)("button",{type:"button",onClick:()=>X(e=>!e),tabIndex:-1,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 rounded-lg",style:{color:"rgba(220,225,245,0.7)"},"aria-label":V?"Hide password":"Show password",children:V?(0,n.jsx)(en.X_,{size:18}):(0,n.jsx)(en.kU,{size:18})})]}),(0,n.jsx)("button",{type:"button",disabled:!_||q,onClick:()=>{U(!0),D?.(_)},className:"w-full mt-2.5 rounded-xl py-2.5 text-sm font-semibold text-white transition-opacity disabled:opacity-40",style:{background:"linear-gradient(135deg, #4a6cf7 0%, #6b8aff 100%)"},children:K(q?"remote.unlocking":"remote.unlock")}),L&&!L.ok&&(0,n.jsx)("p",{className:"mt-3 text-xs text-center text-red-300",children:K("remote.unlockFailed")})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center",style:{background:"rgba(120,140,220,0.18)"},children:(0,n.jsx)(en.LM,{size:26,color:"#a9b8ff"})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-white",children:K("remote.lockTitle")}),(0,n.jsx)("p",{className:"text-xs",style:{color:"rgba(220,225,245,0.85)"},children:K("remote.lockGrantDesc")})]})})})]})}var oY=s(80186);let oZ=(e,...t)=>{(0,eo.e)(),e?.(...t)};function oQ({active:e,primary:t,pinned:s,children:r,className:l="",onClick:a,...i}){return(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:a,className:`shrink-0 px-1 h-8 rounded-brand text-xs font-semibold shadow-sm disabled:opacity-50 disabled:cursor-not-allowed min-w-[34px] flex items-center justify-center ${e?"bg-brand-500 text-white shadow-sm transition-all duration-150 ease-out active:scale-[0.94]":s?"bg-brand-500/15 hover:bg-brand-500/25 text-brand-400 transition-all duration-150 ease-out active:scale-[0.94]":t?"bg-green-600 hover:bg-green-700 text-white shadow-sm transition-all duration-150 ease-out active:scale-[0.94]":"bg-surface-2 hover:bg-surface-3 text-text transition-all duration-150 ease-out active:scale-[0.94]"} ${l}`,style:{touchAction:"manipulation",WebkitTapHighlightColor:"transparent"},...i,children:r})}function o0({streaming:e,canvasZoom:t,clipboardNew:s,clipboardText:l,onOpenClipboard:a,selectionMode:i,pointerMode:o,handMode:d,inputMode:u,onToggleHandMode:x,onTogglePointerMode:m,modifierKeys:p,textInputValue:f,textInputRef:h,keyboardOn:b,showTextPanel:g,onResetZoom:v,onRefresh:y,onToggleSelection:w,onToggleModifier:j,onToggleKeyboard:k,onToggleTextPanel:N,onToggleHelp:C,onToggleDebug:S,debugOn:E,onEmitKey:R,onTextInputChange:T,onTextInputFocus:$,onTextInputBlur:M,onTextInputKeyDown:z,onDirectInputChange:P,onSendText:I,onClose:A,onDesktopSwitch:L,controlsHidden:D,onToggleControlsHidden:B,tallLandscape:F}){let K,O,W,_,{t:H,locale:q}=(0,ec.s)(),U=(0,r.useRef)(null),[V]=tI(q),[X,G]=(0,r.useState)(!1),J=tD({lang:tz(V),onText:e=>{T(e);let t=U.current;t&&requestAnimationFrame(()=>{try{t.selectionStart=t.selectionEnd=t.value.length}catch{}t.scrollTop=t.scrollHeight})}});(0,r.useEffect)(()=>{let e=U.current;e&&!window.matchMedia("(orientation: landscape)").matches&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,72)}px`)},[f]);let Y=()=>{J.listening&&J.stop(),oZ(I,e)},Z=`flex gap-1.5 overflow-auto scroll-thin-x py-0.5 pr-2 ${F?"":"landscape:flex-wrap landscape:overflow-y-auto landscape:overflow-x-hidden landscape:py-2 landscape:pr-0 landscape:content-center landscape:justify-center"} rounded-lg`,[Q,ee]=(0,r.useState)(!1),[et,es]=(0,r.useState)(!1),[er,el]=(0,r.useState)(0);(0,r.useEffect)(()=>{if(!s)return void el(0);el(Math.ceil(c.eR.clipboardBadgeTimeout/1e3));let e=setInterval(()=>{el(e=>e<=1?0:e-1)},1e3);return()=>clearInterval(e)},[s,l]);let ea=tO("remoteDesktop.bottomKeys",c.ij,c.D5,"flat"),ei=tO("remoteDesktop.extraKeys",c.ij,c.I9,"grid");(0,r.useEffect)(()=>{if(!g)return;let e=setTimeout(()=>U.current?.focus(),350);return()=>clearTimeout(e)},[g]);let ed=c.eR.pcModeControls,eu=e=>"mouse"!==u||ed[e],ex=window.innerWidth<768,em=(t,s,r=!1,l="")=>{let a=t.label.length>1?"text-[11px]":"",i=`${l} ${a}`.trim();if("modifier"===t.type)return(0,n.jsx)(oQ,{onClick:()=>oZ(j,t.modifier),disabled:!e,active:p[t.modifier],pinned:r,className:i,children:t.label},t.id+s);if("desktop"===t.type){let l="prev"===t.direction?en.JG:"next"===t.direction?en.c_:en.FW;return(0,n.jsxs)(oQ,{onClick:()=>oZ(L,t.direction),disabled:!e,pinned:r,className:i,title:`${t.direction} desktop`,children:[(0,n.jsx)(en.VA,{size:12}),(0,n.jsx)(l,{size:"new"===t.direction?10:12,className:"-ml-0.5"})]},t.id+s)}return(0,n.jsx)(oQ,{onClick:()=>oZ(R,t.key,t.modifiers||[],t.osAdaptive),disabled:!e,primary:!r&&t.primary,pinned:r,className:i,children:t.label},t.id+s)};return(0,n.jsxs)("div",{className:`bg-bg select-none relative landscape:flex landscape:flex-col landscape:shrink-0 ${F||D?"":"landscape:h-full landscape:justify-end"} ${D?"landscape:w-12":F?"landscape:w-full landscape:pl-12":"landscape:w-64"}`,children:[(0,n.jsx)("textarea",{ref:h,rows:1,value:f,onChange:e=>{b?P?.(e.target.value):T(e.target.value)},onKeyDown:z,onFocus:$,onBlur:M,"aria-hidden":"true",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"data-lpignore":"true","data-1p-ignore":"true","data-form-type":"other",name:"remote-keyboard-sink",style:{position:"absolute",opacity:.01,width:1,height:1,border:0,padding:0,left:0,top:0,fontSize:16,resize:"none",pointerEvents:"none",zIndex:-1}}),(0,n.jsx)("div",{className:`absolute top-1 right-1 z-30 ${D||F?"hidden":"hidden landscape:flex"}`,children:(0,n.jsx)(oQ,{onClick:()=>{(0,eo.e)(),B?.(!0)},title:H("remote.hideControls"),children:(0,n.jsx)(en.X_,{size:14})})}),(0,n.jsxs)("div",{className:D?"landscape:hidden":"contents",children:[(0,n.jsxs)("div",{className:`${g?"flex":"hidden"} landscape:flex ${F?"":"landscape:flex-col"} relative z-30 px-2 py-1 gap-2 ${F?"landscape:px-0":"landscape:gap-1 landscape:order-last"}`,children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsx)(t$,{value:f,store:tj,isMobile:ex,onSelect:e=>{T(e),U.current?.focus()}}),(0,n.jsx)("textarea",{ref:U,rows:1,cols:1,value:f,onChange:e=>T(e.target.value),onFocus:$,onKeyDown:t=>{"mouse"===u&&"Enter"===t.key&&!t.shiftKey&&(t.preventDefault(),e&&Y())},placeholder:"mouse"===u?H("remoteControls.enterToSend"):H("remoteControls.typeToSend"),autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"data-lpignore":"true","data-1p-ignore":"true","data-form-type":"other",name:"remote-batch-input",className:`block w-full px-3 py-2 pr-8 bg-surface-2 rounded text-text text-sm placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out resize-none overflow-y-auto ${F?"":"landscape:!h-16"}`,disabled:!e}),f?(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{T(""),U.current?.focus()},title:H("voice.clear"),className:"absolute right-1.5 top-1.5 w-5 h-5 flex items-center justify-center text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(en.X,{size:14})}):(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>G(!0),title:H("history.title"),className:"absolute right-1.5 top-1.5 w-5 h-5 flex items-center justify-center text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(en.BZ,{size:14})})]}),(0,n.jsxs)("div",{className:"flex gap-2 items-center justify-end",children:[J.active&&(0,n.jsx)("div",{className:"relative shrink-0",children:(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{J.listening?J.stop():(document.activeElement?.blur(),J.start(f))},disabled:!e,title:"not-allowed"===J.error||"service-not-allowed"===J.error?H("voice.denied"):H("voice.dictate"),className:`h-9 w-9 flex items-center justify-center rounded-full transition-all duration-150 ease-out disabled:opacity-40 ${J.listening?"bg-red-500/90 text-white animate-pulse":J.error?"bg-surface-2 text-red-400":"bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text"}`,children:J.listening?(0,n.jsx)(en.jj,{size:18}):(0,n.jsx)(en.GO,{size:18})})}),(0,n.jsx)(oY.A,{variant:"primary",size:"sm",className:"!px-2.5 shrink-0",onMouseDown:e=>e.preventDefault(),onClick:Y,disabled:!e,children:f.trim()?H("remoteControls.send"):(0,n.jsx)(en.Lt,{size:16,strokeWidth:2.5})})]})]}),(0,n.jsx)("div",{className:`overflow-hidden transition-all duration-300 ${Q?"max-h-56 opacity-100":"hidden"}`,children:(0,n.jsx)("div",{className:"px-2 py-1",children:(0,n.jsx)("div",{className:"space-y-1",children:ei.rows.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0 flex gap-1.5 overflow-x-auto scroll-thin-x pr-3 rounded-lg",children:e.map((e,s)=>{let n=c.ij.find(t=>t.id===e);return n?em(n,100*t+s):null})}),0===t&&(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,eo.e)(),es(!0)},className:"shrink-0 h-10 w-10 flex items-center justify-center text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-all duration-150 ease-out",title:H("remote.customizeKeys"),children:(0,n.jsx)(en.wB,{size:16})}),t>0&&(0,n.jsx)("div",{className:"shrink-0 h-10 w-10"})]},t))})})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 landscape:hidden",children:[(0,n.jsxs)("div",{className:`${Z} flex-1 min-w-0 px-0 py-0 landscape:py-0`,children:[(0,n.jsx)(oQ,{onClick:()=>oZ(A),title:H("remote.back"),pinned:!0,className:"landscape:hidden",children:(0,n.jsx)(en.JG,{size:16})}),s&&l?(0,n.jsxs)(oQ,{onClick:()=>oZ(a),className:"!text-red-500 landscape:hidden",title:H("common.clipboard"),children:[(0,n.jsx)(en.Ir,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"tabular-nums",children:er})]}):(0,n.jsxs)(oQ,{onClick:()=>oZ(v),disabled:!e,className:"text-text landscape:hidden",title:H("remote.resetZoom"),children:[Math.round(100*t),"%"]}),(0,n.jsx)(oQ,{onClick:()=>oZ(y),disabled:!e,title:H("remote.refresh"),className:"landscape:hidden",children:(0,n.jsx)(en.e9,{size:14})}),eu("rectangleSelect")&&(0,n.jsx)(oQ,{onClick:()=>oZ(w),disabled:!e,active:i,title:H("remote.rectangleSelection"),className:"landscape:hidden",children:"□"}),eu("pointerModeToggle")&&(0,n.jsx)(oQ,{onClick:()=>oZ(m),disabled:!e,active:"trackpad"===o,title:"trackpad"===o?H("remoteControls.trackpadMode"):H("remoteControls.directMode"),className:"landscape:hidden",children:(0,n.jsx)("span",{className:"text-base leading-none",children:"\uD83D\uDDB1️"})}),eu("handMode")&&"trackpad"===o&&(0,n.jsx)(oQ,{onClick:()=>oZ(x),disabled:!e,active:d,title:H("remote.handMode"),className:"landscape:hidden",children:(0,n.jsx)(en.Ud,{size:14})}),eu("keyboardToggle")&&(0,n.jsx)(oQ,{onClick:()=>oZ(k),disabled:!e,active:b,title:H("remote.toggleKeyboard"),className:"landscape:hidden",children:(0,n.jsx)(en.s3,{size:14})}),eu("textPanel")&&(0,n.jsx)(oQ,{onClick:()=>oZ(N),disabled:!e,active:g,title:H("remote.textBatchInput"),className:"landscape:hidden",children:"Aa"}),eu("help")&&(0,n.jsx)(oQ,{onClick:()=>oZ(C),title:H("remote.help"),className:"landscape:hidden",children:(0,n.jsx)(en.mN,{size:14})})]}),(0,n.jsx)(oQ,{onClick:()=>{(0,eo.e)(),ee(e=>!e)},active:Q,pinned:!0,className:"landscape:hidden shrink-0",title:H("remote.extraKeys"),children:Q?(0,n.jsx)(en.X,{size:16}):(0,n.jsx)(en.a4,{size:16})})]}),eu("modifierRow")&&(K=ea.keys.filter(e=>e.id!==c.Ic),O=c.ij.find(e=>e.id===c.Ic),W=(0,n.jsx)(oQ,{onClick:()=>{(0,eo.e)(),ee(e=>!e)},active:Q,pinned:!0,title:H("remote.extraKeys"),children:Q?(0,n.jsx)(en.X,{size:16}):(0,n.jsx)(en.a4,{size:16})}),_=O?em(O,"pinned",!0):null,(0,n.jsxs)("div",{className:`px-2 py-1 safe-area-bottom ${F?"landscape:px-0":"landscape:py-2"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 landscape:hidden",children:[(0,n.jsx)("div",{className:`${Z} flex-1 min-w-0`,children:K.map((e,t)=>em(e,t))}),_]}),(0,n.jsxs)("div",{className:`${Z} hidden ${F?"landscape:flex":""}`,children:[K.map((e,t)=>em(e,t)),W,_]}),(0,n.jsxs)("div",{className:`hidden ${F?"":"landscape:flex"} landscape:flex-col gap-1`,children:[(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[K.slice(0,5).map((e,t)=>em(e,t)),W]}),(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[K.slice(5).map((e,t)=>em(e,t)),_]})]})]}))]}),(0,n.jsxs)("div",{className:`flex-col gap-1.5 p-1.5 ${D?"hidden landscape:flex":"hidden"}`,children:[(0,n.jsx)(oQ,{onClick:()=>{(0,eo.e)(),B?.(!1)},title:H("remote.showControls"),children:(0,n.jsx)(en.kU,{size:16})}),(0,n.jsx)(oQ,{onClick:()=>oZ(k),disabled:!e,active:b,title:H("remote.toggleKeyboard"),children:(0,n.jsx)(en.s3,{size:16})})]}),(0,n.jsx)(tU,{isOpen:et,onClose:()=>es(!1),title:H("remote.customizeRemoteKeys"),tabs:[{id:"bottom",label:H("remoteControls.bottomRow"),hook:ea,excludeIds:[c.Ic]},{id:"extra",label:H("remoteControls.extraPanel"),hook:ei}]}),(0,n.jsx)(tC,{isOpen:X,store:tj,onSelect:e=>{T(e),U.current?.focus()},onClose:()=>G(!1)})]})}let o1="bg-surface-2 hover:bg-surface-3 text-text",o2="bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text",o5="bg-brand-500 text-white";function o3({onClick:e,title:t,disabled:s,className:r,children:l}){return(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,eo.e)(),e()},disabled:s,title:t,className:`shrink-0 w-9 h-9 rounded-brand flex items-center justify-center transition-all duration-150 active:scale-[0.94] ${r} ${s?"disabled:opacity-50":""}`,children:l})}function o4({streaming:e,canvasZoom:t,pointerMode:s,handMode:r,keyboardOn:l,selectionMode:a,show:i,onBack:o,onRefresh:c,onResetZoom:d,onTogglePointerMode:u,onToggleHandMode:x,onToggleKeyboard:m,onShowHelp:p,onToggleSelection:f}){let{t:h}=(0,ec.s)();return(0,n.jsxs)("div",{className:"hidden landscape:flex flex-col items-center gap-1.5 py-2 px-1 bg-bg shrink-0 landscape:w-12 z-20",children:[(0,n.jsx)(o3,{onClick:o,title:h("remote.back"),className:"bg-brand-500/15 hover:bg-brand-500/25 text-brand-400",children:(0,n.jsx)(en.JG,{size:18})}),(0,n.jsx)(o3,{onClick:c,disabled:!e,title:h("remote.refresh"),className:o2,children:(0,n.jsx)(en.e9,{size:16})}),(0,n.jsxs)(o3,{onClick:d,disabled:!e,title:h("remote.resetZoom"),className:`text-[10px] font-semibold ${o1}`,children:[Math.round(100*t),"%"]}),i("pointerModeToggle")&&(0,n.jsx)(o3,{onClick:u,disabled:!e,title:h("trackpad"===s?"remoteControls.trackpadMode":"remoteControls.directMode"),className:`text-base leading-none ${"trackpad"===s?o5:o1}`,children:"\uD83D\uDDB1️"}),i("handMode")&&"trackpad"===s&&(0,n.jsx)(o3,{onClick:x,disabled:!e,title:h("remote.handMode"),className:r?o5:o1,children:(0,n.jsx)(en.Ud,{size:16})}),i("keyboardToggle")&&(0,n.jsx)(o3,{onClick:m,disabled:!e,title:h("remote.toggleKeyboard"),className:l?o5:o2,children:(0,n.jsx)(en.s3,{size:16})}),i("help")&&(0,n.jsx)(o3,{onClick:p,title:h("remote.help"),className:o2,children:(0,n.jsx)(en.mN,{size:16})}),i("rectangleSelect")&&(0,n.jsx)(o3,{onClick:f,disabled:!e,title:h("remote.rectangleSelection"),className:a?o5:o1,children:"□"})]})}function o6({onClose:e,inputMode:t="touch",pointerMode:s="direct"}){let{t:l}=(0,ec.s)();(0,r.useEffect)(()=>{let t=t=>{"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),e?.())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e]);let a="mouse"===t?[{title:l("remoteHelp.mouseTitle"),items:[{key:l("remoteHelp.mouseClickKey"),desc:l("remoteHelp.mouseClickDesc")},{key:l("remoteHelp.mouseRightKey"),desc:l("remoteHelp.mouseRightDesc")},{key:l("remoteHelp.mouseWheelKey"),desc:l("remoteHelp.mouseWheelDesc")},{key:l("remoteHelp.mouseDoubleKey"),desc:l("remoteHelp.mouseDoubleDesc")}]},{title:l("remoteHelp.keyboardTitle"),items:[{key:l("remoteHelp.keyPhysicalKey"),desc:l("remoteHelp.keyPhysicalDesc")},{key:l("remoteHelp.keyModifierKey"),desc:l("remoteHelp.keyModifierDesc")}]}]:"trackpad"===s?[{title:l("remoteHelp.gesturesTrackpadTitle"),items:[{key:l("remoteHelp.trackpadSwipeKey"),desc:l("remoteHelp.trackpadSwipeDesc")},{key:l("remoteHelp.trackpadScrollLockKey"),desc:l("remoteHelp.trackpadScrollLockDesc")},{key:l("remoteHelp.trackpadTapKey"),desc:l("remoteHelp.trackpadTapDesc")},{key:l("remoteHelp.trackpad2TapKey"),desc:l("remoteHelp.trackpad2TapDesc")},{key:l("remoteHelp.trackpad2SwipeKey"),desc:l("remoteHelp.trackpad2SwipeDesc")},{key:l("remoteHelp.trackpadPinchKey"),desc:l("remoteHelp.trackpadPinchDesc")}]},{title:l("remoteHelp.toolbarTitle"),items:[{key:"✋",desc:l("remoteHelp.toolbarHandDesc")},{key:"\uD83D\uDDB1️",desc:l("remoteHelp.toolbarMouseDirectDesc")},{key:"⌨️ / Aa",desc:l("remoteHelp.toolbarKeyboardDesc")}]}]:[{title:l("remoteHelp.gesturesDirectTitle"),items:[{key:l("remoteHelp.directTapKey"),desc:l("remoteHelp.directTapDesc")},{key:l("remoteHelp.directLongKey"),desc:l("remoteHelp.directLongDesc")},{key:l("remoteHelp.directDoubleKey"),desc:l("remoteHelp.directDoubleDesc")},{key:l("remoteHelp.directScrollKey"),desc:l("remoteHelp.directScrollDesc")},{key:l("remoteHelp.directPinchKey"),desc:l("remoteHelp.directPinchDesc")},{key:l("remoteHelp.directPanKey"),desc:l("remoteHelp.directPanDesc")}]},{title:l("remoteHelp.toolbarTitle"),items:[{key:"\uD83D\uDDB1️",desc:l("remoteHelp.toolbarMouseTrackpadDesc")},{key:"⌨️ / Aa",desc:l("remoteHelp.toolbarKeyboardDesc")},{key:"□",desc:l("remoteHelp.toolbarRectDesc")}]}],i=l("mouse"===t?"remoteHelp.modePc":"trackpad"===s?"remoteHelp.modeTrackpad":"remoteHelp.modeDirect");return(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 bg-black/60 flex items-center justify-center p-4",onClick:e,children:(0,n.jsxs)("div",{className:"card-elev max-w-lg w-full max-h-full overflow-y-auto",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border sticky top-0 bg-surface z-10",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h2",{className:"text-text text-base font-semibold",children:l("remote.help")}),(0,n.jsx)("span",{className:"text-brand-400 text-xs font-mono",children:i})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-surface-2 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(en.X,{size:18})})]}),(0,n.jsx)("div",{className:"p-4 space-y-4",children:a.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-brand-400 text-xs font-semibold uppercase tracking-wider mb-2",children:e.title}),(0,n.jsx)("ul",{className:"space-y-1.5",children:e.items.map(e=>(0,n.jsxs)("li",{className:"flex gap-3 text-sm",children:[(0,n.jsx)("span",{className:"text-text font-mono bg-bg px-2 py-0.5 rounded text-xs shrink-0 min-w-[120px] text-center",children:e.key}),(0,n.jsx)("span",{className:"text-text-muted",children:e.desc})]},e.key))})]},e.title))})]})})}function o8({stats:e,mode:t,onReset:s,onClose:l,onCopy:a,onForceWsDisconnect:i,onToggleWsBlock:o,isWsBlocked:c}){var d,u;let x,{t:m}=(0,ec.s)(),[p,f]=(0,r.useState)(!1);return p?(0,n.jsx)("div",{className:"fixed top-4 right-4 z-50",children:(0,n.jsxs)("button",{onClick:()=>f(!1),className:"bg-surface-2 text-text px-4 py-2 rounded-lg shadow-md hover:bg-surface-3 transition-all duration-150 ease-out active:scale-[0.97]",children:["\uD83D\uDD0D ",m("remote.debug")]})}):(0,n.jsxs)("div",{className:"fixed top-4 right-4 z-50 card-elev p-4 min-w-[280px] text-sm",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3 pb-2 border-b border-border",children:[(0,n.jsxs)("h3",{className:"text-text font-semibold flex items-center gap-2",children:["\uD83D\uDD0D ",m("remote.debugTitle")]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>f(!0),className:"text-text-muted hover:text-text transition-colors",title:m("remote.minimize"),children:"─"}),(0,n.jsx)("button",{onClick:l,className:"text-text-muted hover:text-text transition-colors",title:m("common.close"),children:"✕"})]})]}),(0,n.jsxs)("div",{className:"space-y-2 mb-3",children:[(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Mode:"}),(0,n.jsx)("span",{className:"rtc"===t?"text-blue-400 font-semibold":"text-yellow-400 font-semibold",children:"rtc"===t?"RTC enabled":"WS only"})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.transport"),":"]}),(0,n.jsx)("span",{className:e.webrtcPercent>50?"text-blue-400 font-semibold":"text-text-muted",children:e.webrtcPercent>50?"WebRTC ✅":"WebSocket"})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.fps"),":"]}),(0,n.jsx)("span",{className:`font-semibold ${(d=e.fps)>=15?"text-green-400":d>=10?"text-yellow-400":"text-red-400"}`,children:e.fps})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.latency"),":"]}),(0,n.jsx)("span",{className:`font-semibold ${(u=e.latency)<50?"text-green-400":u<100?"text-yellow-400":"text-red-400"}`,children:(x=e.latency,`${Math.round(x)}ms`)})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.tilesPerSec"),":"]}),(0,n.jsx)("span",{className:"text-text font-semibold",children:e.tilesPerSec})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.bandwidth"),":"]}),(0,n.jsxs)("span",{className:"text-text font-semibold",children:[e.bandwidthMBps," MB/s"]})]})]}),(0,n.jsxs)("div",{className:"border-t border-border pt-3 mb-3 space-y-1",children:[(0,n.jsxs)("div",{className:"flex justify-between items-center text-xs",children:[(0,n.jsx)("span",{className:"text-blue-400",children:"WebRTC:"}),(0,n.jsxs)("span",{className:"text-text-muted",children:[e.webrtcTiles.toLocaleString()," tiles (",e.webrtcPercent,"%)"]})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center text-xs",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"WebSocket:"}),(0,n.jsxs)("span",{className:"text-text-muted",children:[e.wsTiles.toLocaleString()," tiles (",100-e.webrtcPercent,"%)"]})]})]}),(0,n.jsxs)("div",{className:"flex gap-2 border-t border-border pt-3",children:[(0,n.jsx)("button",{onClick:s,className:"flex-1 bg-surface hover:bg-surface-2 text-text py-2 px-3 rounded transition-colors text-xs",children:m("remote.clearStats")}),(0,n.jsx)("button",{onClick:a,className:"flex-1 bg-surface hover:bg-surface-2 text-text py-2 px-3 rounded transition-colors text-xs",children:"Copy"})]}),(i||o)&&(0,n.jsxs)("div",{className:"flex gap-2 mt-2",children:[i&&(0,n.jsx)("button",{onClick:i,className:"flex-1 bg-red-900/40 hover:bg-red-900/60 text-red-300 py-2 px-3 rounded transition-colors text-xs",title:"Disconnect WS once (auto-reconnect)",children:"⚡ Kill WS"}),o&&(0,n.jsx)("button",{onClick:o,className:`flex-1 py-2 px-3 rounded transition-colors text-xs ${c?"bg-yellow-900/60 hover:bg-yellow-900/80 text-yellow-200":"bg-surface hover:bg-surface-2 text-text"}`,title:"Block WS reconnect to test RTC standalone",children:c?"\uD83D\uDD12 WS Blocked":"\uD83D\uDEAB Block WS"})]})]})}function o9({text:e,onClose:t}){let[s,l]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t]);let a=async()=>{try{await navigator.clipboard?.writeText(e),l(!0),setTimeout(()=>l(!1),1500)}catch{}};return(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 bg-black/60 flex items-center justify-center p-4",onClick:t,children:(0,n.jsxs)("div",{className:"card-elev max-w-lg w-full max-h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(en.m0,{size:16,className:"text-brand-400"}),(0,n.jsx)("h2",{className:"text-text text-base font-semibold",children:"Clipboard"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-surface-2 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(en.X,{size:18})})]}),(0,n.jsx)("div",{className:"p-4 overflow-y-auto flex-1",children:(0,n.jsx)("pre",{className:"text-text text-sm whitespace-pre-wrap break-all bg-bg rounded p-3 font-mono min-h-[120px] max-h-[55dvh] overflow-y-auto scroll-thin",children:e||""})}),(0,n.jsx)("div",{className:"flex justify-end gap-2 p-4 border-t border-border",children:(0,n.jsxs)("button",{onClick:a,disabled:!e,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-brand bg-brand-500 hover:bg-brand-600 disabled:opacity-50 text-white text-sm font-semibold transition-colors",children:[s?(0,n.jsx)(en.aJ,{size:14}):(0,n.jsx)(en.m0,{size:14}),"Copy"]})})]})})}function o7({onClose:e,busRef:t,protocolRef:l,connected:a,carrier:i,hostPlatform:o}){let{t:u}=(0,ec.s)(),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(!1),[h,b]=(0,r.useState)(!1),[g,v]=tK("remoteDesktop.showTextPanel",!0),[y,w]=tK("remoteDesktop.keyboard",!1),[j,k]=tK("remoteDesktop.controlsHidden",!1),[N,C]=tK("remoteDesktop.pointerMode",c.eR.pointerMode),[S,E]=tK("remoteDesktop.handMode",!1),R=tF(),T=c.eR.pcModeControls,[$,M]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=window.matchMedia("(orientation: landscape)"),t=()=>M(e.matches);return t(),e.addEventListener?.("change",t),()=>e.removeEventListener?.("change",t)},[]);let z=$&&Math.min(window.screen.width,window.screen.height)>=700;(0,r.useEffect)(()=>{"mouse"===R&&"direct"!==N&&C("direct")},[R,N,C]);let{stats:P,trackTilesReceived:I,resetStats:A}=function(){let[e,t]=(0,r.useState)(oX),s=(0,r.useRef)({frameCount:0,lastFpsTime:Date.now(),tilesReceived:0,lastTilesTime:Date.now(),bytesReceived:0,lastBandwidthTime:Date.now(),latencies:[],webrtcTilesTotal:0,wsTilesTotal:0});return{stats:e,trackTilesReceived:(0,r.useCallback)((e,n)=>{let r=s.current,l=Date.now();r.frameCount++;let a=e.tiles?.length||0;r.tilesReceived+=a;let i="number"==typeof e.bytes?e.bytes:e.tiles?.reduce((e,t)=>e+(t.imageBuffer?.byteLength||t.imageBuffer?.length||0),0)||0;if(r.bytesReceived+=i,e.timestamp){let t=Date.now()-e.timestamp;r.latencies.push({value:t,time:l}),r.latencies=r.latencies.filter(e=>l-e.time<6e4)}if(n?.startsWith("dc")||"webrtc"===n?r.webrtcTilesTotal+=a:r.wsTilesTotal+=a,l-r.lastFpsTime>=500){let e=(l-r.lastFpsTime)/1e3,s=Math.round(r.frameCount/e),n=r.latencies.length>0?Math.round(r.latencies.reduce((e,t)=>e+t.value,0)/r.latencies.length):0,a=Math.round(r.tilesReceived/e),i=(r.bytesReceived/e/1024/1024).toFixed(2),o=r.webrtcTilesTotal+r.wsTilesTotal,c=o>0?Math.round(r.webrtcTilesTotal/o*100):0;t({fps:s,latency:n,tilesPerSec:a,bandwidthMBps:parseFloat(i),webrtcTiles:r.webrtcTilesTotal,wsTiles:r.wsTilesTotal,webrtcPercent:c}),r.frameCount=0,r.tilesReceived=0,r.bytesReceived=0,r.lastFpsTime=l}},[]),resetStats:(0,r.useCallback)(()=>{let e=s.current;e.frameCount=0,e.lastFpsTime=Date.now(),e.tilesReceived=0,e.lastTilesTime=Date.now(),e.bytesReceived=0,e.lastBandwidthTime=Date.now(),e.latencies=[],e.webrtcTilesTotal=0,e.wsTilesTotal=0,t(oX)},[])}}(),[L,D]=(0,r.useState)(c.eR.debug?.panel??!1),[B,F]=(0,r.useState)(!1),K=c.eR.enableWebRTC?"rtc":"ws",O=(0,r.useCallback)(()=>{let e={mode:K,...P,ts:new Date().toISOString()};navigator.clipboard?.writeText(JSON.stringify(e,null,2)).catch(()=>{})},[P,K]),W=(0,r.useRef)(P);(0,r.useEffect)(()=>{W.current=P},[P]),(0,r.useEffect)(()=>{(0,d.c)("remote",`[stats] interval started, mode=${K}`);let e=setInterval(()=>{(0,d.c)("remote",`[stats][${K}]`,JSON.stringify(W.current))},5e3);return()=>{(0,d.c)("remote","[stats] interval stopped"),clearInterval(e)}},[K]);let{streaming:_,emitRequestScreenWithHashes:H,emitMousePress:q,emitMouseRelease:U,emitMouseClick:V,emitMouseMove:X,emitMouseDragSelect:G,emitKeyPress:J,emitTypeText:Y,emitScroll:Z,emitBoostStream:Q,emitSetFocus:ee,emitDesktopSwitch:et}=function(e,t){let[s,n]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(t&&e?.current)return n(!0),()=>n(!1)},[t,e]);let l=(0,r.useCallback)((t,s)=>{e?.current?.emit(t,s)},[e]),a=(0,r.useCallback)((e,t,n="left")=>{s&&l("mouse-press",{x:e,y:t,button:n})},[l,s]),i=(0,r.useCallback)((e,t,n="left")=>{s&&l("mouse-release",{x:e,y:t,button:n})},[l,s]),o=(0,r.useCallback)((e,t,n="left",r=!1)=>{s&&l("mouse-click",{x:e,y:t,button:n,double:r})},[l,s]),c=(0,r.useCallback)((e,t)=>{s&&l("mouse-move",{x:e,y:t})},[l,s]),d=(0,r.useCallback)((e,t,n,r)=>{s&&l("mouse-drag-select",{startX:e,startY:t,endX:n,endY:r})},[l,s]),u=(0,r.useCallback)((e,t=[])=>{s&&l("key-press",{key:e,modifier:t})},[l,s]),x=(0,r.useCallback)(e=>{s&&l("type-text",{text:e})},[l,s]),m=(0,r.useCallback)((e,t=20,n=!1)=>{s&&l("scroll",{direction:e,amount:t,horizontal:n})},[l,s]),p=(0,r.useCallback)(()=>{s&&l("boost-stream")},[l,s]),f=(0,r.useCallback)((e,t=1)=>{s&&l("set-focus",{rect:e,zoom:t,viewerWidth:window.innerWidth,dpr:window.devicePixelRatio||1})},[l,s]),h=(0,r.useCallback)(e=>{s&&l("request-screen-with-hashes",{tileHashes:e})},[l,s]),b=(0,r.useCallback)(e=>{s&&l("desktop-switch",{direction:e})},[l,s]);return{streaming:s,emitRequestScreenWithHashes:h,emitMousePress:a,emitMouseRelease:i,emitMouseClick:o,emitMouseMove:c,emitMouseDragSelect:d,emitKeyPress:u,emitTypeText:x,emitScroll:m,emitBoostStream:p,emitSetFocus:f,emitDesktopSwitch:b}}(t,a),es={emitRequestScreenWithHashes:H,emitMousePress:q,emitMouseRelease:U,emitMouseClick:V,emitMouseMove:X,emitMouseDragSelect:G,emitKeyPress:J,emitTypeText:Y,emitScroll:Z,emitBoostStream:Q},en=(0,r.useCallback)(()=>{f(!0)},[]);(0,r.useEffect)(()=>{i&&(0,d.c)("remote",`[remote] carrier: ${i}`)},[i]);let{canvasRef:er,canvasContainerRef:el,canvasZoom:ea,canvasPan:ed,fitScale:eu,baseCanvasSize:ex,zoomGestureTimeoutRef:em,clickIndicator:ep,virtualCursor:ef,handHolding:eh,scrollLock:eb,getCanvasCoordinates:eg,resetZoom:ev,resetPan:ey,panForKeyboard:ew,centerVirtualCursor:ej,startHandHold:ek,releaseHandHold:eN,handleCanvasInteraction:eC,handleCanvasDimensions:eS,serverDimensionsRef:eE}=function(e){let t=function(){let e=(0,r.useRef)(null),t=(0,r.useRef)(null),[s,n]=(0,r.useState)(1),[l,a]=(0,r.useState)({x:0,y:0}),[i,o]=(0,r.useState)(1),[d,u]=(0,r.useState)({width:0,height:0}),x=(0,r.useRef)({width:0,height:0}),m=(0,r.useRef)({x:0,y:0}),p=i*s,f=(0,r.useCallback)(()=>{let e=t.current;return e?{width:e.clientWidth,height:e.clientHeight}:null},[]),h=(0,r.useCallback)(e=>({width:d.width*e,height:d.height*e}),[d]),b=(0,r.useCallback)((n,r)=>{let a=e.current,o=t.current;return a&&o&&0!==a.width?function({canvasPoint:e,canvasWidth:t,canvasHeight:s}){return{percentX:oA(e.x/t*100,0,100),percentY:oA(e.y/s*100,0,100)}}({canvasPoint:oL({clientX:n,clientY:r,containerRect:o.getBoundingClientRect(),pan:l,totalScale:i*s}),canvasWidth:a.width,canvasHeight:a.height}):{percentX:0,percentY:0}},[l,s,i]),g=(0,r.useCallback)((e,t)=>{let n=i*s;n<=0||(m.current={x:(e-l.x)/n,y:(t-l.y)/n})},[i,s,l]),v=(0,r.useCallback)(()=>{n(1),a({x:0,y:0})},[]),y=(0,r.useCallback)(()=>a({x:0,y:0}),[]),w=(0,r.useCallback)((e,t)=>{let n=f();if(!n)return;let r=i*s;if(r<=0)return;let l=t||m.current,o=oD(n,h(s));a(t=>{if(!e||s<=1)return oB(t,o);let{y:a}=function({focus:e,containerHeight:t,totalScale:s}){return{y:t/3-e.y*s}}({focus:l,containerHeight:n.height,totalScale:r});return oB({x:t.x,y:a},o)})},[f,h,i,s]),j=(0,r.useCallback)(()=>{let s,n=t.current,r=e.current,l=x.current;if(!n||!r||0===l.width||0===l.height)return;let a=(s={width:n.clientWidth,height:n.clientHeight},Math.min(s.width/l.width,s.height/l.height));o(a),u({width:l.width*a,height:l.height*a})},[]);(0,r.useEffect)(()=>{let e=null,s=null,n=()=>{let e=t.current;if(!e)return void j();let n=e.clientWidth,r=e.clientHeight,l=0,a=0,i=()=>{let t=e.clientWidth,o=e.clientHeight;if(t===n&&o===r){if(++l>=c.eR.resizeStableFrames){s=null,j();return}}else l=0,n=t,r=o;if(a++>=c.eR.resizeMaxFrames){s=null,j();return}s=requestAnimationFrame(i)};s=requestAnimationFrame(i)},r=()=>{e&&clearTimeout(e),s&&(cancelAnimationFrame(s),s=null),e=setTimeout(n,c.eR.resizeDebounceMs)};return window.addEventListener("resize",r),window.addEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.addEventListener("resize",r),()=>{e&&clearTimeout(e),s&&cancelAnimationFrame(s),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.removeEventListener("resize",r)}},[j]),(0,r.useEffect)(()=>{a(e=>{let n=t.current;if(!n)return e;let r=oB(e,oD({width:n.clientWidth,height:n.clientHeight},{width:d.width*s,height:d.height*s}));return r.x===e.x&&r.y===e.y?e:r})},[d,s]);let k=(0,r.useCallback)((s,n)=>{x.current={width:s.width,height:s.height};let r=e.current,l=t.current;if(!r||!l)return!1;let a=r.width!==s.width||r.height!==s.height;r.width=s.width,r.height=s.height;let i=r.getContext("2d");return i.imageSmoothingEnabled=!1,a&&(i.clearRect(0,0,r.width,r.height),i.fillStyle="#2a2a2a",i.fillRect(0,0,r.width,r.height),n?.current&&n.current.clear()),j(),a},[j]);return{canvasRef:e,canvasContainerRef:t,canvasZoom:s,setCanvasZoom:n,canvasPan:l,setCanvasPan:a,fitScale:i,totalScale:p,baseCanvasSize:d,serverDimensionsRef:x,containerSize:f,displaySizeAt:h,getCanvasCoordinates:b,recordInteractPx:g,resetZoom:v,resetPan:y,panForKeyboard:w,handleCanvasDimensions:k}}(),{canvasRef:s,canvasContainerRef:n,canvasZoom:l,setCanvasZoom:a,canvasPan:i,setCanvasPan:o,fitScale:d,baseCanvasSize:u,containerSize:x,displaySizeAt:m,getCanvasCoordinates:p,recordInteractPx:f}=t,[h,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(0),w=(0,r.useRef)({x:0,y:0}),[j,k]=(0,r.useState)(!1),N=(0,r.useRef)(null),[C,S]=(0,r.useState)(null),E=(0,r.useRef)(null),R=(0,r.useRef)(!1),T=(0,r.useRef)({x:0,y:0}),$=(0,r.useRef)(0),M=(0,r.useRef)({x:0,y:0}),[z,P]=(0,r.useState)(!1),I=(0,r.useRef)({x:0,y:0}),A=(0,r.useRef)({x:0,y:0}),L=(0,r.useRef)(0),D=(0,r.useRef)(null),[B,F]=(0,r.useState)({x:0,y:0}),K=(0,r.useRef)(0),O=(0,r.useRef)(0),W=(0,r.useRef)(null),_=(0,r.useRef)({time:0,distance:0,centerX:0,centerY:0}),H=(0,r.useRef)(!1),q=(0,r.useRef)(0),U=(0,r.useRef)(!1),V=(0,r.useRef)(null),X=(0,r.useRef)(!1),[G,J]=(0,r.useState)(!1),Y=(0,r.useRef)(null),Z=(0,r.useRef)(!1),[Q,ee]=(0,r.useState)(!1),et=(0,r.useRef)(null),es=(0,r.useRef)({x:0,y:0}),en=(0,r.useRef)(!1),er=(0,r.useRef)(null),el=(0,r.useRef)(0),ea=(0,r.useCallback)((e,t)=>{let s=n.current;if(!s)return;let r=s.getBoundingClientRect(),a=e-r.left,i=t-r.top,o=oA(7.5*l,5,15);f(a,i),S({x:a,y:i,size:o}),setTimeout(()=>S(null),500)},[l,n,f]),ei=(0,r.useCallback)(()=>{E.current&&(clearTimeout(E.current),E.current=null)},[]),ec=(0,r.useCallback)((t,s,n,r)=>{ei(),R.current=!1,T.current={x:t,y:s},E.current=setTimeout(()=>{R.current=!0,ea(t,s),e?.emitMouseClick(n,r,"right")},c.eR.longPressDelay)},[ei,ea,e]),ed=(0,r.useCallback)((e,t)=>{let s=Date.now(),n=function({now:e,lastTime:t,lastPos:s,x:n,y:r,cfg:l}){let a=Math.abs(n-s.x),i=Math.abs(r-s.y);return e-t<l.doubleClickDelay&&a<l.moveThreshold&&i<l.moveThreshold}({now:s,lastTime:$.current,lastPos:M.current,x:e,y:t,cfg:c.eR});return $.current=s,M.current={x:e,y:t},n},[]),eu=(0,r.useCallback)(()=>{D.current&&(cancelAnimationFrame(D.current),D.current=null),A.current={x:0,y:0},I.current={x:0,y:0},P(!1)},[]),ex=(0,r.useCallback)(()=>{let t=()=>{var s,n;let r=(s=A.current,n=c.eR,Math.abs(s.y)<n.momentumMinVelocity?null:{scrollY:Math.round(s.y*n.edgeScrollMultiplier),nextVelocity:{x:s.x*n.momentumFriction,y:s.y*n.momentumFriction}});if(!r)return eu();Math.abs(r.scrollY)>=1&&e?.emitScroll(r.scrollY>0?"up":"down",Math.abs(r.scrollY),!1),A.current=r.nextVelocity,D.current=requestAnimationFrame(t)};D.current=requestAnimationFrame(t)},[e,eu]);(0,r.useEffect)(()=>()=>{ei(),eu()},[ei,eu]);let em=(0,r.useCallback)(t=>{let{edgeScrollThreshold:s,edgeScrollMultiplier:n}=c.eR,r=oK({accum:I.current.y,delta:t,threshold:s,multiplier:n});I.current.y=r.accum,r.scroll&&e?.emitScroll(r.scroll>0?"up":"down",Math.abs(r.scroll),!1)},[e]),ep=(0,r.useCallback)(t=>{let{edgeScrollThreshold:s,edgeScrollMultiplier:n}=c.eR,r=oK({accum:I.current.x,delta:t,threshold:s,multiplier:n});I.current.x=r.accum,r.scroll&&e?.emitScroll(r.scroll>0?"right":"left",Math.abs(r.scroll),!0)},[e]),ef=(0,r.useCallback)((e,t)=>({percentX:oA(e.x/t.width*100,0,100),percentY:oA(e.y/t.height*100,0,100)}),[]),eh=(0,r.useCallback)(t=>{let n=s.current;if(!n||0===n.width)return;let{percentX:r,percentY:l}=ef(t,n);e?.emitMouseMove?.(r,l)},[e,s,ef]);(0,r.useEffect)(()=>{let t=t=>{if(null==et.current||t.pointerType&&"mouse"!==t.pointerType)return;let r=s.current,l=n.current;if(!r||!l)return;let{percentX:a,percentY:i}=p(t.clientX,t.clientY),o=et.current;et.current=null,e?.emitMouseRelease?.(a,i,o)};return window.addEventListener("pointerup",t),window.addEventListener("pointercancel",t),()=>{window.removeEventListener("pointerup",t),window.removeEventListener("pointercancel",t)}},[p,e,s,n]);let eb=(0,r.useCallback)((t,r,u)=>{let{streaming:f,pointerMode:C="direct"}=u;if(!f||!e)return;let S={canvasRef:s,canvasContainerRef:n,containerSize:x,displaySizeAt:m,getCanvasCoordinates:p,socketEmitFunctions:e,canvasZoom:l,fitScale:d,virtualCursor:B,canvasPan:i,setCanvasZoom:a,setCanvasPan:o,setVirtualCursor:F,isZooming:h,isPanning:g,isEdgeScrolling:z,recentZoomGesture:j,lastTouchDistanceRef:y,lastTouchCenterRef:w,setIsZooming:b,setIsPanning:v,setIsEdgeScrolling:P,setRecentZoomGesture:k,gestureLockRef:W,gestureStartRef:_,multiTouchLatchRef:H,twoFingerMaxMovedRef:q,touchOutsideRef:U,longPressTriggeredRef:R,touchStartPosRef:T,edgeScrollAccumRef:I,velocityRef:A,lastTouchTimeRef:L,touchStartTimeRef:K,touchTotalMoveRef:O,handLongPressTimerRef:V,handHoldingRef:X,setHandHolding:J,scrollLongPressTimerRef:Y,scrollLockRef:Z,setScrollLock:ee,mouseDownButtonRef:et,wheelAccumRef:es,wheelActiveRef:en,wheelEndTimerRef:er,wheelLastBoostRef:el,zoomGestureTimeoutRef:N,showClickIndicator:ea,cancelLongPress:ei,startLongPress:ec,checkDoubleClick:ed,stopMomentum:eu,startMomentumScroll:ex,emitScrollFromDelta:em,emitHScrollFromDelta:ep,cursorPercent:ef,emitVirtualCursor:eh};if(t.nativeEvent?.pointerType==="mouse"||"wheel"===t.type||"contextmenu"===t.type||"dblclick"===t.type)return("wheel"===t.type||"contextmenu"===t.type)&&t.preventDefault(),function(e,t,s,n){let{socketEmitFunctions:r,getCanvasCoordinates:l,showClickIndicator:a}=e,{streaming:i,selectionMode:o,handleSelection:d}=n;if(!i||!r)return;let u=c.eR.mouseButtonMap[t.button]||"left";if("wheel"===s){var x,m;let{percentX:s,percentY:n}=l(t.clientX,t.clientY),a=(x=t.deltaMode,m=c.eR,1===x?m.wheelLineHeight:2===x?m.wheelPageHeight:1),i=t.deltaY*a,o=t.deltaX*a;if(t.ctrlKey||t.metaKey){let s=e.canvasContainerRef.current,n=e.canvasRef.current;if(!s||!n)return;let r=s.getBoundingClientRect(),l={x:t.clientX-r.left,y:t.clientY-r.top},a={width:s.clientWidth,height:s.clientHeight},o=i>0?-1:1;e.setCanvasZoom(t=>{let s=oA(t+o*c.eR.wheelZoomStep,1,4);return s===t?t:(e.setCanvasPan(n=>oF({prevZoom:t,prevPan:n,focal:l,nextZoomRaw:s,maxZoom:4,containerSize:a,displaySizeAt:e.displaySizeAt}).pan),s)});return}if(e.wheelActiveRef.current){let t=Date.now();t-e.wheelLastBoostRef.current>=c.eR.wheelBoostInterval&&(r.emitBoostStream?.(),e.wheelLastBoostRef.current=t)}else r.emitBoostStream?.(),r.emitMouseMove?.(s,n),e.wheelActiveRef.current=!0,e.wheelLastBoostRef.current=Date.now();e.wheelEndTimerRef.current&&clearTimeout(e.wheelEndTimerRef.current),e.wheelEndTimerRef.current=setTimeout(()=>{e.wheelActiveRef.current=!1,e.wheelAccumRef.current.x=0},150);let d=c.eR.wheelScrollMultiplier;if(i&&e.emitScrollFromDelta(-i*d),o){let{edgeScrollThreshold:t,edgeScrollMultiplier:s}=c.eR,n=oK({accum:e.wheelAccumRef.current.x,delta:o*d,threshold:t,multiplier:s});e.wheelAccumRef.current.x=n.accum,n.scroll&&r.emitScroll?.(n.scroll>0?"right":"left",Math.abs(n.scroll),!0)}return}if("contextmenu"===s){let{percentX:e,percentY:s}=l(t.clientX,t.clientY);a(t.clientX,t.clientY),r.emitMouseClick?.(e,s,"right");return}if("dblclick"===s)return;if(o){"pointerdown"===s?d?.(t.clientX,t.clientY,"start"):"pointermove"===s&&null!=e.mouseDownButtonRef.current?d?.(t.clientX,t.clientY,"move"):"pointerup"===s&&(d?.(t.clientX,t.clientY,"end"),e.mouseDownButtonRef.current=null),"pointerdown"===s&&(e.mouseDownButtonRef.current=u);return}let{percentX:p,percentY:f}=l(t.clientX,t.clientY);if("pointerdown"===s){e.mouseDownButtonRef.current=u,a(t.clientX,t.clientY),r.emitMousePress?.(p,f,u);return}if("pointermove"===s){null!=e.mouseDownButtonRef.current&&r.emitMouseMove?.(p,f);return}if("pointerup"===s){let t=e.mouseDownButtonRef.current||u;e.mouseDownButtonRef.current=null,r.emitMouseRelease?.(p,f,t)}}(S,t,r,u);t.preventDefault(),t.type.startsWith("touch")&&t.touches?.length>=2&&(H.current=!0,Y.current&&(clearTimeout(Y.current),Y.current=null),Z.current&&(Z.current=!1,ee(!1),I.current={x:0,y:0}),V.current&&(clearTimeout(V.current),V.current=null)),"trackpad"===C&&t.type.startsWith("touch")&&function(e,t,s,n){let r=e.canvasRef.current;if(!r||0===r.width)return!0;let{selectionMode:l,dragMode:a,isDragging:i,setIsDragging:o,setDragMode:d,handleSelection:u,handMode:x=!1,onHandRelease:m}=n;if(t.touches?.length>=2||!(!e.multiTouchLatchRef.current&&(t.touches?.length===1||"touchend"===s)))return!1;let p=t.touches?.[0]||t.changedTouches?.[0];if(!p)return!0;if("touch"===s){if(e.touchStartTimeRef.current=Date.now(),e.touchTotalMoveRef.current=0,e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=Date.now(),l){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);return u?.(0,0,"start",{...n,percentOverride:{percentX:t,percentY:s}}),!0}return x&&!e.handHoldingRef.current&&(e.handLongPressTimerRef.current&&clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=setTimeout(()=>{e.handLongPressTimerRef.current=null;let t=e.canvasRef.current;if(!t||0===t.width)return;let{percentX:s,percentY:n}=e.cursorPercent(e.virtualCursor,t);e.handHoldingRef.current=!0,e.setHandHolding(!0),(0,eo.e)(15),e.socketEmitFunctions.emitMousePress?.(s,n,"left")},c.eR.longPressDelay)),x||e.scrollLockRef.current||(e.scrollLongPressTimerRef.current&&clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=setTimeout(()=>{e.scrollLongPressTimerRef.current=null,e.scrollLockRef.current=!0,e.setScrollLock(!0),e.edgeScrollAccumRef.current={x:0,y:0},(0,eo.e)(15)},c.eR.longPressDelay)),!0}if("touchmove"===s){let t=p.clientX-e.lastTouchCenterRef.current.x,s=p.clientY-e.lastTouchCenterRef.current.y;if(e.touchTotalMoveRef.current+=Math.abs(t)+Math.abs(s),e.scrollLockRef.current)return e.emitScrollFromDelta(s),e.emitHScrollFromDelta(t),e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=Date.now(),!0;e.scrollLongPressTimerRef.current&&e.touchTotalMoveRef.current>c.eR.trackpadTapMaxMove&&(clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=null);let a=Date.now(),i=function({deltaX:e,deltaY:t,dt:s,cfg:n}){let r=Math.sqrt(e*e+t*t)/s,l=1+Math.min(n.trackpadAcceleration,r*n.trackpadAcceleration);return n.trackpadSensitivity*l}({deltaX:t,deltaY:s,dt:Math.max(1,a-e.lastTouchTimeRef.current),cfg:c.eR}),o=Math.max(1e-4,e.fitScale*e.canvasZoom),d=t*i/o,m=s*i/o;return l?e.setVirtualCursor(t=>{let s={x:oA(t.x+d,0,r.width-1),y:oA(t.y+m,0,r.height-1)},{percentX:l,percentY:a}=e.cursorPercent(s,r);return e.emitVirtualCursor(s),u?.(0,0,"move",{...n,percentOverride:{percentX:l,percentY:a}}),s}):(x&&!e.handHoldingRef.current&&e.handLongPressTimerRef.current&&e.touchTotalMoveRef.current>c.eR.trackpadTapMaxMove&&(clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=null),e.setVirtualCursor(t=>{let s={x:oA(t.x+d,0,r.width-1),y:oA(t.y+m,0,r.height-1)};if(e.emitVirtualCursor(s),e.handHoldingRef.current){let{percentX:t,percentY:n}=e.cursorPercent(s,r);e.socketEmitFunctions.emitMouseMove?.(t,n)}let n=e.containerSize();if(n&&e.canvasZoom>1){let t={width:r.width*o,height:r.height*o},l=oD(n,t);e.setCanvasPan(e=>{let r=function({cursor:e,pan:t,containerSize:s,displaySize:n,totalScale:r,marginRatio:l}){let a=s.width*l,i=s.height*l,o=e.x*r+t.x,c=e.y*r+t.y,d={x:0,y:0};return o<a?d.x=a-o:o>s.width-a&&(d.x=-(o-(s.width-a))),c<i?d.y=i-c:c>s.height-i&&(d.y=-(c-(s.height-i))),d}({cursor:s,pan:e,containerSize:n,displaySize:t,totalScale:o,marginRatio:c.eR.trackpadEdgeMarginRatio});return oB({x:e.x+r.x,y:e.y+r.y},l)})}return s})),e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=a,!0}if("touchend"===s){if(l){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);return u?.(0,0,"end",{...n,percentOverride:{percentX:t,percentY:s}}),!0}if(x){if(e.handLongPressTimerRef.current&&(clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=null),e.handHoldingRef.current){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);e.socketEmitFunctions.emitMouseRelease?.(t,s,"left"),e.handHoldingRef.current=!1,e.setHandHolding(!1),m?.()}return!0}if(e.scrollLongPressTimerRef.current&&(clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=null),e.scrollLockRef.current)return e.scrollLockRef.current=!1,e.setScrollLock(!1),e.edgeScrollAccumRef.current={x:0,y:0},!0;let t=Date.now()-e.touchStartTimeRef.current;if(e.touchTotalMoveRef.current<=c.eR.trackpadTapMaxMove&&t<=c.eR.trackpadTapMaxDuration){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r),n=e.checkDoubleClick(e.virtualCursor.x,e.virtualCursor.y);a?i?(o(!1),d(!1),e.socketEmitFunctions.emitMouseRelease(t,s,"left")):(o(!0),e.socketEmitFunctions.emitMousePress(t,s,"left")):e.socketEmitFunctions.emitMouseClick(t,s,"left",n)}return!0}return!1}(S,t,r,u)||function(e,t,s,n){let r,l,{selectionMode:a,selectionStart:i,dragMode:o,isDragging:d,setIsDragging:u,setDragMode:x,isMobile:m,handleSelection:p,pointerMode:f="direct"}=n;if(t.type.startsWith("touch")&&t.touches?.length>=2&&!a){var h;let n,r,l,a=(n=(h=t.touches)[0].clientX-h[1].clientX,Math.sqrt(n*n+(r=h[0].clientY-h[1].clientY)*r)),i={x:((l=t.touches)[0].clientX+l[1].clientX)/2,y:(l[0].clientY+l[1].clientY)/2};if("touch"===s){e.setIsZooming(!0),e.lastTouchDistanceRef.current=a,e.lastTouchCenterRef.current=i,e.gestureLockRef.current=null,e.gestureStartRef.current={time:Date.now(),distance:a,centerX:i.x,centerY:i.y},e.twoFingerMaxMovedRef.current=0;return}if("touchmove"===s&&e.isZooming){let t=e.canvasContainerRef.current;if(!t)return;if(null===e.gestureLockRef.current){let t=Date.now()-e.gestureStartRef.current.time,s=Math.abs(a-e.gestureStartRef.current.distance),n=Math.sqrt((i.x-e.gestureStartRef.current.centerX)**2+(i.y-e.gestureStartRef.current.centerY)**2);e.twoFingerMaxMovedRef.current=Math.max(e.twoFingerMaxMovedRef.current,s,n),e.gestureLockRef.current=function({elapsed:e,deltaDistance:t,deltaCentroid:s,cfg:n}){let r=t>=n.gestureDistanceThreshold,l=s>=n.gestureCentroidThreshold;if(!r&&!l&&e<n.gestureLockDelay)return null;let a=s>.5?t/s:1/0;return a>=n.gestureDominanceRatio&&r?"zoom":a<=1/n.gestureDominanceRatio&&l?"scroll":r&&!l?"zoom":l&&!r?"scroll":null}({elapsed:t,deltaDistance:s,deltaCentroid:n,cfg:c.eR})}if("scroll"===e.gestureLockRef.current){let t=i.y-e.lastTouchCenterRef.current.y;if(!e.isEdgeScrolling){let t=e.canvasRef.current,s="trackpad"===f&&t&&t.width>0?e.cursorPercent(e.virtualCursor,t):e.getCanvasCoordinates(i.x,i.y);e.socketEmitFunctions?.emitBoostStream?.(),e.socketEmitFunctions?.emitMouseMove?.(s.percentX,s.percentY),e.setIsEdgeScrolling(!0)}e.emitScrollFromDelta(t),e.lastTouchDistanceRef.current=a,e.lastTouchCenterRef.current=i;return}if("zoom"===e.gestureLockRef.current&&e.lastTouchDistanceRef.current>0){let s=t.getBoundingClientRect(),n={width:t.clientWidth,height:t.clientHeight},r={x:i.x-s.left,y:i.y-s.top},l=e.canvasZoom*(a/e.lastTouchDistanceRef.current);e.setCanvasPan(t=>oF({prevZoom:e.canvasZoom,prevPan:t,focal:r,nextZoomRaw:l,maxZoom:4,containerSize:n,displaySizeAt:e.displaySizeAt}).pan),e.setCanvasZoom(oA(l,1,4)),e.lastTouchDistanceRef.current=a}e.lastTouchCenterRef.current=i;return}}if(t.type.startsWith("touch")&&t.touches?.length===1){let n=t.touches[0];if(e.isZooming){e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY};return}if("touch"===s){if(e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY},e.lastTouchTimeRef.current=Date.now(),e.velocityRef.current={x:0,y:0},e.edgeScrollAccumRef.current={x:0,y:0},e.stopMomentum(),e.touchOutsideRef.current=!function(e,t,s){let n=e.canvasRef.current,r=e.canvasContainerRef.current;if(!n||!r||0===n.width)return!1;let l=oL({clientX:t,clientY:s,containerRect:r.getBoundingClientRect(),pan:e.canvasPan,totalScale:e.fitScale*e.canvasZoom});return l.x>=0&&l.x<=n.width&&l.y>=0&&l.y<=n.height}(e,n.clientX,n.clientY),a)p(n.clientX,n.clientY,"start");else if(!o&&!e.touchOutsideRef.current){let{percentX:t,percentY:s}=e.getCanvasCoordinates(n.clientX,n.clientY);e.startLongPress(n.clientX,n.clientY,t,s)}return}if("touchmove"===s){let t=Math.abs(n.clientX-e.touchStartPosRef.current.x),s=Math.abs(n.clientY-e.touchStartPosRef.current.y);if((t>c.eR.moveThreshold||s>c.eR.moveThreshold)&&e.cancelLongPress(),a&&i)return p(n.clientX,n.clientY,"move");if(!a&&!o){let t=n.clientX-e.lastTouchCenterRef.current.x,s=n.clientY-e.lastTouchCenterRef.current.y,r=Date.now(),l=r-e.lastTouchTimeRef.current;if(l>0&&(e.velocityRef.current={x:t/l*16,y:s/l*16},e.lastTouchTimeRef.current=r),Math.abs(t)>5||Math.abs(s)>5){e.cancelLongPress();let r=e.getCanvasCoordinates(n.clientX,n.clientY),l=Math.abs(s)>1.5*Math.abs(t),a=t=>{l&&(e.isEdgeScrolling||(e.socketEmitFunctions?.emitBoostStream?.(),e.socketEmitFunctions?.emitMouseMove?.(r.percentX,r.percentY),e.setIsEdgeScrolling(!0)),e.emitScrollFromDelta(t))};if(1===e.canvasZoom){l&&a(s),e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY};return}e.setIsPanning(!0);let i=e.containerSize()||{width:0,height:0},o=e.displaySizeAt(e.canvasZoom);e.setCanvasPan(n=>{let r=function({prevPan:e,deltaX:t,deltaY:s,containerSize:n,displaySize:r}){let l=oD(n,r),a=oB({x:e.x+t,y:e.y+s},l),i=Math.abs(a.y-e.y)>.5?0:e.y+s-a.y;return{pan:a,overflowY:i}}({prevPan:n,deltaX:t,deltaY:s,containerSize:i,displaySize:o});return Math.abs(r.overflowY)>0?a(r.overflowY):(e.edgeScrollAccumRef.current.y=0,e.setIsEdgeScrolling(!1)),r.pan}),e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY}}return}}}if("touchend"===s){if(e.cancelLongPress(),"trackpad"===f&&e.isZooming&&0===(t.touches?.length||0)&&null===e.gestureLockRef.current&&Date.now()-e.gestureStartRef.current.time<=c.eR.trackpadTapMaxDuration&&e.twoFingerMaxMovedRef.current<=c.eR.trackpadTapMaxMove){let t=e.canvasRef.current;if(t&&t.width>0&&e.socketEmitFunctions?.emitMouseClick){let{percentX:s,percentY:n}=e.cursorPercent(e.virtualCursor,t);e.socketEmitFunctions.emitMouseClick(s,n,"right"),(0,eo.e)(15)}}e.gestureLockRef.current=null,0===(t.touches?.length||0)&&(e.multiTouchLatchRef.current=!1);let s=e.isZooming,n=e.isPanning,r=e.isEdgeScrolling,l=e.longPressTriggeredRef.current;if(e.longPressTriggeredRef.current=!1,s&&(e.setRecentZoomGesture(!0),e.zoomGestureTimeoutRef.current&&clearTimeout(e.zoomGestureTimeoutRef.current),e.zoomGestureTimeoutRef.current=setTimeout(()=>e.setRecentZoomGesture(!1),200)),r&&(Math.abs(e.velocityRef.current.x)>c.eR.momentumMinVelocity||Math.abs(e.velocityRef.current.y)>c.eR.momentumMinVelocity)?e.startMomentumScroll():e.stopMomentum(),e.setIsZooming(!1),e.setIsPanning(!1),s||n||r||e.recentZoomGesture||l)return;if(t.type.startsWith("touch")){let s=t.changedTouches?.[0];if(s){if(a)p(s.clientX,s.clientY,"end");else if(!e.touchOutsideRef.current){let{percentX:t,percentY:n}=e.getCanvasCoordinates(s.clientX,s.clientY);if(e.showClickIndicator(s.clientX,s.clientY),o)d?(u(!1),x(!1),e.socketEmitFunctions.emitMouseRelease(t,n,"left")):(u(!0),e.socketEmitFunctions.emitMousePress(t,n,"left"));else{let r=e.checkDoubleClick(s.clientX,s.clientY);e.socketEmitFunctions.emitMouseClick(t,n,"left",r)}}}}return}if(e.isZooming||e.isPanning)return;if(t.type.startsWith("touch")){if(t.touches?.length!==1)return;r=t.touches[0].clientX,l=t.touches[0].clientY}else r=t.clientX,l=t.clientY;let{percentX:b,percentY:g}=e.getCanvasCoordinates(r,l);if("click"===s)if(a)p(r,l,i?"end":"start");else if(e.showClickIndicator(r,l),o)d?(u(!1),x(!1),e.socketEmitFunctions.emitMouseRelease(b,g,"left")):(u(!0),e.socketEmitFunctions.emitMousePress(b,g,"left"));else{let t=e.checkDoubleClick(r,l);e.socketEmitFunctions.emitMouseClick(b,g,"left",t)}else if("move"===s&&!m){if(a&&i)return p(r,l,"move");e.socketEmitFunctions.emitMouseMove(b,g)}}(S,t,r,u)},[h,g,z,l,j,d,B,i,p,ea,e,ei,ec,ed,eu,ex,eh,em,ep,s,n,x,m,o,a,ef]);(0,r.useEffect)(()=>{let e=s.current;e&&0!==e.width&&F(t=>0===t.x&&0===t.y?{x:e.width/2,y:e.height/2}:t)},[u,s]);let eg=(0,r.useCallback)(()=>{let e=s.current,t=x();if(!e||!t||0===e.width)return;let n=d*l;n<=0||F({x:oA((t.width/2-i.x)/n,0,e.width-1),y:oA((t.height/2-i.y)/n,0,e.height-1)})},[d,l,i,s,x]),ev=(0,r.useCallback)(()=>{let t=s.current;if(!t||0===t.width||X.current)return;V.current&&(clearTimeout(V.current),V.current=null);let{percentX:n,percentY:r}=ef(B,t);X.current=!0,J(!0),(0,eo.e)(15),e?.emitBoostStream?.(),e?.emitMousePress?.(n,r,"left")},[B,e,s,ef]),ey=(0,r.useCallback)(()=>{if(!X.current)return;let t=s.current,n=t&&t.width>0?B.x/t.width*100:0,r=t&&t.height>0?B.y/t.height*100:0;e?.emitMouseRelease?.(n,r,"left"),X.current=!1,J(!1)},[B,e,s]);return{canvasRef:s,canvasContainerRef:n,canvasZoom:l,canvasPan:i,fitScale:d,baseCanvasSize:u,zoomGestureTimeoutRef:N,clickIndicator:C,virtualCursor:B,handHolding:G,scrollLock:Q,getCanvasCoordinates:p,resetZoom:t.resetZoom,resetPan:t.resetPan,panForKeyboard:t.panForKeyboard,centerVirtualCursor:eg,startHandHold:ev,releaseHandHold:ey,handleCanvasInteraction:eb,handleCanvasDimensions:t.handleCanvasDimensions,serverDimensionsRef:t.serverDimensionsRef}}(es),eR=(0,r.useCallback)(()=>{C(e=>{let t="trackpad"===e?"direct":"trackpad";return"trackpad"===t&&ej(),t})},[ej,C]),{textInputValue:eT,setTextInputValue:e$,textInputRef:eM,modifierKeys:ez,selectionMode:eP,selectionStart:eI,selectionRect:eA,dragMode:eL,isDragging:eD,setIsDragging:eB,setDragMode:eF,toggleModifierKey:eK,toggleSelectionMode:eO,handleTextInputFocus:eW,handleCanvasKeyPress:e_,sendTextInput:eH,handleSelection:eq,handleModifiedTextInput:eU,handleDirectInputChange:eV,emitKeyWithActiveModifiers:eX}=function(e){let[t,s]=(0,r.useState)(""),[n,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(null),[d,u]=(0,r.useState)({ctrl:!1,cmd:!1,alt:!1,shift:!1}),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(null),[h,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),j=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=()=>{let e=window.innerWidth<=768||/Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);return l(e),e},t=()=>{e()?i((window.visualViewport?.height||window.innerHeight)<.75*window.screen.height):i(!1)};return e(),window.addEventListener("resize",t),window.visualViewport&&window.visualViewport.addEventListener("resize",t),()=>{window.removeEventListener("resize",t),window.visualViewport&&window.visualViewport.removeEventListener("resize",t)}},[]),(0,r.useEffect)(()=>()=>{j.current&&clearInterval(j.current)},[]);let k=(0,r.useCallback)(e=>{u(t=>({...t,[e]:!t[e]})),n&&o.current&&o.current.focus()},[n]),N=(0,r.useCallback)(()=>{m(e=>!e),f(null),b(null)},[]),C=(0,r.useCallback)(()=>{v(e=>!e),y&&w(!1)},[y]),S=(0,r.useCallback)(()=>{},[]),E=(0,r.useCallback)((t,s)=>{if(!s||!e?.emitKeyPress)return;let n=t.key;if("Shift"===n||"Control"===n||"Meta"===n||"Alt"===n)return;"F12"!==n&&t.preventDefault();let r=[];t.ctrlKey&&r.push("control"),t.metaKey&&r.push("command"),t.altKey&&r.push("alt"),t.shiftKey&&r.push("shift");let l=Object.keys(d).filter(e=>d[e]);for(let e of l){let t=c.tC[e];t&&!r.includes(t)&&r.push(t)}let a=c.FO[n]??(1===n.length?n:n.toLowerCase());e.emitKeyPress(a,r),l.length>0&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1})},[d,e]),R=(0,r.useCallback)((t,s,r=!1)=>{s&&e?.emitScroll&&(j.current&&clearInterval(j.current),e.emitScroll(t,20,r),j.current=setInterval(()=>{e?.emitScroll&&s&&e.emitScroll(t,20,r)},c.eR.scrollInterval),n&&o.current&&a&&setTimeout(()=>o.current?.focus(),10))},[n,a,e]),T=(0,r.useCallback)(e=>R("up",e),[R]),$=(0,r.useCallback)(e=>R("down",e),[R]),M=(0,r.useCallback)(e=>R("left",e,!0),[R]),z=(0,r.useCallback)(e=>R("right",e,!0),[R]),P=(0,r.useCallback)(()=>{j.current&&(clearInterval(j.current),j.current=null)},[]),I=tj(e=>e.addCommand),A=(0,r.useCallback)(n=>{if(!n||!e?.emitTypeText)return;if(!t.trim())return void e.emitKeyPress?.("enter",[]);let r=document.activeElement===o.current;e.emitTypeText(t),I(t),s(""),r&&o.current?.focus()},[t,e,o,I]),L=(0,r.useRef)(""),D=(0,r.useRef)(null),B=(0,r.useCallback)((t,n)=>{n&&t&&e?.emitTypeText&&(L.current+=t,s(""),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{let t=L.current;L.current="",D.current=null,t&&e.emitTypeText(t)},150))},[e]),F=(0,r.useCallback)(t=>{if(!e?.emitKeyPress)return;let s=Object.keys(d).filter(e=>d[e]),n=s.map(e=>c.tC[e]);e.emitKeyPress(t,n),s.length>0&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1})},[d,e]),K=(0,r.useCallback)(e=>{e&&(F("backspace"),n&&o.current&&a&&o.current.focus())},[n,a,F]),O=(0,r.useCallback)((e,t)=>{t&&(F(e),n&&o.current&&a&&o.current.focus())},[n,a,F]),W=(0,r.useCallback)(e=>{e&&(F("escape"),n&&o.current&&a&&o.current.focus())},[n,a,F]),_=(0,r.useCallback)(e=>{e&&(F("tab"),n&&o.current&&a&&o.current.focus())},[n,a,F]),H=(0,r.useCallback)((e,t)=>{t&&(F("enter"),e&&e.preventDefault(),n&&o.current&&a&&o.current.focus())},[n,a,F]),q=(0,r.useCallback)((t,s,n,r)=>{let{streaming:l,getCanvasCoordinates:a,baseCanvasSize:i,canvasZoom:o,canvasPan:c,percentOverride:d}=r;if(!x||!l||!e?.emitMouseDragSelect)return;let{percentX:u,percentY:h}=d||a(t,s);if("start"===n)f({x:u,y:h}),b(null);else if("move"===n&&p){let e=i.width*o,t=i.height*o;b({x:Math.min(p.x,u)*e/100+c.x,y:Math.min(p.y,h)*t/100+c.y,width:Math.abs(u-p.x)*e/100,height:Math.abs(h-p.y)*t/100})}else"end"===n&&p&&(e.emitMouseDragSelect(p.x,p.y,u,h),setTimeout(()=>{f(null),m(!1),b(null)},500))},[x,p,e]),U=(0,r.useCallback)((n,r,l=!1)=>{if(!r||!e?.emitTypeText||!e?.emitKeyPress)return;let a=n.key.toLowerCase();if(["shift","control","meta","alt"].includes(a)||"Unidentified"===n.key||229===n.keyCode)return;let i=Object.keys(d).filter(e=>d[e]),o=i.length>0,x=n.ctrlKey||n.metaKey||n.altKey||n.shiftKey;if(l){n.preventDefault();let t=i.map(e=>c.tC[e]);n.ctrlKey&&!t.includes("control")&&t.push("control"),n.metaKey&&!t.includes("command")&&t.push("command"),n.altKey&&!t.includes("alt")&&t.push("alt"),n.shiftKey&&!t.includes("shift")&&t.push("shift"),c.FO[a]?a=c.FO[a]:" "===a?a="space":1===n.key.length&&(a=n.key),e.emitKeyPress(a,t),o&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1}),s("");return}if("Enter"===n.key){n.preventDefault(),t.trim()&&(e.emitTypeText(t),I(t),s(""));return}let m=/^[a-z0-9]$/i.test(n.key);if((o||x)&&(!m||o)){n.preventDefault();let t=i.map(e=>c.tC[e]);n.ctrlKey&&!t.includes("control")&&t.push("control"),n.metaKey&&!t.includes("command")&&t.push("command"),n.altKey&&!t.includes("alt")&&t.push("alt"),n.shiftKey&&!t.includes("shift")&&t.push("shift"),c.FO[a]?a=c.FO[a]:" "===a&&(a="space"),e.emitKeyPress(a,t),u({ctrl:!1,cmd:!1,alt:!1,shift:!1}),s("")}},[d,t,e,I]);return{textInputValue:t,setTextInputValue:s,textInputRef:o,keyboardVisible:a,modifierKeys:d,selectionMode:x,selectionStart:p,selectionRect:h,dragMode:g,isDragging:y,setIsDragging:w,setDragMode:v,toggleModifierKey:k,toggleSelectionMode:N,toggleDragMode:C,handleTextInputFocus:S,handleCanvasKeyPress:E,startScrollUp:T,startScrollDown:$,startScrollLeft:M,startScrollRight:z,stopScrolling:P,sendTextInput:A,sendBackspace:K,sendArrowKey:O,sendEscKey:W,sendTabKey:_,sendEnterKey:H,handleSelection:q,handleModifiedTextInput:U,handleDirectInputChange:B,emitKeyWithActiveModifiers:F}}(es),{keyboardOnRef:eG,toggleKeyboard:eJ,toggleTextPanel:eY,handleTextInputBlur:eZ}=function({streaming:e,keyboardOn:t,setKeyboardOn:s,showTextPanel:n,setShowTextPanel:l,textInputRef:a,canvasContainerRef:i,panForKeyboard:o,pointerMode:c,virtualCursor:d}){let u=(0,r.useRef)(t);(0,r.useEffect)(()=>{u.current=t},[t]);let x=(0,r.useCallback)(()=>{let e=!t;u.current=e,s(e),e?a.current?.focus():a.current?.blur()},[t]),m=(0,r.useRef)(!1);(0,r.useEffect)(()=>{e&&!m.current&&u.current&&(m.current=!0,a.current?.focus())},[e]);let p=(0,r.useCallback)(()=>{let e=!n;!e&&t&&a.current?.focus(),l(e)},[n,t]),f=(0,r.useCallback)(()=>{u.current&&!n&&setTimeout(()=>a.current?.focus(),0)},[n]),h=(0,r.useRef)(null);return(0,r.useEffect)(()=>{h.current="trackpad"===c?d:null},[c,d]),(0,r.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=e.height,s=0,n=()=>{let n=e.height<t;t=e.height;let r=i.current;if(!r)return;let l=r.clientHeight;cancelAnimationFrame(s);let a=0,c=()=>{r.clientHeight!==l||a++>30?o(n,h.current):s=requestAnimationFrame(c)};s=requestAnimationFrame(c)};return e.addEventListener("resize",n),()=>{cancelAnimationFrame(s),e.removeEventListener("resize",n)}},[i,o]),{keyboardOnRef:u,toggleKeyboard:x,toggleTextPanel:p,handleTextInputBlur:f}}({streaming:_,keyboardOn:y,setKeyboardOn:w,showTextPanel:g,setShowTextPanel:v,textInputRef:eM,canvasContainerRef:el,panForKeyboard:ew,pointerMode:N,virtualCursor:ef}),eQ=(0,r.useCallback)((e,t=[],s=!1)=>{_&&(t.length>0?J(e,s&&"darwin"===o?t.map(e=>"control"===e?"command":e):t):eX(e))},[_,o,J,eX]),e0=(0,r.useCallback)(()=>{E(e=>{let t=!e;return t?(eP&&eO(),ek()):eN(),t})},[E,eP,eO,ek,eN]),e1=function(e,t,n){let[l,a]=(0,r.useState)(126),[i,o]=(0,r.useState)(!1),d=(0,r.useRef)(new Set),u=(0,r.useRef)(new Map),x=(0,r.useRef)([]),m=(0,r.useRef)(!1),p=(0,r.useRef)(0),f=(0,r.useRef)(new Set),h=(0,r.useRef)(new Set),b=(0,r.useRef)(new Map),g=(0,r.useRef)(new Map),v=(0,r.useRef)(null),y=(0,r.useRef)(t);(0,r.useEffect)(()=>{y.current=t},[t]);let w=(0,r.useCallback)(()=>{v.current=null;let t=n?.current;if(!t)return void g.current.clear();let s=t.getContext("2d"),r=0;for(let[e,t]of g.current){let{bitmap:n,x:l,y:a,width:i,height:c,frameTs:u,invalidateTileHash:x}=t;if((b.current.get(e)??u)>u){n?.close?.();continue}try{s.drawImage(n,l,a,i,c),d.current.add(e),o(!0),u>r&&(r=u),n?.close?.()}catch{x()}}g.current.clear(),r>0&&e?.current?.emit("tile-ack",{ts:r})},[n,e]),j=(0,r.useCallback)((e=!1)=>{e&&v.current&&(cancelAnimationFrame(v.current),v.current=null),v.current||(v.current=requestAnimationFrame(w))},[w]),k=(0,r.useCallback)(e=>{if(n?.current)try{let t=n.current.getContext("2d");t.imageSmoothingEnabled=!1;let s=new Image;s.onload=()=>{if(n?.current)try{t.drawImage(s,0,0,e.screen.width,e.screen.height),d.current.clear();for(let e=0;e<l;e++)d.current.add(e);o(!0)}catch(e){}},s.src=e.screen.imageBase64}catch(e){console.error("Full screen error:",e)}},[n,l]),N=(0,r.useCallback)(e=>{if(n?.current)try{if(n.current.getContext("2d"),p.current=Date.now(),e.currentHashes&&Array.isArray(e.currentHashes)&&(x.current=e.currentHashes,m.current=!1),!e.tiles?.length)return;let t=e.timestamp||Date.now();for(let s of e.tiles){let e=u.current.get(s.tileIndex),n=b.current.get(s.tileIndex)??0;t>=n&&(e?.controller&&(e.controller.cancelled=!0),b.current.set(s.tileIndex,t),null!=s.hash&&(x.current[s.tileIndex]=s.hash))}if(void 0!==e.hasBitmap){for(let s of e.tiles){if(!s.bitmap&&!s.imageBuffer)continue;if((b.current.get(s.tileIndex)??t)>t){s.bitmap?.close?.();continue}let e=o_(x,s.tileIndex);s.bitmap?g.current.set(s.tileIndex,{bitmap:s.bitmap,x:s.x,y:s.y,width:s.width,height:s.height,frameTs:t,invalidateTileHash:e}):oV(oW(s.imageBuffer)).then(n=>{n&&(g.current.set(s.tileIndex,{bitmap:n,x:s.x,y:s.y,width:s.width,height:s.height,frameTs:t,invalidateTileHash:e}),j(!0))}).catch(()=>{e()})}j(!0);return}let s=[];for(let t=0;t<e.tiles.length;t+=c.eR.batchSize)s.push(e.tiles.slice(t,t+c.eR.batchSize));s.forEach((e,s)=>{let r=setTimeout(()=>{f.current.delete(r),e.forEach(e=>{if(!e.imageBuffer&&!e.imageBase64)return;if((b.current.get(e.tileIndex)??t)>t)return void u.current.delete(e.tileIndex);let s={cancelled:!1};u.current.set(e.tileIndex,{controller:s});let r=setTimeout(()=>{s.cancelled=!0,u.current.delete(e.tileIndex),x.current[e.tileIndex]=null},c.eR.tileLoadTimeout),l=o_(x,e.tileIndex),a=a=>{s.cancelled||!n?.current?a?.close?.():(clearTimeout(r),u.current.delete(e.tileIndex),g.current.set(e.tileIndex,{bitmap:a,x:e.x,y:e.y,width:e.width,height:e.height,frameTs:t,invalidateTileHash:l}),j())};if(e.imageBuffer&&"u">typeof createImageBitmap)oV(oW(e.imageBuffer)).then(a).catch(()=>{if(s.cancelled)return;let t=new Image,n=URL.createObjectURL(oW(e.imageBuffer));t.onload=()=>{a(t),URL.revokeObjectURL(n)},t.onerror=()=>{URL.revokeObjectURL(n),clearTimeout(r),u.current.delete(e.tileIndex),l()},t.src=n});else{let t=new Image;if(e.imageBuffer){let s=URL.createObjectURL(oW(e.imageBuffer));t.onload=()=>{a(t),URL.revokeObjectURL(s)},t.onerror=()=>{URL.revokeObjectURL(s),clearTimeout(r),u.current.delete(e.tileIndex),l()},t.src=s}else t.onload=()=>a(t),t.onerror=()=>{clearTimeout(r),u.current.delete(e.tileIndex),l()},t.src=`data:image/jpeg;base64,${e.imageBase64}`}})},s*c.eR.batchDelay);f.current.add(r)})}catch(e){console.error("Tiles data error:",e)}},[n]),C=(0,r.useCallback)((e,t,n="ws")=>{if(!e)return;let r=e instanceof ArrayBuffer?e:e?.buffer;if(!r)return;let l=function(){if(!1===oH)return null;if(oH)return oH;try{return(oH=new Worker(s.tu(new URL(s.p+s.u(1311),s.b)))).onmessage=({data:{tiles:e,timestamp:t,id:s,hasBitmap:n,error:r}})=>{let l=oU.get(s);if(!l){if(e)for(let t of e)t.bitmap?.close?.();return}clearTimeout(l.timer),oU.delete(s),l.resolve(r?null:{tiles:e,timestamp:t,hasBitmap:n})},oH}catch{return oH=!1,null}}();if(!l)return;let a=r.byteLength,i=++oq;new Promise(e=>{let s=setTimeout(()=>{oU.has(i)&&(oU.delete(i),e(null))},c.eR.tileLoadTimeout),n=c.eR.decodeQueueCap;for(;oU.size>=n;){let e=oU.keys().next().value,t=oU.get(e);if(!t)break;clearTimeout(t.timer),oU.delete(e),t.resolve(null)}oU.set(i,{resolve:e,timer:s}),l.postMessage({buffer:r,id:i,v:t},[r])}).then(e=>{e&&(2===t&&(m.current=!1),N({tiles:e.tiles,timestamp:e.timestamp,hasBitmap:e.hasBitmap,bytes:a,transport:n}))})},[N]),S=(0,r.useCallback)(e=>C(e,1,"ws"),[C]),E=(0,r.useCallback)(e=>C(e,2,"ws"),[C]),R=(0,r.useCallback)(e=>{e&&(p.current=Date.now(),e.currentHashes&&Array.isArray(e.currentHashes)&&(x.current=e.currentHashes,m.current=!1))},[]),T=(0,r.useCallback)(e=>{e()},[]),$=(0,r.useCallback)(e=>{e.tileCount&&a(e.tileCount)},[]),M=(0,r.useCallback)(()=>{if(!e?.current||!y.current||m.current||0===x.current.length||Date.now()-p.current<c.eR.lastDataThreshold)return;m.current=!0,e.current.emit("request-screen-with-hashes",{tileHashes:x.current});let t=setTimeout(()=>{h.current.delete(t),m.current=!1},1e3);h.current.add(t)},[]),z=(0,r.useCallback)(()=>{for(let[,e]of u.current.entries())e.controller&&(e.controller.cancelled=!0);if(u.current.clear(),x.current=[],d.current.clear(),b.current.clear(),p.current=0,m.current=!1,o(!1),oH&&!1!==oH)try{oH.terminate()}catch{}for(let e of(oH=null,oU.values()))try{e.resolve(null)}catch{}oU.clear(),v.current&&(cancelAnimationFrame(v.current),v.current=null),g.current.clear()},[]);return(0,r.useEffect)(()=>{let e=f.current,t=h.current;return()=>{e.forEach(clearTimeout),e.clear(),t.forEach(clearTimeout),t.clear()}},[]),{renderedTilesRef:d,totalTileCount:l,hasFrame:i,handleFullScreenData:k,handleTilesData:N,handleTilesBinary:S,handleTilesBinaryV2:E,handleTilesMeta:R,startStreamingWithTiles:T,handleScreenDimensions:$,cleanupTiles:z,requestScreenWithHashes:M}}(t,_,er),{screenLocked:e2,unlockReady:e5,unlockResult:e3,setUnlockResult:e4,clipboardText:e6,clipboardNew:e8,setClipboardNew:e9,monitors:e7,activeMonitorIndex:te,cursorShape:tt}=function({busRef:e,connected:t,streaming:s,canvasRef:n,serverDimensionsRef:l,handleCanvasDimensions:a,resetPan:i,zoomGestureTimeoutRef:o,trackTilesReceived:u,tiles:x}){let[m,p]=(0,r.useState)(!1),[f,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(""),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)([]),[C,S]=(0,r.useState)(0),[E,R]=(0,r.useState)(null),T=(0,r.useRef)(null),{renderedTilesRef:$,handleFullScreenData:M,handleTilesData:z,handleTilesBinary:P,handleTilesBinaryV2:I,handleTilesMeta:A,handleScreenDimensions:L,cleanupTiles:D,requestScreenWithHashes:B}=x;return(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t)return;D();let n=e=>{L(e),a(e,$)},r=e=>M(e),l=e=>{let t=e.transport||"ws";t!==T.current&&(T.current=t,(0,d.c)("remote",`[remote] tiles via ${t}`)),u(e,t),z(e)},c=e=>console.error("Screen error:",e),x=({locked:e,ready:t}={})=>{p(!!e),h(!!t),e&&g(null)},m=e=>g(e||null),f=(e,t)=>{"ws"!==T.current&&(T.current="ws",(0,d.c)("remote",`[remote] tiles via ws${t}`)),u(function(e,t=Date.now()){let{tileCount:s,timestamp:n,bytes:r}=function(e,t=Date.now()){let s=e instanceof ArrayBuffer?e:e?.buffer,n=s?.byteLength||0,r=0,l=t;if(s&&s.byteLength>=12){let e=new DataView(s);r=e.getUint32(0,!0),l=e.getFloat64(4,!1)}return{tileCount:r,timestamp:l,bytes:n}}(e,t);return{tiles:Array(s),timestamp:n,bytes:r}}(e),"ws")},b=e=>{f(e,""),P(e)},v=e=>A(e),w=e=>{f(e," v2"),I(e)},k=()=>{D(),s.emit("get-screen-dimensions"),s.emit("get-unlock-state"),s.emit("start-streaming")},C=()=>k(),E=({text:e,hash:t})=>{y(s=>t&&t===E._lastHash?s:(E._lastHash=t||null,e||"")),j(!0)},B=({list:e,activeIndex:t})=>{N(Array.isArray(e)?e:[]),"number"==typeof t&&S(t)},F=e=>{D(),i(),"number"==typeof e?.monitorIndex&&S(e.monitorIndex)};s.on("screen-dimensions",n),s.on("full-screen-data",r),s.on("tiles-data",l),s.on("tiles-data-binary",b),s.on("tiles-bin-v2",w),s.on("tiles-meta",v),s.on("screen-error",c),s.on("screen-locked",x),s.on("unlock-result",m),s.on("remote:ready",C),s.on("clipboard-update",E),s.on("monitors",B),s.on("frame_meta",F);let K=e=>R(e?.shape??null);return s.on("cursor-shape",K),k(),()=>{s.emit("stop-streaming"),s.off("screen-dimensions",n),s.off("full-screen-data",r),s.off("tiles-data",l),s.off("tiles-data-binary",b),s.off("tiles-bin-v2",w),s.off("tiles-meta",v),s.off("screen-error",c),s.off("screen-locked",x),s.off("unlock-result",m),s.off("remote:ready",C),s.off("clipboard-update",E),s.off("monitors",B),s.off("frame_meta",F),s.off("cursor-shape",K),D(),o.current&&clearTimeout(o.current)}},[t]),(0,r.useEffect)(()=>{if(!s||!t||!e?.current)return;let n=setInterval(()=>{0===$.current.size?e.current.emit("request-screen-with-hashes",{tileHashes:[]}):B()},c.eR.hashRequestInterval);return()=>clearInterval(n)},[s,t,e,B,$]),(0,r.useEffect)(()=>{if(!t)return;let s=()=>{let t=n.current;if(!t||t.width>0)return!0;let{width:s,height:r}=l.current||{};return s>0?a({width:s,height:r},$):e.current?.emit("get-screen-dimensions"),!1};if(s())return;let r=setInterval(()=>{s()&&clearInterval(r)},c.eR.restreamDelay);return()=>clearInterval(r)},[t,e,n,l,a,$]),(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t)return;let n=()=>{document.hidden?s.emit("stop-streaming"):s.emit("start-streaming")};return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[t,e]),{screenLocked:m,unlockReady:f,unlockResult:b,setUnlockResult:g,clipboardText:v,clipboardNew:w,setClipboardNew:j,monitors:k,activeMonitorIndex:C,cursorShape:E}}({busRef:t,connected:a,streaming:_,canvasRef:er,serverDimensionsRef:eE,handleCanvasDimensions:eS,resetPan:ey,zoomGestureTimeoutRef:em,trackTilesReceived:I,tiles:e1});(0,r.useEffect)(()=>{if(!e8)return;let e=setTimeout(()=>e9(!1),c.eR.clipboardBadgeTimeout);return()=>clearTimeout(e)},[e8,e6,e9]),(0,r.useEffect)(()=>{if(!_)return;let e=setTimeout(()=>{let e=er.current,t=el.current;if(!e||!t||0===e.width)return;if(ea<=1)return void ee(null,1);let s=eu*ea;if(s<=0)return;let n=Math.max(0,-ed.x/s),r=Math.max(0,-ed.y/s),l=Math.min(e.width-n,t.clientWidth/s),a=Math.min(e.height-r,t.clientHeight/s);ee({x:Math.floor(n),y:Math.floor(r),w:Math.ceil(l),h:Math.ceil(a)},ea)},c.eR.focusDebounce);return()=>clearTimeout(e)},[_,ea,ed,eu,er,el,ee]);let ts=(0,r.useCallback)(()=>E(!1),[E]),tn=(0,r.useCallback)(e=>{t?.current?.emit("select_monitor",{index:e})},[t]),tr=(0,r.useCallback)(()=>{S&&E(!1),eO()},[S,E,eO]),tl=e=>t=>{eC(t,e,{streaming:_,selectionMode:eP,selectionStart:eI,dragMode:eL,isDragging:eD,setIsDragging:eB,setDragMode:eF,isMobile:e.includes("touch"),pointerMode:N,handMode:S,onHandRelease:ts,handleSelection:(e,t,s,n)=>eq(e,t,s,{streaming:_,getCanvasCoordinates:eg,baseCanvasSize:ex,canvasZoom:ea,canvasPan:ed,...n})})};return(0,n.jsxs)("div",{className:`bg-bg text-text flex flex-col h-full w-full ${z?"":"landscape:flex-row"}`,style:{userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent"},onContextMenu:e=>e.preventDefault(),children:[(0,n.jsxs)("div",{className:"flex flex-row flex-1 min-h-0",children:[a&&(0,n.jsx)(o4,{streaming:_,canvasZoom:ea,pointerMode:N,handMode:S,keyboardOn:y,selectionMode:eP,show:e=>"mouse"!==R||T?.[e],onBack:en,onRefresh:()=>{_&&H([])},onResetZoom:ev,onTogglePointerMode:eR,onToggleHandMode:e0,onToggleKeyboard:eJ,onShowHelp:()=>m(!0),onToggleSelection:tr}),a?(0,n.jsx)(oJ,{canvasRef:er,canvasContainerRef:el,canvasZoom:ea,canvasPan:ed,fitScale:eu,streaming:_,hasFrame:e1.hasFrame,selectionRect:eA,clickIndicator:ep,pointerMode:N,selectionMode:eP,handMode:S,handHolding:eh,scrollLock:eb,virtualCursor:ef,cursorShape:tt,inputMode:R,keyboardOn:y,monitors:e7,activeMonitorIndex:te,onSelectMonitor:tn,onPointerDown:tl("pointerdown"),onPointerMove:tl("pointermove"),onPointerUp:tl("pointerup"),onWheel:tl("wheel"),onContextMenu:tl("contextmenu"),onDoubleClick:tl("dblclick"),onTouchStart:tl("touch"),onTouchMove:tl("touchmove"),onTouchEnd:tl("touchend"),onKeyDown:e=>e_(e,_),screenLocked:e2,unlockReady:e5,unlockResult:e3,onUnlockSubmit:e=>{e4(null),t?.current?.emit("desktop-unlock",{text:e})}}):(0,n.jsxs)("div",{className:"flex-1 min-w-0 empty-stage",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("div",{className:"empty-half",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",u("workspaces.emptyTagRemote")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:u("workspaces.emptyWordRemote")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:u("workspaces.emptyMetaRemote")}}),(0,n.jsxs)("span",{className:"empty-go",children:[(0,n.jsx)(oT.A,{size:"sm"}),u("remote.connecting")]})]})]})]}),(0,n.jsx)(o0,{streaming:_,canvasZoom:ea,clipboardNew:e8,clipboardText:e6,onOpenClipboard:()=>{e9(!1),b(!0)},onDesktopSwitch:et,selectionMode:eP,pointerMode:N,handMode:S,inputMode:R,onToggleHandMode:e0,onTogglePointerMode:eR,modifierKeys:ez,textInputValue:eT,textInputRef:eM,keyboardOn:y,showTextPanel:g,onResetZoom:ev,onRefresh:()=>_&&H([]),onToggleSelection:tr,onToggleModifier:eK,onToggleKeyboard:eJ,onToggleTextPanel:eY,controlsHidden:j,onToggleControlsHidden:k,tallLandscape:z,onToggleHelp:()=>m(!0),onEmitKey:eQ,onTextInputChange:e$,onTextInputFocus:eW,onTextInputBlur:eZ,onTextInputKeyDown:e=>eU(e,_,y),onDirectInputChange:e=>eV(e,_),onSendText:eH,onClose:en,onToggleDebug:()=>D(e=>!e),debugOn:L}),L&&(0,n.jsx)(o8,{onForceWsDisconnect:()=>t?.current?.disconnect(),onToggleWsBlock:()=>{let e=l?.current;if(!e)return;let t=!e.wsBlocked;e.setWsBlocked(t),F(t)},isWsBlocked:B,stats:P,mode:K,onReset:A,onCopy:O,onClose:()=>D(!1)}),x&&(0,n.jsx)(o6,{inputMode:R,pointerMode:N,onClose:()=>{m(!1),y&&eM.current?.focus()}}),h&&(0,n.jsx)(o9,{text:e6,onClose:()=>b(!1)}),(0,n.jsx)(ei.A,{isOpen:p,onClose:()=>{f(!1),y&&eM.current?.focus()},onConfirm:()=>e?.(),title:u("remote.exitRemote"),message:u("remoteControls.exitConfirmMessage"),confirmText:u("connection.exit"),cancelText:u("common.cancel")})]})}let ce={"9remote.cc":"sites.9remote.cc","dev.9remote.cc":"sites-dev.9remote.cc",localhost:"sites.localhost","127.0.0.1":"sites.localhost","::1":"sites.localhost"},ct=function(){let e=window.location;if(!e)return"https://sites.9remote.cc";let{hostname:t,protocol:s,port:n}=e,r=ce[t];return r?n?`${s}//${r}:${n}`:`${s}//${r}`:(console.warn(`[sites] no sites host is known for ${t}; local sites are unavailable here`),null)}(),cs="site-nav",cn="site-error",cr=null,cl=!1,ca=new Map;function ci(e){if(!e||"string"!=typeof e.reqId)return;let t=ca.get(e.reqId);if(e.error){if(!t?.resolve)return;clearTimeout(t.timer),ca.delete(e.reqId),t.resolve({reqId:e.reqId,error:e.error});return}if(!t)return;0===e.seq&&(t.total=e.total,t.status=e.status,t.headers=e.headers),t.slots[e.seq]=e.b64||"";let s=function(e){let t=ca.get(e);if(!t||null==t.total)return null;for(let e=0;e<t.total;e++)if(void 0===t.slots[e])return null;let s=t.slots.join("");return clearTimeout(t.timer),ca.delete(e),{reqId:e,status:t.status,headers:t.headers,bodyB64:s}}(e.reqId);s&&t.resolve&&t.resolve(s)}function co(e){var t;if("string"!=typeof(t=e.origin)||""===t||"null"===t||t!==ct)return;let s=e.data;if(s&&"object"==typeof s){if("site:request"===s.type)return void(function(e){let{reqId:t}=e;return new Promise(s=>{let n={slots:[],total:null,status:null,headers:null,resolve:s,timer:null};n.timer=setTimeout(()=>{ca.delete(t),s({reqId:t,error:"timeout"})},75e3),ca.set(t,n),cr?.emit?.("site:httpRequest",e,()=>{})})})(s.payload).then(t=>{try{e.source?.postMessage({type:"site:reply",id:s.id,payload:t},ct)}catch{}});if("site:nav"===s.type)return void window.dispatchEvent(new CustomEvent(cs,{detail:{port:s.port,path:s.path}}));if("site:ready"!==s.type){if("site:swBlocked"===s.type)return void window.dispatchEvent(new CustomEvent(cn,{detail:{message:"service-worker-blocked"}}));if("site-error"===s.type)return void window.dispatchEvent(new CustomEvent(cn,{detail:{message:s.message,port:s.port}}))}}}async function cc(e){e&&(cr=e,cr.off?.("site:httpChunk",ci),cr.on?.("site:httpChunk",ci)),cl||(cl=!0,window.addEventListener("message",co))}function cd({isOpen:e,onClose:t,onOpenSite:s,busRef:l,connected:a}){let{t:i}=(0,ec.s)(),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)([]),[x,m]=(0,r.useState)({}),[p,f]=(0,r.useState)(""),[h,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(""),y=(0,r.useRef)(null),w=()=>{if(a){var e;let t;c(null),(e=l?.current,t=e?.current||e,new Promise(e=>{if(!t?.connected)return e(null);let s=setTimeout(()=>e(null),8e3);t.emit("getLocalSites",t=>{clearTimeout(s),e(Array.isArray(t?.sites)?t.sites:null)})})).then(e=>c(e||[]))}};if((0,r.useEffect)(()=>{if(!e)return;u(si()),m(so()),w();let t=requestAnimationFrame(()=>y.current?.focus());return()=>cancelAnimationFrame(t)},[e,a,l]),(0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&null===h&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener("keydown",s,!0),()=>window.removeEventListener("keydown",s,!0)},[e,h,t]),!e||"u"<typeof document)return null;let j=o||[],k=new Set(j.map(e=>e.port)),N=e=>x[e.port]||e.name||`Port ${e.port}`,C=e=>{(0,eo.e)(),s(Number(e)),t()},S=()=>{let e=parseInt(p,10);if(!isNaN(e)&&!(e<1)&&!(e>65535)){if(!k.has(e)&&!d.includes(e)){let t=[...d,e];u(t),sa(sn,t)}f(""),C(e)}},E=()=>{if(null==h)return;let e=g.trim(),t={...x};e?t[h]=e:delete t[h],m(t),sa(sr,t),b(null),v("")},R=d.filter(e=>!k.has(e));return(0,sU.createPortal)((0,n.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center px-4",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[4px] animate-in fade-in duration-150",onClick:t}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:"relative card-elev w-full max-w-md max-h-[85vh] flex flex-col animate-in zoom-in-95 duration-200",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 shrink-0",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:i("sites.newTabTitle")}),(0,n.jsx)("p",{className:"text-sm text-text-muted mt-0.5 truncate",children:i("sites.selectSitePreview")})]}),(0,n.jsx)("button",{onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors shrink-0",title:i("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsx)("div",{className:"px-4 pb-3 border-b border-border shrink-0",children:(0,n.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,n.jsx)("span",{className:"text-text-muted text-sm whitespace-nowrap",children:"http://localhost:"}),(0,n.jsx)("input",{ref:y,type:"number",value:p,onChange:e=>f(e.target.value),onKeyDown:e=>"Enter"===e.key&&S(),placeholder:i("sites.portPlaceholder"),min:"1",max:"65535",className:"flex-1 px-3 py-2 bg-surface-2 rounded-brand text-text placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 text-sm min-w-0 transition-all duration-150"}),(0,n.jsx)("button",{onClick:S,disabled:!p,className:"px-4 py-2 bg-brand-500 hover:bg-brand-600 disabled:bg-surface-2 disabled:cursor-not-allowed text-white text-sm font-medium rounded-brand transition-all duration-150",children:i("sites.open")})]})}),(0,n.jsx)("div",{className:"p-4 overflow-y-auto modal-scrollable",style:{maxHeight:"45vh"},children:a?null===o?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-8 text-brand-500 text-sm",children:[(0,n.jsx)(en.kr,{size:16,className:"animate-spin"}),(0,n.jsx)("span",{children:i("sites.loadingSites")})]}):(0,n.jsxs)("div",{className:"space-y-2",children:[R.map(e=>(0,n.jsx)(cu,{port:e,label:N({port:e}),detected:!1,editing:h===e,editValue:g,onEditValue:v,onStartEdit:()=>{b(e),v(x[e]||"")},onSaveEdit:E,onCancelEdit:()=>{b(null),v("")},onRemove:()=>{var t;let s;return t=e,void(u(s=d.filter(e=>e!==t)),sa(sn,s))},onOpen:()=>C(e),t:i},`saved-${e}`)),j.map(e=>(0,n.jsx)(cu,{port:e.port,label:N(e),protocol:e.protocol,detected:!0,editing:h===e.port,editValue:g,onEditValue:v,onStartEdit:()=>{b(e.port),v(x[e.port]||"")},onSaveEdit:E,onCancelEdit:()=>{b(null),v("")},onOpen:()=>C(e.port),t:i},`auto-${e.port}`)),0===j.length&&0===R.length&&(0,n.jsxs)("div",{className:"text-center py-8",children:[(0,n.jsx)(en.qz,{size:24,className:"text-text-muted mx-auto mb-2"}),(0,n.jsx)("p",{className:"text-text text-sm font-medium",children:i("sites.noSitesFound")}),(0,n.jsx)("p",{className:"text-text-muted text-xs mt-1",children:i("sites.startServerHint")})]})]}):(0,n.jsx)("div",{className:"py-8 text-center text-sm text-text-muted",children:i("sites.notConnected",{defaultValue:"Not connected to the agent"})})}),(0,n.jsxs)("div",{className:"px-5 py-3 border-t border-border flex items-center justify-between shrink-0",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted",children:j.length>0?i("sites.foundCount",{n:j.length,suffix:j.length>1?"s":""}):""}),(0,n.jsxs)("button",{onClick:w,disabled:!a,className:"flex items-center gap-2 px-3 py-1.5 text-sm text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-50",children:[(0,n.jsx)(en.e9,{className:null===o&&a?"animate-spin text-brand-500":"",size:16}),i("sites.refresh")]})]})]})]}),document.body)}function cu({port:e,label:t,protocol:s,detected:r,editing:l,editValue:a,onEditValue:i,onStartEdit:o,onSaveEdit:c,onCancelEdit:d,onRemove:u,onOpen:x,t:m}){return(0,n.jsxs)("div",{className:"w-full px-4 py-3 bg-surface-2 hover:bg-surface-3 rounded-brand-lg transition-colors group flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:x,className:"flex-1 flex items-center gap-3 text-left min-w-0",children:[(0,n.jsx)("span",{className:`w-2.5 h-2.5 rounded-full shrink-0 ${r?"bg-green-500 animate-pulse":"bg-surface-3"}`}),(0,n.jsxs)("span",{className:"min-w-0 flex-1",children:[l?(0,n.jsx)("input",{type:"text",value:a,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&c(),"Escape"===e.key&&d()},onClick:e=>e.stopPropagation(),autoFocus:!0,placeholder:`Port ${e}`,className:"w-full px-2 py-1 bg-surface ring-2 ring-brand-500/40 rounded-brand text-text text-sm focus:outline-none"}):(0,n.jsx)("span",{className:"block text-text font-medium truncate",children:t}),(0,n.jsxs)("span",{className:"block text-xs text-text-muted mt-0.5",children:[s?`${s} \xb7 `:"","Port ",e]})]})]}),l?(0,n.jsx)("button",{onClick:c,className:"px-3 py-1.5 text-sm font-medium text-brand-500 hover:bg-surface-3 rounded-brand transition-colors shrink-0",title:m("sites.saveTitle"),children:m("sites.saveTitle")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),o()},className:"p-2 text-text-muted hover:text-brand-500 hover:bg-surface-3 rounded-brand transition-colors shrink-0",title:m("sites.editNameTitle"),children:(0,n.jsx)(en.gH,{size:16})}),!r&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-2 text-text-muted hover:text-red-400 hover:bg-surface-3 rounded-brand transition-colors shrink-0",title:m("sites.removeTitle"),children:(0,n.jsx)(en.TB,{size:16})})]})]})}let cx=0,cm=(e,t)=>{let s={port:e,path:t||"/"};return{key:`site-${++cx}`,port:e,path:s.path,srcTick:0,hist:[s],histIdx:0}},cp=e=>e?`localhost:${e.port}${e.path||"/"}`:"",cf={"service-worker-blocked":"sites.errorSwBlocked","bridge not connected — open the 9Remote app":"sites.errorNoBridge","no-session":"sites.errorNoSession",timeout:"sites.errorTimeout","no reply from the agent":"sites.errorNoReply"};function ch({busRef:e,connected:t=!1,initialPort:s,initialPath:l,onBack:a}){let{t:i}=(0,ec.s)(),[o,c]=(0,r.useState)(()=>{if(!s)return{tabs:[],activeKey:"",address:""};let e=cm(s,l);return{tabs:[e],activeKey:e.key,address:cp(e)}}),[d,u]=(0,r.useState)(!1),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(null),{tabs:h,activeKey:b,address:g}=o,v=h.find(e=>e.key===b)||null,y=(0,r.useRef)(new Set),w=(0,r.useCallback)(t=>{y.current.has(t)||(y.current.add(t),e?.current?.emit?.("startProxySession",t))},[e]),j=(0,r.useCallback)(t=>{y.current.delete(t),e?.current?.emit?.("endProxySession",t)},[e]);(0,r.useEffect)(()=>{cc(e?.current)},[e]),(0,r.useEffect)(()=>{let e=e=>{let{message:t,port:s}=e.detail||{};t&&(u(!1),f({message:i(cf[t]||"sites.errorGeneric",{port:s})}))};return window.addEventListener(cn,e),()=>window.removeEventListener(cn,e)},[i]),(0,r.useEffect)(()=>{let e=e=>{let{port:t,path:s}=e.detail||{};t&&c(e=>({tabs:e.tabs.map(n=>{if(n.key!==e.activeKey)return n;let r=n.hist[n.histIdx];if(r&&r.port===t&&r.path===(s||"/"))return{...n,port:t,path:s};let l=[...n.hist.slice(0,n.histIdx+1),{port:t,path:s||"/"}];return{...n,port:t,path:s,hist:l,histIdx:l.length-1}}),activeKey:e.activeKey,address:`localhost:${t}${s||"/"}`}))};return window.addEventListener(cs,e),()=>window.removeEventListener(cs,e)},[]),(0,r.useEffect)(()=>{let e=new Set(h.map(e=>e.port));for(let t of[...y.current])e.has(t)||j(t)},[h,j]),(0,r.useEffect)(()=>()=>{for(let t of y.current)e?.current?.emit?.("endProxySession",t);y.current.clear()},[e]);let k=(e,t="/")=>{(0,eo.e)(),w(e),u(!0),f(null),c(s=>{if(s.tabs.find(e=>e.key===s.activeKey))return{tabs:s.tabs.map(n=>{if(n.key!==s.activeKey)return n;let r=n.hist[n.histIdx];if(r&&r.port===e&&r.path===t)return{...n,port:e,path:t,srcTick:n.srcTick+1};let l=[...n.hist.slice(0,n.histIdx+1),{port:e,path:t}];return{...n,port:e,path:t,srcTick:n.srcTick+1,hist:l,histIdx:l.length-1}}),activeKey:s.activeKey,address:`localhost:${e}${t}`};let n=cm(e,t);return{tabs:[...s.tabs,n],activeKey:n.key,address:cp(n)}})},N=()=>{v&&((0,eo.e)(),u(!0),f(null),c(e=>({...e,tabs:e.tabs.map(t=>t.key===e.activeKey?{...t,srcTick:t.srcTick+1}:t)})))},C=e=>{if(!v)return;let t=v.histIdx+e,s=v.hist[t];s&&((0,eo.e)(),w(s.port),u(!0),c(e=>({tabs:e.tabs.map(n=>n.key===e.activeKey?{...n,port:s.port,path:s.path,srcTick:n.srcTick+1,histIdx:t}:n),activeKey:e.activeKey,address:cp(s)})))},S=()=>{(0,eo.e)(),m(!0)};return(0,n.jsxs)("div",{className:"absolute inset-0 z-20 flex flex-col bg-surface text-text transition-all duration-300 ease-out animate-in slide-in-from-bottom",children:[(0,n.jsxs)("div",{className:"h-11 flex items-center gap-1 px-2 border-b border-border-subtle shrink-0 overflow-x-auto modal-scrollable",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),a?.()},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors shrink-0",title:i("common.close"),children:(0,n.jsx)(en.JG,{size:18})}),h.map(e=>(0,n.jsxs)("div",{className:`group flex items-center gap-1.5 pl-3 pr-1.5 h-8 rounded-brand text-xs cursor-pointer max-w-[160px] shrink-0 transition-colors ${e.key===b?"bg-surface-3 text-text":"bg-surface-2 text-text-muted hover:bg-surface-3"}`,onClick:()=>c(t=>({...t,activeKey:e.key,address:cp(e)})),children:[(0,n.jsx)(en.qz,{size:13,className:"shrink-0"}),(0,n.jsxs)("span",{className:"truncate",children:[":",e.port]}),(0,n.jsx)("button",{onClick:t=>{var s;t.stopPropagation(),s=e.key,(0,eo.e)(),c(e=>{let t=e.tabs.findIndex(e=>e.key===s),n=e.tabs.filter(e=>e.key!==s);if(s!==e.activeKey)return{...e,tabs:n};let r=n[Math.min(t,n.length-1)];return{tabs:n,activeKey:r?.key||"",address:cp(r)}})},className:"p-0.5 rounded opacity-60 hover:opacity-100 hover:bg-surface shrink-0",title:i("common.close"),children:(0,n.jsx)(en.X,{size:12})})]},e.key)),(0,n.jsx)("button",{onClick:S,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors shrink-0",title:i("sites.browserNewTab"),children:(0,n.jsx)(en.FW,{size:16})}),d&&(0,n.jsx)(en.kr,{size:14,className:"animate-spin text-brand-500 shrink-0 ml-1"})]}),(0,n.jsxs)("div",{className:"h-11 flex items-center gap-1 px-2 border-b border-border-subtle shrink-0",children:[(0,n.jsx)("button",{onClick:()=>C(-1),disabled:!v||0===v.histIdx,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-40 shrink-0",title:i("sites.goBack"),children:(0,n.jsx)(en.JG,{size:16})}),(0,n.jsx)("button",{onClick:()=>C(1),disabled:!v||v.histIdx>=v.hist.length-1,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-40 shrink-0",title:i("sites.goForward"),children:(0,n.jsx)(en.c_,{size:16})}),(0,n.jsx)("button",{onClick:()=>{v&&k(v.port,"/")},disabled:!v,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-40 shrink-0",title:i("menu.home"),children:(0,n.jsx)(en.ww,{size:15})}),(0,n.jsx)("input",{type:"text",value:g,onChange:e=>c(t=>({...t,address:e.target.value})),onKeyDown:e=>{let t;return"Enter"===e.key&&void((t=function(e,t){let s=(e||"").trim();if(!s)return null;let n=s.match(/^(?:https?:\/\/)?localhost:(\d{1,5})(\/.*)?$/i);return n||(n=s.match(/^:(\d{1,5})(\/.*)?$/))||(n=s.match(/^(\d{1,5})(\/.*)?$/))&&Number(n[1])>=1&&65535>=Number(n[1])?{port:Number(n[1]),path:n[2]||"/"}:s.startsWith("/")&&t?{port:t,path:s}:null}(g,v?.port))&&k(t.port,t.path))},placeholder:i("sites.browserAddressPlaceholder"),spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"flex-1 min-w-0 px-3 py-1.5 bg-surface-2 rounded-brand text-sm text-text placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40"}),(0,n.jsx)("button",{onClick:N,disabled:!v,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors disabled:opacity-40 shrink-0",title:i("editor.reload"),children:(0,n.jsx)(en.kt,{size:15})})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-white relative",children:[!t&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center text-sm text-text-muted bg-surface",children:i("sites.browserNotConnected")}),h.map(e=>(0,n.jsx)("iframe",{src:function(e,t,s=0){let n=Number(e);if(!Number.isInteger(n)||n<1||n>65535||!ct)return null;let r=s?`?r=${s}`:"";return`${ct}/proxy.html${r}#port=${n}&path=${encodeURIComponent(t||"/")}`}(e.port,e.path,e.srcTick),title:`site-${e.port}`,className:`w-full h-full border-0 absolute inset-0 ${e.key===b?"":"hidden"}`,onLoad:()=>{e.key===b&&u(!1)}},e.key)),!v&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 p-6 text-center bg-surface",children:[(0,n.jsx)(en.qz,{size:28,className:"text-text-muted"}),(0,n.jsx)("p",{className:"text-text text-sm font-medium",children:i("sites.noSitesFound")}),(0,n.jsxs)("button",{onClick:S,className:"flex items-center gap-2 px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-medium rounded-brand transition-colors",children:[(0,n.jsx)(en.FW,{size:16}),i("sites.newTabTitle")]})]}),p&&v&&(0,n.jsxs)("div",{className:"absolute inset-x-0 top-0 z-20 flex items-start gap-3 px-4 py-3 bg-red-500/90 text-white text-sm",children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 break-words",children:p.message}),(0,n.jsx)("button",{onClick:N,className:"px-2 py-1 rounded bg-white/20 hover:bg-white/30 shrink-0 font-medium",children:i("sites.refresh")}),(0,n.jsx)("button",{onClick:()=>f(null),className:"p-1 shrink-0 opacity-80 hover:opacity-100",title:i("common.close"),children:(0,n.jsx)(en.X,{size:14})})]})]}),(0,n.jsx)(cd,{isOpen:x,onClose:()=>m(!1),onOpenSite:e=>k(e),busRef:e,connected:t})]})}function cb({files:e,loading:t,onFileClick:s,onFolderClick:r,onMoreClick:l,selectedPath:a,gitStatusMap:i={},workspacePath:o}){let{t:c}=(0,ec.s)();return t?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-text-muted",children:c("common.loading")})}):0===e.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-text-muted",children:c("files.emptyFolder")})}):(0,n.jsx)("div",{children:e.map((e,t)=>{var d;let u=i[d=e.path,!o?d:d.replace(o+"/","")],x="folder-changed"===u?"text-yellow-400":F.vs[u]||"";return(0,n.jsxs)("div",{className:`w-full px-4 py-1.5 flex items-center gap-2.5 border-b border-border hover:bg-surface-2 transition ${a===e.path?"bg-surface-2":""}`,children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),"folder"===e.type?r(e):s(e)},className:"flex-1 flex items-center gap-2.5 text-left min-w-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:r6(e,18)}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:`truncate text-sm ${x||"text-text"}`,title:e.name,children:[e.name,u&&"folder-changed"!==u&&(0,n.jsxs)("span",{className:"ml-2 text-xs opacity-70",children:["[",u,"]"]})]}),"folder"!==e.type&&e.sizeFormatted&&(0,n.jsx)("div",{className:"text-text-subtle text-xs",children:e.sizeFormatted})]})]}),l&&(0,n.jsx)("button",{onClick:t=>{let s;(0,eo.e)(),t.stopPropagation(),s=t.currentTarget.getBoundingClientRect(),l?.(e,{x:s.right,y:s.top})},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded transition flex-shrink-0",title:c("menu.settings"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"19",r:"2"})]})}),"folder"===e.type&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),r(e)},className:"p-1 text-text-muted flex-shrink-0",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:"M9 5l7 7-7 7"})})})]},e.path)})})}function cg({workspace:e,initialPath:t,fileBus:s,onBack:l,onOpenFile:a,onOpenGit:i,onSetWorkspace:o,onSwitchWorkspace:c,onPathChange:d,isBrowsing:u=!1,hideSwitchWorkspace:x=!1,scope:m=""}){let{t:p}=(0,ec.s)(),[f,h]=(0,r.useState)(t||e),[b,g]=(0,r.useState)([]),[v,y]=(0,r.useState)(!0),[w,j]=(0,r.useState)(""),[k,N]=(0,r.useState)(null),[C,S]=(0,r.useState)(!1),[E,R]=(0,r.useState)("file"),[T,$]=(0,r.useState)(""),[M,z]=(0,r.useState)({isOpen:!1}),[P,I]=(0,r.useState)(null),[A,L]=(0,r.useState)(!1),[D,B]=(0,r.useState)({}),[K,O]=(0,r.useState)(!1),[W,_]=(0,r.useState)(""),[H,q]=(0,r.useState)([]),[U,V]=(0,r.useState)(!1),X=(0,r.useRef)(null),[G]=(0,r.useState)(()=>window.innerWidth>=eV.jK),J=(0,r.useCallback)(async e=>{if(u){L(!1),B({});return}let t=await rU(s,e);L(t.hasGit);let n=t.map;B(e=>!function(e,t){let s=Object.keys(e||{}),n=Object.keys(t||{});if(s.length!==n.length)return!1;for(let s of n)if(e[s]!==t[s])return!1;return!0}(e,n)?n:e)},[s,u]),Y=(0,r.useCallback)(async e=>{y(!0),j("");let t=await s.getFiles(e,!0);if(t.success){let e=t.files;u&&(e=t.files.filter(e=>"folder"===e.type)),g(t=>{if(t.length!==e.length)return e;for(let s=0;s<e.length;s++)if(t[s]?.name!==e[s]?.name)return e;return t}),h(t.currentPath)}else j(t.error),g([]);y(!1)},[s,u]),{transfer:Z,dragOver:Q,conflict:ee,downloadState:et,startUpload:es,handleDrop:er,handleDragOver:el,handleDragLeave:ea,handleDownload:ed,resolveConflict:eu}=function({fileBus:e,currentPath:t,isBrowsing:s,onDone:n,onError:l}){let[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),p=(0,r.useRef)(0),f=(0,r.useCallback)(async s=>{if(!s.length||!e.uploadFiles)return;let r=++p.current;i({total:s.length,done:0,current:s[0]?.file?.name||"",ratio:0}),await e.uploadFiles(t,s,{onConflict:({file:e},t)=>new Promise(s=>{u({name:t||e.name,resolve:s})}),onProgress:(e,t)=>{r===p.current&&i(s=>s?{...s,current:e.name,ratio:t}:s)},onFileDone:e=>{r===p.current&&i(e=>e?{...e,done:e.done+1}:e)}}),r===p.current&&i(null),n?.(t)},[e,t,n]),h=(0,r.useCallback)(async e=>{if(e.preventDefault(),c(!1),s)return;let t=await ln(e.dataTransfer);t.length&&((0,eo.e)(),f(t))},[s,f]),b=(0,r.useCallback)(e=>{e.preventDefault(),s||c(!0)},[s]),g=(0,r.useCallback)(e=>{e.preventDefault(),c(!1)},[]);(0,r.useEffect)(()=>{if(s)return;let e=async e=>{let t=Array.from(e.clipboardData?.files||[]);if(!t.length)return;let s=t.map(e=>({file:e,relativePath:e.name}));(0,eo.e)(),f(s)};return window.addEventListener("paste",e),()=>window.removeEventListener("paste",e)},[s,f]);let v=(0,r.useRef)(0),y=(0,r.useCallback)(t=>{if(!e.downloadFile)return;let s=++v.current;m({name:t.name,ratio:0}),e.downloadFile(t.path,{onSave:(e,n)=>{let r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=n?.fileName||t.name,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(r.href),s===v.current&&m(null)},onProgress:e=>{s===v.current&&m(t=>t?{...t,ratio:e}:t)},onError:e=>{l?.(e.message||"Download failed"),s===v.current&&m(null)}})},[e,l]),w=(0,r.useCallback)(e=>{d?.resolve(e),u(null)},[d]);return{transfer:a,dragOver:o,conflict:d,downloadState:x,startUpload:f,handleDrop:h,handleDragOver:b,handleDragLeave:g,handleDownload:y,resolveConflict:w}}({fileBus:s,currentPath:f,isBrowsing:u,onDone:Y,onError:j}),ex=(0,r.useCallback)(t=>{if(_(t),X.current&&clearTimeout(X.current),!t||t.length<2){q([]),V(!1);return}V(!0),X.current=setTimeout(async()=>{let n=await s.searchFiles(e,t);n.success&&q(n.files),V(!1)},300)},[e,s]),em=(0,r.useCallback)(()=>{O(!1),_(""),q([])},[]);(0,r.useEffect)(()=>{Y(t||e),u||J(e)},[e,t,u]),(0,r.useEffect)(()=>()=>{X.current&&clearTimeout(X.current)},[]),(0,r.useEffect)(()=>{!u&&d&&d(f)},[f,u,d]);let ef=e=>{Y(e.path)},eh=()=>N(null),eb=async()=>{if(!P||!P.newName.trim())return;let e=f+"/"+P.newName.trim(),t=await s.renameItem(P.file.path,e);t.success?Y(f):j(t.error),I(null)},eg=async()=>{if(!T.trim())return;let e=f+"/"+T.trim(),t=await s.createItem(e,E);t.success?(Y(f),S(!1),$("")):j(t.error)},ev=(0,r.useRef)(null),ey=(0,r.useRef)(null),ew=e=>{let t=Array.from(e.target.files||[]);if(e.target.value="",!t.length)return;let s=t.map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}));S(!1),es(s)},ej=async t=>{if(!e||!s||!t?.path)return;eh();let n=t.path.startsWith(e)?t.path.slice(e.length).replace(/^\/+/,""):t.path,r=await lm(s,e,n,"folder"===t.type);r?.success&&(J(e),window.dispatchEvent(new CustomEvent(F.GW)))},ek=f===e,eN="p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]";return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface px-4 py-3 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),l()},className:eN,title:p("common.close"),children:(0,n.jsx)(en.X,{size:20})}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("div",{className:"text-text font-medium truncate text-sm",children:f.replace(/^\/Users\/[^/]+/,"~")})}),u&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),ep(f,m),o(f)},className:"px-3 py-2 bg-brand-500 hover:bg-brand-600 text-white text-xs rounded-brand transition-all duration-150 ease-out active:scale-[0.97] font-medium shadow-sm",title:p("files.setAsWorkspaceTitle"),children:p("files.setWorkspace")}),!u&&c&&!x&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),c()},className:eN,title:p("files.switchWorkspace"),children:(0,n.jsx)(en.Bm,{className:"text-brand-500",size:20})}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),O(!0)},className:eN,title:p("files.searchFiles"),children:(0,n.jsx)(en.vj,{className:"text-brand-500",size:20})}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),i()},disabled:!A,className:`p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.96] ${A?"bg-surface-2 hover:bg-surface-3 text-text":"bg-surface-2/30 text-text-muted cursor-not-allowed"}`,title:A?p("git.title"):p("files.noGitRepo"),children:(0,n.jsx)(en.Zr,{className:A?"text-brand-500":"text-text-muted",size:20})})]}),K&&(0,n.jsx)(lc,{query:W,loading:U,onChange:ex,onClose:em}),w&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm",children:w}),Z&&(0,n.jsx)(lo,{label:`${p("files.copying")} ${Z.done+1}/${Z.total}: ${Z.current}`,ratio:Z.ratio}),et&&(0,n.jsx)(lo,{label:`${p("files.downloading")}: ${et.name}`,ratio:et.ratio}),K&&W.length>=2?(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto",children:U?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.searching")}):0===H.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.noFilesFound")}):(0,n.jsx)("div",{children:H.map(t=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),a(t.path),em()},className:"w-full px-4 py-3 flex items-center gap-3 border-b border-border hover:bg-surface transition-colors text-left",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:"binary"===t.type?(0,n.jsx)(en.lP,{size:20,className:"text-red-500/70"}):(0,n.jsx)(en.ZH,{size:20,className:"text-text-subtle"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-text truncate",title:t.name,children:t.name}),(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",title:t.path,children:t.path.replace(e,"").replace(/^\//,"")})]}),t.sizeFormatted&&(0,n.jsx)("span",{className:"text-text-muted text-xs flex-shrink-0",children:t.sizeFormatted})]},t.path))})}):(0,n.jsxs)(n.Fragment,{children:["/"!==f&&!ek&&!K&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),Y(f.split("/").slice(0,-1).join("/")||"/")},className:"w-full px-4 py-3 flex items-center gap-3 border-b border-border hover:bg-surface transition-colors text-left flex-shrink-0",children:[(0,n.jsx)(en.JG,{className:"text-green-500",size:28}),(0,n.jsx)("span",{className:"text-green-500",children:f.split("/").pop()||"/"})]}),(0,n.jsx)("div",{className:`flex-1 min-h-0 overflow-auto ${!u?"pb-20":""} ${Q?"bg-brand-500/5 ring-2 ring-inset ring-brand-500/40":""}`,onDrop:er,onDragOver:el,onDragLeave:ea,children:u?(0,n.jsx)("div",{className:"p-4",children:v?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("common.loading")}):0===b.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.emptyFolder")}):(0,n.jsx)("div",{className:"grid grid-cols-2 gap-3",children:b.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),ef(e)},className:"bg-surface hover:bg-surface-2 rounded-brand-lg p-2 flex flex-col items-center gap-1 transition-all duration-150 ease-out active:scale-[0.98] text-center",children:[(0,n.jsx)(en.vd,{size:48,className:"text-yellow-500/80"}),(0,n.jsx)("span",{className:"text-text text-xs font-medium truncate w-full",title:e.name,children:e.name})]},e.path))})}):(0,n.jsx)(cb,{files:b,loading:v,onFileClick:e=>{if(!u){if("binary"===e.type){j(p("files.cannotOpenBinary")),setTimeout(()=>j(""),3e3);return}a?.(e.path,f)}},onFolderClick:ef,onMoreClick:(e,t)=>{N({file:e,x:t.x,y:t.y})},gitStatusMap:D,workspacePath:e})})]}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),S(!0)},className:"absolute bottom-[max(1.5rem,calc(env(safe-area-inset-bottom)+0.5rem))] right-6 w-14 h-14 bg-brand-500 hover:bg-brand-600 text-white rounded-full shadow-lg shadow-brand-500/30 flex items-center justify-center transition-all duration-200",children:(0,n.jsx)(en.FW,{size:24})}),k&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-40",onClick:eh}),(0,n.jsxs)("div",{className:"fixed z-50 card-elev overflow-hidden min-w-[140px]",style:{right:16,top:Math.min(k.y,window.innerHeight-160)},children:[(0,n.jsxs)("button",{onClick:()=>{var e;(0,eo.e)(),e=k.file,eh(),I({file:e,newName:e.name})},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.gH,{size:16}),p("files.rename")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),navigator.clipboard?.writeText(k.file.path).catch(()=>{}),eh()},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.QR,{size:16}),p("files.copyPath")]}),G&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),eh(),ed(k.file)},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.f5,{size:16}),p("files.download")]}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),ej(k.file)},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.X_,{size:16}),p("git.addToGitignore",{defaultValue:"Add to .gitignore"})]}),(0,n.jsxs)("button",{onClick:()=>{var e;(0,eo.e)(),e=k.file,eh(),z({isOpen:!0,title:p("files.deleteConfirmTitle"),message:p("files.deleteConfirmMessage",{name:e.name}),onConfirm:async()=>{let t=await s.deleteItem(e.path);t.success?Y(f):j(t.error)}})},className:"w-full px-4 py-3 text-left text-red-400 hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(en.TB,{size:16}),p("files.delete")]})]})]}),C&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ld,{type:E,name:T,onTypeChange:R,onNameChange:$,onSubmit:eg,onPickFile:()=>ev.current?.click(),onPickFolder:()=>ey.current?.click(),onClose:()=>S(!1)}),(0,n.jsx)("input",{ref:ev,type:"file",multiple:!0,className:"hidden",onChange:ew}),(0,n.jsx)("input",{ref:ey,type:"file",className:"hidden",webkitdirectory:"",onChange:ew})]}),P&&(0,n.jsx)(lu,{value:P.newName,onChange:e=>I({...P,newName:e}),onSubmit:eb,onClose:()=>I(null)}),(0,n.jsx)(ei.A,{isOpen:M.isOpen,onClose:()=>z({isOpen:!1}),onConfirm:M.onConfirm,title:M.title,message:M.message}),ee&&(0,n.jsx)(lx,{name:ee.name,onResolve:eu})]})}let cv=[{label:"Esc",key:"Escape"},{label:"Tab",key:"Tab"},{label:"←",key:"ArrowLeft"},{label:"→",key:"ArrowRight"},{label:"↑",key:"ArrowUp"},{label:"↓",key:"ArrowDown"},{label:"Ctrl",modifier:"ctrl"},{label:"Opt",modifier:"alt"}],cy=[{label:"Undo",key:"z",ctrl:!0},{label:"Redo",key:"y",ctrl:!0},{label:"{}",text:"{}"},{label:"()",text:"()"},{label:"[]",text:"[]"},{label:'""',text:'""'},{label:"=>",text:" => "},{label:"Aa",toggleTextInput:!0}];function cw({viewRef:e}){let{t}=(0,ec.s)(),[s,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(""),x=(0,r.useRef)(null),m=t=>{let s=e.current;if(!s)return;let{from:n,to:r}=s.state.selection.main;s.dispatch({changes:{from:n,to:r,insert:t},selection:{anchor:n+t.length}}),s.focus()},p=(t,{ctrl:n=!1,alt:r=!1}={})=>{let o=e.current;o&&(o.contentDOM.dispatchEvent(new KeyboardEvent("keydown",{key:t,code:1===t.length?`Key${t.toUpperCase()}`:t,ctrlKey:n||s,altKey:r||a,metaKey:n||s,bubbles:!0,cancelable:!0})),o.focus(),l(!1),i(!1))},f=e=>`flex-1 py-2 text-text text-xs rounded-brand transition-all duration-200 border ${e?"bg-brand-500 border-brand-400 shadow-md shadow-brand-500/30":"bg-surface-2 hover:bg-surface-2 border-border hover:border-brand-500"}`;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:`bg-surface transition-all duration-300 overflow-hidden ${o?"max-h-24 opacity-100":"max-h-0 opacity-0"}`,children:(0,n.jsxs)("div",{className:"p-2 flex gap-2 items-center",children:[(0,n.jsx)("textarea",{ref:x,value:d,onChange:e=>u(e.target.value),placeholder:t("editor.typeText"),rows:1,className:"w-full px-3 py-2 bg-surface-2 rounded text-text text-base placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out resize-none"}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d.trim()&&(m(d),u("")),c(!1)},disabled:!d.trim(),className:"px-4 py-2 bg-brand-500 hover:bg-brand-600 disabled:bg-surface-2 disabled:opacity-50 text-white text-sm font-medium rounded transition-all duration-150 ease-out active:scale-[0.97] shadow-sm flex-shrink-0",children:t("editor.insert")})]})}),(0,n.jsxs)("div",{className:"bg-surface border-t border-border px-2 pt-2 pb-safe flex flex-col gap-1 flex-shrink-0",children:[(0,n.jsx)("div",{className:"flex gap-1",children:cv.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),"ctrl"===e.modifier?(l(e=>!e),i(!1)):"alt"===e.modifier?(i(e=>!e),l(!1)):p(e.key)},className:f("ctrl"===e.modifier&&s||"alt"===e.modifier&&a),children:e.label},e.label))}),(0,n.jsx)("div",{className:"flex gap-1",children:cy.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),e.toggleTextInput?(c(e=>!e),o||setTimeout(()=>x.current?.focus(),350)):e.text?m(e.text):e.key&&p(e.key,{ctrl:e.ctrl,alt:e.alt})},className:f(e.toggleTextInput&&o),children:e.label},e.label))})]})]})}function cj({filePath:e,fileBus:t,onBack:s,line:l,column:a,workspace:i,diffStatus:o,preview:c=!1}){let{t:d}=(0,ec.s)(),u=lH(e),x=!!o,m=e.split("/").pop(),p=lU({filePath:x||u?"":e,fileBus:t}),f=lV({dirty:!x&&!u&&p.dirty,onSave:p.save}),h=(0,r.useRef)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(!1),C=x||u?null:(0,F.YO)(e),[S,E]=(0,r.useState)(c&&!!C),[R,T]=(0,r.useState)(0),[$,M]=(0,r.useState)(e),[z,P]=(0,r.useState)(!1);$!==e&&(M(e),E(c&&!!C)),p.justSaved!==z&&(P(p.justSaved),p.justSaved&&T(e=>e+1));let I=(0,r.useCallback)((e,t)=>{h.current=t},[]);(0,r.useEffect)(()=>{if(x||!i||!e)return;let s=!1;return t.gitFileStatus(i,e).then(e=>{s||y(e?.success&&e.status?e:null)}),()=>{s=!0}},[e,i,t]);let A=async()=>{if(!v||!i)return;if((0,F.u)(e))return void j("image");N(!0);let s=await t.gitDiff(i,v.file,v.status);N(!1),s?.success&&j(s.diff||"")};(0,r.useEffect)(()=>{if(!o||!i||!e)return;let s=!1,n=setTimeout(async()=>{if((0,F.u)(e))return void j("image");N(!0);let n=await t.gitDiff(i,e,o);!s&&(N(!1),n?.success&&j(n.diff||""))},0);return()=>{s=!0,clearTimeout(n)}},[o,i,e,t]);let L=async()=>{let e=h.current?.state.doc.toString();if(null!=e)try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),1500)}catch{}};return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface px-4 py-3 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),f.guard(s)},className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",children:(0,n.jsx)(en.JG,{size:20})}),(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"text-text font-medium truncate",children:m}),p.dirty&&(0,n.jsx)("span",{className:"w-2 h-2 bg-yellow-400 rounded-full flex-shrink-0",title:d("editor.unsaved")}),p.justSaved&&(0,n.jsx)("span",{className:"text-green-400 text-xs flex-shrink-0",children:d("editor.saved")}),b&&(0,n.jsx)("span",{className:"text-green-400 text-xs flex-shrink-0",children:d("editor.copied",{defaultValue:"Copied"})})]}),v&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),A()},disabled:k,className:"p-2 bg-surface-2 hover:bg-surface-3 text-orange-400 rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",title:d("editor.gitDiff"),children:k?(0,n.jsx)(en.kr,{className:"animate-spin",size:16}):(0,n.jsx)(en.Zr,{size:16})}),C&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),E(e=>!e)},title:d(S?"editor.editCode":"editor.preview"),className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",children:S?(0,n.jsx)(en.GD,{size:16}):(0,n.jsx)(en.kU,{size:16})}),!u&&!x&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),L()},className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",title:d("editor.copy",{defaultValue:"Copy"}),children:(0,n.jsx)(en.QR,{size:16})}),!u&&!x&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),p.save()},disabled:!p.dirty||p.saving,className:`px-3 py-2 rounded-brand transition-all duration-150 ease-out flex items-center gap-1 ${p.dirty&&!p.saving?"bg-brand-500 hover:bg-brand-600 text-white shadow-sm active:scale-[0.97]":"bg-surface-2 text-text-muted cursor-not-allowed"}`,children:[p.saving?(0,n.jsx)(en.kr,{className:"animate-spin",size:16}):(0,n.jsx)(en.eM,{size:16}),(0,n.jsx)("span",{className:"hidden sm:inline",children:d("editor.save")})]})]}),p.error&&!u&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm break-words",children:p.error}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:x?(0,F.u)(e)?(0,n.jsx)(af,{filePath:e,status:o,workspace:i,fileBus:t}):(0,n.jsx)("div",{className:"h-full overflow-auto p-2",children:k?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted",children:d("common.loading")}):w?(0,n.jsx)(am,{diff:w}):(0,n.jsx)("div",{className:"h-32 flex items-center justify-center text-text-muted text-sm",children:d("git.noChanges")})}):u?(0,n.jsx)(lq,{filePath:e,fileBus:t}):S&&C?(0,n.jsx)(ad,{kind:C,filePath:e,fileBus:t,content:p.content,reloadKey:R}):p.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted",children:d("common.loading")}):(0,n.jsx)(l9,{filePath:e,content:p.content,onTextChanged:p.onTextChanged,onRegisterView:(e,t)=>{p.register(e),I(e,t)},onSave:p.save,line:l,column:a})}),!x&&null!==w&&(0,n.jsxs)("div",{className:"absolute inset-0 z-30 bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface-2 px-4 py-3 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-text font-medium truncate",children:d("editor.gitDiff")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),j(null)},className:"p-2 text-text-muted hover:text-text rounded-brand",children:(0,n.jsx)(en.X,{size:18})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto p-2",children:(0,F.u)(e)?(0,n.jsx)(af,{filePath:e,status:v?.status,workspace:i,fileBus:t}):w?(0,n.jsx)(am,{diff:w}):(0,n.jsx)("div",{className:"h-32 flex items-center justify-center text-text-muted text-sm",children:d("git.noChanges")})})]}),!u&&!x&&!p.loading&&!S&&(0,n.jsx)(cw,{viewRef:h}),(0,n.jsx)(lX,{isOpen:f.asking,fileName:m,onSave:f.saveThenLeave,onDiscard:f.discardAndLeave,onCancel:f.cancel})]})}function ck({workspace:e,fileBus:t,branch:s,changedCount:l,onDone:a,onClose:i}){let{t:o}=(0,ec.s)(),[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||u||i()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i,u]);let f=c.trim().length>0&&!u,h=async()=>{let s=await t.gitAdd(e);if(!s.success)return{ok:!1,text:s.error||o("git.stageFailed")};let n=await t.gitCommit(e,c.trim());return n.success?{ok:!0,text:lk(o,n.output)}:{ok:!1,text:n.output||n.error||o("git.commitFailed")}},b=async()=>{if(!f)return;(0,eo.e)(),x(!0),p(null);let e=await h();x(!1),p(e),e.ok&&(d(""),a?.())},g=async()=>{if(u)return;(0,eo.e)(),x(!0),p(null);let s=await t.gitPush(e);x(!1),p({ok:s.success,text:s.success?lN(o,s.output):s.output||s.error||o("git.pushFailed")}),s.success&&a?.()},v=async()=>{if(!f)return;(0,eo.e)(),x(!0),p(null);let s=await h();if(!s.ok){x(!1),p(s);return}d("");let n=await t.gitPush(e);x(!1),p({ok:n.success,text:n.success?lN(o,n.output):n.output||n.error||o("git.pushFailed")}),a?.()};return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:()=>!u&&i()}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsxs)("h3",{className:"text-lg font-semibold text-text flex items-center gap-2",children:[(0,n.jsx)(en.Zr,{size:18,className:"text-brand-500"}),o("git.title"),s?` \xb7 ${s}`:""]}),(0,n.jsx)("button",{onClick:()=>!u&&i(),className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":o("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsxs)("div",{className:"px-5 pb-5 flex flex-col gap-4",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)("textarea",{value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),v())},rows:2,placeholder:o("git.commitPlaceholder"),disabled:u,className:"w-full px-3 py-2 bg-surface-2 text-text text-sm rounded-brand outline-none focus:ring-1 focus:ring-brand-500 resize-y min-h-[54px] max-h-[200px] disabled:opacity-60"}),(0,n.jsx)("span",{className:"text-xs text-text-subtle",children:o("git.stageAllNote",{count:l})})]}),(0,n.jsxs)("button",{onClick:v,disabled:!f,className:"w-full px-4 py-2.5 text-sm bg-brand-500 hover:bg-brand-500/80 text-white font-medium rounded-brand transition-colors flex items-center justify-center gap-2 disabled:opacity-40 disabled:cursor-not-allowed",children:[u?(0,n.jsx)(en.kr,{size:16,className:"animate-spin"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(en.aJ,{size:16}),(0,n.jsx)(en.Do,{size:16})]}),(0,n.jsx)("span",{children:o("git.commitAndPush")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1.5 py-0.5 rounded bg-white/20 text-white leading-none",children:"⌘↵"})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:b,disabled:!f,className:"flex-1 px-4 py-2 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)(en.aJ,{size:16}),o("git.commit")]}),(0,n.jsxs)("button",{onClick:g,disabled:u,className:"flex-1 px-4 py-2 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)(en.Do,{size:16}),o("git.push")]})]}),m&&(0,n.jsx)("pre",{className:`text-xs whitespace-pre-wrap break-words px-3 py-2 rounded-brand max-h-32 overflow-y-auto ${m.ok?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:m.text})]})]})]})}function cN({workspace:e,fileBus:t,onBack:s,onOpenFile:l}){let{t:a}=(0,ec.s)(),[i,o]=(0,r.useState)("status"),[c,d]=(0,r.useState)(!0),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(""),[f,h]=(0,r.useState)([]),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(""),[k,N]=(0,r.useState)(!1),[C,S]=(0,r.useState)({isOpen:!1}),[E,R]=(0,r.useState)(""),[T,$]=(0,r.useState)(null),[M,z]=(0,r.useState)(null),[P,I]=(0,r.useState)(!1),A=(0,r.useCallback)(async()=>{d(!0),p("");let s=await t.gitStatus(e);s.success?h(s.files):p(s.error),t.gitBranch(e).then(e=>{e?.success&&(R(e.branch),$(e.ahead??null),z(e.behind??null))}),d(!1)},[e,t]),L=(0,r.useCallback)(async(s=null,n=null)=>{if(g(s),y(n),s&&(0,F.u)(s)){j("image"),N(!0),x(!1);return}x(!0),p("");let r=await t.gitDiff(e,s,n);r.success?(j(r.diff),N(!0)):p(r.error),x(!1)},[e,t]);(0,r.useEffect)(()=>{A()},[A]);let D=(0,r.useCallback)(()=>{if(o("diff"),!k&&f.length>0){let e=f[0];L(e.path,e.status)}},[k,L,f]),B=(0,r.useCallback)(()=>{b&&v&&K(b,v)},[b,v]),K=(0,r.useCallback)((s,n)=>{let r=s.split("/").pop(),l="?"===n;S({isOpen:!0,title:a("git.discardConfirmTitle"),message:l?a("git.discardConfirmDelete",{name:r}):a("git.discardConfirmDiscard",{name:r}),onConfirm:async()=>{let r=await t.gitDiscard(e,s,n);if(r.success){if(await A(),"diff"===i){let e=f.filter(e=>e.path!==s);e.length>0?L(e[0].path,e[0].status):(o("status"),g(null),j(""),N(!1))}}else p(r.error)}})},[t,e,A,L,f,i,a]),O=(0,r.useCallback)(t=>{let s=e.endsWith("/")?`${e}${t}`:`${e}/${t}`;l?.(s)},[e,l]),[W,_]=(0,r.useState)(null),H=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),q=(0,r.useCallback)((e,t)=>{t.preventDefault(),t.stopPropagation(),(0,eo.e)(),_({file:e,x:t.clientX,y:t.clientY})},[]),U=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=await lm(t,e,s.path);n?.success&&(window.dispatchEvent(new CustomEvent(F.GW)),A())},[e,t,A]),V=(0,r.useCallback)(t=>{let s=e.endsWith("/")?`${e}${t.path}`:`${e}/${t.path}`;return[{key:"open",label:a("common.open",{defaultValue:"Open"}),icon:ly.ExternalLink,disabled:"D"===t.status,onClick:()=>O(t.path)},{key:"copyPath",label:a("files.copyPath",{defaultValue:"Copy Path"}),icon:ly.Copy,onClick:()=>H(s)},{key:"copyRel",label:a("files.copyRelPath",{defaultValue:"Copy Relative Path"}),icon:ly.FileText,onClick:()=>H(t.path)},{key:"copyName",label:a("files.copyName",{defaultValue:"Copy Filename"}),icon:ly.FileText,onClick:()=>H(t.path.split("/").pop())},{key:"addToGitignore",label:a("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:ly.EyeOff,onClick:()=>U(t)},{key:"discard",label:a("git.discardChangesTitle",{defaultValue:"Discard Changes"}),icon:ly.Undo2,danger:!0,onClick:()=>K(t.path,t.status)}]},[e,a,O,H,U,K]),X={modified:f.filter(e=>"M"===e.status),added:f.filter(e=>"A"===e.status),deleted:f.filter(e=>"D"===e.status),untracked:f.filter(e=>"?"===e.status)},G=e=>{let t=e.path.split("/").pop(),s=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")+1):"",r=e.added>0||e.deleted>0;return(0,n.jsx)("div",{className:"px-3 py-2 bg-surface rounded hover:bg-surface-2 transition",onContextMenu:t=>q(e,t),children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:r6({name:t,path:e.path,type:"file"},18)}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),L(e.path,e.status),o("diff")},className:"flex-1 min-w-0 text-left",children:[(0,n.jsx)("div",{className:"text-text font-medium truncate",title:e.path,children:t}),s&&(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",title:s,children:s})]}),r&&(0,n.jsxs)("div",{className:"flex items-center gap-1 text-xs flex-shrink-0",children:[e.added>0&&(0,n.jsxs)("span",{className:"text-[var(--success)]",children:["+",e.added]}),e.deleted>0&&(0,n.jsxs)("span",{className:"text-[var(--danger)]",children:["-",e.deleted]})]}),"D"!==e.status&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eo.e)(),O(e.path)},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-200 flex-shrink-0",title:a("git.openFile"),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:"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:t=>{t.stopPropagation(),(0,eo.e)(),K(e.path,e.status)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-all duration-200 flex-shrink-0",title:a("git.discardChangesTitle"),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)("span",{className:`font-mono font-bold w-5 h-5 flex items-center justify-center text-[11px] rounded flex-shrink-0 bg-surface-2 ${F.vs[e.status]}`,children:e.status})]})},e.path)};return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-4 py-3 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),s()},className:"p-2 bg-surface-2 hover:bg-surface-2 text-text rounded-brand transition-all duration-200",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:"M15 19l-7-7 7-7"})})}),(0,n.jsxs)("h1",{className:"text-text text-lg font-semibold truncate flex items-center gap-2",children:[a("git.title"),E?(0,n.jsxs)("span",{className:"text-text-muted font-normal",children:[" \xb7 ",E]}):null,T>0&&(0,n.jsxs)("span",{className:"text-xs font-medium px-1.5 py-0.5 rounded-brand bg-brand-500/15 text-brand-500",children:["↑",T]}),M>0&&(0,n.jsxs)("span",{className:"text-xs font-medium px-1.5 py-0.5 rounded-brand bg-surface-3 text-text-muted",children:["↓",M]})]}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),I(!0)},className:"ml-auto p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-200",title:a("git.gitActions"),children:(0,n.jsx)(en.Zr,{className:"w-5 h-5"})}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),"status"===i?A():L(b,v)},className:"p-2 bg-surface-2 hover:bg-surface-2 text-text rounded-brand transition-all duration-200",title:a("common.refresh"),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:"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.jsxs)("div",{className:"flex border-b border-border flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),o("status")},className:`flex-1 py-3 text-center font-medium transition ${"status"===i?"text-text border-b-2 border-brand-500":"text-text-muted hover:text-text"}`,children:a("git.status")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),D()},className:`flex-1 py-3 text-center font-medium transition ${"diff"===i?"text-text border-b-2 border-brand-500":"text-text-muted hover:text-text"}`,children:a("git.diffTab")})]}),m&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm",children:m}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden modal-scrollable",children:"status"===i?c?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("common.loading")}):(0,n.jsx)("div",{className:"p-4 space-y-4",children:0===f.length?(0,n.jsx)("div",{className:"text-center text-text-muted py-8",children:a("git.noChanges")}):(0,n.jsxs)(n.Fragment,{children:[X.modified.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.modified")," (",X.modified.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:X.modified.map(G)})]}),X.added.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.added")," (",X.added.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:X.added.map(G)})]}),X.deleted.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.deleted")," (",X.deleted.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:X.deleted.map(G)})]}),X.untracked.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.untrackedTitle")," (",X.untracked.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:X.untracked.map(G)})]})]})}):(0,n.jsxs)("div",{className:"p-4 min-w-0",children:[f.length>0&&(0,n.jsxs)("div",{className:"flex gap-2 mb-4",children:[(0,n.jsx)("select",{value:b||"",onChange:e=>{(0,eo.e)();let t=f.find(t=>t.path===e.target.value);t&&L(t.path,t.status)},className:"flex-1 min-w-0 px-3 py-2 bg-surface-2 rounded-brand text-text focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out",children:f.map(e=>(0,n.jsxs)("option",{value:e.path,children:["[",e.status,"] ",e.path]},e.path))}),b&&"D"!==v&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,eo.e)(),O(b)},disabled:u,className:"h-9 w-9 flex-shrink-0 bg-surface-2 hover:bg-surface-3 disabled:cursor-not-allowed text-text rounded-brand transition-all duration-200 flex items-center justify-center",title:a("git.openFile"),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:"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:()=>{(0,eo.e)(),B()},disabled:!b||u,className:"h-9 w-9 flex-shrink-0 bg-red-500/10 hover:bg-red-500/20 disabled:bg-surface-2 disabled:cursor-not-allowed text-red-400 rounded-brand transition-all duration-200 flex items-center justify-center",title:a("git.discardChangesTitle"),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"})})})]}),u?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("common.loading")}):b&&(0,F.u)(b)?(0,n.jsx)(af,{filePath:b,status:v,workspace:e,fileBus:t}):w?(0,n.jsx)(am,{diff:w}):(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("git.noChanges")})]})}),(0,n.jsx)(ei.A,{isOpen:C.isOpen,onClose:()=>S({isOpen:!1}),onConfirm:C.onConfirm,title:C.title,message:C.message}),P&&(0,n.jsx)(ck,{workspace:e,fileBus:t,branch:E,changedCount:f.length,onDone:A,onClose:()=>I(!1)}),W&&(0,n.jsx)(lv,{x:W.x,y:W.y,items:V(W.file),onClose:()=>_(null)})]})}let cC=[{id:F.Kr.explorer,Icon:en.sv,label:"Explorer"},{id:F.Kr.search,Icon:en.vj,label:"Search"},{id:F.Kr.scm,Icon:en.Zr,label:"Source Control"}];function cS({active:e,onClick:t,label:s,children:r}){return(0,n.jsx)("button",{type:"button",title:s,onClick:t,className:`relative w-10 h-10 flex items-center justify-center rounded-brand transition-all duration-150 ease-out active:scale-[0.96] ${e?"bg-surface-2 text-text border-l-2 border-brand-500":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:r})}function cE({activePanel:e,onSelectPanel:t,onBack:s}){let r=e=>{(0,eo.e)(10),t?.(e)};return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-between bg-surface border-r border-border py-2",style:{width:F.zT},children:[(0,n.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,n.jsx)(cS,{onClick:()=>{(0,eo.e)(10),s?.()},label:"Back",children:(0,n.jsx)(en.JG,{size:20})}),cC.map(({id:t,Icon:s,label:l})=>(0,n.jsx)(cS,{active:e===t,onClick:()=>r(t),label:l,children:(0,n.jsx)(s,{size:20})},t))]}),(0,n.jsx)("div",{className:"flex flex-col items-center gap-1",children:(0,n.jsx)(cS,{active:e===F.Kr.settings,onClick:()=>r(F.Kr.settings),label:"Settings",children:(0,n.jsx)(en.wB,{size:20})})})]})}function cR({active:e,onClick:t,title:s,children:r}){return(0,n.jsx)("button",{type:"button",title:s,onClick:()=>{(0,eo.e)(),t()},className:`px-2 h-6 text-xs rounded-brand border transition-colors ${e?"bg-brand-500 text-white border-brand-500":"bg-surface-2 text-text-muted border-border hover:bg-surface-3"}`,children:r})}function cT({workspace:e,fileBus:t,onOpenFile:s}){let[l,a]=(0,r.useState)(""),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),[f,h]=(0,r.useState)(""),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)([]),[C,S]=(0,r.useState)(!1),[E,R]=(0,r.useState)(!1),[T,$]=(0,r.useState)(new Set),[M,z]=(0,r.useState)(!1),P=(0,r.useRef)(null),I=(0,r.useCallback)(async()=>{if(!l||!e||!t?.searchInFiles){N([]),R(!1);return}S(!0);let s=await t.searchInFiles(e,l,{caseSensitive:c,wholeWord:u,regex:m,includeGlob:f,excludeGlob:b});if(S(!1),s?.success){R(!1);let e=s.results||[];N(e),$(new Set(e.map(e=>e.path)))}else R(!0),N([])},[l,e,t,c,u,m,f,b]);(0,r.useEffect)(()=>{if(P.current&&clearTimeout(P.current),!l){N([]),S(!1);return}return P.current=setTimeout(I,400),()=>clearTimeout(P.current)},[l,c,u,m,f,b,I]);let A=(0,r.useMemo)(()=>{let e=0;for(let t of k)e+=(t.matches||[]).length;return{files:k.length,matches:e}},[k]),L=(0,r.useCallback)(e=>{$(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),D=(0,r.useCallback)(async()=>{if(!l||!e||!t?.replaceInFiles||!k.length)return;let s=k.map(e=>e.path);S(!0),await t.replaceInFiles(e,l,i,{caseSensitive:c,wholeWord:u,regex:m,includeGlob:f,excludeGlob:b},s),S(!1),I()},[l,i,e,t,k,c,u,m,f,b,I]);return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text",children:[(0,n.jsxs)("div",{className:"px-3 pt-3 pb-2 space-y-2 border-b border-border",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(en.vj,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-subtle"}),(0,n.jsx)("input",{value:l,onChange:e=>a(e.target.value),placeholder:"Search",className:"w-full bg-surface-2 border border-border rounded-brand pl-7 pr-7 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),l&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),a("")},className:"absolute right-1 top-1/2 -translate-y-1/2 p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(en.X,{size:12})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,n.jsx)(cR,{active:c,onClick:()=>d(!c),title:"Match Case",children:"Aa"}),(0,n.jsx)(cR,{active:u,onClick:()=>x(!u),title:"Whole Word",children:"ab"}),(0,n.jsx)(cR,{active:m,onClick:()=>p(!m),title:"Regex",children:".*"}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)(cR,{active:w,onClick:()=>j(!w),title:"Toggle Replace",children:"↔"}),(0,n.jsx)(cR,{active:v,onClick:()=>y(!v),title:"Filters",children:"…"})]}),w&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{value:i,onChange:e=>o(e.target.value),placeholder:"Replace",className:"flex-1 bg-surface-2 border border-border rounded-brand px-2 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),(0,n.jsx)("button",{type:"button",disabled:!l||!k.length,onClick:()=>{(0,eo.e)(),z(!0)},className:"px-2 h-8 text-xs rounded-brand bg-brand-500 text-white hover:opacity-90 disabled:opacity-40 disabled:cursor-not-allowed",children:"Replace All"})]}),v&&(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("input",{value:f,onChange:e=>h(e.target.value),placeholder:"files to include",className:"w-full bg-surface-2 border border-border rounded-brand px-2 h-7 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),(0,n.jsx)("input",{value:b,onChange:e=>g(e.target.value),placeholder:"files to exclude",className:"w-full bg-surface-2 border border-border rounded-brand px-2 h-7 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"})]}),(0,n.jsx)("div",{className:`text-[11px] ${E?"text-danger":"text-text-muted"}`,children:C?"Searching...":E?"Search failed — try again":l?`${A.matches} results in ${A.files} files`:"Type to search"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:k.map(e=>{let t=T.has(e.path),r=function(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}(e.path),a=function(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(0,t):""}(e.path);return(0,n.jsxs)("div",{className:"border-b border-border/60",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),L(e.path)},className:"w-full flex items-center gap-1 px-2 py-1 hover:bg-surface-2 text-left",children:[t?(0,n.jsx)(en.yQ,{size:12,className:"text-text-subtle"}):(0,n.jsx)(en.c_,{size:12,className:"text-text-subtle"}),(0,n.jsx)("span",{className:"truncate text-xs text-text",title:e.path,children:r}),(0,n.jsx)("span",{className:"truncate text-[11px] text-text-muted flex-1",title:a,children:a}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 rounded-brand bg-surface-3 text-text-muted",children:e.matches?.length||0})]}),t&&(0,n.jsx)("div",{className:"pl-5",children:(e.matches||[]).map((t,r)=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),s?.(e.path,{line:t.line,column:t.column})},className:"w-full text-left px-2 py-0.5 text-[11px] text-text-muted hover:bg-surface-2 truncate font-mono",title:t.lineText,children:[(0,n.jsx)("span",{className:"text-text-subtle mr-2",children:t.line}),function(e,t,{caseSensitive:s,wholeWord:r,regex:l}){let a,i;if(!t)return e;try{let e=l?t:t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");r&&!l&&(e=`\\b${e}\\b`),a=new RegExp(e,s?"g":"gi")}catch{return e}let o=[],c=0,d=0;for(;null!==(i=a.exec(e))&&d++<500;)i.index>c&&o.push(e.slice(c,i.index)),o.push((0,n.jsx)("span",{className:"bg-brand-500/30 text-text rounded-sm",children:i[0]},`${i.index}-${d}`)),c=i.index+i[0].length,i.index===a.lastIndex&&a.lastIndex++;return c<e.length&&o.push(e.slice(c)),o}(t.lineText||"",l,{caseSensitive:c,wholeWord:u,regex:m})]},`${e.path}-${r}`))})]},e.path)})}),(0,n.jsx)(ei.A,{isOpen:M,onClose:()=>z(!1),onConfirm:D,title:"Replace All",message:`Replace ${A.matches} matches in ${A.files} files?`,confirmText:"Replace All",cancelText:"Cancel"})]})}let c$="px-3 my-2 text-[11px] uppercase tracking-wider text-text-muted",cM="flex items-center justify-between px-3 py-2 hover:bg-surface-2";function cz({value:e,onChange:t}){return(0,n.jsx)("button",{type:"button",onClick:()=>{(0,eo.e)(),t(!e)},className:`relative w-9 h-5 rounded-full transition-colors ${e?"bg-brand-500":"bg-surface-3"}`,children:(0,n.jsx)("span",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${e?"translate-x-4":"translate-x-0.5"}`})})}function cP(){let[e,t]=tK(F.d5.editorFontSize,F.A0),[s,r]=tK(F.d5.wordWrap,!1),[l,a]=tK("fileExplorer.showHidden",!0),i=e=>{t(Math.max(F.xr,Math.min(F.bd,Number(e)||F.A0)))};return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text overflow-auto",children:[(0,n.jsx)("div",{className:c$,children:"Editor"}),(0,n.jsxs)("div",{className:cM,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Font Size"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"range",min:F.xr,max:F.bd,value:e,onChange:e=>i(e.target.value),className:"w-24 accent-brand-500"}),(0,n.jsx)("input",{type:"number",min:F.xr,max:F.bd,value:e,onChange:e=>i(e.target.value),className:"w-12 bg-surface-2 border border-border rounded-brand px-1 h-6 text-xs text-text text-center focus:outline-none focus:border-brand-500"})]})]}),(0,n.jsxs)("div",{className:cM,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Word Wrap"}),(0,n.jsx)(cz,{value:s,onChange:r})]}),(0,n.jsx)("div",{className:c$,children:"Files"}),(0,n.jsxs)("div",{className:cM,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Show Hidden Files"}),(0,n.jsx)(cz,{value:l,onChange:a})]}),(0,n.jsx)("div",{className:c$,children:"About"}),(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-text-muted",children:"VSCode-like File Explorer for 9remote"})]})}let cI={[F.Kr.explorer]:"Explorer",[F.Kr.search]:"Search",[F.Kr.scm]:"Source Control",[F.Kr.settings]:"Settings"};function cA({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a}){let i=cI[e]||"",o=e===F.Kr.explorer;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[!o&&(0,n.jsxs)("div",{style:{height:32},className:"bg-surface px-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"uppercase tracking-wider text-xs text-text-muted",children:i}),(0,n.jsx)("button",{type:"button",title:"Refresh",onClick:()=>{(0,eo.e)(10),s?.refresh?.()},className:"w-7 h-7 flex items-center justify-center rounded-brand text-text-muted hover:text-text hover:bg-surface-2 transition-all duration-150 ease-out active:scale-[0.96]",children:(0,n.jsx)(en.e9,{size:14})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:function({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a}){switch(e){case F.Kr.explorer:return(0,n.jsx)(lg,{workspace:t,fileBus:s,onOpenFile:r,activeFile:a,onSwitchWorkspace:l});case F.Kr.search:return(0,n.jsx)(cT,{workspace:t,fileBus:s,onOpenFile:r});case F.Kr.scm:return(0,n.jsx)(lM,{workspace:t,fileBus:s,onOpenFile:r});case F.Kr.settings:return(0,n.jsx)(cP,{});default:return null}}({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a})})]})}function cL({openedFiles:e,activeFile:t,dirtyFiles:s,onActivate:l,onClose:a,onCloseOthers:i,onCloseAll:o}){let[c,d]=(0,r.useState)(null),u=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!c)return;let e=e=>{u.current&&!u.current.contains(e.target)&&d(null)};return window.addEventListener("mousedown",e),()=>window.removeEventListener("mousedown",e)},[c]),e?.length)?(0,n.jsxs)("div",{className:"flex overflow-x-auto bg-surface border-b border-border flex-shrink-0 relative",children:[e.map(e=>{let r=e===t,i=s?.has(e),o=(0,F.pA)(e),c=o?(0,F.Ax)(e).absPath:e,u=o?`${c.split("/").pop()} (diff)`:c.split("/").pop(),x=o?null:r6({name:c.split("/").pop()||c,type:"file",path:c},14);return(0,n.jsxs)("div",{onClick:()=>{(0,eo.e)(),l(e)},onMouseDown:t=>{1===t.button&&(t.preventDefault(),(0,eo.e)(),a(e))},onContextMenu:t=>{t.preventDefault(),d({path:e,x:t.clientX,y:t.clientY})},className:`group flex items-center gap-2 px-3 py-1.5 border-r border-border cursor-pointer text-sm flex-shrink-0 select-none ${r?"bg-bg text-text border-t-2 border-t-brand-500":"bg-surface text-text-muted hover:text-text"}`,children:[x?(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:x}):(0,n.jsx)(en.Ay,{name:"File",size:14,className:"text-text-muted"}),(0,n.jsx)("span",{className:"truncate max-w-[160px]",title:c,children:u}),i?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand-500 flex-shrink-0"}):null,(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,eo.e)(),a(e)},className:`p-0.5 rounded hover:bg-surface-3 transition-opacity ${r||i?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:(0,n.jsx)(en.X,{size:14})})]},e)}),c&&(0,n.jsx)("div",{ref:u,style:{top:c.y,left:c.x},className:"fixed z-50 bg-surface-2 border border-border rounded-brand shadow-lg py-1 text-sm min-w-[160px]",children:[{label:"Close",action:()=>a(c.path)},{label:"Close Others",action:()=>i(c.path)},{label:"Close All",action:()=>o()}].map(e=>(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),e.action(),d(null)},className:"w-full text-left px-3 py-1.5 text-text hover:bg-surface-3 transition-colors",children:e.label},e.label))})]}):null}function cD({workspace:e,filePath:t}){if(!t)return(0,n.jsx)("div",{className:"bg-bg border-b border-border px-3 py-1 text-xs text-text-muted h-7"});let s=e?e.split("/").filter(Boolean).pop():"",l=(e&&t.startsWith(e+"/")?t.slice(e.length+1):t).split("/").filter(Boolean),a=s?[s,...l]:l,i=a.length-1;return(0,n.jsx)("div",{className:"bg-bg border-b border-border px-3 py-1 text-xs text-text-muted flex items-center gap-1 overflow-x-auto whitespace-nowrap",children:a.map((e,t)=>(0,n.jsxs)(r.Fragment,{children:[(0,n.jsx)("span",{className:t===i?"text-text font-medium":"hover:text-text cursor-default",children:e}),t<i&&(0,n.jsx)(en.c_,{size:12,className:"flex-shrink-0"})]},t))})}function cB({filePath:e,workspace:t,fileBus:s,isActive:l,onCursorChange:a,onDirtyChange:i,onRegisterSaver:o,previewSeq:c=0}){let{t:d}=(0,ec.s)(),u=!(0,F.pA)(e)&&!lH(e),x=lU({filePath:u?e:"",fileBus:s}),m=u?(0,F.YO)(e):null,[p,f]=(0,r.useState)(!!c&&!!m),[h,b]=(0,r.useState)(0),[g,v]=(0,r.useState)(e),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(c);return(g!==e?(v(e),f(!1)):j!==c&&(k(c),c&&m&&f(!0)),x.justSaved!==y&&(w(x.justSaved),x.justSaved&&b(e=>e+1)),(0,r.useEffect)(()=>{i?.(e,u&&x.dirty)},[e,u,x.dirty,i]),(0,r.useEffect)(()=>{if(u)return o?.(e,x.save),()=>{o?.(e,null),i?.(e,!1)}},[e,u,x.save,o,i]),(0,r.useEffect)(()=>{if(!l||!u)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()&&(e.preventDefault(),x.save())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l,u,x]),(0,F.pA)(e))?(0,n.jsx)(ah,{diffPath:e,workspace:t,fileBus:s}):lH(e)?(0,n.jsx)(lq,{filePath:e,fileBus:s}):(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[x.error&&(0,n.jsx)("div",{className:"px-4 py-2 text-sm text-red-400 bg-red-500/15 border-b border-red-500/40 break-words",children:x.error}),m&&(0,n.jsx)("div",{className:"px-3 py-1.5 flex items-center justify-end bg-surface border-b border-border-subtle flex-shrink-0",children:(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),f(e=>!e)},title:d(p?"editor.editCode":"editor.preview"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:p?(0,n.jsx)(en.GD,{size:13}):(0,n.jsx)(en.kU,{size:13})})}),x.dirty&&(0,n.jsxs)("div",{className:"px-3 py-1.5 flex items-center gap-2 bg-surface border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("span",{className:"flex-1 text-[11px] text-text-muted",children:d("editor.unsaved")}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),x.save()},disabled:x.saving,className:"px-2.5 py-1 flex items-center gap-1.5 text-[11px] font-medium text-white bg-brand-500 hover:bg-brand-600 rounded-brand disabled:opacity-50 transition-colors",children:[(0,n.jsx)(en.eM,{size:12})," ",d(x.saving?"editor.saving":"editor.save")]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:p&&m?(0,n.jsx)(ad,{kind:m,filePath:e,fileBus:s,content:x.content,reloadKey:h}):x.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:d("common.loading")}):(0,n.jsx)(l9,{filePath:e,content:x.content,onTextChanged:x.onTextChanged,onRegisterView:x.register,onSave:x.save,onCursorChange:a})})]})}function cF({workspace:e,fileBus:t,openedFiles:s,activeFile:l,onActivateFile:a,onCloseFile:i,onCloseOthers:o,onCloseAll:c,onOpenFile:d,onEditorStateChange:u,previewRequest:x}){let[m,p]=(0,r.useState)(()=>new Set),[f,h]=(0,r.useState)(null),b=(0,r.useRef)(new Map);(0,r.useEffect)(()=>{if(!m.size)return;let e=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[m.size]);let g=(0,r.useCallback)((e,t)=>{p(s=>{if(s.has(e)===t)return s;let n=new Set(s);return t?n.add(e):n.delete(e),n})},[]),v=(0,r.useCallback)((e,t)=>{t?b.current.set(e,t):b.current.delete(e)},[]),y=(0,r.useCallback)(e=>{if(!m.has(e))return i?.(e);h(e)},[m,i]),w=(0,r.useCallback)(async e=>{for(let t of s.filter(t=>t!==e&&m.has(t)))if(!1===await b.current.get(t)?.())return;e?o?.(e):c?.()},[s,m,o,c]),j=(0,r.useCallback)(async()=>{!1!==await b.current.get(f)?.()&&(h(null),i?.(f))},[f,i]),k=(0,r.useCallback)(()=>{h(null),i?.(f)},[f,i]);return l?(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-bg min-h-0",children:[(0,n.jsx)(cL,{openedFiles:s,activeFile:l,dirtyFiles:m,onActivate:a,onClose:y,onCloseOthers:e=>w(e),onCloseAll:()=>w(null)}),(0,n.jsx)(cD,{workspace:e,filePath:l}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.map(s=>(0,n.jsx)("div",{className:s===l?"h-full":"hidden",children:(0,n.jsx)(cB,{filePath:s,workspace:e,fileBus:t,isActive:s===l,onCursorChange:u,onDirtyChange:g,onRegisterSaver:v,previewSeq:x?.path===s?x.seq:0})},s))}),(0,n.jsx)(lX,{isOpen:!!f,fileName:f?.split("/").pop(),onSave:j,onDiscard:k,onCancel:()=>h(null)})]}):(0,n.jsx)("div",{className:"flex-1 flex flex-col bg-bg min-h-0",children:(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-text-muted gap-3 p-6",children:[(0,n.jsx)(en.Bm,{size:64,className:"opacity-40"}),(0,n.jsx)("div",{className:"text-sm",children:"Open a file from the Explorer to get started"}),(0,n.jsxs)("div",{className:"text-xs flex items-center gap-2",children:[(0,n.jsx)("kbd",{className:"px-2 py-0.5 bg-surface-2 border border-border rounded text-text-subtle font-mono",children:"Cmd/Ctrl+P"}),(0,n.jsx)("span",{children:"Quick Open"})]})]})})}function cK({gitBranch:e,line:t,column:s,language:r,encoding:l,activeFile:a,sidebarVisible:i,onToggleSidebar:o,bottomVisible:c,onTogglePanel:d}){return(0,n.jsx)(rb,{left:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),o?.()},className:rg,title:i?"Hide Sidebar":"Show Sidebar",children:(0,n.jsx)(en.Ay,{name:i?"PanelLeftClose":"PanelLeftOpen",size:12})}),a&&(0,n.jsxs)("span",{className:rv,children:[(0,n.jsx)(en.Zr,{size:12,className:"opacity-60"}),e||"no branch"]})]}),right:(0,n.jsxs)(n.Fragment,{children:[d&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:rg,title:c?"Hide Terminal":"Show Terminal",children:(0,n.jsx)(en.Ay,{name:"Terminal",size:12})}),a&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:rv,children:`Ln ${t||1}, Col ${s||1}`}),(0,n.jsx)("span",{className:rv,children:r||"plaintext"}),(0,n.jsx)("span",{className:rv,children:l||"UTF-8"})]})]})})}let cO=ti()?"⌘":"Ctrl+",cW=[{id:"openExplorer",label:"View: Show Explorer",icon:"FolderOpen",shortcut:""},{id:"openSearch",label:"View: Show Search",icon:"Search",shortcut:""},{id:"openScm",label:"View: Show Source Control",icon:"GitBranch",shortcut:""},{id:"openSettings",label:"View: Show Settings",icon:"Settings",shortcut:""},{id:"toggleSidebar",label:"View: Toggle Sidebar Visibility",icon:"PanelLeft",shortcut:`${cO}B`},{id:"togglePanel",label:"View: Toggle Terminal Panel",icon:"Terminal",shortcut:`${cO}J`},{id:"closeAll",label:"View: Close All Editors",icon:"X",shortcut:""},{id:"switchWorkspace",label:"Workspaces: Switch Workspace",icon:"Folder",shortcut:""}];function c_({mode:e="files",onSetMode:t,workspace:s,fileBus:l,onClose:a,onOpenFile:i,onAction:o}){let[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(0),[m,p]=(0,r.useState)([]),[f,h]=(0,r.useState)(!1),b=(0,r.useRef)(null),g=(0,r.useRef)(null),v=(0,r.useMemo)(()=>{let e=c.trim().toLowerCase();return e?cW.filter(t=>t.label.toLowerCase().includes(e)):cW},[c]),y="commands"===e?v:m;(0,r.useEffect)(()=>{x(0)},[e,c,m]),(0,r.useEffect)(()=>{if("files"!==e)return;let t=c.trim();if(!t||!l||!s){p([]),h(!1);return}return h(!0),g.current&&clearTimeout(g.current),g.current=setTimeout(async()=>{let e=await l.searchFiles(s,t);p(e?.success&&Array.isArray(e.files)?e.files:[]),h(!1)},200),()=>{g.current&&clearTimeout(g.current)}},[c,e,l,s]);let w=(0,r.useCallback)(s=>{let n=s.target.value;if("files"===e&&n.startsWith(">")){t?.("commands"),d(n.slice(1));return}d(n)},[e,t]),j=(0,r.useCallback)(t=>{let s=y[t];s&&((0,eo.e)(8),"commands"===e?o?.(s.id):i?.(s.path),a?.())},[y,e,o,i,a]),k=(0,r.useCallback)(e=>{if("Escape"===e.key){e.preventDefault(),a?.();return}if("ArrowDown"===e.key){e.preventDefault(),x(e=>Math.min(e+1,Math.max(y.length-1,0)));return}if("ArrowUp"===e.key){e.preventDefault(),x(e=>Math.max(e-1,0));return}"Enter"===e.key&&(e.preventDefault(),j(u))},[y.length,u,a,j]),N="files"===e?"Type `>` for commands":"Type `?` for help",C="files"===e?"Search files by name…":"Type a command…";return(0,n.jsx)("div",{className:"fixed inset-0 z-50 bg-black/40",onMouseDown:a,children:(0,n.jsxs)("div",{className:"absolute top-20 left-1/2 -translate-x-1/2 w-[640px] max-w-[90vw] card-elev bg-surface border border-border rounded-brand overflow-hidden",onMouseDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border",children:[(0,n.jsx)(en.Ay,{name:"commands"===e?"Command":"Search",size:16,className:"text-text-muted"}),(0,n.jsx)("input",{ref:b,autoFocus:!0,type:"text",value:c,onChange:w,onKeyDown:k,placeholder:C,className:"flex-1 bg-transparent outline-none border-0 text-text placeholder:text-text-muted text-sm"}),(0,n.jsx)("span",{className:"text-xs text-text-muted hidden sm:inline",children:N})]}),(0,n.jsx)("div",{className:"max-h-[400px] overflow-auto",children:0===y.length?"files"!==e||c.trim()?f?(0,n.jsxs)("div",{className:"px-4 py-6 text-center text-text-muted text-sm flex items-center justify-center gap-2",children:[(0,n.jsx)(en.Ay,{name:"Loader2",size:14,className:"animate-spin"}),"Searching…"]}):(0,n.jsx)("div",{className:"px-4 py-10 text-center text-text-muted text-sm",children:"No results"}):(0,n.jsx)("div",{className:"px-4 py-10 text-center text-text-muted text-sm",children:"Start typing to search files in workspace"}):(0,n.jsx)("ul",{className:"py-1",children:y.map((t,s)=>{let r=s===u;if("commands"===e)return(0,n.jsxs)("li",{onMouseEnter:()=>x(s),onClick:()=>j(s),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${r?"bg-brand-500/20 text-text":"text-text-muted hover:bg-surface-2"}`,children:[(0,n.jsx)(en.Ay,{name:t.icon,size:16}),(0,n.jsx)("span",{className:"flex-1 text-sm",children:t.label}),t.shortcut?(0,n.jsx)("kbd",{className:"text-xs text-text-muted px-1.5 py-0.5 bg-surface-2 rounded",children:t.shortcut}):null]},t.id);let l=t.name||(t.path?t.path.split(/[\\/]/).pop():""),a=t.relativePath||t.path||"";return(0,n.jsxs)("li",{onMouseEnter:()=>x(s),onClick:()=>j(s),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${r?"bg-brand-500/20 text-text":"text-text-muted hover:bg-surface-2"}`,children:[(0,n.jsx)(en.Ay,{name:"File",size:16}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-sm font-semibold text-text truncate",title:l,children:l}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",title:a,children:a})]})]},t.path||s)})})})]})})}function cH({height:e,onResize:t,onClose:s,bus:l,connected:a,sessions:i=[],onCreateSession:o,onDeleteSession:c,onRenameSession:d}){let[u,x]=(0,r.useState)(i[0]?.id||null),m=(0,r.useRef)(null),p=(0,r.useRef)(!1);(0,r.useEffect)(()=>{0!==i.length&&(u&&i.find(e=>e.id===u)||x(i[0].id))},[i,u]),(0,r.useEffect)(()=>{0===i.length&&o&&!p.current&&(p.current=!0,o(e=>x(e))),i.length>0&&(p.current=!1)},[i.length,o]);let f=(0,r.useCallback)(()=>{(0,eo.e)(),o?.(e=>x(e))},[o]),h=(0,r.useCallback)((e,t)=>{e.stopPropagation(),(0,eo.e)(),c?.(t)},[c]),b=(0,r.useCallback)(e=>{e.preventDefault();let s=m.current?.parentElement;if(!s)return;let n=s.getBoundingClientRect(),r=e=>{if(0===e.buttons)return void l();let s=(n.bottom-e.clientY)/n.height*100;t(Math.max(F.kS,Math.min(F._C,s)))},l=()=>{window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),window.removeEventListener("blur",l),document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.body.style.cursor="row-resize",window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),window.addEventListener("blur",l)},[t]);return(0,n.jsxs)("div",{ref:m,className:"bg-bg border-t border-border flex flex-col flex-shrink-0",style:{height:`${e}%`},children:[(0,n.jsx)("div",{onMouseDown:b,className:"h-1 cursor-row-resize bg-border hover:bg-surface-3 transition-colors -mt-1 relative z-10"}),(0,n.jsxs)("div",{className:"bg-surface border-b border-border flex items-center px-2 flex-shrink-0 overflow-x-auto",children:[(0,n.jsxs)("div",{className:"flex items-center text-text-muted text-xs uppercase tracking-wider px-2 py-1.5 mr-1",children:[(0,n.jsx)(en.BK,{size:12,className:"mr-1"}),"Terminal"]}),i.map(e=>{let t=e.id===u;return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),x(e.id)},className:`group flex items-center gap-1.5 px-2 py-1.5 text-xs transition-colors max-w-[160px] ${t?"text-text bg-bg border-t-2 border-text-muted":"text-text-muted hover:text-text"}`,title:e.name,children:[(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)(en.X,{size:12,onClick:t=>h(t,e.id),className:"opacity-0 group-hover:opacity-100 hover:text-danger flex-shrink-0"})]},e.id)}),(0,n.jsx)("button",{onClick:f,className:"p-1 text-text-muted hover:text-text rounded hover:bg-surface-2 ml-1 flex-shrink-0",title:"New Terminal",children:(0,n.jsx)(en.FW,{size:14})}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),s()},className:"p-1 text-text-muted hover:text-text rounded hover:bg-surface-2 ml-1 flex-shrink-0",title:"Close Panel",children:(0,n.jsx)(en.X,{size:14})})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[i.map((e,t)=>(0,n.jsx)("div",{className:"absolute inset-0",style:{display:e.id===u?"block":"none"},children:(0,n.jsx)(nV,{bus:l,connected:a,sessionId:e.id,isVisible:e.id===u,isFocused:e.id===u,showFocusBorder:!1,bgIndex:t})},e.id)),0===i.length&&(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:"Creating terminal session..."})]})]})}function cq({workspace:e,fileBus:t,onBack:s,onSwitchWorkspace:l,initialOpenedFiles:a,onOpenedFilesChange:i,bus:o,connected:c,sessions:d,onCreateTerminalSession:u,onDeleteTerminalSession:x,onRenameTerminalSession:m,initialActiveFile:p,viewType:f,openFileRef:h}){let[b,g]=tK(F.d5.activityPanel,F.Kr.explorer);(0,r.useEffect)(()=>{"git"===f?g(F.Kr.scm):"files"===f&&g(F.Kr.explorer)},[f,g]);let[v,y]=tK(F.d5.sidebarVisible,!0),[w,j]=tK(F.d5.sidebarWidth,F.Qw),[k,N]=tK(F.d5.bottomPanelVisible,!1),[C,S]=tK(F.d5.bottomPanelHeight,F.LN),E=(0,r.useRef)(null),[R,T]=(0,r.useState)(!1),$=(0,r.useCallback)(e=>{e.preventDefault();let t=E.current;if(!t)return;let s=t.getBoundingClientRect();T(!0);let n=e=>{if(0===e.buttons)return void r();let t=(e.clientX-s.left)/s.width*100;j(Math.max(F.hh,Math.min(F.vd,t)))},r=()=>{window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",r),window.removeEventListener("blur",r),document.body.style.userSelect="",document.body.style.cursor="",T(!1)};document.body.style.userSelect="none",document.body.style.cursor="col-resize",window.addEventListener("mousemove",n),window.addEventListener("mouseup",r),window.addEventListener("blur",r)},[j]),[M,z]=(0,r.useState)(a||[]),[P,I]=(0,r.useState)(p||a?.[0]||null),[A,L]=(0,r.useState)({line:1,column:1,language:"",encoding:"UTF-8"}),[D,B]=(0,r.useState)(""),[K,O]=(0,r.useState)({path:null,seq:0}),[W,_]=(0,r.useState)(!1),[H,q]=(0,r.useState)("commands");(0,r.useEffect)(()=>{i?.(M,P)},[M,P,i]);let U=(0,r.useCallback)((e,t={})=>{z(t=>[e,...t.filter(t=>t!==e)].slice(0,F.L0)),I(e),t.line&&L(e=>({...e,jumpLine:t.line,jumpColumn:t.column})),t.preview&&O(t=>({path:e,seq:t.seq+1}))},[]);(0,r.useEffect)(()=>{h&&(h.current=U)},[h,U]);let V=(0,r.useCallback)(e=>{z(t=>{let s=t.filter(t=>t!==e);return P===e&&I(s[0]||null),s})},[P]),X=(0,r.useCallback)(e=>{z([e]),I(e)},[]),G=(0,r.useCallback)(()=>{z([]),I(null)},[]);return(0,r.useEffect)(()=>{e&&t&&t.gitBranch?.(e).then(e=>{e?.success&&B(e.branch||"")}).catch(()=>{})},[e,t]),!function({onToggleSidebar:e,onSave:t,onCloseTab:s,onCommandPalette:n,onQuickOpen:l,onTogglePanel:a}={}){let i=(0,r.useRef)({});(0,r.useEffect)(()=>{i.current={onToggleSidebar:e,onSave:t,onCloseTab:s,onCommandPalette:n,onQuickOpen:l,onTogglePanel:a}}),(0,r.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey,s=e.key.toLowerCase(),n=e.shiftKey,r=i.current;if(t&&n&&"p"===s||t&&!n&&"k"===s){e.preventDefault(),r.onCommandPalette?.();return}if(t&&!n&&"p"===s){e.preventDefault(),r.onQuickOpen?.();return}if(t&&!n&&"s"===s){e.preventDefault(),r.onSave?.();return}if(t&&!n&&"w"===s){e.preventDefault(),r.onCloseTab?.();return}if(t&&!n&&"b"===s){e.preventDefault(),r.onToggleSidebar?.();return}t&&!n&&"j"===s&&r.onTogglePanel&&(e.preventDefault(),r.onTogglePanel())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[])}({onToggleSidebar:()=>y(e=>!e),onTogglePanel:()=>N(e=>!e),onSave:()=>{window.dispatchEvent(new CustomEvent("fileExplorer:save"))},onCloseTab:()=>P&&V(P),onCommandPalette:()=>{q("commands"),_(!0)},onQuickOpen:()=>{q("files"),_(!0)}}),(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)(cE,{activePanel:b,onSelectPanel:e=>{b===e&&v?y(!1):(g(e),y(!0))},onBack:s}),(0,n.jsxs)("div",{ref:E,className:"flex-1 min-w-0 min-h-0 flex relative",children:[(0,n.jsx)("div",{className:`bg-surface flex-shrink-0 overflow-hidden min-h-0 flex flex-col ${R?"":"transition-[width] duration-200 ease-out"}`,style:{width:v?`${w}%`:0},"aria-hidden":!v,children:(0,n.jsx)(cA,{activePanel:b,workspace:e,fileBus:t,onOpenFile:U,onSwitchWorkspace:l,activeFile:P})}),(0,n.jsx)("div",{onMouseDown:$,className:`cursor-col-resize bg-border hover:bg-brand-500/50 flex-shrink-0 ${R?"":"transition-[width,background-color] duration-200 ease-out"} ${v?"w-1":"w-0"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 min-h-0 flex flex-col",children:[(0,n.jsx)(cF,{workspace:e,fileBus:t,openedFiles:M,activeFile:P,onActivateFile:I,onCloseFile:V,onCloseOthers:X,onCloseAll:G,onOpenFile:U,onEditorStateChange:L,previewRequest:K}),k&&o&&(0,n.jsx)(cH,{height:C,onResize:S,onClose:()=>N(!1),bus:o,connected:c,sessions:d,onCreateSession:u,onDeleteSession:x,onRenameSession:m})]})]})]}),(0,n.jsx)(cK,{gitBranch:D,line:A.line,column:A.column,language:A.language,encoding:A.encoding,activeFile:P,sidebarVisible:v,onToggleSidebar:()=>y(e=>!e),bottomVisible:k,onTogglePanel:()=>N(e=>!e)}),W&&(0,n.jsx)(c_,{mode:H,workspace:e,fileBus:t,onClose:()=>_(!1),onOpenFile:U,onSetMode:q,onAction:e=>{_(!1),"toggleSidebar"===e?y(e=>!e):"togglePanel"===e?N(e=>!e):"closeAll"===e?G():"switchWorkspace"===e?l?.():"openExplorer"===e?(g(F.Kr.explorer),y(!0)):"openSearch"===e?(g(F.Kr.search),y(!0)):"openScm"===e?(g(F.Kr.scm),y(!0)):"openSettings"===e&&(g(F.Kr.settings),y(!0))}})]})}function cU({isOpen:e,onClose:t}){let{t:s}=(0,ec.s)(),l=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!e)return;document.activeElement?.blur?.();let s=requestAnimationFrame(()=>{l.current?.focus()}),n=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener("keydown",n,!0),()=>{cancelAnimationFrame(s),window.removeEventListener("keydown",n,!0)}},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:t}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",tabIndex:-1,className:"relative card-elev max-w-md w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200 outline-none",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:s("shortcuts.title")}),(0,n.jsx)("button",{ref:l,onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out focus:outline-none focus:ring-2 focus:ring-brand-500/40","aria-label":s("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable px-5 pb-5",children:(0,n.jsx)("ul",{className:"flex flex-col divide-y divide-border-subtle/40",children:tr.map(e=>(0,n.jsxs)("li",{className:"flex items-center justify-between gap-4 py-2 first:pt-1",children:[(0,n.jsx)("span",{className:"text-sm text-text min-w-0 truncate",children:s(`shortcuts.${e.id}`)}),(0,n.jsx)("span",{className:"inline-flex items-center gap-1 flex-shrink-0",children:tu(e).map(e=>(0,n.jsx)("kbd",{className:tc,children:e},e))})]},e.id))})})]})]}):null}function cV({retryStatus:e,approvalStatus:t,connected:s,onLogout:r,onRetryNow:l,suppress:a=!1,firstConnect:i=!1}){let{t:o}=(0,ec.s)(),c=t===z.J2.pending||t===z.J2.rejected;if(a&&!c)return null;let d=()=>{r?r():(sessionStorage.clear(),window.location.replace("/login"))};return t===z.J2.pending?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(oT.A,{size:"lg"}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.waitingApproval")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.approvalDescription")}),(0,n.jsx)("p",{className:"text-text-muted text-sm mt-1",children:o("connection.approvalHint")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:"mt-4 w-full py-2 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.cancel")})]})})}):t===z.J2.rejected?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto bg-red-500/20 rounded-full flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-8 h-8 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"})})}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.rejectedTitle")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.rejectedDescription")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:"mt-6 w-full py-3 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.backToLogin")})]})})}):s||!e?.isRetrying&&!e?.failed||i&&!e?.failed||e?.isRetrying&&e.attempt<z.si?null:(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:e.isRetrying?(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(oT.A,{size:"lg"}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.retrying")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.attemptOf",{n:e.attempt,total:e.maxAttempts})}),(0,n.jsx)("div",{className:"mt-4 w-full bg-surface-2 rounded-full h-2",children:(0,n.jsx)("div",{className:"bg-brand-500 h-2 rounded-full transition-all duration-300",style:{width:`${e.attempt/e.maxAttempts*100}%`}})}),l&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),l()},className:"mt-4 w-full py-2 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:"mt-2 w-full py-2 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.exit")})]}):(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto bg-red-500/20 rounded-full flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-8 h-8 text-red-500",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)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.failed")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.failedDescription",{n:e.maxAttempts})}),l&&(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),l()},className:"mt-6 w-full py-3 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),d()},className:`w-full py-3 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98] ${l?"mt-2":"mt-6"}`,children:o("connection.backToLogin")})]})})})}let cX={remote:en.VA,mobile:en.wO,sites:en.qz,notifications:en.Ir,folder:en.Bm,note:en.y8},cG=e=>{let t={hiddenHeaderButtons:e.hiddenHeaderButtons,toggleHeaderButton:e.toggleHeaderButton};for(let s of eV.Fz)"pane"===s.group&&(t[s.storeKey]=e[s.storeKey],t[s.setterKey]=e[s.setterKey]);return t};function cJ(){let e=(0,h.B)((0,D.k)(cG));return{buttons:eV.Fz,isOn:t=>"header"===t.group?!e.hiddenHeaderButtons.includes(t.id):!!e[t.storeKey],toggle:t=>"header"===t.group?e.toggleHeaderButton(t.id):e[t.setterKey](!e[t.storeKey])}}function cY(e,t){let s=!!window.ReactNativeWebView,n=s||"u">typeof navigator&&"serviceWorker"in navigator&&"PushManager"in window,[l,a]=(0,r.useState)(()=>!!window.ReactNativeWebView&&"1"!==localStorage.getItem(eI)),[i,o]=(0,r.useState)(!1);(0,r.useEffect)(()=>{s||"serviceWorker"in navigator&&"PushManager"in window&&navigator.serviceWorker.ready.then(e=>e.pushManager?.getSubscription()).then(e=>a(!!e)).catch(()=>{})},[s]);let c=(0,r.useCallback)(async()=>{if(!i){if((0,eo.e)(),o(!0),l)await t?.(),a(!1);else{await e?.();let t=s;if(!s&&"serviceWorker"in navigator&&"PushManager"in window)try{let e=await navigator.serviceWorker.ready;t=!!await e.pushManager?.getSubscription()}catch{t=!1}a(t)}o(!1)}},[l,i,e,t,s]);return{supported:n,enabled:l,loading:i,toggle:c,isExpoWebView:s}}function cZ(e,t){let s=(0,h.B)(e=>e.artifactEnabled),n=(0,h.B)(e=>e.setArtifactEnabled),l=!!(0,h.B)(e=>e.agentCaps?.artifact),[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(!0);(0,r.useEffect)(()=>()=>{o.current=!1},[]),!t&&a&&i(!1);let c=(0,r.useCallback)(r=>{let l=e?.current;if(!l||!t||a)return;(0,eo.e)();let c="boolean"==typeof r?r:!s;i(!0),n(c),l.emit("setArtifactEnabled",{enabled:c},e=>{o.current&&(i(!1),e?.success||n(!c))})},[e,t,a,s,n]);return{supported:l,enabled:s,loading:a,toggle:c}}var cQ=s(52345);let c0=cQ.dI.filter(e=>tM[e.code]);function c1({isOpen:e,value:t,onSelect:s,onClose:l}){let{t:a}=(0,ec.s)();return((0,r.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[e,l]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:l}),(0,n.jsxs)("div",{className:"relative card-elev max-w-lg w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:a("voice.language")}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":a("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable p-3",children:(0,n.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:c0.map(e=>{let r=e.code===t;return(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.code,void((0,eo.e)(),s(t),l())},className:`px-2 py-2 rounded-brand flex items-center gap-2 transition-all duration-150 ease-out active:scale-[0.97] min-w-0 ${r?"bg-brand-500 text-white":"text-text hover:bg-surface-2"}`,children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${e.country}.png`,alt:e.label,className:"w-[17px] h-[12px] object-cover rounded-[2px] flex-shrink-0",loading:"lazy"}),(0,n.jsx)("span",{className:"flex-1 text-sm font-medium truncate text-left",children:e.label}),r&&(0,n.jsx)(en.aJ,{size:14,className:"flex-shrink-0"})]},e.code)})})})]})]}):null}let c2="w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs font-mono text-text placeholder-text-muted focus:outline-none focus:border-brand-500",c5="px-3 py-1.5 rounded-brand text-xs font-medium transition-colors",c3=[{value:"browser",label:"Browser"},{value:"ai",label:"AI Speech To Text"}];function c4({active:e,onClick:t,children:s}){return(0,n.jsx)("button",{type:"button",onClick:t,className:`px-2.5 py-1 rounded-brand text-[11px] border transition-colors ${e?"border-brand-500 bg-brand-500/10 text-brand-400":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"}`,children:s})}function c6({state:e}){if(!e)return null;let t=e.busy?"text-text-muted animate-pulse":e.ok?"text-green-500":"text-red-400";return(0,n.jsx)("p",{className:`text-[11px] leading-relaxed break-words ${t}`,children:e.msg})}function c8({onClose:e}){let t=$(),{mode:s,setMode:l,preset:a,setPreset:i,setField:o}=t,{locale:c}=(0,ec.s)(),[d,u]=tI(c),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(null),[h,b]=(0,r.useState)(null),v=p?.busy||h?.busy,N=cQ.dI.find(e=>e.code===d),C="gemini"===a?t.geminiKeys.some(e=>e.trim()):"openrouter"===a?!!t.openrouterKey.trim():!!t.customKey.trim(),R="custom"===a?t.customModel:(t[`${a}Model`]||"").trim()||y[a].model,T=async()=>{(0,eo.e)(),f({busy:!0,msg:"Testing…"});try{let e=S($.getState());await w(e,{model:e.model,messages:[{role:"user",content:"hi"}],max_tokens:1}),f({ok:!0,msg:"Key & model OK"})}catch(e){f({ok:!1,msg:j(e)})}},M=async()=>{if((0,eo.e)(),!C)return void b({ok:!1,msg:"Enter an API key first"});b({busy:!0,msg:"Recording…"});try{let e=await E($.getState(),await k());b({ok:!!e,msg:e||"(empty reply)"})}catch(e){b({ok:!1,msg:j(e)})}};return(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:e}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:"Voice input"}),(0,n.jsx)("button",{onClick:e,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":"Close",children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable px-5 pb-5 flex flex-col gap-3",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,eo.e)(),m(!0)},className:"w-full px-3 py-2 rounded-brand bg-surface-2/50 text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors",children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:"Language"}),N&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 text-xs text-text-muted",children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${N.country}.png`,alt:"",className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{children:N.label})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:c3.map(e=>(0,n.jsx)(c4,{active:s===e.value,onClick:()=>{(0,eo.e)(),l(e.value)},children:e.label},e.value))}),"browser"===s?(0,n.jsx)("p",{className:"text-xs leading-relaxed text-text-muted",children:"Uses the browser's built-in speech recognition (Chrome, Safari, Edge). Not available in Firefox."}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:Object.entries(y).map(([e,t])=>(0,n.jsx)(c4,{active:a===e,onClick:()=>{(0,eo.e)(),i(e)},children:t.label},e))}),(0,n.jsxs)("p",{className:`text-[11px] leading-relaxed ${C?"text-text-muted":"text-amber-500"}`,children:["custom"===a?"Any OpenAI-compatible /chat/completions endpoint":`${y[a].note}`,!C&&" \xb7 No key yet"]}),"custom"!==a&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Model"}),(0,n.jsx)("input",{type:"text",value:t[`${a}Model`]||"",onChange:e=>o(`${a}Model`,e.target.value),placeholder:R,className:c2,autoComplete:"off"})]}),"gemini"===a&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-semibold text-text",children:"API keys — one per line"}),(0,n.jsxs)("a",{href:"https://aistudio.google.com/app/apikey",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-[11px] text-brand-500 hover:text-brand-400 hover:underline transition-colors",children:["AI Studio ",(0,n.jsx)(en.Gr,{size:10})]})]}),(0,n.jsx)("textarea",{rows:3,value:t.geminiKeys.join("\n"),onChange:e=>o("geminiKeys",e.target.value.split("\n")),placeholder:"AIza…\nAIza…",className:`${c2} resize-y`,autoComplete:"off"})]}),"openrouter"===a&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-semibold text-text",children:"API key"}),(0,n.jsxs)("a",{href:"https://openrouter.ai/settings/keys",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-[11px] text-brand-500 hover:text-brand-400 hover:underline transition-colors",children:["OpenRouter ",(0,n.jsx)(en.Gr,{size:10})]})]}),(0,n.jsx)("input",{type:"password",value:t.openrouterKey,onChange:e=>o("openrouterKey",e.target.value),placeholder:"sk-or-…",className:c2,autoComplete:"off"})]}),"custom"===a&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Endpoint"}),(0,n.jsx)("input",{type:"text",value:t.customEndpoint,onChange:e=>o("customEndpoint",e.target.value),placeholder:g,className:c2,autoComplete:"off"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Model"}),(0,n.jsx)("input",{type:"text",value:t.customModel,onChange:e=>o("customModel",e.target.value),placeholder:"e.g. google/gemini-2.5-flash",className:c2,autoComplete:"off"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"API key"}),(0,n.jsx)("input",{type:"password",value:t.customKey,onChange:e=>o("customKey",e.target.value),placeholder:"sk-…",className:c2,autoComplete:"off"})]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:T,disabled:v,className:`${c5} bg-brand-500 hover:bg-brand-600 text-white disabled:opacity-50`,children:"Test key"}),(0,n.jsx)("button",{type:"button",onClick:M,disabled:v,className:`${c5} bg-surface-2/70 hover:bg-surface-2 text-text disabled:opacity-50`,children:"Test voice"})]}),p&&(0,n.jsx)(c6,{state:p}),h&&(0,n.jsx)(c6,{state:h})]})]})]}),x&&(0,n.jsx)(c1,{isOpen:x,value:d,onSelect:u,onClose:()=>m(!1)})]})}function c9({dense:e=!1}){let t=$(e=>e.enabled),s=$(e=>e.mode),l=$(e=>e.preset),a=$(e=>e.setEnabled),[i,o]=(0,r.useState)(!1),c="ai"===s?y[l]?.label||"AI":"Browser",d=()=>{(0,eo.e)(),o(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:e?"w-full py-1 text-sm text-text flex items-center gap-2.5 cursor-pointer select-none":"w-full px-3 py-2 rounded-brand flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 cursor-pointer select-none transition-colors",onClick:d,children:[(0,n.jsx)(en.GO,{size:16,className:`${e?"text-text":"text-brand-500"} flex-shrink-0`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"truncate",children:"Voice input"}),(0,n.jsx)("span",{className:"text-xs text-text-muted shrink-0",children:c})]}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:"Speak instead of typing — chat, terminal, remote"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Voice configuration","aria-label":"Voice configuration",className:"shrink-0 px-2 h-7 flex items-center justify-center rounded-brand border border-border-subtle/60 hover:border-border hover:bg-surface-3/50 text-text-muted hover:text-text text-xs transition-colors",children:"Config"}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,eo.e)(),a(!t)},"aria-label":"Toggle voice input",className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${t?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${t?"translate-x-4":"translate-x-0.5"}`})})]}),i&&(0,n.jsx)(c8,{onClose:()=>o(!1)})]})}function c7({onRemote:e,onFiles:t,onCommandNotes:s,onCommunity:l,onInstallApp:a,canInstall:i=!1,isInstalled:o=!1,onLogout:c,connected:d=!0,remoteAvailable:u=!1,showTheme:x=!1,theme:m="default",onThemeChange:p,hideActions:f=[],busRef:b=null,subscribeToPush:g=null,unsubscribeFromPush:v=null,onOpenBackgroundPicker:y}){let{t:w}=(0,ec.s)(),j=tF(),k=tf(e=>e.open),N=eb(e=>e.close),{connectionMode:C="tunnel",agentVersion:S}=eb(e=>e.context),E=cJ(),R=ne(e=>!1),T=(0,h.B)(e=>e.webglEnabled),$=(0,h.B)(e=>e.setWebglEnabled),M=(0,h.B)(e=>e.fontSize),z=(0,h.B)(e=>e.setFontSize),P=(0,h.B)(e=>e.terminalTheme),I=(0,h.B)(e=>e.setTerminalTheme),A=(0,h.B)(e=>e.terminalBackgrounds),{theme:L}=(0,n_.D)(),[D,B]=(0,r.useState)(!1),[F,K]=(0,r.useState)(!1),[O,W]=(0,r.useState)(!1),[_,H]=(0,r.useState)(!1),[q,U]=(0,r.useState)(!1),V=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!D)return;let e=e=>{V.current&&!V.current.contains(e.target)&&B(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[D]);let X=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!_)return;let e=e=>{X.current&&!X.current.contains(e.target)&&H(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[_]);let[G,J]=(0,r.useState)(!1);(0,r.useEffect)(()=>{J(window.innerWidth<768)},[]);let Y=cY(g,v),Z=cZ(b,d),Q=Y.isExpoWebView||!!window.ReactNativeWebView||/9Remote-Mobile/i.test(navigator.userAgent),ee=window.matchMedia("(display-mode: standalone)").matches||Q,[et,es]=(0,r.useState)(()=>window.CURRENT_ORIENTATION||localStorage.getItem("expo_orientation")||"portrait");return(0,r.useEffect)(()=>{if(!Q)return;let e=e=>{if(e){es(e);try{localStorage.setItem("expo_orientation",e)}catch{}}};window.handleScreenOrientationChange=e;try{window.ReactNativeWebView?.postMessage(JSON.stringify({type:"GET_SCREEN_ORIENTATION"}))}catch{}return()=>{window.handleScreenOrientationChange===e&&(window.handleScreenOrientationChange=void 0)}},[Q]),(0,r.useCallback)(e=>{(0,eo.e)(),es(e);try{localStorage.setItem("expo_orientation",e)}catch{}try{window.ReactNativeWebView?.postMessage(JSON.stringify({type:"SET_SCREEN_ORIENTATION",orientation:e}))}catch{}},[]),(0,n.jsxs)("div",{className:"p-3 space-y-0.5",children:[!ee&&!o&&a&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),a()},className:"w-full px-3 py-1.5 mb-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.f5,{className:"text-brand-500 flex-shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0 truncate",children:w("menu.installApp")}),i&&(0,n.jsx)("span",{className:"flex-shrink-0 px-2 py-0.5 bg-brand-500 text-white text-xs font-medium rounded-full",children:w("pwaGuide.installNow")})]}),Y.supported&&(0,n.jsxs)("button",{onClick:Y.toggle,disabled:Y.loading,className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 disabled:opacity-50 text-text rounded-brand-lg text-left flex items-center justify-between gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(en.Ir,{className:"text-brand-500",size:16}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsx)("span",{className:"text-sm",children:w("menu.notifications")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:w("menu.notificationsHint")})]})]}),Y.loading?(0,n.jsx)(en.kr,{className:"animate-spin text-text-muted",size:16}):(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Y.enabled?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${Y.enabled?"translate-x-4":"translate-x-0.5"}`})})]}),!f.includes("headerButtons")&&(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),K(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.jz,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.settingsButtons")}),(0,n.jsx)(en.yQ,{className:`text-text-muted transition-transform duration-200 ${F?"rotate-180":""}`,size:16})]}),F&&(0,n.jsx)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:eV.GL.map(({group:e,titleKey:t})=>(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)("p",{className:"pt-1 text-[11px] font-semibold uppercase tracking-wide text-text-muted",children:w(t)}),E.buttons.filter(t=>t.group===e).map(e=>{if("remote"===e.id||"mobile"===e.id)return null;let t=cX[e.id],s=E.isOn(e);return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),E.toggle(e)},className:"w-full py-1 hover:bg-surface-2 text-text rounded-brand text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(t,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w(e.labelKey)}),(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${s?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-0.5"}`})})]},e.id)})]},e))})]}),!f.includes("terminalSettings")&&(0,n.jsxs)("div",{ref:V,className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),B(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.BK,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.terminalSettings")}),(0,n.jsx)(en.yQ,{className:`text-text-muted transition-transform duration-200 ${D?"rotate-180":""}`,size:16})]}),D&&(0,n.jsxs)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),$(!T)},className:"w-full py-1 hover:bg-surface-2 text-text rounded-brand text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.VA,{className:"text-text",size:16}),(0,n.jsxs)("div",{className:"flex flex-col flex-1",children:[(0,n.jsx)("span",{className:"text-sm",children:w("menu.webgl")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:w("menu.webglHint")})]}),(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${T?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${T?"translate-x-4":"translate-x-0.5"}`})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 pt-1.5",children:[(0,n.jsx)(en.ZU,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.fontSize")}),(0,n.jsx)("select",{value:M??(G?12:14),onChange:e=>{(0,eo.e)(),z(Number(e.target.value))},className:"ml-auto bg-surface-2 text-text text-sm rounded-brand px-2 py-1 focus:outline-none focus:ring-2 focus:ring-brand-500/40",children:Array.from({length:G?7:9},(e,t)=>t+10).map(e=>(0,n.jsxs)("option",{value:e,children:[e,"px"]},e))})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(en.es,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.terminalTheme")}),(0,n.jsxs)("select",{value:P,onChange:e=>{(0,eo.e)(),I(e.target.value)},className:"ml-auto bg-surface-2 text-text text-xs rounded-brand px-2 py-1 max-w-[55%] focus:outline-none focus:ring-2 focus:ring-brand-500/40",children:[(0,n.jsx)("option",{value:"default",children:"Vesper (Default)"}),nT.g4.filter(e=>e.mode===L).map(e=>(0,n.jsx)("option",{value:e.key,children:e.label},e.key))]})]})]})]}),(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),W(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.Kq,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.settingsMcp")}),(0,n.jsx)(en.yQ,{className:`text-text-muted transition-transform duration-200 ${O?"rotate-180":""}`,size:16})]}),O&&(0,n.jsxs)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:[(0,n.jsx)(c9,{dense:!0}),Z.supported&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(en.jz,{className:"text-text shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0",children:w("menu.artifactPanel")}),(0,n.jsx)("button",{onClick:Z.toggle,disabled:Z.loading||!d,className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors disabled:opacity-60 ${Z.enabled?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${Z.enabled?"translate-x-4":"translate-x-0.5"}`})})]}),(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-text-muted",children:w("menu.artifactHint")})]})]})]}),"dark"===L&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),y?.()},className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.de,{className:"text-brand-500 flex-shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0",children:w("menu.terminalBackground")}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate max-w-[90px]","data-tip":A.length>1?`${(0,eV.Pz)(A[0])} +${A.length-1}`:(0,eV.Pz)(A[0]),children:A.length>1?`${(0,eV.Pz)(A[0])} +${A.length-1}`:(0,eV.Pz)(A[0])}),(0,n.jsx)(en.c_,{size:16,className:"text-text-muted flex-shrink-0"})]}),R&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),N(),ne.getState().toggle()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(en.cC,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:"Jarvis"})]}),s&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),s()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(en.iU,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.commandNotes")})]}),"mouse"===j&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),N(),k()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(en.s3,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("shortcuts.menuLabel")})]}),l&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),l()},className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.zW,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.community")})]}),(0,n.jsxs)("div",{ref:X,className:"rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),H(e=>!e)},className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.e9,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.reloadRestart")}),(0,n.jsx)(en.yQ,{className:`text-text-muted transition-transform duration-200 ${_?"rotate-180":""}`,size:16})]}),_&&(0,n.jsx)("div",{className:"bg-surface-2/50 px-3 pb-1.5 space-y-0",children:(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),U(!0),setTimeout(()=>window.location.reload(),150)},disabled:q,className:"w-full py-1.5 text-text text-left flex items-center gap-2.5 rounded-brand transition duration-150 ease-out hover:text-brand-500 active:scale-[0.99] disabled:opacity-70",children:[(0,n.jsx)(en.e9,{size:16,className:`ml-3 ${q?"animate-spin":""}`}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.reload")})]})})]}),c&&(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),c()},className:"w-full px-3 py-1.5 bg-surface hover:bg-red-500/15 text-text hover:text-red-400 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(en.nU,{className:"text-red-400",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.logout")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 mt-4 mr-1",children:["local"===C&&(0,n.jsx)("span",{className:"text-xs font-semibold px-2 py-0.5 rounded-full bg-green-500/15 text-green-400",children:"LAN"}),(0,n.jsxs)("p",{className:"text-text-muted text-sm",children:[w("menu.version")," ","3.0.25",S?` / 9Remote ${S}`:""]})]})]})}var de=s(2163);function dt(){if("u"<typeof navigator)return"unknown";let e=navigator.userAgent.toLowerCase();return/iphone|ipad|ipod/.test(e)?"ios":/android/.test(e)?"android":/mac/.test(e)?"macos":/win/.test(e)?"windows":"desktop"}function ds(){let{t:e}=(0,ec.s)(),[t]=(0,r.useState)(dt),[s,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)("idle"),o=eb(e=>e.context.apiKey),c=eG(e=>e.canInstall),d=eG(e=>e.isInstalled),u=eG(e=>e.install),x=async()=>{i("installing"),i("accepted"===await u()?"done":"idle")},m=async e=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return!1}},p=async()=>{!o||await m(o)&&(l(!0),setTimeout(()=>l(!1),2e3))},f=+!!o,h=()=>o?(0,n.jsxs)("div",{className:"flex items-start gap-3 mb-4",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:"1"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-2",children:e("pwaGuide.copyYourKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm mb-2",children:e("pwaGuide.copyKeyHint")}),(0,n.jsxs)("div",{className:`w-full flex items-center justify-between gap-2 px-3 py-2.5 rounded-brand border transition-colors ${s?"bg-green-500/10 border-green-500/30":"bg-bg border-border hover:border-brand-500/50 focus-within:border-brand-500/50"}`,children:[(0,n.jsx)("button",{type:"button",onClick:p,className:"flex-1 min-w-0 text-left bg-transparent outline-none border-0 p-0 cursor-pointer","aria-label":e("pwaGuide.tapToCopyApiKey"),children:(0,n.jsx)("code",{className:"block text-sm text-text font-mono truncate",children:(0,de.o)(o)})}),(0,n.jsx)("button",{type:"button",onClick:p,className:`flex items-center gap-1 text-sm flex-shrink-0 ${s?"text-green-400":"text-brand-500"}`,children:s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(en.aJ,{size:14})," ",e("pwaGuide.copiedBang")]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(en.QR,{size:14})," ",e("pwaGuide.copy")]})})]})]})]}):null,b=()=>c?(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.installNow")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.installNowHint")})]}),(0,n.jsxs)("button",{type:"button",onClick:x,disabled:"installing"===a,className:"flex-shrink-0 flex items-center gap-1 px-3 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-medium rounded-brand transition-all duration-150 active:scale-[0.97] disabled:opacity-70 disabled:cursor-wait",children:[(0,n.jsx)(en.f5,{size:14}),"installing"===a?e("pwaGuide.installing"):e("pwaGuide.installNow")]})]}):null;return d?(0,n.jsx)("div",{className:"p-6",children:(0,n.jsxs)("div",{className:"text-center py-12",children:[(0,n.jsx)("div",{className:"inline-flex p-4 bg-green-500/10 rounded-brand-lg mb-4",children:(0,n.jsx)(en.aJ,{className:"text-green-500",size:48})}),(0,n.jsx)("p",{className:"text-text font-semibold mb-2",children:e("pwaGuide.alreadyInstalled")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.alreadyInstalledHint")})]})}):(0,n.jsxs)("div",{className:"p-6 space-y-6",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 pb-4 border-b border-border",children:[(0,n.jsx)("div",{className:"p-2 bg-brand-500/10 rounded-brand",children:(()=>{switch(t){case"ios":case"android":return(0,n.jsx)(en.wO,{className:"text-brand-500",size:24});default:return(0,n.jsx)(en.VA,{className:"text-brand-500",size:24})}})()}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-text font-medium",children:e("pwaGuide.installationGuide")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:(()=>{switch(t){case"ios":return e("pwaGuide.iosPlatform");case"android":return e("pwaGuide.androidPlatform");case"macos":return e("pwaGuide.macosPlatform");case"windows":return e("pwaGuide.windowsPlatform");default:return e("pwaGuide.desktopPlatform")}})()})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-text font-medium mb-4",children:e("pwaGuide.installationSteps")}),(()=>{switch(t){case"ios":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1.5",children:"Download 9Remote on App Store"}),(0,n.jsxs)("a",{href:"https://apps.apple.com/us/app/9remote/id6796664210",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-semibold rounded-brand transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.81-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M15.97 6.38c.62-.75 1.04-1.8 0.92-2.85-.9.04-2 .6-2.65 1.35-.58.66-1.09 1.73-.95 2.76.99.08 2.03-.51 2.68-1.26z"})}),"Get on App Store"]})]})]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]})]});case"android":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1.5",children:"Download 9Remote on Google Play"}),(0,n.jsxs)("a",{href:"https://play.google.com/store/apps/details?id=cc.remote9.app&pli=1",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-semibold rounded-brand transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M3.609 1.814L13.793 12 3.61 22.186a2.128 2.128 0 0 1-.22-.964V2.778c0-.36.08-.694.22-.964zm11.233 11.234l2.584 2.584-11.834 6.83 9.25-9.414zm0-2.096L5.592 1.538l11.834 6.83-2.584 2.584zm1.485 1.048l3.633 2.098a1.328 1.328 0 0 0 0-2.296l-3.633-2.098-1.048 1.048 1.048 1.048z"})}),"Get on Google Play"]})]})]}),c&&(0,n.jsxs)("div",{className:"pt-2 border-t border-border",children:[(0,n.jsx)("p",{className:"text-xs text-text-muted mb-2",children:"Or install directly as Web App (PWA):"}),b()]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]})]});case"macos":case"windows":case"desktop":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),b(),c&&(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]}),!c&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.lookInstallIcon")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.lookInstallIconHint")})]})]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.clickInstallPaste")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.clickInstallPasteHint")})]})]}),(0,n.jsx)("div",{className:"mt-6 p-3 bg-blue-500/10 rounded-brand",children:(0,n.jsxs)("p",{className:"text-blue-200 text-sm",children:["\uD83D\uDCA1 ",e("pwaGuide.alternativeHint")]})})]})]});default:return(0,n.jsx)("p",{className:"text-text-muted text-center py-8",children:e("pwaGuide.loadingPlatform")})}})()]})]})}let dn=[{command:"npm i 9router -g"},{command:"curl -fsSL https://claude.ai/install.sh | bash"},{command:"npm i -g @openai/codex"},{command:"curl -fsSL https://opencode.ai/install | bash"}],{storageKey:dr,maxNotes:dl}={storageKey:"9remote_command_notes_v2",maxNotes:50};function da({isOpen:e,onClose:t}){let{t:s}=(0,ec.s)(),{notes:l,addNote:a,updateNote:i,deleteNote:o}=function(){let[e,t]=(0,r.useState)([]),s=(0,r.useCallback)(()=>{try{let e=localStorage.getItem(dr);if(e)return JSON.parse(e);let t=dn.map((e,t)=>({id:`default_${t}`,...e}));return localStorage.setItem(dr,JSON.stringify(t)),t}catch(e){return console.error("Failed to load command notes:",e),[]}},[]);(0,r.useEffect)(()=>{t(s())},[s]);let n=(0,r.useCallback)(e=>{try{localStorage.setItem(dr,JSON.stringify(e)),t(e)}catch(e){console.error("Failed to persist command notes:",e)}},[]),l=(0,r.useCallback)(t=>{n([{id:Date.now().toString(),command:t},...e].slice(0,dl))},[e,n]),a=(0,r.useCallback)((t,s)=>{n(e.map(e=>e.id===t?{...e,command:s}:e))},[e,n]),i=(0,r.useCallback)(t=>{n(e.filter(e=>e.id!==t))},[e,n]);return{notes:e,addNote:l,updateNote:a,deleteNote:i}}(),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(null),[m,p]=(0,r.useState)(""),f=(0,r.useRef)(null),[h,b]=(0,r.useState)(null);(0,r.useEffect)(()=>{e&&setTimeout(()=>f.current?.focus(),100)},[e,u]),(0,r.useEffect)(()=>{if(!e||!window.visualViewport)return;let t=window.visualViewport,s=()=>b(t.height);return s(),t.addEventListener("resize",s),t.addEventListener("scroll",s),()=>{t.removeEventListener("resize",s),t.removeEventListener("scroll",s)}},[e]),(0,r.useEffect)(()=>{let s=s=>{"Escape"===s.key&&e&&t()};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[e,t]);let g=(0,r.useCallback)((e,t)=>{(0,eo.e)(),navigator.clipboard?.writeText(t).catch(()=>{}),d(e),setTimeout(()=>d(null),2e3)},[]),v=(0,r.useCallback)(e=>{(0,eo.e)(),x(e.id),p(e.command)},[]),y=(0,r.useCallback)(()=>{m.trim()&&((0,eo.e)(),u?(i(u,m.trim()),x(null)):a(m.trim()),p(""))},[m,u,a,i]),w=(0,r.useCallback)(e=>{(0,eo.e)(),o(e),u===e&&(x(null),p(""))},[o,u]),j=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),y())},[y]);return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:t}),(0,n.jsxs)("div",{className:"absolute top-0 right-0 w-[85vw] sm:w-96 max-w-md bg-surface border-l border-border shadow-2xl flex flex-col slide-in-right",style:{height:h?`${h}px`:"100%"},onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0 safe-area-top",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(en.iU,{size:20,className:"text-brand-500"}),(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("commandNotes.title")})]}),(0,n.jsx)("button",{onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable",children:[0===l.length&&(0,n.jsxs)("div",{className:"text-center text-text-muted py-8",children:[(0,n.jsx)(en.iU,{size:32,className:"mx-auto mb-3 text-text-muted"}),(0,n.jsx)("p",{className:"text-sm",children:s("commandNotes.noSavedCommands")}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-1",children:s("commandNotes.addFirstBelow")})]}),l.map(e=>(0,n.jsx)("div",{className:"px-4 py-3 border-b border-border/50 hover:bg-surface-2/30 transition-colors group",children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>g(e.id,e.command),title:s("commandNotes.clickToCopy"),children:[(0,n.jsx)("p",{className:"text-sm text-text font-mono break-all",children:e.command}),c===e.id&&(0,n.jsx)("span",{className:"text-xs text-green-400 mt-1 inline-block",children:s("commandNotes.copiedBang")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:()=>g(e.id,e.command),className:"p-1.5 text-text-muted hover:text-brand-400 rounded transition-colors",title:s("commandNotes.copy"),children:c===e.id?(0,n.jsx)(en.aJ,{size:14,className:"text-green-400"}):(0,n.jsx)(en.QR,{size:14})}),(0,n.jsx)("button",{onClick:()=>v(e),className:"p-1.5 text-text-muted hover:text-brand-400 rounded transition-colors",title:s("commandNotes.edit"),children:(0,n.jsx)(en.gH,{size:14})}),(0,n.jsx)("button",{onClick:()=>w(e.id),className:"p-1.5 text-text-muted hover:text-red-400 rounded transition-colors",title:s("commandNotes.delete"),children:(0,n.jsx)(en.TB,{size:14})})]})]})},e.id))]}),(0,n.jsx)("div",{className:"px-3 py-3 border-t border-border flex-shrink-0 safe-area-bottom",children:(0,n.jsxs)("div",{className:"flex gap-2 items-end",children:[(0,n.jsx)("textarea",{ref:f,value:m,onChange:e=>p(e.target.value),onKeyDown:j,placeholder:u?s("commandNotes.editCommandPlaceholder"):s("commandNotes.addCommandPlaceholder"),rows:2,className:"flex-1 bg-surface-2 rounded-brand px-3 py-2 text-text text-sm placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out font-mono resize-none"}),(0,n.jsx)("button",{onClick:y,disabled:!m.trim(),className:"p-2.5 bg-brand-600 hover:bg-brand-500 disabled:bg-surface-2 disabled:cursor-not-allowed text-text rounded-brand transition-colors flex-shrink-0",title:u?s("commandNotes.update"):s("commandNotes.add"),children:(0,n.jsx)(en.Vn,{size:18})})]})})]})]}):null}let di=[{id:"facebook",label:"Facebook Group",description:"Report bugs & suggest features to 9Team community",url:"https://www.facebook.com/groups/9teamvn",icon:"Facebook",color:"#1877F2"},{id:"github",label:"GitHub",description:"Source code & issue tracker",url:"https://github.com/decolua/9remote",icon:"Github",color:"#ffffff"}];function dc({isOpen:e,onClose:t}){let{t:s}=(0,ec.s)();return((0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&t?.()};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-md card-elev slide-in-top",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("community.title")}),(0,n.jsx)("button",{onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-2",children:[(0,n.jsx)("p",{className:"text-text-muted text-sm px-1 mb-2",children:s("community.description")}),di.map(e=>(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.url,void((0,eo.e)(),window.open(t,"_blank","noopener,noreferrer"))},className:"w-full px-4 py-3 bg-surface-2 hover:bg-surface-3 text-text rounded-brand-lg text-left flex items-center gap-3 transition-all duration-150 ease-out active:scale-[0.99] group",children:[(0,n.jsx)("span",{className:"flex items-center justify-center w-10 h-10 rounded-brand flex-shrink-0",style:{backgroundColor:`${e.color}1a`,color:e.color},children:(0,n.jsx)(en.Ay,{name:e.icon,size:22})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium truncate",children:e.label}),e.description&&(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",children:e.description})]}),(0,n.jsx)(en.Gr,{className:"text-text-muted group-hover:text-brand-500 flex-shrink-0",size:18})]},e.id))]})]})]}):null}var dd=s(18057);let du=[{id:"general",labelKey:"menu.settingsGeneral",icon:"Settings"},{id:"appearance",labelKey:"menu.settingsAppearance",icon:"Palette"},{id:"terminal",labelKey:"menu.settingsTerminalTab",icon:"Terminal"},{id:"background",labelKey:"menu.terminalBackground",icon:"Image"},{id:"buttons",labelKey:"menu.settingsButtons",icon:"PanelRight"},{id:"mcp",labelKey:"menu.settingsMcp",icon:"Zap"},{id:"shortcuts",labelKey:"shortcuts.menuLabel",icon:"Keyboard"}];function dx({isOpen:e,onClose:t,busRef:s,inline:l=!1}){let{t:a}=(0,ec.s)(),i=(0,h.B)(e=>e.terminalBackgrounds);(0,h.B)(e=>e.setTerminalBackgrounds);let o=(0,h.B)(e=>e.terminalBackgroundOpacity),c=(0,h.B)(e=>e.setTerminalBackgroundOpacity),d=(0,h.B)(e=>e.customBackgrounds),{saving:u,error:x,setError:m,fileInput:p,openPicker:f}=sX(s),[b,g]=(0,r.useState)(()=>window.innerWidth>=eV.jK);(0,r.useEffect)(()=>{let e=()=>g(window.innerWidth>=eV.jK);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&(m(""),t())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,t,m]);let v=()=>{m(""),t()};if(!l&&!e)return null;let y=o??eV._z,{min:w,max:j,step:k}=eV.DW,N=`${(y-w)/(j-w)*100}%`,C=(0,eV.IJ)(i,d),S=(e,t,s)=>{let r="none"===e,l=r?-1:C.indexOf(e),a=r?0===C.length:-1!==l;return(0,n.jsxs)("button",{onClick:()=>(e=>{(0,eo.e)();let{terminalBackgrounds:t,setTerminalBackgrounds:s}=h.B.getState();s("none"===e?[]:t.includes(e)?t.filter(t=>t!==e):[...t,e])})(e),className:"group relative block w-full aspect-[9/16] rounded-2xl overflow-hidden transition-transform duration-200 ease-out active:scale-[0.97] shadow-sm",children:[s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("img",{src:s,alt:t,className:"absolute inset-0 h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.03]",loading:"lazy"}),(0,n.jsx)("span",{className:"pointer-events-none absolute inset-0",style:{background:`rgba(0,0,0,${eV.t})`}}),(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 h-1/4 bg-gradient-to-t from-black/75 to-transparent"}),(0,n.jsx)("span",{className:"absolute bottom-2 left-0 right-0 px-2 text-xs font-medium text-white truncate",children:t})]}):(0,n.jsxs)("span",{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 transition-colors ${a?"bg-brand-500/10 text-brand-500":"bg-surface-2 text-text-muted group-hover:text-text"}`,children:[(0,n.jsx)(en.P6,{size:24,strokeWidth:1.75}),(0,n.jsx)("span",{className:"text-xs font-medium",children:t})]}),(0,n.jsx)("span",{className:`pointer-events-none absolute inset-0 rounded-2xl transition-shadow duration-200 ${a?"ring-1 ring-inset ring-brand-500":"ring-1 ring-inset ring-white/15 group-hover:ring-brand-500/60"}`}),a&&!r&&(0,n.jsx)("span",{className:"absolute top-2 right-2 flex items-center justify-center w-6 h-6 bg-brand-500 rounded-full shadow-lg text-white text-xs font-semibold",children:l+1})]})},E=(0,n.jsxs)("div",{className:l||b?"grid grid-cols-3 gap-3":"grid grid-cols-2 gap-3",children:[Object.entries(eV.vk).map(([e,t])=>(0,n.jsx)("div",{children:S(e,t.label,t.src)},e)),d.map(e=>(0,n.jsxs)("div",{className:"relative",children:[S(`custom:${e.id}`,a("menu.bgCustomLabel"),e.dataUrl),(0,n.jsx)("button",{onClick:()=>{var t;let n;return t=e.id,(0,eo.e)(),n=s?.current,void(n?.emit&&n.emit("bg:delete",{id:t},e=>{if(!e?.success)return void m(e?.error||a("menu.bgDeleteFailed"));let s=`custom:${t}`,{customBackgrounds:n,setCustomBackgrounds:r,terminalBackgrounds:l,setTerminalBackgrounds:i}=h.B.getState();r(n.filter(e=>e.id!==t)),i(l.filter(e=>e!==s))}))},className:"absolute top-2 left-2 flex items-center justify-center w-7 h-7 rounded-full bg-black/55 text-white backdrop-blur-sm hover:bg-red-500/80 transition-colors","aria-label":a("common.delete"),children:(0,n.jsx)(en.X,{size:13})})]},`custom:${e.id}`)),(0,n.jsxs)("button",{onClick:f,disabled:u,className:"group relative block w-full aspect-[9/16] rounded-2xl overflow-hidden border-2 border-dashed border-border flex flex-col items-center justify-center gap-2 text-text-muted hover:border-brand-500 hover:text-brand-500 transition-colors disabled:opacity-40",children:[u?(0,n.jsx)(en.kr,{size:24,className:"animate-spin"}):(0,n.jsx)(en.FW,{size:24,strokeWidth:1.75}),(0,n.jsx)("span",{className:"text-xs font-medium",children:a("menu.bgAdd")})]})]}),R=C.length>0&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-3 px-1 pt-1",children:[(0,n.jsx)("span",{className:"text-xs text-text flex-shrink-0",children:a("menu.bgDim")}),(0,n.jsx)("input",{type:"range",min:w,max:j,step:k,value:y,onChange:e=>c(Number(e.target.value)),className:"brand-range flex-1 min-w-0",style:{"--pct":N},"aria-label":a("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums flex-shrink-0",children:[Math.round(100*y),"%"]})]}),T=C.length>0&&(0,n.jsxs)("div",{className:"flex-shrink-0 border-t border-border px-5 pt-3 pb-[max(1.25rem,env(safe-area-inset-bottom))]",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-sm text-text",children:a("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums",children:[Math.round(100*y),"%"]})]}),(0,n.jsx)("input",{type:"range",min:w,max:j,step:k,value:y,onChange:e=>c(Number(e.target.value)),className:"brand-range brand-range-lg",style:{"--pct":N},"aria-label":a("menu.bgDim")})]}),$=x&&(0,n.jsx)("div",{className:`px-3 py-2 rounded-brand bg-red-500/10 border border-red-500/30 text-red-500 text-xs break-all ${l?"":"flex-shrink-0 mx-5 mb-2"}`,children:x});return l?(0,n.jsxs)("div",{className:"h-full flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[E,$]}),R,p]}):(0,sU.createPortal)((0,n.jsxs)("div",{className:b?"fixed inset-0 z-[60] flex items-center justify-center p-4":"fixed inset-0 z-[60] flex flex-col justify-end",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:v}),(0,n.jsxs)("div",{className:b?"relative w-full max-w-lg max-h-[80vh] rounded-brand-lg border border-border-subtle bg-surface shadow-2xl flex flex-col overflow-hidden animate-in zoom-in-95 duration-200":"relative rounded-t-3xl border-t border-border bg-surface/95 backdrop-blur-xl shadow-2xl max-h-[88dvh] flex flex-col animate-in slide-in-from-bottom duration-300 ease-out",children:[!b&&(0,n.jsx)("div",{className:"pt-3 pb-1 flex justify-center flex-shrink-0",children:(0,n.jsx)("div",{className:"w-10 h-1 rounded-full bg-border"})}),(0,n.jsxs)("div",{className:`px-6 pb-3 flex items-center justify-between flex-shrink-0 ${b?"pt-4":""}`,children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:a("menu.terminalBackground")}),(0,n.jsx)("button",{onClick:v,className:"p-2 -mr-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-full transition-colors","aria-label":a("common.close"),children:(0,n.jsx)(en.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable px-5 pb-4",children:E}),$,T]}),p]}),document.body)}let dm={Settings:en.wB,Palette:en.es,Terminal:en.BK,Bell:en.Ir,Sparkles:en.sU,Keyboard:en.s3,Zap:en.Kq,PanelRight:en.jz,Image:en._V,Bot:en.cC};function dp({context:e,callbacks:t,canInstall:s,isInstalled:l,install:a,onClose:i}){let{t:o,locale:c}=(0,ec.s)(),{theme:d,setTheme:u}=(0,n_.D)(),[x,m]=(0,r.useState)("general"),[p,f]=(0,r.useState)(!1),[b,g]=(0,r.useState)(!1),v=cQ.dI.find(e=>e.code===c),y=(0,h.B)(e=>e.webglEnabled),w=(0,h.B)(e=>e.setWebglEnabled),j=(0,h.B)(e=>e.fontSize),k=(0,h.B)(e=>e.setFontSize),N=(0,h.B)(e=>e.terminalTheme),C=(0,h.B)(e=>e.setTerminalTheme),S=cJ(),E=cY(e.subscribeToPush,e.unsubscribeFromPush),R=cZ(e.busRef,e.connected),T=ne(e=>!1),$=R.supported,M=e.agentVersion,z=(0,r.useMemo)(()=>e.hideActions||[],[e.hideActions]),P=!(window.matchMedia("(display-mode: standalone)").matches||window.ReactNativeWebView)&&!l,I=(0,r.useMemo)(()=>du.filter(e=>"codespace"!==e.id&&("terminal"!==e.id||!z.includes("terminalSettings"))),[z]),A=I.find(e=>e.id===x);(0,r.useEffect)(()=>{document.activeElement?.blur?.();let e=e=>{"Escape"!==e.key||b||(e.preventDefault(),e.stopPropagation(),i())};return window.addEventListener("keydown",e,!0),document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",e,!0),document.body.style.overflow=""}},[i,b]);let L=(0,r.useCallback)(e=>{(0,eo.e)(),i(),setTimeout(()=>e?.(),50)},[i]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:i}),(0,n.jsxs)("div",{className:"relative w-full max-w-4xl h-[85vh] max-h-[640px] bg-surface border border-border rounded-brand-lg shadow-2xl flex overflow-hidden",role:"dialog","aria-modal":"true","aria-label":o("menu.settings"),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("nav",{className:"w-52 flex-shrink-0 bg-bg/40 border-r border-border flex flex-col",children:[(0,n.jsx)("div",{className:"h-12 flex items-center px-4 border-b border-border",children:(0,n.jsx)("h2",{className:"text-base font-semibold text-text",children:o("menu.settings")})}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-0.5 modal-scrollable",children:I.map(e=>{let t=dm[e.icon],s=x===e.id;return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),m(e.id)},className:`w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm transition-colors ${s?"bg-brand-500/15 text-brand-500":"text-text-muted hover:bg-surface-2 hover:text-text"}`,children:[(0,n.jsx)(t,{size:16}),(0,n.jsx)("span",{children:o(e.labelKey)})]},e.id)})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center gap-2",children:["local"===e.connectionMode&&(0,n.jsx)("span",{className:"text-[10px] font-semibold px-1.5 py-0.5 rounded-full bg-green-500/15 text-green-400",children:"LAN"}),(0,n.jsxs)("p",{className:"text-text-muted text-xs truncate",children:["3.0.25",M?` / ${M}`:""]})]})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("div",{className:"h-12 flex items-center justify-between gap-2 pl-6 pr-3 border-b border-border",children:["install"===x?(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),m("general")},className:"-ml-2 px-2 py-1 text-sm font-medium text-text hover:bg-surface-2 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)(en.JG,{size:16}),o("pwa.title")]}):(0,n.jsx)("h3",{className:"text-sm font-medium text-text truncate",children:o(A?.labelKey||"menu.settings")}),(0,n.jsx)("button",{onClick:i,className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0","aria-label":o("common.close"),children:(0,n.jsx)(en.X,{size:18})})]}),(0,n.jsxs)("div",{className:`flex-1 overflow-y-auto modal-scrollable px-6 ${"background"===x?"py-4":"py-5"}`,children:["background"===x&&(0,n.jsx)(dx,{inline:!0,busRef:e.busRef}),"general"===x&&(0,n.jsxs)("div",{className:"space-y-6",children:[(E.supported||P)&&(0,n.jsxs)(df,{children:[E.supported&&(0,n.jsx)(db,{icon:en.Ir,label:o("menu.notifications"),hint:o("menu.notificationsHint"),value:E.enabled,loading:E.loading,onChange:E.toggle}),P&&(0,n.jsx)(dh,{icon:en.f5,label:o("menu.installApp"),badge:s?o("pwaGuide.installNow"):null,onClick:()=>s?L(a):m("install")})]}),(0,n.jsx)(df,{title:o("menu.reloadRestart"),children:(0,n.jsx)(dh,{icon:en.e9,iconClass:p?"animate-spin":"",label:o("menu.reload"),disabled:p,onClick:()=>{(0,eo.e)(),f(!0),setTimeout(()=>window.location.reload(),150)}})}),t.onLogout&&(0,n.jsx)(df,{title:o("menu.settingsAccount"),children:(0,n.jsx)(dh,{icon:en.nU,label:o("menu.logout"),danger:!0,onClick:()=>L(t.onLogout)})})]}),"appearance"===x&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(df,{title:o("menu.theme"),children:(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,n.jsx)(dv,{icon:en.bd,label:o("menu.themeLight"),active:"light"===d,onClick:()=>{(0,eo.e)(),u("light")}}),(0,n.jsx)(dv,{icon:en.AX,label:o("menu.themeDark"),active:"dark"===d,onClick:()=>{(0,eo.e)(),u("dark")}})]})}),(0,n.jsx)(df,{title:o("menu.language"),children:(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),g(!0)},className:"w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors",children:[(0,n.jsx)(en.qz,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:o("menu.language")}),v&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 text-text-muted",children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${v.country}.png`,alt:"",className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{className:"text-xs",children:v.label})]}),(0,n.jsx)(en.c_,{size:15,className:"text-text-muted flex-shrink-0"})]})})]}),"terminal"===x&&(0,n.jsx)("div",{className:"space-y-6",children:(0,n.jsxs)(df,{title:o("menu.terminalSettings"),children:[(0,n.jsx)(dg,{icon:en.ZU,label:o("menu.fontSize"),children:(0,n.jsx)("select",{value:j??14,onChange:e=>{(0,eo.e)(),k(Number(e.target.value))},className:"bg-surface-2 text-text text-sm rounded-brand px-2 py-1 focus:outline-none focus:ring-2 focus:ring-brand-500/40",children:Array.from({length:9},(e,t)=>t+10).map(e=>(0,n.jsxs)("option",{value:e,children:[e,"px"]},e))})}),(0,n.jsx)(dg,{icon:en.es,label:o("menu.terminalTheme"),children:(0,n.jsxs)("select",{value:N,onChange:e=>{(0,eo.e)(),C(e.target.value)},className:"bg-surface-2 text-text text-sm rounded-brand px-2 py-1 max-w-[220px] focus:outline-none focus:ring-2 focus:ring-brand-500/40",children:[(0,n.jsx)("option",{value:"default",children:"Vesper (Default)"}),nT.g4.filter(e=>e.mode===d).map(e=>(0,n.jsx)("option",{value:e.key,children:e.label},e.key))]})}),(0,n.jsx)(db,{icon:en.VA,label:o("menu.webgl"),hint:o("menu.webglHint"),value:y,onChange:w})]})}),"buttons"===x&&(0,n.jsx)("div",{className:"space-y-6",children:eV.GL.map(({group:e,titleKey:t})=>(0,n.jsx)(df,{title:o(t),children:S.buttons.filter(t=>t.group===e).map(e=>(0,n.jsx)(db,{icon:cX[e.id],label:o(e.labelKey),value:S.isOn(e),onChange:()=>S.toggle(e)},e.id))},e))}),"mcp"===x&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(c9,{}),$&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(db,{icon:en.jz,label:o("menu.artifactPanel"),hint:o("menu.artifactHint"),value:R.enabled,loading:R.loading,disabled:!e.connected,onChange:R.toggle}),(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-text-muted",children:o("menu.mcpRestartHint")})]})]}),"jarvis"===x&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(db,{icon:en.cC,label:o("menu.jarvisToggle"),hint:o("menu.jarvisToggleHint"),value:T,onChange:e=>{ne.getState().setSettings({enabled:e}),e||ne.getState().setOpen(!1)}}),$&&!R.enabled&&(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-amber-400",children:o("menu.jarvisMcpOff")}),(0,n.jsx)(nd,{busRef:e.busRef})]}),"shortcuts"===x&&(0,n.jsx)("ul",{className:"flex flex-col divide-y divide-border-subtle/40",children:tr.map(e=>(0,n.jsxs)("li",{className:"flex items-center justify-between gap-4 px-3 py-2 rounded-brand hover:bg-surface-2 first:pt-1",children:[(0,n.jsx)("span",{className:"text-sm text-text min-w-0 truncate",children:o(`shortcuts.${e.id}`)}),(0,n.jsx)("span",{className:"inline-flex items-center gap-1 flex-shrink-0",children:tu(e).map(e=>(0,n.jsx)("kbd",{className:tc,children:e},e))})]},e.id))}),"install"===x&&(0,n.jsx)(ds,{})]})]})]}),(0,n.jsx)(dd.A,{isOpen:b,onClose:()=>g(!1)})]})}function df({title:e,children:t}){return(0,n.jsxs)("section",{children:[e&&(0,n.jsx)("h4",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-muted mb-2",children:e}),(0,n.jsx)("div",{className:"space-y-1",children:t})]})}function dh({icon:e,iconClass:t="",label:s,badge:r,danger:l,disabled:a,onClick:i}){return(0,n.jsxs)("button",{onClick:i,disabled:a,className:`w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm transition-colors ${a?"text-text-muted cursor-not-allowed opacity-60":l?"text-text hover:bg-red-500/15 hover:text-red-400":"text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(e,{size:16,className:`${l?"text-red-400":"text-brand-500"} ${t}`}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:s}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 px-2 py-0.5 bg-brand-500 text-white text-xs font-medium rounded-full",children:r})]})}function db({icon:e,label:t,hint:s,value:r,loading:l,disabled:a,onChange:i}){return(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),i(!r)},disabled:l||a,className:"w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors disabled:opacity-60",children:[(0,n.jsx)(e,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"block truncate",children:t}),s&&(0,n.jsx)("span",{className:"block text-xs text-text-muted truncate",children:s})]}),l?(0,n.jsx)(en.kr,{size:16,className:"animate-spin text-text-muted"}):(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors flex-shrink-0 ${r?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${r?"translate-x-4":"translate-x-0.5"}`})})]})}function dg({icon:e,label:t,children:s}){return(0,n.jsxs)("div",{className:"w-full px-3 py-2 rounded-brand flex items-center gap-2.5 text-sm text-text",children:[(0,n.jsx)(e,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:t}),s]})}function dv({icon:e,label:t,active:s,onClick:r}){return(0,n.jsxs)("button",{onClick:r,className:`px-3 py-3 rounded-brand flex items-center gap-2.5 text-sm border transition-colors ${s?"border-brand-500 bg-brand-500/10 text-brand-500":"border-border text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(e,{size:16}),(0,n.jsx)("span",{children:t})]})}function dy(){let e,t,{t:s,locale:l}=(0,ec.s)(),{formattedStars:a}=(0,sQ.w)(),i=cQ.dI.find(e=>e.code===l)||cQ.dI[0],o=eb(e=>e.isOpen),c=eb(e=>e.activePanel),d=eb(e=>e.context),x=eb(e=>e.callbacks),m=(0,u.d)(e=>e.carrier),p=eb(e=>e.close),f=eb(e=>e.setActivePanel);eb(e=>e.openMenu);let h=eG(e=>e.install),b=eG(e=>e.canInstall),g=eG(e=>e.isInstalled),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(!1),[C,S]=(0,r.useState)(!1),{theme:E,toggleTheme:R}=(0,n_.D)(),[T,$]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=()=>$(window.innerWidth>=eV.jK);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>(o?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[o]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o&&p()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[o,p]);let M=(0,r.useCallback)(()=>f("pwa"),[f]),z=(0,r.useCallback)(()=>{(0,eo.e)(),f("menu")},[f]),P=(0,r.useCallback)(()=>{p(),x.onRemote?.()},[p,x]),I=(0,r.useCallback)(()=>{p(),x.onFiles?.()},[p,x]),A=(0,r.useCallback)(()=>{b?(p(),h()):M()},[b,p,h,M]),L=(0,r.useCallback)(()=>{p(),setTimeout(()=>{x.onLogout?.()},50)},[p,x]),D=(0,r.useCallback)(e=>{x.onThemeChange?.(e)},[x]);(0,r.useCallback)(()=>{p(),y(!0)},[p]);let B=(0,r.useCallback)(()=>{y(!1)},[]);(0,r.useCallback)(()=>{p(),j(!0)},[p]);let F=(0,r.useCallback)(()=>{j(!1)},[]),K=(0,r.useCallback)(()=>{p(),S(!0)},[p]),O=(0,r.useCallback)(()=>{S(!1)},[]),W=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(da,{isOpen:v,onClose:B}),(0,n.jsx)(dc,{isOpen:w,onClose:F}),(0,n.jsx)(dx,{isOpen:C,onClose:O,busRef:d.busRef})]});return o?T?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(dp,{context:d,callbacks:x,canInstall:b,isInstalled:g,install:h,onClose:p}),W]}):(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:p}),(0,n.jsxs)("div",{className:"absolute top-0 right-0 bottom-0 w-[85vw] sm:w-96 max-w-md bg-surface border-l border-border shadow-2xl flex flex-col slide-in-right pt-[var(--safe-top)] pb-[var(--safe-bottom)]",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:["menu"!==c&&(0,n.jsx)("button",{onClick:z,className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors mr-1","aria-label":s("common.back"),children:(0,n.jsx)(en.JG,{size:20})}),(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("pwa"===c?"pwa.title":"menu.title")}),"menu"===c&&(t=(e=m||d.carrier)&&"ws"!==e,(0,n.jsx)("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider ${t?"bg-blue-500/15 text-blue-400 border border-blue-500/30":"bg-yellow-500/15 text-yellow-500 border border-yellow-500/30"}`,title:`Carrier: ${t?`WebRTC (${e})`:"WebSocket"}`,children:t?"RTC":"WS"}))]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:["menu"===c&&(0,n.jsxs)(n.Fragment,{children:[s0.l7&&(0,n.jsxs)("a",{href:s0.rl,target:"_blank",rel:"noopener noreferrer",className:"px-2 py-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex items-center gap-1.5 text-xs font-medium",title:"Star on GitHub","aria-label":"Star on GitHub",children:[(0,n.jsx)(en.Cp,{size:16}),(0,n.jsx)(en.FE,{size:13,className:"text-yellow-500 fill-yellow-500"}),a&&(0,n.jsx)("span",{className:"font-mono text-[11px] leading-none",children:a})]}),(0,n.jsx)("button",{onClick:()=>{(0,eo.e)(),R()},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("menu.theme"),title:s("menu.theme"),children:"dark"===E?(0,n.jsx)(en.bd,{size:18}):(0,n.jsx)(en.AX,{size:18})}),(0,n.jsxs)("button",{onClick:()=>{(0,eo.e)(),N(!0)},className:"px-2 py-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex items-center gap-1.5 text-sm font-medium","aria-label":s("menu.language"),title:s("menu.language"),children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${i.country}.png`,alt:i.label,className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{className:"uppercase",children:i.code})]})]}),(0,n.jsx)("button",{onClick:p,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("common.close"),children:(0,n.jsx)(en.X,{size:20})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable",children:["menu"===c&&(0,n.jsx)(c7,{onRemote:d.remoteAvailable?P:null,onFiles:I,onInstallApp:A,canInstall:b,isInstalled:g,onLogout:L,connected:d.connected,remoteAvailable:d.remoteAvailable,showTheme:d.showTheme,theme:d.theme,onThemeChange:D,hideActions:d.hideActions||[],busRef:d.busRef,subscribeToPush:d.subscribeToPush,unsubscribeFromPush:d.unsubscribeFromPush,onOpenBackgroundPicker:K}),"pwa"===c&&(0,n.jsx)(ds,{})]})]}),(0,n.jsx)(da,{isOpen:v,onClose:B}),(0,n.jsx)(dc,{isOpen:w,onClose:F}),(0,n.jsx)(dx,{isOpen:C,onClose:O,busRef:d.busRef}),(0,n.jsx)(dd.A,{isOpen:k,onClose:()=>N(!1)})]}):W}var dw=s(61826),dj=s(31735);function dk({hydrated:e,apiKey:t}){return!function(e){let t=(0,l.usePathname)(),s=(0,l.useSearchParams)(),n=(0,l.useRouter)(),{viewStack:a,pushView:i,setViewStack:o}=(0,h.B)((0,D.k)(e=>({viewStack:e.viewStack,pushView:e.pushView,setViewStack:e.setViewStack}))),c=a[a.length-1],d=dw.yP.includes(c?.type)?a[a.length-2]:c,u=(0,r.useRef)(null),x=(0,r.useRef)(null),m=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!e)return;let n=(0,dw.mn)(t,s);if(!n)return;let r=(0,dw.O5)(n);if(r===u.current||(u.current=r,d&&(0,dw.O5)(d)===r))return;m.current="url";let l=(0,dw.dX)(a,n);l?o(l):i(n)},[e,t,s]),(0,r.useEffect)(()=>{if(!e||dw.yP.includes(c?.type))return;let r=(0,dw.O5)(c);if(r===u.current)return;let l=(0,dw.O5)((0,dw.mn)(t,s)),i="url"===m.current;i&&(m.current=null);let o=x.current?.type==="terminal"&&c?.type==="terminal",d=c?.type==="list"&&1===a.length;m.current="store",u.current=r,x.current=c,i||r===l||(o||d?n.replace(r):n.push(r))},[e,c,t,s])}(e),(0,dj.H$)(t),null}function dN({children:e}){let t,s,b,g,v,y,w,j,k,N,C,S,E,R,T,K,{t:O}=(0,ec.s)(),[W,_]=(0,r.useState)(!1);(0,r.useEffect)(()=>{!function(){if(eJ)return;eJ=!0;let e=eG.getState();(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),eG.getState().setDeferredPrompt(e)}),window.addEventListener("appinstalled",()=>{eG.getState().setDeferredPrompt(null),eG.getState().setIsInstalled(!0)}),window.matchMedia("(display-mode: standalone)").matches)?e.setIsInstalled(!0):navigator.getInstalledRelatedApps&&navigator.getInstalledRelatedApps().then(t=>{t?.length&&e.setIsInstalled(!0)}).catch(()=>{})}()},[]);let{viewStack:H,openedSessions:q,pushView:U,popView:V,setViewStack:X,addOpenedSession:G,removeOpenedSession:J,reorderOpenedSessions:Y,activeWorkspaceId:Z,setActiveWorkspaceId:Q,livePanes:ee,touchLivePane:et,mountedWorkspaces:en,markWorkspaceMounted:er,reset:el,cwdBySession:eo,sidebarCollapsed:eu,toggleSidebar:ex,sidebarWidth:eh,setSidebarWidth:eg,paneWidths:ev,setPaneWidth:ew,rightPanelOpen:eN,rightPanelTabs:eC,rightPanelWidth:eS,toggleRightPanel:eR,setRightPanelTab:eT,setRightPanelWidth:eM,editorFilePath:ez,editorPanelWidth:eA,setEditorPanelWidth:eL,openEditorFile:eD,closeEditorFile:eB,editorPreviewSeq:eF,mobileOpen:eK,mobileMode:eO,mobilePanelWidth:eW,setMobileOpen:e_,setMobileMode:eH,setMobilePanelWidth:eX,setMobileSession:eZ,artifactTitle:eQ,pushArtifact:e0,removeArtifact:e1}=(0,h.B)((0,D.k)(e=>({viewStack:e.viewStack,openedSessions:e.openedSessions,pushView:e.pushView,popView:e.popView,setViewStack:e.setViewStack,addOpenedSession:e.addOpenedSession,removeOpenedSession:e.removeOpenedSession,reorderOpenedSessions:e.reorderOpenedSessions,activeWorkspaceId:e.activeWorkspaceId,setActiveWorkspaceId:e.setActiveWorkspaceId,livePanes:e.livePanes,touchLivePane:e.touchLivePane,mountedWorkspaces:e.mountedWorkspaces,markWorkspaceMounted:e.markWorkspaceMounted,reset:e.reset,cwdBySession:e.cwdBySession,sidebarCollapsed:e.sidebarCollapsed,toggleSidebar:e.toggleSidebar,sidebarWidth:e.sidebarWidth,setSidebarWidth:e.setSidebarWidth,paneWidths:e.paneWidths,setPaneWidth:e.setPaneWidth,rightPanelOpen:e.rightPanelOpen,rightPanelTabs:e.rightPanelTabs,rightPanelWidth:e.rightPanelWidth,toggleRightPanel:e.toggleRightPanel,setRightPanelTab:e.setRightPanelTab,setRightPanelWidth:e.setRightPanelWidth,editorFilePath:e.editorFilePath,editorPanelWidth:e.editorPanelWidth,setEditorPanelWidth:e.setEditorPanelWidth,openEditorFile:e.openEditorFile,closeEditorFile:e.closeEditorFile,editorPreviewSeq:e.editorPreviewSeq,mobileOpen:e.mobileOpen,mobileMode:e.mobileMode,mobilePanelWidth:e.mobilePanelWidth,setMobileOpen:e.setMobileOpen,setMobileMode:e.setMobileMode,setMobilePanelWidth:e.setMobilePanelWidth,setMobileSession:e.setMobileSession,artifactTitle:e.artifactTitle,pushArtifact:e.pushArtifact,removeArtifact:e.removeArtifact}))),e2=(0,l.useRouter)(),{getAuth:e4,setAuth:e6,clearAuth:e8}=(0,a.Fo)(),[e9,e7]=(0,r.useState)(()=>e4()),ts=(0,u.d)(e=>e.authKey);(0,r.useEffect)(()=>{ts&&e7(e4())},[ts,e4]),(0,r.useEffect)(()=>{_(!0),!e9?.apiKey&&(0,x._r)()&&window.location.port===String(m._8)&&fetch(m.Go).then(e=>e.ok?e.json():null).then(e=>{if(e?.permanentKey){let t=e.permanentKey,s=(0,p.Uo)(t),n=(0,p.Cj)(t);(0,f.LG)(s,{tail:n});let r={apiKey:s,tunnelUrl:window.location.origin,mode:"local",tempKey:null,localIp:null};e6(r),e7(r)}}).catch(()=>{})},[e9,e6]),(0,r.useEffect)(()=>{if(!window.__TAURI__)return;let e=e=>{("F5"===e.key||(e.metaKey||e.ctrlKey)&&"r"===e.key.toLowerCase())&&(e.preventDefault(),window.location.reload())},t=e=>{let t=e.target?.tagName;"INPUT"===t||"TEXTAREA"===t||e.target?.isContentEditable||e.preventDefault()};return window.addEventListener("keydown",e),window.addEventListener("contextmenu",t),()=>{window.removeEventListener("keydown",e),window.removeEventListener("contextmenu",t)}},[]);let{bus:tr,busRef:ta,protocolRef:to,disconnect:tc,reconnect:td,connected:tu,connectionMode:tp,carrier:tg,remoteAvailable:tv,mobileAvailable:ty,platform:tw,agentVersion:tj,retryStatus:tk,approvalStatus:tN,admitted:tC,loadSessions:tS,createSession:tE,deleteSession:tR,renameSession:tT,createWorkspace:t$,renameWorkspace:tM,deleteWorkspace:tz,setWorkspaceHiddenRepos:tP,reorderSession:tI}=function(){let[e,t]=(0,r.useState)([]),[s,n]=(0,r.useState)([]),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(null),C=(0,u.d)(e=>e.approvalStatus),S=(0,u.d)(e=>e.admitted),{getAuth:E}=(0,a.Fo)(),R=(0,r.useCallback)(e=>{u.d.getState().applyApproval(e)},[]),T=(0,r.useCallback)(async()=>{let e=E();if(e?.tempKey)try{await fetch(`${m.O}/api/temp-key/remove`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({tempKey:e.tempKey})}),sessionStorage.removeItem("tempKey")}catch(e){console.error("Failed to remove temp key:",e)}},[E]),D=(0,r.useRef)(null),B=(0,r.useRef)({sessions:!1,workspaces:!1}),F=e=>{B.current[e]=!0},K=(0,r.useCallback)(e=>{(0,A.Lq)("switch",`lists untrusted (${e}) → refetch`),B.current={sessions:!1,workspaces:!1}},[]),O=(0,r.useCallback)(e=>{if(!Array.isArray(e))return;for(let t of(F("sessions"),e))t?.id&&t?.agent&&h.B.getState().setSessionAgent(t.id,t.agent);t(t=>(0,P.nk)(t,e)?t:e);let s=M.rh.getState();(0,P.nk)(s.hosts[s.currentKey]?.sessions,e)||L({sessions:e})},[]),W=(0,r.useCallback)(e=>{if(!Array.isArray(e))return;F("workspaces"),n(t=>(0,P.nk)(t,e)?t:e);let t=M.rh.getState();(0,P.nk)(t.hosts[t.currentKey]?.workspaces,e)||L({workspaces:e})},[]),_=(0,r.useRef)(0),H=(0,r.useRef)(0),q=(0,r.useRef)(null),U=(0,r.useRef)(0),V=(0,r.useCallback)(e=>{let t=++_.current;e.emit("getSessions",e=>{(0,A.Lq)("diag",`getSessions ack seq=${t} type=${Array.isArray(e)?"list":typeof e} n=${Array.isArray(e)?e.length:"-"}`),t===_.current&&O(e)})},[O]),X=(0,r.useCallback)(e=>{let t=++H.current;e.emit("getWorkspaces",e=>{t===H.current&&W(e)})},[W]),G=(0,r.useCallback)((e,t=!1)=>{if(e){if(t)clearTimeout(q.current);else if(q.current)return;else if(Date.now()-U.current<1e3)return;q.current=setTimeout(()=>{q.current=null,U.current=Date.now(),(0,A.Lq)("diag",`fetchLists FIRE (bus=${e?"ok":"null"} connected-already=${B.current.sessions}/${B.current.workspaces})`),X(e),V(e)},120)}},[V,X]),J={fragOut:!0,binOut:!0,hb:1,env2:1,fragCtl:1},Y=e=>{(0,A.Lq)("switch",`caps → ${JSON.stringify(J)} announced`),e.emit("caps",J)},Z=(0,r.useRef)(null),{bus:Q,busRef:ee,protocolRef:et,connected:es,connectionMode:en,carrier:er,retryStatus:el,disconnect:ea,reconnect:ei}=function(e={}){let{namespace:t="",socketOptions:s={},redirectOnNoAuth:n="/",onConnect:h,onDisconnect:b,onApproval:g}=e,v=(0,l.useRouter)(),{getAuth:y,setAuth:w}=(0,a.Fo)(),j=function(){let[e]=(0,r.useState)(()=>{let e=localStorage.getItem(i);return e||(e=globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,localStorage.setItem(i,e)),e});return e}(),k=(0,r.useRef)(null),N=(0,r.useRef)(null),[C,S]=(0,r.useState)(!1),[E,R]=(0,r.useState)("tunnel"),[T,$]=(0,r.useState)("ws"),[M,z]=(0,r.useState)({isRetrying:!1,attempt:0,maxAttempts:10,failed:!1}),P=(0,u.d)(e=>e.authKey),I=(0,r.useRef)(!1),[A,L]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e=!1,r=null;return(async()=>{let l=y();if((0,x._r)()&&window.location.port===String(m._8)&&!P&&l?.tunnelUrl!==window.location.origin)try{let e=await fetch(m.Go),t=e.ok?await e.json():null;if(e.ok&&t?.permanentKey){let e=t.permanentKey,s=(0,p.Uo)(e),n=(0,p.Cj)(e);(0,f.LG)(s,{tail:n}),l={apiKey:s,tunnelUrl:window.location.origin,mode:"local",tempKey:null,localIp:t.localIp||null},w(l)}}catch{}if(e)return;if(!l?.apiKey){u.d.getState().reset(),v.push(n);return}try{if("1"===sessionStorage.getItem("9remote_manual_disconnect"))return void u.d.getState().setConnection({deliberate:!0})}catch{}let a={tunnelUrl:l.tunnelUrl,localIp:l.localIp||null,namespace:t,socketOptions:{...s,auth:{apiKey:l.apiKey,tempKey:l.tempKey??null,deviceId:j,...s.auth}},apiKey:l.apiKey,deviceId:j,tempKey:l.tempKey??null,onConnect:(t,s)=>{if(e)return;I.current=!0,k.current=t,u.d.getState().setConnection({deliberate:!1,everConnected:!0});let n=s||N.current?.connectionMode||"tunnel";S(!0),R(n),u.d.getState().setConnection({bus:t,connected:!0,connectionMode:n,endpoint:l.tunnelUrl}),(0,d.c)("transport","[transport] ws connected"),h?.(t,l)},onDisconnect:t=>{e||((0,d.c)("transport",`[transport] ws disconnect reason=${t}`),k.current=null,S(!1),u.d.getState().setConnection({connected:!1}),b?.(t))},onApproval:g,onRetryStatus:t=>{e||(z(t),u.d.getState().setRetryStatus(t))}},i=l.tunnelUrl===window.location.origin,C=c.eR.enableWebRTC&&!i?{enableWebRTC:!0,enableTurn:c.eR.enableTurn,apiKey:l.apiKey,onUpgrade:e=>(0,d.c)("transport",`[transport] upgraded to ${e}`),onFallback:e=>(0,d.c)("transport",`[transport] fallback to ${e}`),onTransportChange:t=>{e||($(t),u.d.getState().setCarrier(t),(0,d.c)("transport",`[transport] active=${t}`))}}:null;N.current=r=new o.g(a,C),k.current=r.busRef.current,u.d.getState().setConnection({bus:k.current,busRef:k,protocolRef:N,deliberate:!1,...I.current?{}:{connected:!1,admitted:!1},connectionMode:"tunnel",carrier:"ws"}),r.connect()})(),()=>{e=!0,r?.disconnect(),N.current=null,k.current=null}},[P,A]),{bus:k.current,busRef:k,protocolRef:N,connected:C,connectionMode:E,carrier:T,retryStatus:M,disconnect:()=>{N.current?.disconnect(),N.current=null,k.current=null,S(!1),u.d.getState().reset(),u.d.getState().setConnection({deliberate:!0});try{sessionStorage.setItem("9remote_manual_disconnect","1")}catch{}},reconnect:()=>{try{sessionStorage.removeItem("9remote_manual_disconnect")}catch{}L(e=>e+1)}}}({namespace:"",redirectOnNoAuth:"/",onConnect:(0,r.useCallback)((e,s)=>{(R(z.J2.reconnect),L({status:"full"}),K("pm-connect"),Z.current===e)?G(e):(Z.current=e,e.on("device:pendingApproval",()=>{(0,A.Lq)("diag","EVENT device:pendingApproval arrived"),(0,d.c)("auth","[auth] agent says: waiting for host approval"),R(z.J2.pending)}),e.on("device:approved",()=>{(0,A.Lq)("diag","EVENT device:approved arrived → applying"),R(z.J2.approved),u.d.getState().setAdmitted(!0),(0,f.I8)(),T()}),e.on("terminal:ready",()=>{(0,d.c)("auth","[auth] terminal:ready (NOT an admission signal)"),G(e)}),e.on("connect",()=>{K("carrier-connect"),e.emit("device:clientReady"),Y(e),G(e)}),e.on("device:rejected",()=>{(0,A.Lq)("diag","EVENT device:rejected arrived → applying"),R(z.J2.rejected),D.current?.()}),e.on("device:tailRejected",e=>{if(e?.reason===z.ML.sealUnreadable)return;D.current?.();let t=E();(0,f.cH)(t?.apiKey),(0,f.cH)(t?.tempKey),sessionStorage.clear(),sessionStorage.setItem(z.Jd,e?.reason||z.ML.mismatch),window.location.replace("/login")}),e.on("serverInfo",e=>{let t=M.rh.getState(),s=!!t.hosts[t.currentKey]?.updating;if(L({platform:e.platform||null,version:e.version||null,isCodespaces:!!e.isCodespaces,updateAvailable:!s&&(0,I.U)(e.updateAvailable?.version,e.version)?e.updateAvailable:null,canSelfUpdate:!!e.canSelfUpdate,remoteAvailable:!!e.remoteAvailable,mobileAvailable:!!e.mobileAvailable}),g(e.remoteAvailable),y(!!e.mobileAvailable),j(e.platform),N(e.version||null),h.B.getState().setAgentCaps(e.caps||{}),h.B.getState().setArtifactEnabled(e.artifactEnabled),h.B.getState().setMcpClients(e.mcpClients),e.voiceConfig)$.getState().syncFromAgent(e.voiceConfig);else{let e=$.getState();(e.geminiKeys.some(e=>e.trim())||e.openrouterKey||e.customKey||e.customEndpoint)&&e.pushToAgent()}}),e.on("sessionClosed",e=>{t(t=>t.filter(t=>t.id!==e));let s=M.rh.getState(),n=s.hosts[s.currentKey]?.sessions;n?.some(t=>t.id===e)&&L({sessions:n.filter(t=>t.id!==e)}),h.B.getState().closeSession(e)}),e.on("session-renamed",({sessionId:e,name:s}={})=>{if(!e)return;t(t=>t.map(t=>t.id===e?{...t,name:s}:t));let n=M.rh.getState(),r=n.hosts[n.currentKey]?.sessions;r?.some(t=>t.id===e)&&L({sessions:r.map(t=>t.id===e?{...t,name:s}:t)})}),e.on("sessionAgentChanged",({sessionId:e,agent:t}={})=>{e&&t&&(h.B.getState().setSessionAgent(e,t),h.B.getState().invalidateAgentHistory())}),e.on("sessionsChanged",()=>G(e,!0)),e.on("workspacesChanged",()=>G(e)),Y(e),u.d.getState().setConnection({approvalStatus:null}),e.emit("device:clientReady"))},[T,G,R,E,K]),onApproval:R});(0,r.useEffect)(()=>{D.current=ea},[ea]);let eo=(0,r.useCallback)(()=>G(ee.current),[ee,G]),ec=(0,r.useCallback)(()=>G(ee.current,!0),[ee,G]);(0,r.useEffect)(()=>()=>{q.current&&(clearTimeout(q.current),q.current=null)},[]),(0,r.useEffect)(()=>{if(!es)return;let e=setInterval(()=>{B.current.sessions&&B.current.workspaces||eo()},2e3);return()=>clearInterval(e)},[es,eo]),(0,r.useEffect)(()=>{if(!es)return;let e=()=>{"visible"===document.visibilityState&&eo()};return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[es,eo]);let ed=(0,r.useCallback)((e,n,r,l,a,i=!1,o=null,c=null)=>{if(!ee.current)return;"function"==typeof n?(a=n,n=null,r=null,l=null):"function"==typeof r?(a=r,r=null,l=null):"function"==typeof l&&(a=l,l=null);let d="string"==typeof o?o:o?.id||null;ee.current.emit("createSession",{name:e,shellId:n,workspaceId:r,cwd:l,nameIsAuto:i,agent:d,replaces:c},i=>{if(i?.success){if(i.sessionId){d&&h.B.getState().setSessionAgent(i.sessionId,d);let a=s.find(e=>e.id===r)?.path||null,o={id:i.sessionId,name:i.name||e||"Terminal",createdAt:Date.now(),cwd:i.cwd||l||null,workspaceId:r||null,groupId:r||null,workspacePath:a,shellId:i.shellId||n||null,shellLabel:i.shellLabel||null,agent:d||null},c=e=>[...e.filter(e=>e.id!==i.sessionId&&e.id!==i.replaced),o];t(c);let u=M.rh.getState(),x=u.hosts[u.currentKey]?.sessions;x&&L({sessions:c(x)})}ec()}a?.(i)})},[ee,ec,s]),eu=(0,r.useCallback)((e,t,s)=>{"function"==typeof t&&(s=t,t=null),ee.current?.emit("createWorkspace",{name:e,path:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),ex=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("renameWorkspace",{workspaceId:e,name:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),em=(0,r.useCallback)((e,t)=>{ee.current?.emit("deleteWorkspace",{workspaceId:e},e=>{e?.success&&ec(),t?.(e)})},[ee,ec]),ep=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("setWorkspaceHiddenRepos",{workspaceId:e,paths:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),ef=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("moveSession",{sessionId:e,workspaceId:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),eh=(0,r.useCallback)((e,t)=>{ee.current?.emit("reorderSession",{orderedIds:e},e=>{e?.success&&ec(),t?.(e)})},[ee,ec]),eb=(0,r.useCallback)(e=>{ee.current&&ee.current.emit("getShells",t=>e?.(t))},[ee]),eg=(0,r.useCallback)((e,t)=>{ee.current&&ee.current.emit("deleteSession",e,e=>{e.success&&ec(),t?.(e)})},[ee,ec]),ev=(0,r.useCallback)((e,t,s)=>{ee.current&&ee.current.emit("renameSession",{sessionId:e,name:t},e=>{e.success&&ec(),s?.(e)})},[ee,ec]);return{bus:Q,busRef:ee,protocolRef:et,disconnect:ea,reconnect:ei,connected:es,connectionMode:en,carrier:er,retryStatus:el,approvalStatus:C,admitted:S,sessions:e,remoteAvailable:b,mobileAvailable:v,platform:w,agentVersion:k,workspaces:s,loadSessions:eo,createSession:ed,getShells:eb,deleteSession:eg,renameSession:ev,createWorkspace:eu,renameWorkspace:ex,deleteWorkspace:em,setWorkspaceHiddenRepos:ep,moveSession:ef,reorderSession:eh}}(),{loadKeys:tA,saveKey:tL,renameKey:tD,removeKey:tB}=(0,nY.u)(),[tF,tK]=(0,r.useState)([]);(0,r.useEffect)(()=>{W&&tK(tA())},[W,tA]),(0,r.useEffect)(()=>{if(!W)return;let e=()=>tK(tA());return window.addEventListener(nY.N,e),()=>window.removeEventListener(nY.N,e)},[W,tA]);let tO=e9?.apiKey?(0,p.Uo)(e9.apiKey):"",tW=ej(tO||null);(0,r.useEffect)(()=>{if(W){if(!tO)return void M.rh.getState().closeAll();M.rh.getState().sync(tF,tO)}},[W,tF,tO]);let t_=(0,M.rh)(e=>e.hosts),tH=t_[tO],tq=(0,r.useMemo)(()=>tH?.sessions||[],[tH]),tU=(0,r.useMemo)(()=>tH?.workspaces||[],[tH]),tV=(0,r.useMemo)(()=>(function(e,t){let s={sessions:[],workspaces:[]};if(!t)return s;for(let n of e){if(n.key===t)continue;let e=`${n.key}:`,r=`${e}_`,l=(n.sessions||[]).some(e=>null==e.workspaceId);for(let t of n.workspaces||[])s.workspaces.push({...t,id:e+t.id,hostKey:n.key});for(let t of(l&&s.workspaces.push({id:r,name:n.label||n.key,hostKey:n.key}),n.sessions||[]))s.sessions.push({...t,workspaceId:null!=t.workspaceId?e+t.workspaceId:r,hostKey:n.key})}return s})(Object.values(t_),tO),[t_,tO]),tX=(0,r.useMemo)(()=>[...tq,...tV.sessions],[tq,tV]),tG=(0,r.useMemo)(()=>[...tU,...tV.workspaces],[tU,tV]),tJ=(0,r.useCallback)((e,t)=>{let s=tA().find(t=>(0,p.Uo)(t.key)===e);s?tD(s.id,t):tL(e,t)},[tA,tD,tL]),[tY,tZ]=(0,r.useState)([]),tQ=function(){let[e,t]=(0,r.useState)(!1),s=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let e=()=>{"visible"===document.visibilityState&&(t(!0),clearTimeout(s.current),s.current=setTimeout(()=>t(!1),4e3))};return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e),clearTimeout(s.current)}},[]),e}(),t0=(0,u.d)(e=>e.bus),t1=(0,u.d)(e=>e.deliberate),t2=(0,u.d)(e=>e.everConnected),t5=!!tH?.updating,t3=(0,r.useRef)({armed:!1,version:null,dropped:!1});(0,r.useEffect)(()=>{if(!tH||!tO)return;let e=t3.current;if(!tH.updating){e.armed=!1,e.dropped=!1;return}if(e.armed||(e.armed=!0,e.version=tH.version||null),tu||(e.dropped=!0),e.dropped&&tu){let t=setTimeout(()=>{let t=M.rh.getState().hosts[tO];t?.version&&e.version&&t.version!==e.version?window.location.reload():M.rh.getState()._patchHost(tO,{updating:!1})},1500);return()=>clearTimeout(t)}},[tH,t5,tu,tO]);let[t4,t6]=(0,r.useState)({isOpen:!1,title:"",message:"",onConfirm:null,confirmText:null});(0,r.useEffect)(()=>{tu&&("win32"===tw?tZ([{id:"cmd",label:"Command Prompt"},{id:"powershell",label:"PowerShell"}]):tZ([]))},[tu,tw]);let t8=es();t=(0,M.rh)(e=>`${e.currentKey}|`+Object.values(e.hosts).filter(e=>"online"===e.status||"full"===e.status).map(e=>e.key).join(",")),(0,r.useEffect)(()=>{let e=M.rh.getState(),s=t.slice(t.indexOf("|")+1),n=[];for(let t of s.split(",").filter(Boolean)){let s=eE(t===e.currentKey?null:t).bus;if(!s)continue;let r=({count:e})=>M.rh.getState()._patchHost(t,{mobileDeviceCount:Number(e)||0});s.on("mobile:devicesChanged",r),s.emit("mobile:deviceCount",{},e=>{e&&"number"==typeof e.count&&r(e)}),n.push(()=>s.off("mobile:devicesChanged",r))}return()=>{for(let e of n)e()}},[t]);let{subscribeToPush:t9,unsubscribeFromPush:t7,notifications:se}=(s=(0,r.useRef)(null),b=ey(e=>e.notifications),(0,h.B)(e=>e.getSelectedSession),(0,h.B)(e=>e.getCurrentView),g=(0,h.B)(e=>e.pushView),v=(0,h.B)(e=>e.addOpenedSession),y=!!window.ReactNativeWebView,w=(0,M.rh)(e=>Object.values(e.hosts).filter(e=>"online"===e.status).map(e=>e.key).join(",")),j=(0,r.useCallback)(e=>{for(let t of(ta?.current&&e(ta.current),Object.values(M.rh.getState().hosts))){if("online"!==t.status)continue;let s=(0,M.eJ)(t.key);s&&e(s)}},[ta]),(0,r.useEffect)(()=>(window.handleNotificationTap=e=>{let t=e?.sessionId;t&&(v(t),g({type:"terminal",sessionId:t}))},()=>{try{delete window.handleNotificationTap}catch(e){window.handleNotificationTap=void 0}}),[g,v]),(0,r.useEffect)(()=>{if(y)return window.handleAppStateChange=e=>{j(t=>t.emit("visibilityChange",!!e))},()=>{try{delete window.handleAppStateChange}catch(e){window.handleAppStateChange=void 0}}},[ta,y,j]),k=(0,r.useCallback)(async()=>{if(ta?.current){if(localStorage.removeItem(eI),y){window.handleExpoPushToken=e=>{j(t=>t.emit("pushSubscribe",{type:"expo",token:e})),s.current={type:"expo",token:e}},window.ReactNativeWebView.postMessage(JSON.stringify({type:"REQUEST_PUSH_TOKEN"}));return}if(!("serviceWorker"in navigator)||!("PushManager"in window))return void console.warn("\uD83D\uDD15 Push not supported");try{let e=await Notification.requestPermission();if("granted"!==e)return;let t=await navigator.serviceWorker.ready;if(!t.pushManager)return;let n=await new Promise(e=>ta.current.emit("getVapidKey",e));if(!n)return;let r=await t.pushManager.getSubscription();r||(r=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n})),j(e=>{e.emit("pushSubscribe",r.toJSON()),e.emit("visibilityChange",document.hidden)}),s.current=r}catch(e){console.error("Push notification setup failed:",e)}}},[ta,y]),(0,r.useEffect)(()=>{let e=ta?.current;if(e&&tu&&"1"!==localStorage.getItem(eI)){if(y){window.handleExpoPushToken=t=>{e.emit("pushSubscribe",{type:"expo",token:t}),s.current={type:"expo",token:t}},window.ReactNativeWebView.postMessage(JSON.stringify({type:"REQUEST_PUSH_TOKEN"}));return}(async()=>{try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return;let t=await navigator.serviceWorker.ready;if(!t.pushManager)return;let s=await t.pushManager.getSubscription();if(!s&&"granted"===Notification.permission){let n=await new Promise(t=>e.emit("getVapidKey",t));n&&(s=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n}))}s&&(e.emit("pushSubscribe",s.toJSON()),e.emit("visibilityChange",document.hidden))}catch(e){}})()}},[ta,tu,y]),(0,r.useEffect)(()=>{s.current&&"1"!==localStorage.getItem(eI)&&j(e=>{let t;return e.emit("pushSubscribe",(t=s.current,t?.type==="expo"?{type:"expo",token:t.token}:t?.toJSON?.()||t))})},[w,j]),(0,r.useEffect)(()=>{let e=ta?.current;if(!e||!tu)return;let t=()=>{e.emit("getStatusState"),e.emit("getNotificationState")},s=()=>M.rh.getState().currentKey,n=e=>M.rh.getState().applyStatusState(s(),e),r=e=>{if(ey.getState().handleStatusChange(e),M.rh.getState().applyStatusChange(s(),e),e&&("done"===e.state||"blocked"===e.state)){let t="done"===e.state,s=e.tool?e.tool.charAt(0).toUpperCase()+e.tool.slice(1):"Terminal",n=t?`${s} \xb7 your turn`:`${s} needs input`;window.__9R_DESKTOP__?.showNotification&&window.__9R_DESKTOP__.showNotification(n,t?"The agent finished its turn and is waiting for you":"Action required to proceed")}},l=e=>M.rh.getState().applyStatusCleared(s(),e),a=e=>ey.getState().handleNotificationState(e),i=()=>t(),o=()=>{e.emit("visibilityChange",document.hidden)},c=()=>t();return e.on("notificationState",a),e.on("notificationCleared",i),e.on("statusState",n),e.on("statusChange",r),e.on("statusCleared",l),e.on("connect",c),document.addEventListener("visibilitychange",o),t(),()=>{e.off("notificationState",a),e.off("notificationCleared",i),e.off("statusState",n),e.off("statusChange",r),e.off("statusCleared",l),e.off("connect",c),document.removeEventListener("visibilitychange",o)}},[ta,tu]),N=e$(),C=(0,r.useMemo)(()=>eP(N).total,[N]),(0,r.useEffect)(()=>{window.__9R_DESKTOP__?.setBadge&&window.__9R_DESKTOP__.setBadge(C),"u">typeof navigator&&"setAppBadge"in navigator&&(C>0?navigator.setAppBadge(C).catch(()=>{}):navigator.clearAppBadge().catch(()=>{}))},[C]),{subscribeToPush:k,unsubscribeFromPush:(0,r.useCallback)(async()=>{localStorage.setItem(eI,"1");try{if(s.current?.type==="expo"){j(e=>e.emit("pushUnsubscribe",s.current.token)),s.current=null;return}if(s.current)await s.current.unsubscribe(),j(e=>e.emit("pushUnsubscribe",s.current.endpoint)),s.current=null;else{let e=await navigator.serviceWorker.ready,t=await e.pushManager.getSubscription();t&&(j(e=>e.emit("pushUnsubscribe",t.endpoint)),await t.unsubscribe())}}catch(e){console.error("Push unsubscribe failed:",e)}},[ta,j]),notifications:b}),st=B(e=>e.setKeyboardOpen),[ss,sn]=(0,r.useState)(()=>window.innerWidth>=eV.jK),sr=(S=(0,r.useRef)(null),(0,r.useCallback)(({enabled:e,sessionIds:t,activeSessionId:s,onSwitch:n})=>({onTouchStart:t=>{if(!e||1!==t.touches.length||function(e,t=e=>"function"==typeof getComputedStyle?getComputedStyle(e).overflowX:""){for(let s=e;s&&1===s.nodeType;s=s.parentElement){let e=t(s);if(("auto"===e||"scroll"===e)&&s.scrollWidth>s.clientWidth)return!0}return!1}(t.target))return S.current=null;let s=t.touches[0];S.current={x:s.clientX,y:s.clientY,time:performance.now()}},onTouchEnd:r=>{let l=S.current;if(S.current=null,!l||!e||t.length<2)return;let a=r.changedTouches[0],i=a.clientX-l.x,o=a.clientY-l.y;if(performance.now()-l.time>eV.bl.maxDuration||Math.abs(i)<eV.bl.minDistance||Math.abs(i)<Math.abs(o)*eV.bl.ratio)return;let c=t.indexOf(s);if(-1===c)return;let d=i<0?t[c+1]:t[c-1];d&&d!==s&&n?.(d)}}),[]));(0,r.useEffect)(()=>{let e=0,t=()=>{clearTimeout(e),e=setTimeout(()=>sn(window.innerWidth>=eV.jK),50)};return window.addEventListener("resize",t),()=>{clearTimeout(e),window.removeEventListener("resize",t)}},[]);let sl=H[H.length-1]||{type:"list"},sa=sl?.type==="terminal"||ss&&sl?.type==="list",si=sl?.type==="terminal"?sl.sessionId:sa&&q[q.length-1]||null,so=function({isDesktop:e,isTerminalView:t,activeSessionId:s,currentView:n,openedSessions:l}){let a=(0,r.useRef)({}),i=(0,r.useRef)({}),o=(0,r.useRef)(null),c=(0,r.useRef)(null),d=(0,r.useRef)(!1),u=(0,r.useRef)(null),x=(0,r.useCallback)((t,s)=>{s?(a.current[t]=s,u.current===t&&e&&!d.current&&(u.current=null,setTimeout(()=>s.focus?.(),50))):delete a.current[t]},[e]),m=(0,r.useCallback)((e,t)=>{t?i.current[e]=t:delete i.current[e]},[]),p=(0,r.useCallback)(t=>{c.current=t,t&&u.current&&e&&d.current&&(u.current=null,setTimeout(()=>t.focus?.(),50))},[e]),f=(0,r.useCallback)(t=>{e&&(u.current=t,setTimeout(()=>{u.current===t&&(u.current=null,d.current&&c.current?.focus?c.current.focus():a.current[t]?.focus?.())},60))},[e]),b=(0,r.useCallback)(()=>{c.current?.openTextPanel?.()},[]),g=(0,r.useCallback)(e=>{d.current=e},[]),v=(0,r.useCallback)(e=>a.current[e]?.focus?.(),[]),y=(0,r.useCallback)(()=>{c.current?.focus?.()},[]),w=(0,r.useCallback)(e=>{d.current?a.current[e]?.focus?.():c.current?.focus?.()},[]),j=(0,r.useRef)(0),k=(0,r.useCallback)(t=>{if(!e)return;if(h.B.getState().fullMode){o.current&&(o.current.scrollLeft=0);return}cancelAnimationFrame(j.current),j.current=0;let s=o.current,n=(0,eY.g4)({container:s,pane:i.current[t]});if(null==n){j.current=requestAnimationFrame(()=>{j.current=0;let e=(0,eY.g4)({container:s,pane:i.current[t]});null!=e&&s.scrollTo({left:e,behavior:"smooth"})});return}s.scrollTo({left:n,behavior:"smooth"})},[e]),N=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!e||n?.type!=="terminal"||!n?.sessionId||N.current===n.sessionId)return;N.current=n.sessionId;let t=requestAnimationFrame(()=>k(n.sessionId));return()=>cancelAnimationFrame(t)},[n?.type,n?.sessionId,e,k]),(0,r.useEffect)(()=>{if(!e||!t||!s)return;let n=setTimeout(()=>{d.current?c.current?.focus?.():a.current[s]?.focus?.()},60);return()=>clearTimeout(n)},[s,e,t]),(0,r.useMemo)(()=>({panesContainerRef:o,registerPaneApi:x,registerPaneElement:m,registerKeyboardTextApi:p,handlePasteFallback:b,handleInputFocusChange:g,focusPane:v,focusKeyboardInput:y,toggleInputFocus:w,scrollPaneIntoView:k,requestFocus:f}),[x,m,p,b,g,v,y,w,k,f])}({isDesktop:ss,isTerminalView:sa,activeSessionId:si,currentView:sl,openedSessions:q}),sc=function({sessions:e,currentView:t,viewStack:s,setViewStack:n,pushView:l,storePopView:a,activeWorkspaceId:i,setActiveWorkspaceId:o,activeSessionId:c,addOpenedSession:d,removeOpenedSession:u,touchLivePane:x,createSession:m,deleteSession:p,renameSession:f,busRef:b,isDesktop:g=!1,requestFocus:v=null}){let{t:y}=(0,ec.s)(),w=(0,r.useCallback)(e=>{let t=[...s];t[t.length-1]={type:"terminal",sessionId:e},n(t)},[s,n]),j=(0,r.useCallback)(t=>e.filter(e=>(0,eY.xs)(e)===(t??null)).map(e=>e.id),[e]),k=(0,r.useCallback)(e=>alert(y("workspace.failedCreateSession",{error:e})),[y]),N=(0,r.useCallback)((s,n)=>{let r=e.find(e=>e.id===s);if(!r&&void 0===n)return;let a=r?(0,eY.xs)(r):n;o(a);let i=j(a);i.forEach(e=>d(e)),d(s),x([...i,s]),"terminal"===t.type?w(s):l({type:"terminal",sessionId:s}),r||v?.(s)},[e,j,d,x,o,t,l,w,v]);(0,r.useEffect)(()=>{let t=e=>{if(e.data?.type!=="NOTIFICATION_CLICK")return;let t=new URLSearchParams(new URL(e.data.url||"",location.origin).search).get("t");t&&N(t)},s=()=>{let t=Object.values(ey.getState().notifications||{});if(!t.length)return;let s=t=>{let s=e.find(e=>e.id===t);return s&&(0,eY.xs)(s)===(i??null)},n=t.sort((e,t)=>{let n=s(e.sessionId),r=s(t.sessionId);return n&&!r?-1:!n&&r?1:"blocked"===e.type&&"blocked"!==t.type?-1:"blocked"===t.type&&"blocked"!==e.type?1:(t.timestamp||0)-(e.timestamp||0)})[0];n?.sessionId&&N(n.sessionId)};return window.addEventListener("message",t),window.addEventListener("9remote:dock-click",s),()=>{window.removeEventListener("message",t),window.removeEventListener("9remote:dock-click",s)}},[N,e,i]),(0,r.useEffect)(()=>{let e=e=>{e.detail?.sessionId&&N(e.detail.sessionId)};return window.addEventListener(eV.vP,e),()=>window.removeEventListener(eV.vP,e)},[N]);let C=(0,r.useCallback)(e=>{let t=j(i);if(t.length<2)return;let s=t.indexOf(c);if(-1===s)return;let n="prev"===e?(s-1+t.length)%t.length:(s+1)%t.length;N(t[n])},[j,i,c,N]),S=(0,r.useCallback)(e=>{let t=j(i);e<0||e>=t.length||N(t[e])},[j,i,N]),E=(0,r.useCallback)((e,s=null,n=null,r=null,a=null,i=!1,c=!1)=>{m(e,n,s,r||null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let n=e5(a,i);n&&h.B.getState().queueStartup(e.sessionId,n),a?.id&&h.B.getState().setSessionAgent(e.sessionId,a.id);let r=s??null;o(r);let c=j(r);c.forEach(e=>d(e)),d(e.sessionId),x([...c,e.sessionId]),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},c,a)},[m,j,d,x,k,t,w,l,o,v]),R=(0,r.useCallback)(e=>{if(!e?.resume)return;let s="ui"===e.mode,n=M.rh.getState().currentKey||"main",r=h.B.getState().agentClisBy[n]?.list?.find(t=>t.id===e.agent)||null,a=s?null:e3(r,e.resume);m(null,null,i,e.cwd||null,n=>{if(!n?.success)return k(n?.error);if(!n.sessionId)return;a&&h.B.getState().queueStartup(n.sessionId,a);let r=s?`${e.agent}-ui`:e.agent;r&&h.B.getState().setSessionAgent(n.sessionId,r),b?.current?.emit("claimAgentSession",{sessionId:n.sessionId,agent:r,conversationId:e.sessionId},()=>h.B.getState().invalidateAgentHistory()),d(n.sessionId),x(n.sessionId),"terminal"===t.type?w(n.sessionId):l({type:"terminal",sessionId:n.sessionId}),v?.(n.sessionId)})},[m,i,d,x,k,w,l,t,v,b]),T=(0,r.useCallback)((e,s=null,n=!1,r=null,a=!1)=>{m(r,e,i,null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let r=e5(s,n);r&&h.B.getState().queueStartup(e.sessionId,r),s?.id&&h.B.getState().setSessionAgent(e.sessionId,s.id),d(e.sessionId),x(e.sessionId),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},a,s)},[m,i,d,x,k,w,l,t,v]),$=(0,r.useCallback)((s,n,r=null,a=!1)=>{m(n,null,i,e.find(e=>e.id===s)?.cwd||null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let n=e.replaced||s;r?.id&&h.B.getState().setSessionAgent(e.sessionId,r.id),n?h.B.getState().replaceOpenedSession(n,e.sessionId):d(e.sessionId),x(e.sessionId),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},a,r,s)},[m,i,k,d,x,w,l,t,v,e]),z=(0,r.useCallback)(e=>{m(null,t=>{if(!t.success)return k(t.error);t.sessionId&&(d(t.sessionId),e?.(t.sessionId))})},[m,d,k]),P=(0,r.useCallback)(t=>{o(t);let s=e.filter(e=>(0,eY.xs)(e)===(t??null));s.forEach(e=>d(e.id)),x(s.map(e=>e.id));let n=s[0];n&&w(n.id)},[e,o,d,x,w]),I=(0,r.useCallback)(s=>{let n=e.find(e=>e.id===s),r=(0,eY.xs)(n),l=t?.type==="terminal"&&t.sessionId===s,i=()=>{if(u(s),h.B.getState().closeSession(s),!l)return;let t=e.filter(e=>e.id!==s),n=t.filter(e=>(0,eY.xs)(e)===r)[0]||t[0];n?(w(n.id),x(n.id)):a()},o=n?.hostKey?M.rh.getState().hosts[n.hostKey]:null;if(o){tt(o).deleteSession(s),i();return}p(s,i)},[e,t,p,u,x,a,w]),A=(0,r.useCallback)((t,s)=>{let n=e.find(e=>e.id===t)?.hostKey;if(n){let e=M.rh.getState().hosts[n];e&&tt(e).renameSession(t,s);return}f(t,s,e=>{e.success||alert(y("workspace.failedRenameSession",{error:e.error}))})},[e,f,y]);return(0,r.useMemo)(()=>({handleSelectSession:N,handleSelectWorkspace:P,handleCreateSession:E,handleQuickCreateSession:T,handleReplaceSession:$,handleResumeAgentSession:R,handleCreateSessionInline:z,handleDeleteSession:I,handleRenameSession:A,switchSession:C,switchToIndex:S}),[N,P,E,T,$,R,z,I,A,C,S])}({sessions:tX,currentView:sl,viewStack:H,setViewStack:X,pushView:U,storePopView:V,activeWorkspaceId:Z,setActiveWorkspaceId:Q,activeSessionId:si,addOpenedSession:G,removeOpenedSession:J,touchLivePane:et,createSession:tE,deleteSession:tR,renameSession:tT,busRef:ta,requestFocus:so.requestFocus}),{systemInfo:sd,mobileEditor:su,setMobileEditor:sx,openFileRef:sm,handleOpenWorkspaceList:sp,handleOpenFiles:sf,handleSelectWorkspace:sh,handleBrowseFolder:sb,handlePathChange:sg,handleOpenFile:sv,handleOpenGit:sy,handleSetWorkspace:sw}=function({pushView:e,viewStack:t,setViewStack:s,currentView:n,cwdBySession:l,sessions:a=[],isDesktop:i,fileBus:o,scope:c=""}){let[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),p=(0,r.useRef)(null),f=(0,r.useCallback)(async()=>{if(!d){let e=await o.getSystemInfo();e.success&&u(e)}e({type:"workspaces"})},[e,o,d]),h=(0,r.useCallback)(async t=>{if(t){ep(t,c),e({type:"files",workspace:t,currentPath:t});return}if("terminal"===n.type){let t=n.sessionId&&(l[n.sessionId]||a.find(e=>e.id===n.sessionId)?.cwd)||null;if(t){ep(t,c),e({type:"files",workspace:t,currentPath:t});return}}let s=em(c);if(s.length>0){let t=s[0];e({type:"files",workspace:t.path,currentPath:t.lastPath||t.path});return}f()},[e,f,n,l,a,c]),b=(0,r.useCallback)(e=>{ep(e,c),s([...t.filter(e=>"workspaces"!==e.type&&"files"!==e.type),{type:"files",workspace:e}])},[t,s]),g=(0,r.useCallback)(t=>{e({type:"browse",path:t})},[e]),v=(0,r.useCallback)((e,t)=>{!function(e,t,s=""){let n=(0,F.kb)(e),r=em(s),l=r.findIndex(e=>e.path===n);-1!==l&&(r[l]={...r[l],lastPath:(0,F.kb)(t)},localStorage.setItem(ed(s),JSON.stringify(r)))}(e,t,c)},[]),y=(0,r.useCallback)((e,t,s={})=>{i?p.current?.(e,s):m({path:e,line:s.line,column:s.column,workspace:n.workspace})},[i,n.workspace]);return{systemInfo:d,mobileEditor:x,setMobileEditor:m,openFileRef:p,handleOpenWorkspaceList:f,handleOpenFiles:h,handleSelectWorkspace:b,handleBrowseFolder:g,handlePathChange:v,handleOpenFile:y,handleOpenGit:(0,r.useCallback)(()=>{let s=t.find(e=>"files"===e.type);s?.workspace&&e({type:"git",workspace:s.workspace})},[e,t]),handleSetWorkspace:(0,r.useCallback)(e=>{ep(e,c),s([...t.filter(e=>"browse"!==e.type&&"workspaces"!==e.type&&"files"!==e.type),{type:"files",workspace:e}])},[t,s])}}({pushView:U,viewStack:H,setViewStack:X,currentView:sl,cwdBySession:eo,sessions:tq,isDesktop:ss,fileBus:t8,scope:tW}),[sj,sk]=(0,r.useState)(null),sN=eb(e=>e.open),sC=(0,r.useMemo)(()=>W?em(tW):[],[W,tU,tW]),sS=(0,r.useCallback)(e=>{sk(null),e&&t$(e.split("/").filter(Boolean).pop()||e,e,t=>{let s=t?.workspace||t?.group;t?.success&&s?.id&&(ep(e,tW),Q(s.id),sc.handleCreateSession(null,s.id,null,e))})},[t$,Q,sc]),sE=(0,r.useCallback)(e=>{if(e)return sS(e);sk({initialPath:null})},[sS]),sR=(0,r.useCallback)((e,t,s,n,r,l,a)=>{let i=tG.find(e=>e.id===t)?.hostKey||Object.values(t_).find(e=>"string"==typeof t&&t.startsWith(`${e.key}:`))?.key;if(i){let o=M.rh.getState().hosts[i];if(!o)return;tt(o,{onSelectSession:sc.handleSelectSession}).createSession(e,ek(t,i),s,n,r,l,a);return}sc.handleCreateSession(e,t,s,n,r,l,a)},[tG,t_,sc]),sT=(0,r.useCallback)(e=>{let t=tX.find(e=>e.id===si)?.hostKey||tG.find(e=>e.id===Z)?.hostKey;if(!t||!e?.resume)return;let s=M.rh.getState().hosts[t];if(!s)return;let n="ui"===e.mode,r=h.B.getState().agentClisBy[t]?.list?.find(t=>t.id===e.agent)||null,l=n?null:e3(r,e.resume),a=n?`${e.agent}-ui`:e.agent,i=ek(Z,t);tt(s,{onSelectSession:sc.handleSelectSession}).createSession(null,i&&"_"!==i?i:null,null,e.cwd||null,null,!1,!1,s=>{s?.success&&s.sessionId&&(l&&h.B.getState().queueStartup(s.sessionId,l),a&&h.B.getState().setSessionAgent(s.sessionId,a),(0,M.Nw)(t,t=>t.emit("claimAgentSession",{sessionId:s.sessionId,agent:a,conversationId:e.sessionId},()=>h.B.getState().invalidateAgentHistory())))})},[tX,tG,si,Z,sc]),s$=(0,r.useCallback)(e=>{sR(null,Z,null,e)},[sR,Z]),sM=tG.find(e=>e.id===Z)?.hostKey||null,sz=sM||tO||"main",sP=th(eE(sM).busRef,sz),sI=tf(e=>e.open),sA=tf(e=>e.isOpen),sL=tf(e=>e.close),[sB,sF]=(0,r.useState)(!1),sK=tU.find(e=>e.id===Z)?.path||tq.find(e=>e.id===si)?.workspacePath||null,sO=(0,r.useCallback)(()=>{let{agentId:e,shellId:t,yolo:s}=te(),n=(sP||[]).flatMap(e=>{let t=tb.H8.find(t=>t.aiEngine===e.id);return t?[e,t]:e}),r=e&&n.find(t=>t.id===e)||null,l=tX.filter(e=>(0,eY.xs)(e)===(Z??null)).length+1;sR(r?`${r.short||r.label} ${l}`:null,Z,r?null:t,null,r,s,!0)},[sP,tX,Z,sR]),sW=(0,r.useCallback)(e=>{let t=tU.map(e=>e.id);if(tq.some(e=>null===(0,eY.xs)(e))&&t.push(null),t.length<2)return;let s=t.indexOf(Z??null),n=-1===s?0:s,r="prev"===e?(n-1+t.length)%t.length:(n+1)%t.length;sc.handleSelectWorkspace(t[r])},[tU,tq,Z,sc]);!function(e,t=!0){let s=(0,r.useRef)(e);(0,r.useEffect)(()=>{s.current=e}),(0,r.useEffect)(()=>{if(!t)return;let e=e=>{if(document.querySelector('[role="dialog"], [aria-modal="true"], .modal-overlay'))return;let t=function(e){let t=ti();if(t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){let t=tl.exec(e.code)||(/^[1-9]$/.test(e.key)?[null,e.key]:null);return t?{id:tn.id,index:Number(t[1])-1}:"ArrowLeft"===e.key?{id:"sessionPrev"}:"ArrowRight"===e.key?{id:"sessionNext"}:"ArrowUp"===e.key?{id:"workspacePrev"}:"ArrowDown"===e.key?{id:"workspaceNext"}:tx(e.target)?null:"Backquote"===e.code||"`"===e.key?{id:"toggleFocus"}:"Equal"===e.code||"="===e.key||"≠"===e.key||"+"===e.key?{id:"fitPanes"}:"KeyW"===e.code||"∑"===e.key||e.key?.toLowerCase()==="w"?{id:"closeTerminal"}:null}if(t&&e.altKey&&e.shiftKey&&!e.ctrlKey&&!e.metaKey){if(tx(e.target))return null;let t=tm(e.target);return"Enter"===e.key||"Enter"===e.code?{id:"newTerminal"}:t?null:"KeyP"===e.code||"π"===e.key||"∏"===e.key||e.key?.toLowerCase()==="p"?{id:"palette"}:"KeyB"===e.code||"ı"===e.key||"∫"===e.key||e.key?.toLowerCase()==="b"?{id:"toggleSidebar"}:"KeyJ"===e.code||"\xd4"===e.key||"∆"===e.key||e.key?.toLowerCase()==="j"?{id:"toggleRightPanel"}:"Slash"===e.code||"?"===e.key||"\xbf"===e.key||"/"===e.key?{id:"help"}:null}if(e.ctrlKey&&!e.shiftKey&&!e.metaKey&&!e.altKey&&("Backquote"===e.code||"`"===e.key)&&!tx(e.target))return{id:"toggleFocus"};if(!t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){if(tx(e.target))return null;if("Equal"===e.code||"="===e.key||"+"===e.key)return{id:"fitPanes"};if("KeyW"===e.code||e.key?.toLowerCase()==="w")return{id:"closeTerminal"}}if(!t&&e.ctrlKey&&e.shiftKey&&!e.altKey&&!e.metaKey){let t=tl.exec(e.code);if(t)return{id:tn.id,index:Number(t[1])-1};if("ArrowLeft"===e.key)return{id:"sessionPrev"};if("ArrowRight"===e.key)return{id:"sessionNext"};if("ArrowUp"===e.key)return{id:"workspacePrev"};if("ArrowDown"===e.key)return{id:"workspaceNext"};if("Equal"===e.code||"="===e.key||"+"===e.key)return{id:"fitPanes"};let s=tm(e.target);if("Enter"===e.key||"Enter"===e.code)return{id:"newTerminal"};if(s)return null;if("KeyP"===e.code||e.key?.toLowerCase()==="p")return{id:"palette"};if("KeyB"===e.code||e.key?.toLowerCase()==="b")return{id:"toggleSidebar"};if("KeyJ"===e.code||e.key?.toLowerCase()==="j")return{id:"toggleRightPanel"};if("Slash"===e.code||"/"===e.key||"?"===e.key)return{id:"help"}}return null}(e);if(!t)return;let n=s.current?.[t.id];n&&(e.preventDefault(),e.stopPropagation(),n(t.index))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[t])}({sessionPrev:()=>sc.switchSession("prev"),sessionNext:()=>sc.switchSession("next"),workspacePrev:()=>sW("prev"),workspaceNext:()=>sW("next"),sessionIndex:e=>sc.switchToIndex(e),closeTerminal:(0,r.useCallback)(()=>{if(sl?.type!=="terminal"||!sl.sessionId)return;let e=tq.find(e=>e.id===sl.sessionId);e&&t6({isOpen:!0,title:O("sessions.deleteTitle"),message:O("sessions.deleteMessage",{name:e.name||O("terminal.defaultName")}),confirmText:O("common.delete"),onConfirm:()=>sc.handleDeleteSession(e.id)})},[sl,tq,sc,O]),toggleFocus:()=>so.toggleInputFocus(si),fitPanes:()=>window.dispatchEvent(new CustomEvent("terminal:fitPanes")),newTerminal:sO,toggleSidebar:ex,toggleRightPanel:eR,palette:()=>{sK&&sF(!0)},help:sI},ss&&sa);let s_=(0,r.useCallback)(e=>{let t=tU.find(e=>e.id===Z)?.path||tq.find(e=>e.id===sl.sessionId)?.workspacePath||null;eB(),U({type:"editor",path:e,workspace:t})},[tU,Z,tq,sl,U,eB]),sH=(0,r.useCallback)((e,t={})=>{if((0,F.pA)(e)){let{status:t,repoPath:s,filePath:n}=(0,F.qu)(e);sx({path:s?`${s}/${n}`:n,workspace:s||void 0,diffStatus:t});return}sx({path:e,workspace:tU.find(e=>e.id===Z)?.path,preview:!!t.preview,artifactSessionId:t.artifactSessionId||null})},[tU,Z,sx]),sq=(0,r.useCallback)((e,t)=>{if(!t?.path)return;let s=t.title||t.path.split("/").pop();ss?eD(t.path,{preview:!0,artifactTitle:s,artifactSessionId:e}):sH(t.path,{preview:!0,artifactSessionId:e})},[ss,eD,sH]);(0,r.useEffect)(()=>{let e=ta.current;if(!e)return;let t=({path:e,title:t,sessionId:s}={})=>{if(!e)return;let n={path:e,title:t||e.split("/").pop(),at:Date.now()};s&&e0(s,n),s&&s!==si||sq(s,n)};return e.on("artifactOpen",t),()=>e.off("artifactOpen",t)},[ta,tu,si,e0,sq]),(0,r.useEffect)(()=>{sa&&void 0!==Z&&er(Z)},[sa,Z,er]);let sU=si?tX.find(e=>e.id===si):null,sV=sU?sU.name||O("terminal.defaultName"):null;(0,r.useEffect)(()=>(eq(Object.keys(se).length,sV),()=>eq(0)),[se,sV]);let[sX,sG]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if("terminal"!==sl.type)return sG(!1);let e=requestAnimationFrame(()=>sG(!0));return()=>cancelAnimationFrame(e)},[sl.type]);let sJ=(0,r.useRef)(null),[sY,sZ]=(0,r.useState)("");(0,r.useEffect)(()=>{let e="terminal"===sl.type?sl.sessionId:null,t=sJ.current;if(sJ.current=e,!sX||!e||!t||e===t)return sZ("");sZ(q.indexOf(e)>q.indexOf(t)?"term-slide-right":"term-slide-left")},[sl,sX,q]);let sQ=(0,r.useCallback)(()=>{if(!ss&&su){su.artifactSessionId&&e1(su.artifactSessionId,su.path),sx(null);return}let e=Array.isArray(H)?H:[],t=e.length>1?e[e.length-2]:{type:"list"};V(),e2.replace((0,dw.O5)(t))},[e2,V,ss,su,sx,e1,H]),s0=(0,r.useCallback)(()=>{if("terminal"!==sl.type)return sQ();X([{type:"list"}])},[sl,sQ,X]);(0,r.useEffect)(()=>{tr&&tS()},[tr,tS]),(0,r.useEffect)(()=>{if(0===tX.length||0===q.length)return;let e=setTimeout(()=>{let e=tX.map(e=>e.id);q.filter(t=>!e.includes(t)).forEach(e=>J(e))},500);return()=>clearTimeout(e)},[tX,q,J]),function({setKeyboardOpen:e}){(0,r.useEffect)(()=>{let t=!1,s=()=>{let s=window.visualViewport,n=s?.height||window.innerHeight,r=s?.offsetTop||0,l=n<window.innerHeight-100;t!==l&&(t=l,e(l)),document.documentElement.style.setProperty("--app-height",`${n}px`),!l&&r>0?document.documentElement.style.transform=`translateY(${-r}px)`:document.documentElement.style.transform="",window.scrollTo(0,0)};document.documentElement.classList.add("terminal-page");let n=0,r=()=>{clearTimeout(n),n=setTimeout(s,100)};return window.visualViewport&&(window.visualViewport.addEventListener("resize",r),window.visualViewport.addEventListener("scroll",r)),window.addEventListener("resize",r),r(),()=>{clearTimeout(n),document.documentElement.classList.remove("terminal-page"),document.documentElement.style.transform="",window.visualViewport&&(window.visualViewport.removeEventListener("resize",r),window.visualViewport.removeEventListener("scroll",r)),window.removeEventListener("resize",r)}},[e]),(0,r.useEffect)(()=>{let e=e=>{e.target.closest(".xterm-viewport,.xterm-screen,.terminal-scroll,.cm-scroller,.cm-content,.overflow-auto,.overflow-x-auto,.overflow-y-auto,.modal-scrollable,.brand-range")||e.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>document.removeEventListener("touchmove",e)},[]),(0,r.useEffect)(()=>{let e=e=>{e.target.matches("input, textarea")&&requestAnimationFrame(()=>window.scrollTo(0,0))};return document.addEventListener("focusin",e),()=>document.removeEventListener("focusin",e)},[])}({setKeyboardOpen:st});let[s1,s2]=(0,r.useState)(null),[s5,s3]=(0,r.useState)(null),s4=eE(s1||tO||null),s6=eE(s5||tO||null),s8=t_[s1||tO],s9=t_[s5||tO],s7=e=>e?.status==="online"||e?.status==="full",ne=(0,r.useCallback)((e=null)=>{s2(e),U({type:"remote"})},[U]),nt=(0,r.useCallback)((e=null)=>{if(!ss){s3(e),U({type:"mobile"});return}if(!eK){s3(e),e_(!0);return}s6.busRef.current?.emit("mobile:stop"),eZ(null),e_(!1),s3(null)},[ss,eK,e_,eZ,s6,U]),ns=(0,r.useCallback)(e=>{eU(e,{startWidth:eW,axis:-1,onWidth:eX})},[eW,eX]),nn=(0,r.useCallback)(()=>{to.current?.retryNow()},[to]),nr=(0,r.useCallback)(()=>{M.rh.getState().closeAll(),el(),e8(),sessionStorage.setItem("9remote_manual_disconnect","1"),window.location.replace("/login")},[el,e8]),nl=(0,r.useCallback)(()=>{t6({isOpen:!0,title:O("workspace.logoutTitle"),message:O("workspace.logoutMessage"),onConfirm:nr})},[nr,O]),na=(0,r.useCallback)(e=>{let t=tA().find(t=>(0,p.Uo)(t.key)===e);t&&tB(t.id),e===tO&&nr()},[tA,tB,tO,nr]),ni=(0,r.useCallback)(()=>{M.rh.getState().disconnectHost(tO),tc()},[tO,tc]),no=(0,r.useCallback)(()=>{M.rh.getState()._patchHost(tO,{status:"connecting"}),td()},[tO,td]),nc=(0,r.useCallback)(()=>{t6({isOpen:!1,title:"",message:"",onConfirm:null})},[]),nd=(0,r.useCallback)(e=>{Y(e),tI(e)},[Y,tI]),nu=(0,r.useCallback)(e=>{Z&&ew(Z,e)},[Z,ew]),nx=(0,r.useMemo)(()=>({open:eN,tabs:eC,width:eS,onTabChange:eT,onResize:eM,onToggle:eR,onNewTerminal:s$}),[eN,eC,eS,eT,eM,eR,s$]),nm=(0,r.useMemo)(()=>({filePath:ez,previewSeq:eF,artifactTitle:eQ,width:eA,onResize:eL,onOpen:ss?eD:sH,onClose:eB,onOpenFull:s_}),[ez,eF,eQ,eA,eL,ss,eD,sH,eB,s_]),np=(0,r.useMemo)(()=>({open:eK,mode:eO,width:eW,busRef:s6.busRef,protocolRef:s6.pmRef,connected:s5?s7(s9):tu,onResizeStart:ns}),[eK,eO,eW,s6,s5,s9,tu,ns]);if(!W||!t0&&!t1)return(0,n.jsx)(o$,{label:O("workspace.loading")});let nf=tu&&tv?ne:null,nh=tu&&ty?nt:null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(oM.A,{}),(0,n.jsx)(r.Suspense,{fallback:null,children:(0,n.jsx)(dk,{hydrated:W,apiKey:e9?.apiKey})}),(0,n.jsxs)("div",{className:"terminal-container h-[var(--app-height,100vh)] fixed inset-0 overflow-hidden overscroll-none",children:[!ss&&(0,n.jsx)("div",{className:`absolute inset-0 transition-opacity duration-150 ease-out ${"list"===sl.type?"opacity-100 z-10":"opacity-0 z-0 pointer-events-none"}`,children:(0,n.jsx)(oz,{sessions:tq,cwdBySession:eo,connected:tu,onSelect:sc.handleSelectSession,onCreate:sc.handleCreateSession,onDelete:sc.handleDeleteSession,onRename:sc.handleRenameSession,onResumeAgentSession:sc.handleResumeAgentSession,onLogout:nl,onOpenRemote:nf,onOpenRemoteHost:ne,tunnelUrl:e9?.tunnelUrl,apiKey:e9?.apiKey,connectionMode:tp,isActive:"list"===sl.type,busRef:ta,subscribeToPush:t9,unsubscribeFromPush:t7,agentVersion:tj,carrier:tg,workspaces:tU,onAddWorkspace:sE,homeDir:sd?.homedir,onRenameWorkspace:tM,onDeleteWorkspace:tz,onReorderSession:nd,recentWorkspaces:sC,shells:tY,onRenameHost:tJ,onDeleteHost:na,onMainDisconnect:ni,onMainReconnect:no})}),(ss||q.length>0)&&(0,n.jsx)(oR,{platform:tw,agentVersion:tj,sessions:tX,workspaces:tG,onCreateAnyHost:sR,onQuickCreateHostAware:sO,onResumeAgentSessionForeign:sT,activeSessionId:si,activeSession:sU,activeWorkspaceId:Z,openedSessions:q,livePanes:ee,mountedWorkspaces:en,cwdBySession:eo,isDesktop:ss,isTerminalView:sa,slideClass:sY,shells:tY,sidebarCollapsed:eu,sidebarWidth:eh,setSidebarWidth:eg,paneWidth:Z?ev[Z]??null:null,setPaneWidth:Z?nu:void 0,toggleSidebar:ex,paneRegistry:so,bindSwipeTab:sr,nav:sc,onBack:s0,atStackBottom:ss&&"list"===sl.type,onOpenRemote:nf,onOpenMobile:nh,onOpenRemoteHost:ne,onOpenMobileHost:nt,onOpenFiles:sf,onLogout:nl,onDeleteWorkspace:tz,onReorderSession:tI,onAddWorkspace:sE,onSetHiddenRepos:tP,onOpenSettings:sN,onRenameHost:tJ,onDeleteHost:na,onMainDisconnect:ni,onMainReconnect:no,homeDir:sd?.homedir,recentWorkspaces:sC,onOpenArtifact:sq,rightPanel:nx,editorPanel:nm,mobilePanel:np,fileBus:t8,tunnelUrl:e9?.tunnelUrl,apiKey:e9?.apiKey,connectionMode:tp,subscribeToPush:t9,unsubscribeFromPush:t7}),sj&&(0,n.jsx)(sD,{fileBus:t8,scope:tW,initialPath:sj.initialPath,onSelect:sS,onClose:()=>sk(null)}),"remote"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(o7,{onClose:()=>{s2(null),sQ()},busRef:s4.busRef,protocolRef:s4.pmRef,connected:s1?s7(s8):tu,carrier:s1?s8?.carrier||"ws":tg,hostPlatform:s8?.platform||tw})}),"mobile"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(rA,{onClose:()=>{s3(null),sQ()},busRef:s6.busRef,protocolRef:s6.pmRef,connected:s5?s7(s9):tu})}),"site"===sl.type&&(0,n.jsx)(ch,{busRef:sl.hostKey?eE(sl.hostKey).busRef:ta,connected:sl.hostKey?s7(t_[sl.hostKey]):tu,initialPort:sl.port,initialPath:sl.path,onBack:V}),"workspaces"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(ef,{onSelect:sh,onBrowse:sb,onBack:sQ,isCodespaces:!!tH?.isCodespaces,systemInfo:sd})}),"browse"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cg,{scope:tW,workspace:sl.path,fileBus:t8,onBack:sQ,onSetWorkspace:sw,isBrowsing:!0})}),ss&&("files"===sl.type||"editor"===sl.type||"git"===sl.type)&&(E="files"===sl.type?sl:[...H].reverse().find(e=>"files"===e.type),R=E?.workspace||sl.workspace,T=em(tW).find(e=>e.path===R),K="editor"===sl.type?sl.path:null,(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cq,{workspace:R,fileBus:t8,onBack:sQ,onSwitchWorkspace:sp,initialOpenedFiles:K?[K]:T?.openedFiles||[],initialActiveFile:K||T?.activeFile||null,onOpenedFilesChange:(e,t)=>(function(e,t,s,n=""){let r=(0,F.kb)(e),l=em(n),a=l.findIndex(e=>e.path===r),i=Array.isArray(t)?t.map(e=>e&&"object"==typeof e?{...e,path:(0,F.kb)(e.path)}:e):t,o="string"==typeof s?(0,F.kb)(s):s;if(-1===a){l.unshift({path:r,lastOpened:Date.now(),openedFiles:i,activeFile:o}),localStorage.setItem(ed(n),JSON.stringify(l));return}l[a]={...l[a],openedFiles:i,activeFile:o??null},localStorage.setItem(ed(n),JSON.stringify(l))})(R,e,t,tW),bus:tr,connected:tu,sessions:tq,onCreateTerminalSession:sc.handleCreateSessionInline,onDeleteTerminalSession:sc.handleDeleteSession,onRenameTerminalSession:sc.handleRenameSession,viewType:sl.type,openFileRef:sm},R)})),!ss&&"files"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cg,{scope:tW,workspace:sl.workspace,initialPath:sl.currentPath,fileBus:t8,onBack:sQ,onOpenFile:sv,onOpenGit:sy,onSwitchWorkspace:sp,onPathChange:e=>sg(sl.workspace,e),hideSwitchWorkspace:sl.fromTerminal})}),!ss&&"git"===sl.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-30 transition-all duration-300 ease-out",children:(0,n.jsx)(cN,{workspace:sl.workspace,fileBus:t8,onBack:sQ,onOpenFile:sv})}),!ss&&su&&(0,n.jsx)("div",{className:"absolute inset-0 z-40 transition-all duration-300 ease-out",children:(0,n.jsx)(cj,{filePath:su.path,line:su.line,column:su.column,diffStatus:su.diffStatus,preview:su.preview,fileBus:t8,onBack:()=>{su.artifactSessionId&&e1(su.artifactSessionId,su.path),sx(null)},workspace:su.workspace||sl.workspace})}),(!tu||!tC)&&!t5&&!t1&&(0,n.jsx)(o$,{}),!t5&&(0,n.jsx)(cV,{retryStatus:tk,approvalStatus:tN,connected:tu,suppress:tQ,firstConnect:!t2,onLogout:nr,onRetryNow:nn}),(0,n.jsx)(dy,{}),sB&&sK&&(0,n.jsx)(c_,{mode:"files",workspace:sK,fileBus:t8,onClose:()=>sF(!1),onOpenFile:e=>eD(e)}),(0,n.jsx)(cU,{isOpen:sA,onClose:sL}),(0,n.jsx)(ei.A,{isOpen:t4.isOpen,onClose:nc,onConfirm:t4.onConfirm,title:t4.title,message:t4.message,confirmText:t4.confirmText})]}),(0,n.jsx)("div",{hidden:!0,children:(0,n.jsx)(r.Suspense,{fallback:null,children:e})}),(0,n.jsx)(ea,{})]})}}},e=>{e.O(0,[476,6189,6391,6669,8669,3348,4136,9958,5788,6552,2347,5158,7358],()=>e(e.s=36416)),_N_E=e.O()}]);