@openchamber/web 1.12.2 → 1.12.3

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 (34) hide show
  1. package/dist/assets/{MarkdownRendererImpl-2INOOMmV.js → MarkdownRendererImpl-C2snGm6y.js} +1 -1
  2. package/dist/assets/{MultiRunWindow-BovvaCrr.js → MultiRunWindow-DXXoYCBh.js} +1 -1
  3. package/dist/assets/{NewWorktreeDialog-6y6rHfOQ.js → NewWorktreeDialog-C6394QE9.js} +1 -1
  4. package/dist/assets/OnboardingScreen-CLXmHHBW.js +1 -0
  5. package/dist/assets/{SessionSwitcherDropdown-DSXsR7zB.js → SessionSwitcherDropdown-BMN9gaXo.js} +1 -1
  6. package/dist/assets/{SettingsWindow-Dll7W_Kd.js → SettingsWindow-DXEjjH2f.js} +1 -1
  7. package/dist/assets/{TerminalView-D_ktT_L5.js → TerminalView-CePdcScA.js} +1 -1
  8. package/dist/assets/{es-9Cy-lgBh.js → es-rCA6AcBs.js} +1 -1
  9. package/dist/assets/{ko-BxmPoeb2.js → ko-CTiirGAp.js} +1 -1
  10. package/dist/assets/{main-BpZQobwD.js → main-D1IN8sAs.js} +2 -2
  11. package/dist/assets/{main-D8KFwoUt.js → main-DIwL7PaU.js} +46 -46
  12. package/dist/assets/{miniChat-BdEth0Oc.js → miniChat-DXW_W4_n.js} +2 -2
  13. package/dist/assets/{mobile-BxWzNO1C.js → mobile-DWyy0wq-.js} +2 -2
  14. package/dist/assets/{pl-J7oKZUR2.js → pl-CwJAYYhT.js} +1 -1
  15. package/dist/assets/{pt-BR-p6gRuJwx.js → pt-BR-xndordtt.js} +1 -1
  16. package/dist/assets/{renderElectronMiniChatApp-MNKYhIaT.js → renderElectronMiniChatApp-BmvjGDb_.js} +2 -2
  17. package/dist/assets/{renderMobileApp-DpYY7X9v.js → renderMobileApp-1BEmeUF9.js} +3 -3
  18. package/dist/assets/{uk-BOvMb8eG.js → uk-C52rE_cP.js} +1 -1
  19. package/dist/assets/{useAppFontEffects-DEZpweZZ.js → useAppFontEffects-hYm-4PtP.js} +4 -4
  20. package/dist/assets/{zh-CN-Cv0tBxN1.js → zh-CN-B7IfGwyh.js} +1 -1
  21. package/dist/assets/{zh-TW-CS7R6Ak3.js → zh-TW-DiO_1_-_.js} +1 -1
  22. package/dist/index.html +1 -1
  23. package/dist/mini-chat.html +1 -1
  24. package/dist/mobile.html +1 -1
  25. package/package.json +1 -1
  26. package/server/index.js +0 -15
  27. package/server/lib/fs/routes.js +28 -2
  28. package/server/lib/opencode/env-runtime.js +20 -158
  29. package/server/lib/opencode/env-runtime.test.js +38 -11
  30. package/server/lib/opencode/lifecycle.js +5 -24
  31. package/server/lib/opencode/lifecycle.test.js +0 -2
  32. package/server/lib/opencode/network-runtime.js +1 -1
  33. package/server/lib/opencode/routes.js +1 -1
  34. package/dist/assets/OnboardingScreen-B1Ft9kmW.js +0 -1
@@ -1,34 +1,34 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-DEZpweZZ.js","assets/vendor-.bun-TPgXvEwq.js","assets/vendor--V65Sl9C2.css","assets/index-D9t9eCUC.js","assets/index-BDH6F8f2.css","assets/TerminalView-D_ktT_L5.js","assets/NewWorktreeDialog-6y6rHfOQ.js","assets/mobileLayoutPreference-Dio-WWkI.js","assets/SessionSwitcherDropdown-DSXsR7zB.js","assets/SettingsWindow-Dll7W_Kd.js","assets/MultiRunWindow-BovvaCrr.js","assets/OnboardingScreen-B1Ft9kmW.js"])))=>i.map(i=>d[i]);
2
- import{j as s,c as gt,R as a,b as vi,I as uu,e as El,L as mu,H as et,N as fu,u as qo,g as ro,k as Yo,D as Jo,m as Qo,S as rl,v as il,o as Rl,C as Ml,T as hu,X as Kr,Y as Jm,F as Qm,$ as Xm,a0 as Zm,a1 as ef,a2 as tf,a3 as sf,a4 as nf,a5 as ol,a6 as rf,i as of,s as af,_ as Hi,a7 as uc,a8 as mc,a9 as fc,G as lf}from"./vendor-.bun-TPgXvEwq.js";import{d as cf,b as Rs,e as df,a as Qr,f as al,h as uf,r as Fl,g as Oi,s as pu,i as mf}from"./index-D9t9eCUC.js";import{u as Tt,z as sn,H as I,m as Te,ai as Lt,aj as Ot,ak as _t,al as ua,am as lr,an as mo,ao as hc,ap as zt,aq as ff,ar as Xo,o as cr,t as ae,as as nn,at as Mn,au as rn,av as on,aw as gu,ax as yo,a as Wn,ay as Pr,T as Fe,az as xi,aA as pc,aB as hf,aC as fo,aD as xu,aE as bu,R as cs,y as vt,aF as pf,a6 as yu,x as Xr,w as Ll,D as Es,U as bi,aG as Ol,aH as wu,aI as Gi,aJ as gf,aK as gc,aL as xf,aM as bf,aN as yf,aO as vu,aP as wf,aQ as vf,aR as ju,V as _l,aS as ui,aT as jf,aU as Bl,aV as mi,aW as Vl,aX as Lo,$ as an,aY as Sf,aZ as Su,a_ as Nf,a$ as Nu,b0 as ku,b1 as Xs,b2 as Ys,B as ze,b3 as Gs,b4 as Ks,b5 as ei,b6 as kf,b7 as Cf,b8 as No,b9 as In,ba as Cu,bb as Au,bc as $l,bd as Af,be as Df,bf as xc,bg as bc,bh as fi,I as kn,bi as yi,bj as If,bk as ws,bl as ma,bm as fa,bn as ha,bo as pa,bp as qr,bq as Zr,br as Pf,bs as Tf,bt as cn,bu as Ef,bv as Rf,bw as Mf,bx as Ff,by as Lf,k as _i,bz as ga,bA as Of,bB as _f,bC as Bf,bD as Vf,bE as $f,bF as zf,bG as Wf,bH as Fn,bI as Bn,bJ as Vn,bK as Pn,bL as $n,bM as qs,bN as Dr,bO as Uf,v as ho,M as xa,S as ba,bP as Hf,bQ as tr,bR as Gf,b as ti,d as zl,c as ya,bS as Kf,bT as Du,bU as qf,bV as Yf,e as Wl,bW as Jf,f as _s,bX as wa,bY as Ir,j as Qf,bZ as Xf,b_ as Pa,b$ as Iu,c0 as Pu,c1 as Ul,c2 as va,c3 as Nn,F as yr,c4 as Hl,X as zn,c5 as wi,c6 as ll,c7 as cl,l as Bi,c8 as Tu,c9 as Zf,p as Tr,q as yc,r as wc,ca as eh,cb as Eu,cc as th,n as vc,J as sh,cd as Ta,ce as Gl,cf as Ru,cg as nh,ch as rh,ci as wo,cj as Kl,ck as ih,cl as ja,cm as ql,cn as Mu,co as ko,cp as oh,cq as hi,cr as ah,cs as Fu,ct as lh,cu as ch,cv as jc,cw as Lu,cx as Ou,cy as _u,E as Yl,P as Sa,G as Na,N as dl,cz as Jl,cA as dh,cB as as,cC as po,cD as Vi,cE as Ti,cF as Zo,cG as Sc,cH as En,K as uh,L as mh,cI as fh,cJ as io,cK as hh,cL as Bu,cM as ph,cN as gh,cO as ul,cP as xh,cQ as bh,cR as yh,cS as Nc,cT as wh,cU as vh,cV as jh,cW as Ql,cX as Vu,cY as Sh,cZ as Nh,c_ as kh,c$ as Ch,d0 as Ah,d1 as kc,d2 as Dh,d3 as Ih,d4 as Ph,d5 as Th,d6 as Eh,O as Rh,d7 as Mh,d8 as Fh,Q as Lh,d9 as Oh,A as _h,C as Bh,da as Vh,db as $h,dc as zh,dd as Wh,de as Uh,df as Hh,dg as Gh,dh as Kh,di as qh,dj as Yh,dk as Cc,dl as Jh,dm as Qh,dn as Xh,dp as vo,dq as Zh,dr as Ac,ds as ep,dt as Oo,du as _o,dv as tp,dw as sp,dx as np,dy as rp,dz as ip,dA as op,dB as ap,dC as lp,dD as cp,dE as dp,dF as Dc,dG as Ic,dH as Pc,dI as Tc,dJ as up,dK as mp,W as Ec,Y as fp,dL as hp,Z as pp,_ as gp,dM as xp,dN as bp,a0 as Rc,a1 as Mc,a2 as Fc,dO as yp,a3 as $u,a4 as zu,ab as wp,ac as vp,ad as jp,ae as Sp,af as Np,ag as kp,ah as Cp,a7 as Ap,a8 as Dp,a9 as Ip,aa as Pp}from"./useAppFontEffects-DEZpweZZ.js";import{I as Lc,f as Tp,g as so,h as Oc,i as Ep,j as _c,n as Rp,k as Bc,t as zr,r as Mp,l as Ea,m as go,o as ea,p as Yr,q as ta,s as Wu,v as Uu,U as sa,w as na,x as $i,y as jo,z as zi,A as Hu,B as or,E as Fp,Q as Lp,F as Op,G as _p,H as Bp,J as Gu,P as Xl,K as Vp,L as $p,C as zp,a as Wp,M as Ku,O as qu,R as ml,T as fl,V as hl,W as Up,X as Hp,Y as Ei,N as Gp,D as Kp,e as qp,d as pl,Z as Yp,_ as Jp,$ as Qp,u as Xp,a0 as Zp}from"./NewWorktreeDialog-6y6rHfOQ.js";import{S as eg,C as tg,W as sg,u as Ra}from"./SessionSwitcherDropdown-DSXsR7zB.js";function Yu(t){const{drafts:e,editingDraftId:n,commentText:r,selection:o,isDragging:i,fileLabel:c,newWidgetId:l,mapDraftToRange:u,onSave:m,onCancel:d,onEdit:f,onDelete:g}=t,x=[];for(const p of e){const y=u(p);if(p.id===n){x.push({afterLine:y.end,id:`edit-${p.id}`,content:s.jsx(Lc,{initialText:r,fileLabel:c,lineRange:y,isEditing:!0,onSave:m,onCancel:d},`edit-${p.id}`)});continue}x.push({afterLine:y.end,id:`card-${p.id}`,content:s.jsx(Tp,{draft:p,onEdit:()=>f(p),onDelete:()=>g(p)},`card-${p.id}`)})}if(o&&!n&&!i){const p={...o,start:Math.min(o.start,o.end),end:Math.max(o.start,o.end)};x.push({afterLine:p.end,id:l,content:s.jsx(Lc,{initialText:r,fileLabel:c,lineRange:p,isEditing:!1,onSave:m,onCancel:d},l)})}return x}function Vc(t){const e=gt.c(14);let n,r,o,i;e[0]!==t?({size:o,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=i):(n=e[1],r=e[2],o=e[3],i=e[4]);const c=typeof o=="number"?`${o}px`:o,l=typeof o=="number"?`${o}px`:o;let u;e[5]!==i||e[6]!==c||e[7]!==l?(u={width:c,height:l,...i},e[5]=i,e[6]=c,e[7]=l,e[8]=u):u=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=m):m=e[9];let d;return e[10]!==n||e[11]!==r||e[12]!==u?(d=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:u,...r,children:m}),e[10]=n,e[11]=r,e[12]=u,e[13]=d):d=e[13],d}const ng=(t,e)=>{if(!t)return e("mcpDropdown.status.unknown");switch(t.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:t.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:t.error||""});default:return t.status}},rg=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Ju=({active:t,className:e})=>{const{t:n}=Tt(),o=sn(h=>h.currentDirectory)??null,i=so(h=>h.getStatusForDirectory(o)),c=so(h=>h.refresh),l=so(h=>h.connect),u=so(h=>h.disconnect),m=Oc(h=>h.mcpServers),d=Oc(h=>h.loadMcpConfigs),[f,g]=a.useState(!1),[x,p]=a.useState(null);a.useEffect(()=>{c({directory:o,silent:!0})},[c,o]),a.useEffect(()=>{d({force:!0})},[d]),a.useEffect(()=>{t&&Promise.all([c({directory:o,silent:!0}),d({force:!0})])},[t,c,o,d]);const y=a.useMemo(()=>{const h=new Set(Object.keys(i));for(const N of m)N?.name&&h.add(N.name);return Array.from(h).sort((N,w)=>N.localeCompare(w))},[m,i]),b=a.useCallback(h=>{if(h?.preventDefault(),f)return;g(!0);const N=new Promise(w=>setTimeout(w,500));Promise.all([c({directory:o}),N]).finally(()=>{g(!1)})},[f,c,o]);return s.jsxs("div",{className:Te("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),o&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:o.split("/").pop()||o})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:f,onClick:b,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:Te("h-4 w-4",f&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[y.map(h=>{const N=i[h],w=rg(N),S=N?.status==="connected",v=x===h,j=ng(N,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:Te("h-2 w-2 rounded-full flex-shrink-0",w==="success"&&"bg-status-success",w==="error"&&"bg-status-error",w==="warning"&&"bg-status-warning",w==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(_t,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:h})]})}),s.jsx(Ep,{checked:S,disabled:v,className:"data-[checked]:bg-status-info",onCheckedChange:async k=>{p(h);try{k?await l(h,o):await u(h,o)}finally{p(null)}}})]},h)}),y.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},Jr=[{id:"finder",label:"Finder",appName:"Finder"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm"},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"xcode",label:"Xcode",appName:"Xcode"},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"zed",label:"Zed",appName:"Zed"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"kiro",label:"Kiro",appName:"Kiro"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],gl="finder",xl=new Set(["finder","terminal"]),Zl=t=>typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32"&&t.id==="finder"?{...t,label:"Explorer",appName:"File Explorer"}:t,bl=t=>{if(!t)return null;const e=Jr.find(n=>n.id===t)??null;return e?Zl(e):null},Ma=()=>Jr.filter(t=>xl.has(t.id)).map(t=>({...Zl(t)})),ig=()=>{if(typeof window>"u")return gl;const t=window.localStorage.getItem("openInAppId");return t&&bl(t)?t:gl};let Fa=!1,Ci=!1,Wr=!1,Ur=0,oo=null;const $c=()=>{oo&&(clearTimeout(oo),oo=null)},xr=vi()((t,e)=>({selectedAppId:ig(),availableApps:Ma(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Fa||typeof window>"u")return;Fa=!0;const n=(u,m=!0)=>{if(!Array.isArray(u)||u.length===0){t({availableApps:Ma(),hasLoadedApps:m});return}const d=new Set(u.map(p=>p.name)),f=new Map(u.map(p=>[p.name,p.iconDataUrl??void 0])),x=Jr.filter(p=>d.has(p.appName)||xl.has(p.id)).map(p=>({...Zl(p),iconDataUrl:f.get(p.appName)}));t({availableApps:x,hasLoadedApps:!0})},r=async u=>{if(!lr()||!mo()||Ci||e().hasLoadedApps&&!u)return;const d=Jr.map(f=>f.appName);$c(),Ci=!0,Wr=!1,t({isScanning:!0});try{const{apps:f,success:g,hasCache:x,isCacheStale:p}=await hc(d,u),y=g&&!x&&f.length===0&&Ur<3;if(t({isCacheStale:x?p:!1}),n(f,g?!y:!1),g){if(y){const h=[800,1600,3200][Ur]??3200;Ur+=1,Wr=!0,oo=setTimeout(()=>{r()},h);return}Ur=0,Wr=!1;return}if(Ur<3){const h=[1e3,3e3,7e3][Ur]??7e3;Ur+=1,Wr=!0,oo=setTimeout(()=>{r()},h)}}finally{Ci=!1,Wr||t({isScanning:!1})}};r();const o=u=>{const m=u.detail,d=m&&typeof m.openInAppId=="string"&&m.openInAppId.length>0&&bl(m.openInAppId)?m.openInAppId:null;d&&(window.localStorage.setItem("openInAppId",d),t({selectedAppId:d}))},i=()=>{r()},c=u=>{const m=u.detail;Array.isArray(m)&&(Ur=3,Wr=!1,t({isScanning:!1,isCacheStale:!1}),n(m))};window.addEventListener("openchamber:settings-synced",o),window.addEventListener("openchamber:app-ready",i),window.addEventListener("openchamber:installed-apps-updated",c),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Fa||e().initialize(),!lr()||!mo()||Ci||e().hasLoadedApps&&!n)return;const o=Jr.map(i=>i.appName);$c(),n&&t({hasLoadedApps:!1}),Ci=!0,Wr=!1,t({isScanning:!0});try{const{apps:i,hasCache:c,isCacheStale:l}=await hc(o,n),u=new Set(i.map(g=>g.name)),m=new Map(i.map(g=>[g.name,g.iconDataUrl??void 0])),f=Jr.filter(g=>u.has(g.appName)||xl.has(g.id)).map(g=>({...g,iconDataUrl:m.get(g.appName)}));t({availableApps:f.length>0?f:Ma(),hasLoadedApps:f.length>0,isCacheStale:c?l:!1})}finally{Ci=!1,Wr||t({isScanning:!1})}},selectApp:async n=>{bl(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ua({openInAppId:n}))}})),og="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",ag="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",La=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__!=="win32"?og:t.id==="terminal"?ag:void 0}),zc=t=>{const e=gt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[i,c]=a.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const u=l,m=r||o;if(m&&!i){let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=()=>c(!0),e[2]=g):g=e[2];let x;return e[3]!==m?(x=s.jsx("img",{src:m,alt:"",className:"h-4 w-4 rounded-sm",onError:g}),e[3]=m,e[4]=x):x=e[4],x}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=Te("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let f;return e[6]!==u?(f=s.jsx("span",{className:d,children:u}),e[6]=u,e[7]=f):f=e[7],f},lg=t=>{const e=gt.c(75),{directory:n,className:r}=t,{t:o}=Tt(),i=xr(cg),c=xr(dg),l=xr(ug),u=xr(mg),m=xr(fg),d=xr(hg),f=xr(pg);let g,x;e[0]!==m?(g=()=>{m()},x=[m],e[0]=m,e[1]=g,e[2]=x):(g=e[1],x=e[2]),a.useEffect(g,x);const p=lr()&&mo();let y;e:{let re;e[3]!==c||e[4]!==i?(re=c.find(q=>q.id===i)??c.find(gg)??c[0]??Jr[0],e[3]=c,e[4]=i,e[5]=re):re=e[5];const L=re;if(L){let q;e[6]!==L?(q=La(L),e[6]=L,e[7]=q):q=e[7],y=q;break e}let $;e[8]===Symbol.for("react.memo_cache_sentinel")?($=La(Jr[0]),e[8]=$):$=e[8],y=$}const b=y;if(!p||!n||c.length===0)return null;let h;e[9]!==n?(h=async re=>{await ff(n,re.id,re.appName)||await Xo(n,re.appName)},e[9]=n,e[10]=h):h=e[10];const N=h;let w;e[11]!==N||e[12]!==f?(w=async re=>{await f(re.id),await N(re)},e[11]=N,e[12]=f,e[13]=w):w=e[13];const S=w;let v;e[14]!==n||e[15]!==o?(v=async()=>{(await cr(n)).ok&&ae.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=v):v=e[16];const j=v;let k;e[17]!==r?(k=Te("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=k):k=e[18];let D;e[19]!==N||e[20]!==b?(D=()=>{N(b)},e[19]=N,e[20]=b,e[21]=D):D=e[21];const T=u&&"animate-pulse";let C;e[22]!==T?(C=Te("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",T),e[22]=T,e[23]=C):C=e[23];let P;e[24]!==b.label||e[25]!==o?(P=o("openInApp.actions.openInAria",{app:b.label}),e[24]=b.label,e[25]=o,e[26]=P):P=e[26];let E;e[27]!==b.fallbackIconDataUrl||e[28]!==b.iconDataUrl||e[29]!==b.label?(E=s.jsx(zc,{label:b.label,iconDataUrl:b.iconDataUrl,fallbackIconDataUrl:b.fallbackIconDataUrl}),e[27]=b.fallbackIconDataUrl,e[28]=b.iconDataUrl,e[29]=b.label,e[30]=E):E=e[30];let M;e[31]!==C||e[32]!==P||e[33]!==E||e[34]!==D?(M=s.jsx("button",{type:"button",onClick:D,className:C,"aria-label":P,children:E}),e[31]=C,e[32]=P,e[33]=E,e[34]=D,e[35]=M):M=e[35];let H;e[36]===Symbol.for("react.memo_cache_sentinel")?(H=Te("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=H):H=e[36];let R;e[37]!==o?(R=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=R):R=e[38];let _;e[39]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=_):_=e[39];let z;e[40]!==R?(z=s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",className:H,"aria-label":R,children:_})}),e[40]=R,e[41]=z):z=e[41];let V;e[42]!==j?(V=()=>{j()},e[42]=j,e[43]=V):V=e[43];let F;e[44]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(I,{name:"file-copy",className:"h-4 w-4"}),e[44]=F):F=e[44];let te;e[45]!==o?(te=o("openInApp.actions.copyPath"),e[45]=o,e[46]=te):te=e[46];let Z;e[47]!==te?(Z=s.jsx("span",{className:"typography-ui-label text-foreground",children:te}),e[47]=te,e[48]=Z):Z=e[48];let ne;e[49]!==V||e[50]!==Z?(ne=s.jsxs(zt,{className:"flex items-center gap-2",onClick:V,children:[F,Z]}),e[49]=V,e[50]=Z,e[51]=ne):ne=e[51];let U;e[52]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(Mn,{}),e[52]=U):U=e[52];let ie;if(e[53]!==c||e[54]!==S||e[55]!==b.id){let re;e[57]!==S||e[58]!==b.id?(re=L=>{const $=La(L);return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{S(L)},children:[s.jsx(zc,{label:L.label,iconDataUrl:L.iconDataUrl,fallbackIconDataUrl:$.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:L.label}),b.id===L.id?s.jsx(I,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},L.id)},e[57]=S,e[58]=b.id,e[59]=re):re=e[59],ie=c.map(re),e[53]=c,e[54]=S,e[55]=b.id,e[56]=ie}else ie=e[56];let oe;e[60]!==l||e[61]!==d||e[62]!==o?(oe=l?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{d(!0)},children:[s.jsx(I,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("openInApp.actions.refreshApps")})]}):null,e[60]=l,e[61]=d,e[62]=o,e[63]=oe):oe=e[63];let ge;e[64]!==ne||e[65]!==ie||e[66]!==oe?(ge=s.jsxs(rn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[ne,U,ie,oe]}),e[64]=ne,e[65]=ie,e[66]=oe,e[67]=ge):ge=e[67];let je;e[68]!==z||e[69]!==ge?(je=s.jsxs(on,{children:[z,ge]}),e[68]=z,e[69]=ge,e[70]=je):je=e[70];let Se;return e[71]!==M||e[72]!==je||e[73]!==k?(Se=s.jsxs("div",{className:k,children:[M,je]}),e[71]=M,e[72]=je,e[73]=k,e[74]=Se):Se=e[74],Se};function cg(t){return t.selectedAppId}function dg(t){return t.availableApps}function ug(t){return t.isCacheStale}function mg(t){return t.isScanning}function fg(t){return t.initialize}function hg(t){return t.loadInstalledApps}function pg(t){return t.selectApp}function gg(t){return t.id===gl}const xg=1e6,bg="terminal-store";let Wc=!1;const Oa=t=>typeof t=="object"&&t!==null,yg=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function An(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const _a=(t,e)=>({id:t,terminalSessionId:null,lifecycle:"idle",label:e,iconKey:null,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Ba=t=>({tabs:[t],activeTabId:t.id}),pr=(t,e)=>t.tabs.findIndex(n=>n.id===e),Hs=vi()(uu(El((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=An(n);r&&t(o=>{if(o.sessions.has(r))return o;const i=new Map(o.sessions),c=`tab-${o.nextTabId}`,l=_a(c,"Terminal");return i.set(r,Ba(l)),{sessions:i,nextTabId:o.nextTabId+1}})},getDirectoryState:n=>{const r=An(n);return e().sessions.get(r)},getActiveTab:n=>{const r=An(n),o=e().sessions.get(r);if(!o)return;const i=o.activeTabId;return i?o.tabs.find(c=>c.id===i)??o.tabs[0]:o.tabs[0]},createTab:n=>{const r=An(n);if(!r)return"tab-invalid";const o=`tab-${e().nextTabId}`;return t(i=>{const c=new Map(i.sessions),l=c.get(r),u=i.nextTabId+1,d=`Terminal ${(l?.tabs.length??0)+1}`,f=_a(o,d);return l?c.set(r,{...l,tabs:[...l.tabs,f]}):c.set(r,Ba(f)),{sessions:c,nextTabId:u}}),o},setActiveTab:(n,r)=>{const o=An(n);t(i=>{const c=new Map(i.sessions),l=c.get(o);return!l||l.activeTabId===r||pr(l,r)<0?i:(c.set(o,{...l,activeTabId:r}),{sessions:c})})},setTabLabel:(n,r,o)=>{const i=An(n),c=o.trim();c&&t(l=>{const u=new Map(l.sessions),m=u.get(i);if(!m)return l;const d=pr(m,r);if(d<0||m.tabs[d]?.label===c)return l;const f=[...m.tabs];return f[d]={...f[d],label:c},u.set(i,{...m,tabs:f}),{sessions:u}})},setTabIconKey:(n,r,o)=>{const i=An(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=pr(u,r);if(m<0)return c;const d=o?.trim()||null;if(u.tabs[m]?.iconKey===d)return c;const f=[...u.tabs];return f[m]={...f[m],iconKey:d},l.set(i,{...u,tabs:f}),{sessions:l}})},closeTab:async(n,r)=>{const o=An(n),l=e().sessions.get(o)?.tabs.find(u=>u.id===r)?.terminalSessionId??null;if(l)try{await cf(l)}catch{}t(u=>{const m=new Map(u.sessions),d=m.get(o);if(!d)return u;const f=pr(d,r);if(f<0)return u;const g=d.tabs.filter(b=>b.id!==r),x=Object.fromEntries(Object.entries(u.projectActionRuns).filter(([,b])=>!(b.directory===o&&b.tabId===r))),p=Object.keys(x).length!==Object.keys(u.projectActionRuns).length;if(g.length===0){const b=`tab-${u.nextTabId}`,h=_a(b,"Terminal");return m.set(o,Ba(h)),{sessions:m,nextTabId:u.nextTabId+1,...p?{projectActionRuns:x}:{}}}let y=d.activeTabId;return d.activeTabId===r&&(y=g[Math.min(f,g.length-1)]?.id??g[0]?.id??null),m.set(o,{...d,tabs:g,activeTabId:y}),{sessions:m,...p?{projectActionRuns:x}:{}}})},setTabSessionId:(n,r,o)=>{const i=An(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=pr(u,r);if(m<0)return c;const d=u.tabs[m],f=o!==null&&d.terminalSessionId!==o,g=o?"running":d.terminalSessionId?"exited":d.lifecycle,x={...d,terminalSessionId:o,lifecycle:g,isConnecting:!1,...f?{bufferChunks:[],bufferLength:0}:{}},p=[...u.tabs];return p[m]=x,l.set(i,{...u,tabs:p}),{sessions:l}})},setTabLifecycle:(n,r,o)=>{const i=An(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=pr(u,r);if(m<0)return c;const d=[...u.tabs];return d[m]={...d[m],lifecycle:o,isConnecting:!1},l.set(i,{...u,tabs:d}),{sessions:l}})},setConnecting:(n,r,o)=>{const i=An(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=pr(u,r);if(m<0)return c;const d=[...u.tabs];return d[m]={...d[m],isConnecting:o},l.set(i,{...u,tabs:d}),{sessions:l}})},appendToBuffer:(n,r,o)=>{if(!o)return;const i=An(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=pr(u,r);if(m<0)return c;const d=u.tabs[m],f=c.nextChunkId,g={id:f,data:o},x=[...d.bufferChunks,g];let p=d.bufferLength+o.length;for(;p>xg&&x.length>1;){const b=x.shift();if(!b)break;p-=b.data.length}const y=[...u.tabs];return y[m]={...d,bufferChunks:x,bufferLength:p},l.set(i,{...u,tabs:y}),{sessions:l,nextChunkId:f+1}})},setTabPreviewUrl:(n,r,o,i={})=>{const c=An(n);t(l=>{const u=new Map(l.sessions),m=u.get(c);if(!m)return l;const d=pr(m,r);if(d<0)return l;const f=m.tabs[d],g=i.autoOpened??f.previewAutoOpened,x=i.locked??f.previewUrlLocked;if(f.previewUrl===o&&f.previewAutoOpened===g&&f.previewUrlLocked===x)return l;const p=[...m.tabs];return p[d]={...f,previewUrl:o,previewAutoOpened:g,previewUrlLocked:x},u.set(c,{...m,tabs:p}),{sessions:u}})},markPreviewAutoOpened:(n,r)=>{const o=An(n);t(i=>{const c=new Map(i.sessions),l=c.get(o);if(!l)return i;const u=pr(l,r);if(u<0)return i;const m=l.tabs[u];if(!m.previewUrl||m.previewAutoOpened)return i;const d=[...l.tabs];return d[u]={...m,previewAutoOpened:!0},c.set(o,{...l,tabs:d}),{sessions:c}})},setProjectActionRun:n=>{t(r=>{const o=r.projectActionRuns[n.key];return o&&o.directory===n.directory&&o.actionId===n.actionId&&o.tabId===n.tabId&&o.sessionId===n.sessionId&&o.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(o=>{const i=o.projectActionRuns[n];return!i||i.status===r?o:{projectActionRuns:{...o.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const o={...r.projectActionRuns};return delete o[n],{projectActionRuns:o}})},clearBuffer:(n,r)=>{const o=An(n);t(i=>{const c=new Map(i.sessions),l=c.get(o);if(!l)return i;const u=pr(l,r);if(u<0)return i;const m=[...l.tabs];return m[u]={...m[u],bufferChunks:[],bufferLength:0},c.set(o,{...l,tabs:m}),{sessions:c}})},removeDirectory:n=>{const r=An(n);t(o=>{const i=new Map(o.sessions);i.delete(r);const c=Object.fromEntries(Object.entries(o.projectActionRuns).filter(([,l])=>l.directory!==r));return{sessions:i,projectActionRuns:c}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:bg,storage:mu(()=>gu()),partialize:t=>({sessions:Array.from(t.sessions.entries()).map(([e,n])=>[e,{activeTabId:n.activeTabId,tabs:n.tabs.map(r=>({id:r.id,label:r.label,iconKey:r.iconKey,terminalSessionId:r.terminalSessionId,lifecycle:r.lifecycle,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!Oa(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let o=0;for(const l of n){if(!Array.isArray(l)||l.length!==2)continue;const[u,m]=l;if(typeof u!="string"||!Oa(m))continue;const d=Array.isArray(m.tabs)?m.tabs:[],f=[];for(const p of d){if(!Oa(p))continue;const y=typeof p.id=="string"?p.id:null;if(!y)continue;const b=yg(y);b!==null&&(o=Math.max(o,b));const h=typeof p.terminalSessionId=="string"||p.terminalSessionId===null?p.terminalSessionId:null,N=p.lifecycle,w=N==="idle"||N==="running"||N==="exited"?N:h?"running":"idle";f.push({id:y,label:typeof p.label=="string"?p.label:"Terminal",iconKey:typeof p.iconKey=="string"?p.iconKey:null,terminalSessionId:h,lifecycle:w,createdAt:typeof p.createdAt=="number"?p.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(f.length===0)continue;const g=typeof m.activeTabId=="string"?m.activeTabId:null,x=g?f.some(p=>p.id===g):!1;r.set(u,{tabs:f,activeTabId:x?g:f[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,c=Math.max(e.nextTabId,i,o+1);return{...e,sessions:r,nextChunkId:1,nextTabId:c,hasHydrated:!0}}})));if(typeof window<"u"&&!Wc){Wc=!0;const t=Hs.persist,e=()=>{Hs.getState().hasHydrated||Hs.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const wg=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],vg=["dev","start","preview","serve"];async function jg(t,e,n){if(!t)return null;const r=kg(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const o=Cg(n);if(o){const i=await Ag(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await Sg(t)){const o=await Ng(),i=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function Sg(t){const e=`${t}/index.html`,n=await ra(e,t);return typeof n=="string"&&n.trim().length>0}async function Ng(){try{const t=await Rs("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function kg(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(vg.some(o=>n.includes(o)))return e}return null}function Cg(t){for(const{pattern:e}of wg)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Ag(t){const e=await ra(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),o=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(o.startsWith("bun@"))return"bun";if(o.startsWith("pnpm@"))return"pnpm";if(o.startsWith("yarn@"))return"yarn";if(o.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,o]of n){const i=await ra(`${t}/${r}`,t);if(typeof i=="string"&&i.trim().length>0)return o}return"npm"}async function ra(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await Rs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=yo()?.files;if(n?.readFile)try{const r=await n.readFile(t,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await Rs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Dg(t){try{const e=await ra(`${t}/package.json`,t);if(e==null)return null;const r=JSON.parse(e).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const Ig=t=>new Promise(e=>{window.setTimeout(e,t)}),Pg="\x1B",Tg=new RegExp(`${Pg}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Eg=/https?:\/\/[^\s<>'"`]+/gi,Jn="__openchamber_auto_discover_preview__",Rg=15e3,Mg=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},Fg=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},Lg=t=>{const n=t.replace(Tg,"").match(Eg);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const i of r)try{const c=new URL(i);c.port&&c.port.length>0&&o.push({raw:i,parsed:c})}catch{}if(o.length>0){const i=c=>{const{parsed:l}=c,u=l.hostname.toLowerCase(),m=u==="localhost"||u==="127.0.0.1"||u==="0.0.0.0"||u==="::1",d=l.pathname||"/",f=d.split("/").filter(Boolean).length,g=d==="/"||d==="",x=!!(l.search||l.hash);let p=0;return m&&(p+=50),g&&(p+=30),p-=Math.min(f*5,20),x&&(p-=10),p};return o.sort((c,l)=>i(l)-i(c)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Uc=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:i}=Tt(),{terminal:c,runtime:l}=Wn(),{isMobile:u}=Pr(),m=a.useMemo(()=>lr(),[]),d=_c(Q=>Q.instances),f=_c(Q=>Q.load),g=Fe(Q=>Q.setBottomTerminalOpen),x=Fe(Q=>Q.setActiveMainTab),p=Fe(Q=>Q.setSettingsPage),y=Fe(Q=>Q.setSettingsDialogOpen),b=Fe(Q=>Q.setSettingsProjectsSelectedId),h=Fe(Q=>Q.openContextPreview),N=Hs(Q=>Q.sessions),w=Hs(Q=>Q.ensureDirectory),S=Hs(Q=>Q.setTabLabel),v=Hs(Q=>Q.setTabIconKey),j=Hs(Q=>Q.setActiveTab),k=Hs(Q=>Q.setConnecting),D=Hs(Q=>Q.setTabSessionId),T=Hs(Q=>Q.setTabPreviewUrl),C=Hs(Q=>Q.projectActionRuns),P=Hs(Q=>Q.setProjectActionRun),E=Hs(Q=>Q.updateProjectActionRunStatus),M=Hs(Q=>Q.removeProjectActionRun),[H,R]=a.useState([]),[_,z]=a.useState(null),[V,F]=a.useState(!1),te=a.useRef({}),Z=a.useRef({}),ne=a.useRef({}),U=a.useRef({}),ie=a.useRef(0),oe=t?.id??null,ge=t?.path??"",je=a.useMemo(()=>oe?{id:oe,path:ge}:null,[oe,ge]);a.useEffect(()=>{m&&f().catch(()=>{})},[m,f]);const Se=a.useCallback(async Q=>{await xi(Q)},[]),re=a.useCallback(async()=>{if(!je)return;const Q=ie.current+1;ie.current=Q,F(!0);try{const Me=await pc(je);if(ie.current!==Q)return;const Re=Me.actions;R(Re),z(Ne=>Ne===Jn||Ne&&Re.some(Be=>Be.id===Ne)?Ne:null)}catch{if(ie.current!==Q)return}finally{ie.current===Q&&F(!1)}},[je]),L=a.useMemo(()=>Rp(e||je?.path||""),[e,je?.path]),$=a.useMemo(()=>_?H.find(Q=>Q.id===_)??null:null,[H,_]),q=a.useMemo(()=>({id:Jn,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),he=!u,de=a.useMemo(()=>he?[q,...H]:H,[H,q,he]);a.useEffect(()=>{re()},[re]),a.useEffect(()=>{if(typeof window>"u")return;const Q=Me=>{const Re=Me.detail;oe&&(Re?.projectId&&Re.projectId!==oe||re())};return window.addEventListener(Bc,Q),()=>{window.removeEventListener(Bc,Q)}},[re,oe]),a.useEffect(()=>{_&&(_===Jn&&he||H.some(Q=>Q.id===_)||z(null))},[H,he,_]),a.useEffect(()=>{for(const[Q,Me]of Object.entries(C)){const Ne=N.get(Me.directory)?.tabs.find(Be=>Be.id===Me.tabId);(!Ne||Ne.terminalSessionId!==Me.sessionId)&&M(Q)}},[C,M,N]),a.useEffect(()=>{for(const[Q,Me]of Object.entries(C)){const Re=Z.current[Q]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};Z.current[Q]=Re;const Ne=de.find(We=>We.id===Me.actionId);if(!Ne)continue;const se=N.get(Me.directory)?.tabs.find(We=>We.id===Me.tabId);if(!se||!Array.isArray(se.bufferChunks)||se.bufferChunks.length===0)continue;const O=se.bufferChunks.filter(We=>Re.lastSeenChunkId===null?!0:We.id>Re.lastSeenChunkId);if(O.length===0)continue;const A=O.map(We=>We.data).join(""),K=`${Re.tail}${A}`,pe=!Re.openedUrl&&Ne.autoOpenUrl===!0?Lg(K):null,_e=O[O.length-1]?.id??Re.lastSeenChunkId;if(Re.lastSeenChunkId=_e,Re.tail=K.slice(-512),pe)if(Re.openedUrl=!0,Re.openInPreview){const We=C[Q];We&&(T(We.directory,We.tabId,pe,{locked:!1,autoOpened:!1}),We.status==="waiting-for-preview"&&E(Q,"running"),window.clearTimeout(U.current[Q]),delete U.current[Q],h(We.directory,pe))}else Se(pe),ae.success(i("projectActions.toast.openedUrlFromOutput"));Z.current[Q]=Re}for(const Q of Object.keys(Z.current))C[Q]||(delete Z.current[Q],window.clearTimeout(U.current[Q]),delete U.current[Q])},[de,h,Se,C,T,i,N,E]);const we=a.useCallback(async(Q,Me={})=>{if(!L)throw new Error(i("projectActions.error.noActiveDirectory"));const Re=zr(L,Q.id);w(L);const Ne=Hs.getState(),Be=Ne.getDirectoryState(L);let se=te.current[Re]||null;const O=se?!!Be?.tabs.some(pe=>pe.id===se):!1;(!se||!O)&&(se=Ne.createTab(L),te.current[Re]=se),S(L,se,`Action: ${Q.name}`),v(L,se,Q.icon||"play"),Me.revealTerminal!==!1&&(j(L,se),g(!0),x("terminal"));const K=Hs.getState().getDirectoryState(L)?.tabs.find(pe=>pe.id===se);return{key:Re,tabId:se,sessionId:K?.terminalSessionId??null}},[w,L,x,j,g,v,S,i]),be=a.useCallback(async Q=>{if(l.isVSCode||!o&&u)return;if(!L){ae.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Me=zr(L,Q.id),Re=C[Me];if(!(Re&&Re.status==="running"))try{const Ne=Q.id===Jn?await(async()=>{const[yt,Dt]=await Promise.all([pc({id:je?.id??"",path:L}),Dg(L)]),st=await jg(L,yt.actions,Dt);if(!st)throw new Error(i("contextPanel.preview.noDevServer"));return{id:Jn,name:i("projectActions.actions.autoDiscover"),command:st.command,icon:"search",autoOpenUrl:!0,openUrl:st.previewUrlHint||""}})():Q,Be=Ne.autoOpenUrl===!0&&(Ne.openUrl||"").trim().length>0,{key:se,tabId:O,sessionId:A}=await we(Ne,{revealTerminal:!Be&&Q.id!==Jn});let K=A,pe=!1;if(!K){k(L,O,!0);try{K=(await c.createSession({cwd:L})).sessionId,pe=!0,D(L,O,K)}finally{k(L,O,!1)}}if(!K)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));pe&&await Ig(350),Ne.id===Jn&&(ne.current[se]?.(),k(L,O,!0),ne.current[se]=df(K,yt=>{yt.type==="data"&&typeof yt.data=="string"&&yt.data.length>0&&Hs.getState().appendToBuffer(L,O,yt.data),yt.type==="exit"&&(Hs.getState().setTabLifecycle(L,O,"exited"),Hs.getState().setConnecting(L,O,!1),Hs.getState().removeProjectActionRun(se),delete Z.current[se],ne.current[se]?.(),delete ne.current[se],window.clearTimeout(U.current[se]),delete U.current[se])},()=>{Hs.getState().setConnecting(L,O,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const _e=Ne.autoOpenUrl===!0&&m&&(Ne.desktopOpenSshForward||"").trim().length>0,We=Ne.autoOpenUrl?Fg(Ne.openUrl):null,Le=Ne.autoOpenUrl&&m?Mp(Ne.desktopOpenSshForward,d):null;P({key:se,directory:L,actionId:Ne.id,tabId:O,sessionId:K,status:Ne.id===Jn&&!We?"waiting-for-preview":"running"}),window.clearTimeout(U.current[se]),delete U.current[se],Ne.id===Jn&&!We&&(U.current[se]=window.setTimeout(()=>{Hs.getState().updateProjectActionRunStatus(se,"running"),delete U.current[se]},Rg)),Le?(T(L,O,null,{locked:!0}),Se(Le),ae.success(i("projectActions.toast.openedForwardedUrl"))):We?(T(L,O,We,{locked:!0,autoOpened:!0}),h(L,We),ae.success(i("projectActions.toast.openedActionUrl"))):Be?(T(L,O,null,{locked:!0}),ae.error(i("projectActions.error.invalidCustomUrlFormat"))):_e?(T(L,O,null,{locked:!0}),ae.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):T(L,O,null,{locked:!1,autoOpened:!1}),Z.current[se]={lastSeenChunkId:null,openedUrl:!!Le||!!We||Be,tail:"",openInPreview:Ne.id===Jn};const rt=Mg(Ne.command.trim().replace(/\r\n|\r/g,`
3
- `));await c.sendInput(K,`${rt}\r`)}catch(Ne){M(Me),delete Z.current[Me],ne.current[Me]?.(),delete ne.current[Me],window.clearTimeout(U.current[Me]),delete U.current[Me],ae.error(Ne instanceof Error?Ne.message:i("projectActions.error.failedToRunAction"))}},[d,we,o,u,m,L,Se,h,C,l.isVSCode,M,k,P,T,D,je?.id,i,c]),De=a.useCallback(async Q=>{const Me=zr(L,Q.id),Re=C[Me];if(!Re)return;E(Me,"stopping");try{await c.sendInput(Re.sessionId,"")}catch{}if(await new Promise(se=>{window.setTimeout(se,1e3)}),Hs.getState().getDirectoryState(Re.directory)?.tabs.find(se=>se.id===Re.tabId)?.terminalSessionId===Re.sessionId){if(typeof c.forceKill=="function")try{await c.forceKill({sessionId:Re.sessionId})}catch{}else try{await c.close(Re.sessionId)}catch{}D(Re.directory,Re.tabId,null)}M(Me),delete Z.current[Me],ne.current[Me]?.(),delete ne.current[Me],window.clearTimeout(U.current[Me]),delete U.current[Me]},[L,C,M,D,c,E]),le=a.useCallback(()=>{const Q=$??de[0];if(!Q)return;const Me=zr(L,Q.id),Re=C[Me];if(Re?.status!=="stopping"){if(Re){De(Q);return}be(Q)}},[de,L,be,C,$,De]),ke=a.useCallback((Q,Me=!1)=>{if(z(Q.id),!Me){be(Q);return}const Re=zr(L,Q.id),Ne=C[Re];if(Ne?.status!=="stopping"){if(Ne){De(Q);return}be(Q)}},[L,be,C,De]),ue=a.useCallback(()=>{je?.id&&(b(je.id),p("projects"),y(!0))},[y,p,b,je?.id]);if(l.isVSCode||!o&&u||!je||!L)return null;const ve=$??de[0]??null;if(!ve)return null;const G=ve.icon||"play",Ae=ve.id===Jn?"search":Ea[G]||"play",ce=zr(L,ve.id),fe=C[ce],Ee=fe?.status==="stopping",me=fe?.status==="waiting-for-preview",B=fe?N.get(fe.directory)?.tabs.find(Q=>Q.id===fe.tabId)?.previewUrl??null:null,ye=!!(fe&&B),Oe=()=>{!fe||!B||h(fe.directory,B)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:V||Ee,className:Te("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:le,"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:ve.name}):i("projectActions.actions.runNamedAria",{name:ve.name}),children:Ee||me?s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(I,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(I,{name:Ae,className:"h-5 w-5"})}),ye?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.openPreview"),onClick:Oe,children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(on,{children:[s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(rn,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:ue,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Mn,{}),de.map(Q=>{const Me=Q.icon||"play",Re=Q.id===Jn?"search":Ea[Me]||"play",Ne=zr(L,Q.id),Be=C[Ne],se=!!Be,O=Be?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{ke(Q,!0)},children:[s.jsx(I,{name:Re,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q.name}),O||Be?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):se?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},Q.id)})]})]})]}):s.jsxs("div",{className:Te("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsx("button",{type:"button",onClick:le,disabled:V||Ee,className:Te("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:ve.name}):i("projectActions.actions.runNamedAria",{name:ve.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Ee||me?s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(I,{name:Ae,className:"h-4 w-4"})})}),ye?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe,className:Te(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(on,{children:[s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",className:Te(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(rn,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:ue,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Mn,{}),de.map(Q=>{const Me=Q.icon||"play",Re=Q.id===Jn?"search":Ea[Me]||"play",Ne=zr(L,Q.id),Be=C[Ne],se=!!Be,O=Be?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{ke(Q,!0)},children:[s.jsx(I,{name:Re,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q.name}),O||Be?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):se?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},Q.id)})]})]})]})},ka="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:bg-interactive-hover transition-colors",Og="app-region-no-drag inline-flex h-9 w-9 items-center justify-center gap-2 p-2 rounded-md typography-ui-label font-medium text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:text-foreground hover:bg-interactive-hover transition-colors",Ai=a.memo(function(e){const n=gt.c(17),{visible:r,title:o,ariaLabel:i,onClick:c,className:l,Icon:u,iconClassName:m,pressed:d}=e,f=r===void 0?!0:r,g=d===void 0?!1:d;if(!f)return null;const x=l??ka,p=g&&"bg-interactive-selection text-interactive-selection-foreground";let y;n[0]!==x||n[1]!==p?(y=Te(x,p),n[0]=x,n[1]=p,n[2]=y):y=n[2];const b=m??"h-[18px] w-[18px]";let h;n[3]!==u||n[4]!==b?(h=s.jsx(I,{name:u,className:b}),n[3]=u,n[4]=b,n[5]=h):h=n[5];let N;n[6]!==i||n[7]!==c||n[8]!==g||n[9]!==y||n[10]!==h?(N=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":i,"aria-pressed":g,className:y,children:h})}),n[6]=i,n[7]=c,n[8]=g,n[9]=y,n[10]=h,n[11]=N):N=n[11];let w;n[12]!==o?(w=s.jsx(_t,{children:s.jsx("p",{children:o})}),n[12]=o,n[13]=w):w=n[13];let S;return n[14]!==N||n[15]!==w?(S=s.jsxs(Lt,{children:[N,w]}),n[14]=N,n[15]=w,n[16]=S):S=n[16],S}),_g=a.memo(function(e){const n=gt.c(42),{isMobile:r,githubAuthStatus:o,githubAccounts:i,githubAvatarUrl:c,githubLogin:l,isSwitchingGitHubAccount:u,handleGitHubAccountSwitch:m}=e,{t:d}=Tt();if(!o?.connected||r)return null;if(i.length>1){let p;n[0]===Symbol.for("react.memo_cache_sentinel")?(p=Te(ka,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=p):p=n[0];let y;n[1]!==l||n[2]!==d?(y=l?d("header.github.connectedWithLogin",{login:l}):d("header.github.connected"),n[1]=l,n[2]=d,n[3]=y):y=n[3];let b;n[4]!==c||n[5]!==l||n[6]!==d?(b=c?s.jsx("img",{src:c,alt:l?d("header.github.avatarWithLogin",{login:l}):d("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=c,n[5]=l,n[6]=d,n[7]=b):b=n[7];let h;n[8]!==u||n[9]!==y||n[10]!==b?(h=s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",className:p,title:y,disabled:u,children:b})}),n[8]=u,n[9]=y,n[10]=b,n[11]=h):h=n[11];let N;n[12]!==d?(N=d("header.github.accountsTitle"),n[12]=d,n[13]=N):N=n[13];let w;n[14]!==N?(w=s.jsx(bu,{className:"typography-ui-header font-semibold text-foreground",children:N}),n[14]=N,n[15]=w):w=n[15];let S;n[16]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(Mn,{}),n[16]=S):S=n[16];let v;if(n[17]!==i||n[18]!==m||n[19]!==u||n[20]!==d){let D;n[22]!==m||n[23]!==u||n[24]!==d?(D=T=>{const C=T.user,P=!!T.current;return s.jsxs(zt,{className:"gap-2",disabled:P||u,onSelect:()=>{P||m(T.id)},children:[C?.avatarUrl?s.jsx("img",{src:C.avatarUrl,alt:C.login?d("header.github.avatarWithLogin",{login:C.login}):d("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(I,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:C?.name?.trim()||C?.login||"GitHub"}),C?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:C.login}):null]}),P?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},T.id)},n[22]=m,n[23]=u,n[24]=d,n[25]=D):D=n[25],v=i.map(D),n[17]=i,n[18]=m,n[19]=u,n[20]=d,n[21]=v}else v=n[21];let j;n[26]!==w||n[27]!==v?(j=s.jsxs(rn,{align:"end",className:"w-64",children:[w,S,v]}),n[26]=w,n[27]=v,n[28]=j):j=n[28];let k;return n[29]!==h||n[30]!==j?(k=s.jsxs(on,{children:[h,j]}),n[29]=h,n[30]=j,n[31]=k):k=n[31],k}let f;n[32]!==l||n[33]!==d?(f=l?d("header.github.connectedWithLogin",{login:l}):d("header.github.connected"),n[32]=l,n[33]=d,n[34]=f):f=n[34];let g;n[35]!==c||n[36]!==l||n[37]!==d?(g=c?s.jsx("img",{src:c,alt:l?d("header.github.avatarWithLogin",{login:l}):d("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=c,n[36]=l,n[37]=d,n[38]=g):g=n[38];let x;return n[39]!==f||n[40]!==g?(x=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:f,children:g}),n[39]=f,n[40]=g,n[41]=x):x=n[41],x}),Bg=a.memo(function(e){const n=gt.c(84),{isDesktopApp:r,currentInstanceLabel:o,compactCurrentInstanceLabel:i,currentInstanceIsLocal:c,isDesktopServicesOpen:l,setIsDesktopServicesOpen:u,refreshCurrentInstanceLabel:m,desktopServicesTab:d,setDesktopServicesTab:f,quotaResultsLength:g,fetchAllQuotas:x,servicesTabItems:p,quotaLastUpdated:y,quotaDisplayMode:b,quotaDisplayTabItems:h,handleDisplayModeChange:N,handleUsageRefresh:w,isQuotaLoading:S,isUsageRefreshSpinning:v,hasRateLimits:j,rateLimitGroups:k,expandedFamilies:D,toggleFamilyExpanded:T,shortcutLabel:C,showDevShutdown:P,isDevShutdownInFlight:E,onDevShutdown:M,remoteUpdateInfo:H,remoteUpdateChecking:R,remoteUpdateError:_,onOpenRemoteUpdate:z,showPredValues:V,timeFormatPreference:F}=e,{t:te}=Tt();let Z;n[0]!==d||n[1]!==x||n[2]!==g||n[3]!==m||n[4]!==u?(Z=ke=>{u(ke),ke&&(m(),d==="usage"&&g===0&&x())},n[0]=d,n[1]=x,n[2]=g,n[3]=m,n[4]=u,n[5]=Z):Z=n[5];let ne;n[6]!==o||n[7]!==r||n[8]!==te?(ne=r?te("header.services.openWithCurrent",{current:o}):te("header.services.open"),n[6]=o,n[7]=r,n[8]=te,n[9]=ne):ne=n[9];const U=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let ie;n[10]!==U?(ie=Te(ka,U),n[10]=U,n[11]=ie):ie=n[11];let oe;n[12]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(I,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=oe):oe=n[12];let ge;n[13]!==i||n[14]!==r?(ge=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=ge):ge=n[15];let je;n[16]!==ne||n[17]!==ie||n[18]!==ge?(je=s.jsx(Ot,{asChild:!0,children:s.jsx(nn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":ne,className:ie,children:[oe,ge]})})}),n[16]=ne,n[17]=ie,n[18]=ge,n[19]=je):je=n[19];let Se;n[20]!==o||n[21]!==r||n[22]!==C||n[23]!==te?(Se=r?te("header.services.tooltip.currentInstanceWithShortcuts",{current:o,toggle:C("toggle_services_menu"),nextTab:C("cycle_services_tab")}):te("header.services.tooltip.servicesWithShortcuts",{toggle:C("toggle_services_menu"),nextTab:C("cycle_services_tab")}),n[20]=o,n[21]=r,n[22]=C,n[23]=te,n[24]=Se):Se=n[24];let re;n[25]!==Se?(re=s.jsx(_t,{children:s.jsx("p",{children:Se})}),n[25]=Se,n[26]=re):re=n[26];let L;n[27]!==je||n[28]!==re?(L=s.jsxs(Lt,{children:[je,re]}),n[27]=je,n[28]=re,n[29]=L):L=n[29];let $;n[30]!==x||n[31]!==g||n[32]!==f?($=ke=>{const ue=ke;f(ue),ue==="usage"&&g===0&&x()},n[30]=x,n[31]=g,n[32]=f,n[33]=$):$=n[33];let q;n[34]!==d||n[35]!==p||n[36]!==$?(q=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(go,{items:p,activeId:d,onSelect:$,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=d,n[35]=p,n[36]=$,n[37]=q):q=n[37];let he;n[38]!==c||n[39]!==d||n[40]!==r||n[41]!==l||n[42]!==z||n[43]!==R||n[44]!==_||n[45]!==H||n[46]!==u||n[47]!==te?(he=r&&d==="instance"?s.jsxs("div",{children:[c?null:s.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:te("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:H?.available?te("header.services.remoteUpdate.available",{version:H.version||""}):R?te("header.services.remoteUpdate.checking"):_||te("header.services.remoteUpdate.upToDate")})]}),H?.available?s.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:z,children:te("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(hf,{embedded:!0,open:l&&d==="instance",onOpenChange:zg,onHostSwitched:()=>u(!1)})]}):null,n[38]=c,n[39]=d,n[40]=r,n[41]=l,n[42]=z,n[43]=R,n[44]=_,n[45]=H,n[46]=u,n[47]=te,n[48]=he):he=n[48];let de;n[49]!==d||n[50]!==l?(de=d==="mcp"?s.jsx(Ju,{active:l&&d==="mcp"}):null,n[49]=d,n[50]=l,n[51]=de):de=n[51];let we;n[52]!==d||n[53]!==D||n[54]!==N||n[55]!==w||n[56]!==j||n[57]!==S||n[58]!==v||n[59]!==b||n[60]!==h||n[61]!==y||n[62]!==k||n[63]!==V||n[64]!==te||n[65]!==F||n[66]!==T?(we=d==="usage"?s.jsxs("div",{className:"overflow-x-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:te("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Qu(y,F)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(go,{items:h,activeId:b,onSelect:ke=>{N(ke)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:Te("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:S||v,"aria-label":te("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:Te("h-4 w-4",v&&"animate-spin")})})]})]}),j?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:te("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:k.map((ke,ue)=>{const ve=D[ke.providerId]??[];return s.jsxs(a.Fragment,{children:[ue>0?s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(fo,{providerId:ke.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:ke.providerName})]}),ke.entries.length===0&&(!ke.modelFamilies||ke.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:ke.error??te("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[ke.entries.map(G=>{const[Ae,ce]=G,fe=b==="remaining"?ce.remainingPercent:ce.usedPercent,Ee=ea(ce.usedPercent,ce.resetAt,ce.windowSeconds,Ae),me=Ee?.dailyAllocationPercent!=null?b==="remaining"?100-Yr(Ee.elapsedRatio):Yr(Ee.elapsedRatio):null,B=ta(ce.valueLabel,fe),ye=Wu(ce.resetAt,ce.resetAfterFormatted??ce.resetAtFormatted,F);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Uu(Ae)}),ye?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:ye}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:B==="-"?"":B})]}),s.jsx(sa,{percent:fe,tonePercent:ce.usedPercent,className:"h-1.5",expectedMarkerPercent:me}),Ee&&V?s.jsx(na,{paceInfo:Ee,compact:!0}):null]},`${ke.providerId}-${Ae}`)}),ke.modelFamilies&&ke.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:ke.modelFamilies.map(G=>{const Ae=G.familyId??"other",ce=ve.includes(Ae);return s.jsxs($i,{open:ce,onOpenChange:()=>T(ke.providerId,Ae),children:[s.jsxs(jo,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:G.familyLabel}),ce?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(zi,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:G.models.map(fe=>{const[Ee,me]=fe,B=b==="remaining"?me.remainingPercent:me.usedPercent,ye=ea(me.usedPercent,me.resetAt,me.windowSeconds),Oe=ye?.dailyAllocationPercent!=null?b==="remaining"?100-Yr(ye.elapsedRatio):Yr(ye.elapsedRatio):null,Q=ta(me.valueLabel,B);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Hu(Ee)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Q==="-"?"":Q})]}),s.jsx(sa,{percent:B,tonePercent:me.usedPercent,className:"h-1.5",expectedMarkerPercent:Oe}),ye&&V?s.jsx(na,{paceInfo:ye,compact:!0}):null]},`${ke.providerId}-${Ee}`)})})})]},Ae)})}):null]})]},ke.providerId)})})]}):null,n[52]=d,n[53]=D,n[54]=N,n[55]=w,n[56]=j,n[57]=S,n[58]=v,n[59]=b,n[60]=h,n[61]=y,n[62]=k,n[63]=V,n[64]=te,n[65]=F,n[66]=T,n[67]=we):we=n[67];let be;n[68]!==E||n[69]!==M||n[70]!==P||n[71]!==te?(be=P?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx(zt,{disabled:E,onSelect:()=>{M()},children:te("header.services.shutdownDev")})})]}):null,n[68]=E,n[69]=M,n[70]=P,n[71]=te,n[72]=be):be=n[72];let De;n[73]!==q||n[74]!==he||n[75]!==de||n[76]!==we||n[77]!==be?(De=s.jsxs(rn,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[q,he,de,we,be]}),n[73]=q,n[74]=he,n[75]=de,n[76]=we,n[77]=be,n[78]=De):De=n[78];let le;return n[79]!==l||n[80]!==Z||n[81]!==L||n[82]!==De?(le=s.jsxs(on,{open:l,onOpenChange:Z,children:[L,De]}),n[79]=l,n[80]=Z,n[81]=L,n[82]=De,n[83]=le):le=n[83],le}),Vg=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),$g=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),i=`${r} ${o}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},Qu=(t,e)=>{if(!t)return"-";try{return xu(t,e,{fallback:"-"})}catch{return"-"}},On=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Di=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,Hc=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{const{t:o}=Tt(),i=Fe(ee=>ee.setSessionSwitcherOpen),c=Fe(ee=>ee.toggleSidebar),l=Fe(ee=>ee.toggleBottomTerminal),u=Fe(ee=>ee.toggleRightSidebar),m=Fe(ee=>ee.openContextOverview),d=Fe(ee=>ee.openContextPlan),f=Fe(ee=>ee.openContextBrowser),g=Fe(ee=>ee.closeContextPanel),x=Fe(ee=>ee.contextPanelByDirectory),p=Fe(ee=>ee.activeMainTab),y=Fe(ee=>ee.setActiveMainTab),b=Fe(ee=>ee.shortcutOverrides),h=Fe(ee=>ee.timeFormatPreference),N=cs(ee=>ee.getCurrentModel),w=Wn(),[S,v]=a.useState(!1),j=vt(ee=>ee.getContextUsage),k=vt(ee=>!!ee.newSessionDraft?.open),D=vt(ee=>ee.currentSessionId),T=pf(D??""),C=yu(D??null),P=Xr(ee=>ee.activeSessions),E=Ll(),M=Es(ee=>ee.activeProjectId?ee.projects.find(at=>at.id===ee.activeProjectId)??null:null),H=a.useMemo(()=>{if(!M)return null;const ee=M.label?.trim();if(ee)return ee;const at=M.path.split(/[\\/]/).filter(Boolean);return at[at.length-1]??null},[M]),R=or(ee=>ee.results),_=or(ee=>ee.fetchAllQuotas),z=or(ee=>ee.isLoading),V=or(ee=>ee.lastUpdated),F=or(ee=>ee.displayMode),te=or(ee=>ee.showPredValues),Z=or(ee=>ee.dropdownProviderIds),ne=or(ee=>ee.loadSettings),U=or(ee=>ee.setDisplayMode),{isMobile:ie}=Pr(),oe=bi(ee=>ee.status),ge=bi(ee=>ee.setStatus),je=a.useRef(null),[Se,re]=a.useState(()=>typeof window>"u"?!1:lr()),L=a.useMemo(()=>Ol(),[]),$=wu(),[q,he]=a.useState(!1),de=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),we=a.useMemo(()=>typeof window>"u"?!1:!!window.__OPENCHAMBER_ELECTRON__&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),be=a.useMemo(()=>{if(typeof window>"u")return null;const ee=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof ee=="number"&&Number.isFinite(ee)&&ee>0)return ee;if(typeof navigator>"u")return null;const at=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!at)return null;const St=Number.parseInt(at[1],10),$t=Number.parseInt(at[2],10);return Number.isNaN(St)?null:St===10?$t:St},[]);et.useEffect(()=>{typeof window>"u"||re(lr())},[]);const De=N(),le=De&&typeof De.limit=="object"&&De.limit!==null?De.limit:null,ke=le&&typeof le.context=="number"?le.context:0,ue=le&&typeof le.output=="number"?le.output:0,ve=j(ke,ue),[G,Ae]=a.useState(null),ce=!D||T;et.useEffect(()=>{if(!D){Ae(ee=>ee===null?ee:null);return}if(ve&&ve.totalTokens>0){Ae(ee=>Vg(ee,ve)?ee:ve);return}ce&&Ae(ee=>ee===null?ee:null)},[ve,D,ce]);const fe=Fe(ee=>ee.isSessionSwitcherOpen),Ee=oe?.connected?oe.user?.avatarUrl??null:null,me=oe?.connected?oe.user?.login??null:null,B=oe?.accounts??[],[ye,Oe]=a.useState(!1),[Q,Me]=a.useState(!1),[Re,Ne]=a.useState(!1),[Be,se]=a.useState(!1),[O,A]=a.useState("Local"),[K,pe]=a.useState(!0),[_e,We]=a.useState(!1),[Le,rt]=a.useState(null),[yt,Dt]=a.useState(!1),[st,Pe]=a.useState(null),tt=a.useMemo(()=>$g(O),[O]),[Ye,nt]=a.useState(Se?"instance":"usage"),[ft,mt]=a.useState("usage");et.useEffect(()=>{!Se&&Ye==="instance"&&nt("usage")},[Ye,Se]);const ot=a.useMemo(()=>Gi(),[]),It=!ot&&p==="chat"&&!!G&&G.totalTokens>0,dt=G&&G.contextLimit>0?Math.min(999,G.totalTokens/G.contextLimit*100):0,bt=a.useCallback(async()=>{if(!(typeof window>"u"||!Se))try{if(mo()){A("Local"),pe(!0);return}pe(!1);const ee=await gf(),at=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,St=Qr();if(St&&gc(St,at)){A("Local"),pe(!0);return}const $t=ee.hosts.find(fs=>St?gc(St,xf(fs)):!1);if($t?.label?.trim()){A(bf($t.label.trim()));return}A("Instance")}catch{A("Local"),pe(!0)}},[Se]);et.useEffect(()=>{bt()},[bt]);const He=a.useCallback(async()=>{if(K){rt(null),Pe(null);return}Dt(!0),Pe(null);try{const ee=new URLSearchParams({appType:"web",instanceMode:"remote"}),at=await Rs(`/api/openchamber/update-check?${ee.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!at.ok)throw new Error(`Server responded with ${at.status}`);const St=await at.json();rt({available:St.available??!1,version:St.version,currentVersion:St.currentVersion??"unknown",body:St.body,nextSuggestedCheckInSec:typeof St.nextSuggestedCheckInSec=="number"?St.nextSuggestedCheckInSec:void 0,packageManager:St.packageManager,updateCommand:St.updateCommand})}catch(ee){rt(null),Pe(ee instanceof Error?ee.message:o("header.services.remoteUpdate.error"))}finally{Dt(!1)}},[K,o]);a.useEffect(()=>{rt(null),Pe(null),We(!1)},[K,O]),a.useEffect(()=>{if(!Se||K)return;const ee=3e3,at=3600*1e3;let St=!1,$t=null;const fs=ms=>{$t=window.setTimeout(()=>{if(St||typeof document<"u"&&document.visibilityState!=="visible"){fs(at);return}He().finally(()=>{St||fs(at)})},ms)};return fs(ee),()=>{St=!0,$t!==null&&window.clearTimeout($t)}},[He,K,O,Se]);const Ze=a.useCallback(()=>{if(Le?.available){We(!0);return}He()},[He,Le?.available]);Fp();const Ue=or(ee=>ee.selectedModels),jt=or(ee=>ee.expandedFamilies),Ge=or(ee=>ee.toggleFamilyExpanded),it=a.useMemo(()=>{const ee=[];for(const at of Lp){if(!Z.includes(at.id))continue;const St=R.find(Ws=>Ws.providerId===at.id),$t=St?.usage?.windows??{},fs=St?.usage?.models,ms=Object.entries($t),Qt={providerId:at.id,providerName:at.name,entries:ms,error:St&&!St.ok&&St.configured?St.error:void 0};if(fs&&Object.keys(fs).length>0){const Ws=Ue[at.id]??[],Is=Ws.length>0,Gn=Op(fs,at.id),ur=_p(at.id),_r=Bp(ur);Qt.modelFamilies=[];for(const mn of _r){const ps=Gn.get(mn.id)??[];if(ps.length===0)continue;const Zs=Is?ps.filter(jn=>Ws.includes(jn)):ps;if(Zs.length===0)continue;const vn=[];for(const jn of Zs){const Kn=fs[jn];if(Kn?.windows){const Nr=Object.entries(Kn.windows);Nr.length>0&&vn.push([jn,Nr[0][1]])}}vn.length>0&&Qt.modelFamilies.push({familyId:mn.id,familyLabel:mn.label,models:vn})}const pn=Gn.get(null)??[],Ln=Is?pn.filter(mn=>Ws.includes(mn)):pn;if(Ln.length>0){const mn=[];for(const ps of Ln){const Zs=fs[ps];if(Zs?.windows){const vn=Object.entries(Zs.windows);vn.length>0&&mn.push([ps,vn[0][1]])}}mn.length>0&&Qt.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:mn})}}(ms.length>0||Qt.modelFamilies&&Qt.modelFamilies.length>0||Qt.error)&&ee.push(Qt)}return ee},[Z,R,Ue,o]),Et=it.length>0;a.useEffect(()=>{ne()},[ne]);const lt=a.useCallback(async ee=>{U(ee);try{await ua({usageDisplayMode:ee})}catch(at){console.warn("Failed to update usage display mode:",at)}},[U]),ct=a.useCallback(()=>{if(Be)return;se(!0);const ee=new Promise(at=>setTimeout(at,500));Promise.all([_(),ee]).finally(()=>{se(!1)})},[_,Be]),Bt=a.useMemo(()=>D?E.find(ee=>ee.id===D)??P.find(ee=>ee.id===D)??C??yf().find(ee=>ee.id===D)??null:null,[D,C,P,E]),Ft=a.useRef(null),[qt,Ut]=a.useState(0);a.useEffect(()=>{if(!D){Ft.current&&(Ft.current=null,Ut($t=>$t+1));return}if(Bt){Ft.current={sessionId:D,session:Bt,expiresAt:Date.now()+2e3};return}const ee=Ft.current;if(!ee||ee.sessionId!==D)return;const at=ee.expiresAt-Date.now();if(at<=0){Ft.current=null,Ut($t=>$t+1);return}const St=window.setTimeout(()=>{Ft.current?.sessionId===D&&(Ft.current=null),Ut($t=>$t+1)},at);return()=>{window.clearTimeout(St)}},[D,Bt]);const At=(()=>{if(Bt)return Bt;if(!D)return null;const ee=Ft.current;return ee&&ee.sessionId===D&&ee.expiresAt>Date.now()?ee.session:null})(),Xt=vt(ee=>D?ee.worktreeMetadata.get(D)?.path??"":""),ls=vt(ee=>D?ee.worktreeMetadata.get(D)?.branch?.trim()??null:null),es=vu(ee=>D?ee.getAttachment(D):void 0),Gt=a.useMemo(()=>es?wf(es):null,[es]),pt=a.useMemo(()=>es?es.legacy?"legacy":es.degraded?"degraded":es.worktreeStatus==="missing"?"missing":es.worktreeStatus==="invalid"?"invalid":es.attentionReason?"attention":null:null,[es]),Yt=a.useMemo(()=>On(Xt||""),[Xt]),us=a.useMemo(()=>{const ee=typeof At?.directory=="string"?At.directory:"";return On(ee||"")},[At?.directory]),Jt=vt(ee=>ee.newSessionDraft?.open?On(ee.newSessionDraft.bootstrapPendingDirectory??ee.newSessionDraft.directoryOverride??""):""),ss=a.useMemo(()=>Yt||us||Jt,[Jt,us,Yt]),hs=vt(ee=>{const at=On(Yt||us||"");if(!at)return null;for(const St of ee.availableWorktreesByProject.values()){const fs=St.find(ms=>On(ms.path)===at)?.branch?.trim();if(fs)return fs}return null}),gs=vf(ss||null)||ls||hs,Ms=a.useMemo(()=>{if(!D)return H??"OpenChamber";const ee=At?.title?.trim();return ee&&ee.length>0?ee:"Untitled Session"},[H,At?.title,D]),Vt=a.useMemo(()=>ju(At?.summary),[At?.summary]),vs=a.useMemo(()=>Vt||{additions:0,deletions:0},[Vt]),Ps=vs.additions>0||vs.deletions>0,Ns=a.useMemo(()=>On(ss||M?.path||""),[M?.path,ss]),As=a.useMemo(()=>M?{id:M.id,path:M.path}:null,[M]),Rt=a.useRef(null);a.useEffect(()=>{!As||!Ns||(Rt.current={projectRef:As,directory:Ns})},[Ns,As]);const xt=a.useMemo(()=>As&&Ns?{projectRef:As,directory:Ns}:Rt.current,[Ns,As]),Kt=_l(ee=>ee.planModeEnabled),Ht=vt(ee=>ee.isSessionPlanAvailable),ns=Kt&&D?Ht(D):!1,rs=ns,ds=a.useRef("");a.useEffect(()=>{if(!Kt){Fe.getState().activeMainTab==="plan"&&Fe.getState().setActiveMainTab("chat");return}if(!D)return;const ee=`${D||"none"}:${us||"none"}:${At?.time?.created||0}:${At?.slug||"none"}`;ds.current!==ee&&(ds.current=ee),!ns&&Fe.getState().activeMainTab==="plan"&&Fe.getState().setActiveMainTab("chat")},[Kt,ns,At?.slug,At?.time?.created,D,us]);const W=a.useCallback(async ee=>{if(!(!ee||ye)){Oe(!0);try{const at=w.github?await w.github.authActivate(ee):await(async()=>{const St=await Rs("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:ee})}),$t=await St.json().catch(()=>null);if(!St.ok||!$t)throw new Error($t?.error||St.statusText);return $t})();ge(at)}catch(at){console.error("Failed to switch GitHub account:",at)}finally{Oe(!1)}}},[ye,w.github,ge]),qe=a.useCallback(()=>{if(typeof document>"u")return;const ee=document.activeElement;if(!ee)return;const at=ee.tagName;(at==="INPUT"||at==="TEXTAREA"||at==="SELECT"||ee.isContentEditable)&&ee.blur()},[]),Qe=a.useCallback(()=>{if(ie){qe(),i(!fe);return}c()},[qe,ie,fe,i,c]),ht=a.useCallback(ee=>{const at=ee.currentTarget.getBoundingClientRect();ui("desktop_show_app_menu",{x:at.left,y:at.bottom}).catch(St=>{console.warn("[header] failed to open app menu",St)})},[]),Ct=a.useCallback(()=>{ui("desktop_open_draft_mini_chat_window",{directory:On(ss||M?.path||""),projectId:M?.id??null,apiBaseUrl:Qr(),clientToken:al()}).catch(ee=>{console.warn("[header] failed to open draft mini chat window",ee)})},[M?.id,M?.path,ss]),ut=a.useCallback(()=>{if(k){Ct();return}D&&ui("desktop_open_session_mini_chat_window",{sessionId:D,directory:On(ss||M?.path||""),apiBaseUrl:Qr(),clientToken:al()}).catch(ee=>{console.warn("[header] failed to open session mini chat window",ee)})},[M?.path,D,Ct,k,ss]),ts=a.useCallback(()=>{const ee=On(ss||"");if(!ee)return;const at=x[ee];if(Di(at)==="context"){g(ee);return}m(ee)},[g,x,m,ss]),js=a.useMemo(()=>{const ee=On(ss||"");if(!ee)return!1;const at=x[ee];return Di(at)==="context"},[x,ss]),xs=a.useCallback(()=>{const ee=On(ss||"");if(!ee)return;const at=x[ee];if(Di(at)==="plan"){g(ee);return}d(ee)},[g,x,d,ss]),Bs=a.useCallback(()=>{const ee=On(ss||"");if(!ee)return;const at=x[ee];if(Di(at)==="browser"){g(ee);return}f(ee)},[g,x,f,ss]),Ts=a.useMemo(()=>{const ee=On(ss||"");if(!ee)return!1;const at=x[ee];return Di(at)==="plan"},[x,ss]),dn=a.useMemo(()=>{const ee=On(ss||"");if(!ee)return!1;const at=x[ee];return Di(at)==="browser"},[x,ss]),Ds=ka,Vs=Og,Us=a.useMemo(()=>Q?"services":n?"sessions":r?"git":p,[p,Q,n,r]),bs=a.useCallback(()=>{Me(!1),n&&t&&t(),r&&e&&e(),!t&&fe&&i(!1)},[fe,n,t,e,r,i]),wr=a.useCallback(()=>{n||Me(!1),t?.()},[n,t]),yn=a.useCallback(()=>{r||Me(!1),e?.()},[e,r]),ks=a.useMemo(()=>Se&&de&&!q||$?"pl-[5.5rem]":"pl-3",[Se,q,de,$]);et.useEffect(()=>{if(!Se||!de){he(!1);return}let ee=!1;const at=async()=>{try{const $t=await ui("desktop_is_window_fullscreen");ee||he($t===!0)}catch{ee||he(!1)}},St=()=>{at()};return at(),window.addEventListener("openchamber:window-resized",St),()=>{ee=!0,window.removeEventListener("openchamber:window-resized",St)}},[Se,de]);const ln=a.useMemo(()=>!Se||!de||be===null?"":be>=26?"h-12":be<=15?"h-14":"",[Se,de,be]),Tn=a.useMemo(()=>{if(!(Se&&!we||ot))return{paddingLeft:$?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[Se,$,ot,we]),un=a.useCallback(()=>{if(typeof document>"u")return;const ee=je.current?.getBoundingClientRect().height;ee&&document.documentElement.style.setProperty("--oc-header-height",`${ee}px`)},[]);et.useEffect(()=>{if(typeof window>"u")return;un();const ee=je.current;if(!ee||typeof ResizeObserver>"u")return()=>{};let at=0;const St=()=>{at||(at=requestAnimationFrame(()=>{at=0,un()}))},$t=new ResizeObserver(St);return $t.observe(ee),window.addEventListener("resize",St),window.addEventListener("orientationchange",St),()=>{at&&cancelAnimationFrame(at),$t.disconnect(),window.removeEventListener("resize",St),window.removeEventListener("orientationchange",St)}},[un]),et.useEffect(()=>{un()},[un,ie,ln]);const Un=a.useCallback(async ee=>{const at=ee.target;at.closest(".app-region-no-drag")||at.closest("button, a, input, select, textarea")||ee.button===0&&Se&&await jf()},[Se]),wn=a.useMemo(()=>{if(ie){const ee=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return rs&&ee.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),ee.push({id:"diff",label:o("layout.mainTab.diff"),icon:"diff"},{id:"files",label:o("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:o("layout.mainTab.terminal"),icon:"terminal-box"},{id:"context",label:o("layout.mainTab.context"),icon:"file-list-2"}),ee}return[]},[ie,rs,o]),zs=a.useCallback(ee=>Bl(mi(ee,b)),[b]);et.useEffect(()=>{!ie&&(p==="git"||p==="terminal"||p==="diff"||p==="files"||p==="context")&&y("chat")},[p,ie,y]);const is=a.useMemo(()=>{const ee=[];return Se&&ee.push({value:"instance",label:o("layout.services.instance"),icon:"server"}),ee.push({value:"usage",label:o("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:"plug-2"}),ee},[Se,o]),Fs=a.useMemo(()=>is.map(ee=>({id:ee.value,label:ee.label,icon:s.jsx(I,{name:ee.icon,className:"h-3.5 w-3.5"})})),[is]),dr=a.useMemo(()=>{if(typeof window>"u"||Se||ot)return!1;const ee=window.location.hostname;return ee==="localhost"||ee==="127.0.0.1"||ee==="::1"},[Se,ot]),Cn=a.useCallback(async()=>{if(S)return;v(!0),Ne(!1);const ee=[];let at=!1;try{try{for(const[,St]of Hs.getState().sessions.entries())for(const $t of St.tabs)$t.previewUrl&&ee.push($t.previewUrl)}catch{}try{await uf({})}catch{}try{(await Rs("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:ee})})).ok?at=!0:at=(await Rs("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{at||v(!1)}},[S,Ne]),$s=a.useMemo(()=>[{value:"usage",label:o("header.services.used")},{value:"remaining",label:o("header.services.remaining")}],[o]),Hn=a.useMemo(()=>$s.map(ee=>({id:ee.value,label:ee.label})),[$s]),vr=a.useMemo(()=>[{id:"usage",label:o("layout.services.usage"),icon:s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(I,{name:"command",className:"h-3.5 w-3.5"})}],[o]);et.useEffect(()=>{const ee=at=>{if(Vl(at)&&!at.shiftKey&&!at.altKey){const St=parseInt(at.key,10);St>=1&&St<=wn.length&&(at.preventDefault(),ie&&(qe(),bs()),y(wn[St-1].id))}};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[qe,bs,ie,y,wn]),et.useEffect(()=>{const ee=at=>{const St=mi("toggle_services_menu",b);if(Lo(at,St)){at.preventDefault(),Re?Ne(!1):(Ne(!0),bt(),Ye==="usage"&&R.length===0&&_());return}const $t=mi("cycle_services_tab",b);if(Lo(at,$t)){at.preventDefault();const ms=is.map(Gn=>Gn.value);if(ms.length===0)return;const Qt=ms.indexOf(Ye),Ws=Qt===-1?0:(Qt+1)%ms.length,Is=ms[Ws];nt(Is),Ne(!0),bt(),Is==="usage"&&R.length===0&&_();return}const fs=mi("toggle_context_plan",b);Lo(at,fs)&&(at.preventDefault(),xs())};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[b,Re,Ye,is,R.length,_,bt,xs]);const Er=ee=>{const at=p===ee.id,St=ee.icon==="diff",$t=St?null:ee.icon,fs=ee.id==="chat",ms=Ws=>St?s.jsx(Vc,{size:Ws}):$t?s.jsx(I,{name:$t,className:`h-${Ws/4} w-${Ws/4}`}):null,Qt=s.jsxs("button",{type:"button",onClick:()=>y(ee.id),className:Te("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",at?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",fs&&!ie&&"min-w-[100px] justify-center"),"aria-label":ee.label,"aria-selected":at,role:"tab",children:[ie?ms(20):s.jsxs(s.Fragment,{children:[ms(16),s.jsx("span",{className:"header-tab-label",children:ee.label})]}),ee.badge!==void 0&&ee.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:ee.badge})]});return s.jsx(a.Fragment,{children:Qt},ee.id)},jr=s.jsxs(s.Fragment,{children:[rs&&s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.actions.openPlanAria"),onClick:xs,className:Te(Ds,Ts&&"bg-[var(--interactive-hover)]"),children:s.jsx(I,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(_t,{children:s.jsx("p",{children:o("header.actions.planWithShortcut",{shortcut:zs("toggle_context_plan")})})})]}),s.jsx(lg,{directory:Ns,className:"mr-1"}),s.jsx(Bg,{isDesktopApp:Se,currentInstanceLabel:O,compactCurrentInstanceLabel:tt,currentInstanceIsLocal:K,isDesktopServicesOpen:Re,setIsDesktopServicesOpen:Ne,refreshCurrentInstanceLabel:bt,desktopServicesTab:Ye,setDesktopServicesTab:nt,quotaResultsLength:R.length,fetchAllQuotas:_,servicesTabItems:Fs,quotaLastUpdated:V,quotaDisplayMode:F,showPredValues:te,quotaDisplayTabItems:Hn,handleDisplayModeChange:lt,handleUsageRefresh:ct,isQuotaLoading:z,isUsageRefreshSpinning:Be,hasRateLimits:Et,rateLimitGroups:it,expandedFamilies:jt,toggleFamilyExpanded:Ge,shortcutLabel:zs,showDevShutdown:dr,isDevShutdownInFlight:S,onDevShutdown:Cn,remoteUpdateInfo:Le,remoteUpdateChecking:yt,remoteUpdateError:st,onOpenRemoteUpdate:Ze,timeFormatPreference:h}),s.jsx(Ai,{title:o("header.actions.terminalPanelWithShortcut",{shortcut:zs("toggle_terminal")}),ariaLabel:o("header.actions.toggleTerminalPanelAria"),onClick:l,Icon:"terminal-box"}),ie?null:s.jsx(Ai,{title:o("contextPanel.browser.open"),ariaLabel:o("contextPanel.browser.open"),onClick:Bs,pressed:dn,Icon:"global"}),s.jsx(Ai,{title:o("header.actions.rightSidebarWithShortcut",{shortcut:zs("toggle_right_sidebar")}),ariaLabel:o("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx(_g,{isMobile:ie,githubAuthStatus:oe,githubAccounts:B,githubAvatarUrl:Ee,githubLogin:me,isSwitchingGitHubAccount:ye,handleGitHubAccountSwitch:W})]}),sr=L&&(k||!!D),nr=()=>s.jsxs("div",{onMouseDown:Un,className:Te("app-region-drag relative flex h-12 select-none items-center pr-3",ks,ln),style:Tn,role:"tablist","aria-label":o("header.navigation.mainAria"),children:[we?s.jsx(Ai,{title:o("header.actions.openAppMenu"),ariaLabel:o("header.actions.openAppMenuAria"),onClick:ht,className:`${Ds} shrink-0`,Icon:"menu-2"}):null,s.jsx(Ai,{title:o("header.actions.openSessionsWithShortcut",{shortcut:zs("toggle_sidebar")}),ariaLabel:o("header.actions.openSessionsAria"),onClick:Qe,className:`${Ds} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center pl-3",children:[xt&&s.jsx(Uc,{projectRef:xt.projectRef,directory:xt.directory,className:"mr-2"}),s.jsx(eg,{children:s.jsxs("button",{type:"button","aria-label":o("sessions.switcher.openAria"),className:"app-region-no-drag mr-3 flex min-w-0 flex-col items-start rounded-md px-1 py-0.5 -my-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:k?o("sessions.switcher.draftTitle"):Ms}),H||gs||!k&&(Ps||pt)?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[H?s.jsx("span",{className:"truncate",children:H}):null,gs?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:gs})]}):null,!k&&Ps?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",vs.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",vs.deletions]})]}):null,!k&&pt?s.jsxs("span",{className:Te("inline-flex min-w-0 items-center gap-0.5",pt==="attention"||pt==="invalid"||pt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(I,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Gt})]}):null]}):null]})}),wn.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:wn.map(ee=>Er(ee))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[It&&G?s.jsx(tg,{totalTokens:G.totalTokens,percentage:dt,colorPercentage:G.percentage,contextLimit:G.contextLimit,outputLimit:G.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:ts,pressed:js,className:sr?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ai,{visible:sr,title:o(k?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(k?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:ut,className:Te(Ds,It?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),jr,s.jsx(sg,{visible:we})]})]})]}),Sr=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:wr,className:Te(Vs,Us==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":o(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(I,{name:"layout-left",className:"h-5 w-5"})}):fe?s.jsx("button",{type:"button",onClick:()=>i(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.backAria"),children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Qe,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.openSessionsAria"),children:s.jsx(I,{name:"play-list-add",className:"h-5 w-5"})}),!t&&fe&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!fe||!!t)&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":o("header.navigation.mainAria"),children:wn.map(ee=>{const at=p===ee.id,St=ee.icon==="diff",$t=St?null:ee.icon;return s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{ie&&(qe(),bs()),y(ee.id)},"aria-label":ee.label,"aria-selected":at,role:"tab",className:Te(Vs,"relative rounded-lg",Us===ee.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[St?s.jsx(Vc,{className:"h-5 w-5"}):$t?s.jsx(I,{name:$t,className:"h-5 w-5"}):null,ee.badge!==void 0&&ee.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:ee.badge}),ee.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":o("header.changes.availableAria")})]})}),s.jsx(_t,{children:s.jsx("p",{children:ee.label})})]},ee.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[xt&&s.jsx(Uc,{projectRef:xt.projectRef,directory:xt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(on,{open:Q,onOpenChange:ee=>{ee&&(n&&t&&t(),r&&e&&e()),Me(ee),ee&&R.length===0&&_()},children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:Te(Vs,Us==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(I,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(_t,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(rn,{align:"end",sideOffset:0,positionerClassName:"!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none",className:"h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(go,{items:vr,activeId:ft,onSelect:ee=>{const at=ee;mt(at),at==="usage"&&R.length===0&&_()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>Me(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":o("header.services.closeAria"),children:s.jsx(I,{name:"close",className:"h-5 w-5"})})]})}),ft==="mcp"&&s.jsx(Ju,{active:Q&&ft==="mcp"}),ft==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:o("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Qu(V,h)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>lt("usage"),className:Te("typography-ui-label px-1 pb-0.5 transition-colors",F==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>lt("remaining"),className:Te("typography-ui-label px-1 pb-0.5 transition-colors",F==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.remaining")})]}),s.jsx("button",{type:"button",className:Te("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:ct,disabled:z||Be,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:Te("h-4 w-4",Be&&"animate-spin")})})]})]})}),!Et&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:o("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:it.map((ee,at)=>s.jsxs(a.Fragment,{children:[at>0?s.jsx("div",{className:"mx-4 my-1 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(fo,{providerId:ee.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:ee.providerName})]}),ee.entries.length===0&&(!ee.modelFamilies||ee.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:ee.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[ee.entries.map(([St,$t])=>{const fs=F==="remaining"?$t.remainingPercent:$t.usedPercent,ms=ea($t.usedPercent,$t.resetAt,$t.windowSeconds,St),Qt=ms?.dailyAllocationPercent!=null?F==="remaining"?100-Yr(ms.elapsedRatio):Yr(ms.elapsedRatio):null,Ws=ta($t.valueLabel,fs),Is=Wu($t.resetAt,$t.resetAfterFormatted??$t.resetAtFormatted,h);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Uu(St)}),Is?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Is}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ws==="-"?"":Ws})]}),s.jsx(sa,{percent:fs,tonePercent:$t.usedPercent,className:"h-1.5",expectedMarkerPercent:Qt}),ms&&te?s.jsx(na,{paceInfo:ms,compact:!0}):null]},`${ee.providerId}-${St}`)}),ee.modelFamilies&&ee.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:ee.modelFamilies.map(St=>{const fs=(jt[ee.providerId]??[]).includes(St.familyId??"other");return s.jsxs($i,{open:fs,onOpenChange:()=>Ge(ee.providerId,St.familyId??"other"),children:[s.jsxs(jo,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:St.familyLabel}),fs?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(zi,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:St.models.map(([ms,Qt])=>{const Ws=F==="remaining"?Qt.remainingPercent:Qt.usedPercent,Is=ea(Qt.usedPercent,Qt.resetAt,Qt.windowSeconds),Gn=Is?.dailyAllocationPercent!=null?F==="remaining"?100-Yr(Is.elapsedRatio):Yr(Is.elapsedRatio):null,ur=ta(Qt.valueLabel,Ws);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Hu(ms)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:ur==="-"?"":ur})]}),s.jsx(sa,{percent:Ws,tonePercent:Qt.usedPercent,className:"h-1.5",expectedMarkerPercent:Gn}),Is&&te?s.jsx(na,{paceInfo:Is,compact:!0}):null]},`${ee.providerId}-${ms}`)})})})]},St.familyId??"other")})})]})]},ee.providerId))})]})]})})]}),e?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:yn,className:Te(Vs,"relative",Us==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(I,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(_t,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Rr=Te("header-safe-area relative z-10",ie?"border-b border-border/50 bg-background":"bg-sidebar");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:je,className:Rr,style:{"--padding-scale":"1"},children:ie?Sr():nr()}),s.jsx(Gu,{open:_e,onOpenChange:We,info:Le,downloading:!1,downloaded:!1,progress:null,error:st,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function zg(){}const Gc=180,Kc=640,Wg=110,Ug=t=>{const e=gt.c(44),{isOpen:n,isMobile:r,children:o}=t,{t:i}=Tt(),c=Fe(Hg),l=Fe(Gg),u=Fe(Kg),m=Fe(qg),[d,f]=a.useState(null),[g,x]=a.useState(!1),p=a.useRef(null),y=a.useRef(0),b=a.useRef(c||300),h=Math.min(Kc,Math.max(Gc,c||300));let N,w;e[0]!==n?(N=()=>{n||(f(null),x(!1))},w=[n],e[0]=n,e[1]=N,e[2]=w):(N=e[1],w=e[2]),a.useEffect(N,w);let S,v;e[3]!==l||e[4]!==r||e[5]!==n?(S=()=>{if(r||!n||!l)return;const ie=()=>{const je=p.current?.parentElement?.getBoundingClientRect().height;if(!je||je<=0)return;const Se=Math.max(0,Math.round(je));f(re=>re===Se?re:Se)};ie();const oe=p.current?.parentElement;if(!oe)return;const ge=new ResizeObserver(ie);return ge.observe(oe),()=>{ge.disconnect()}},v=[l,r,n],e[3]=l,e[4]=r,e[5]=n,e[6]=S,e[7]=v):(S=e[6],v=e[7]),a.useEffect(S,v);let j,k;if(e[8]!==l||e[9]!==r||e[10]!==g||e[11]!==u||e[12]!==m?(j=()=>{if(r||!g||l)return;const ie=ge=>{const je=y.current-ge.clientY,Se=Math.min(Kc,Math.max(Gc,b.current+je));u(Se)},oe=()=>{x(!1),Fe.getState().bottomTerminalHeight<=Wg&&m(!1)};return window.addEventListener("pointermove",ie),window.addEventListener("pointerup",oe,{once:!0}),()=>{window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",oe)}},k=[l,r,g,u,m],e[8]=l,e[9]=r,e[10]=g,e[11]=u,e[12]=m,e[13]=j,e[14]=k):(j=e[13],k=e[14]),a.useEffect(j,k),r)return null;const D=n?l?Math.max(0,d??h):h:0,T=n&&l;let C;e[15]!==D||e[16]!==l||e[17]!==n?(C=ie=>{!n||l||(x(!0),y.current=ie.clientY,b.current=D,ie.preventDefault())},e[15]=D,e[16]=l,e[17]=n,e[18]=C):C=e[18];const P=C,E=T?"absolute inset-x-0 bottom-0 z-40":"relative",M=g?"transition-none":"transition-[height] duration-300 ease-in-out",H=(!n||T)&&"border-t-0";let R;e[19]!==H||e[20]!==E||e[21]!==M?(R=Te("flex overflow-hidden border-t border-border bg-sidebar",E,M,H),e[19]=H,e[20]=E,e[21]=M,e[22]=R):R=e[22];let _;e[23]!==D||e[24]!==T?(_=T?{top:0}:{height:`${D}px`,minHeight:`${D}px`,maxHeight:`${D}px`},e[23]=D,e[24]=T,e[25]=_):_=e[25];const z=!n||!l&&D===0;let V;e[26]!==P||e[27]!==l||e[28]!==n||e[29]!==g||e[30]!==i?(V=n&&!l&&s.jsx("div",{className:Te("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",g&&"bg-[var(--interactive-border)]"),onPointerDown:P,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=P,e[27]=l,e[28]=n,e[29]=g,e[30]=i,e[31]=V):V=e[31];const F=!n&&"pointer-events-none select-none opacity-0";let te;e[32]!==F?(te=Te("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",F),e[32]=F,e[33]=te):te=e[33];const Z=!n;let ne;e[34]!==o||e[35]!==te||e[36]!==Z?(ne=s.jsx("div",{className:te,"aria-hidden":Z,children:o}),e[34]=o,e[35]=te,e[36]=Z,e[37]=ne):ne=e[37];let U;return e[38]!==R||e[39]!==_||e[40]!==z||e[41]!==V||e[42]!==ne?(U=s.jsxs("section",{ref:p,className:R,style:_,"aria-hidden":z,children:[V,ne]}),e[38]=R,e[39]=_,e[40]=z,e[41]=V,e[42]=ne,e[43]=U):U=e[43],U};function Hg(t){return t.bottomTerminalHeight}function Gg(t){return t.isBottomTerminalExpanded}function Kg(t){return t.setBottomTerminalHeight}function qg(t){return t.setBottomTerminalOpen}const yl=280,qc=280,Yc=500,Yg=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:o}=Tt(),i=Fe(j=>j.sidebarWidth),c=Fe(j=>j.setSidebarWidth),[l,u]=a.useState(!1),m=a.useRef(0),d=a.useRef(i||yl),f=a.useRef(null),g=a.useRef(null),x=a.useRef(null),p=a.useCallback(j=>Math.min(Yc,Math.max(qc,j)),[]),y=a.useCallback(j=>{const k=x.current;k&&(k.style.width=`${j}px`,k.style.minWidth=`${j}px`,k.style.maxWidth=`${j}px`,k.style.setProperty("--oc-left-sidebar-width",`${j}px`))},[]);if(a.useEffect(()=>{e&&l&&u(!1)},[e,l]),a.useEffect(()=>{l||(f.current=null,g.current=null)},[l]),e)return null;const b=Math.min(Yc,Math.max(qc,i||yl)),h=t?b:0,N=j=>{if(t){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}g.current=j.pointerId,u(!0),m.current=j.clientX,d.current=h,f.current=h,y(h),j.preventDefault()}},w=j=>{if(e||!l||g.current!==j.pointerId)return;const k=j.clientX-m.current,D=p(d.current+k);f.current!==D&&(f.current=D,y(D))},S=j=>{if(g.current!==j.pointerId||e)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const k=p(f.current??h);g.current=null,f.current=null,u(!1),c(k)},v=l?f.current??h:h;return s.jsxs("aside",{ref:x,className:Te("relative flex h-full overflow-hidden border-r border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-r-0",r),style:{width:`${v}px`,minWidth:`${v}px`,maxWidth:`${v}px`,"--oc-left-sidebar-width":`${l?v:b}px`,overflowX:"clip",transitionProperty:l?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||h===0,children:[t&&s.jsx("div",{className:Te("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",l&&"bg-[var(--interactive-border)]"),onPointerDown:N,onPointerMove:w,onPointerUp:S,onPointerCancel:S,role:"separator","aria-orientation":"vertical","aria-label":o("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:Te("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",l&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(an,{children:n})})})]})},wl=420,Jc=360,Qc=860,Jg=({isOpen:t,children:e,className:n})=>{const{t:r}=Tt(),o=Fe(v=>v.rightSidebarWidth),i=Fe(v=>v.setRightSidebarWidth),[c,l]=a.useState(!1),u=a.useRef(0),m=a.useRef(o||wl),d=a.useRef(null),f=a.useRef(null),g=a.useRef(null),x=a.useCallback(v=>Math.min(Qc,Math.max(Jc,v)),[]),p=a.useCallback(v=>{const j=g.current;j&&(j.style.width=`${v}px`,j.style.minWidth=`${v}px`,j.style.maxWidth=`${v}px`,j.style.setProperty("--oc-right-sidebar-width",`${v}px`))},[]),y=Math.min(Qc,Math.max(Jc,o||wl)),b=t?y:0,h=v=>{if(t){try{v.currentTarget.setPointerCapture(v.pointerId)}catch{}f.current=v.pointerId,l(!0),u.current=v.clientX,m.current=b,d.current=b,p(b),v.preventDefault()}},N=v=>{if(!c||f.current!==v.pointerId)return;const j=u.current-v.clientX,k=x(m.current+j);d.current!==k&&(d.current=k,p(k))},w=v=>{if(f.current!==v.pointerId)return;try{v.currentTarget.releasePointerCapture(v.pointerId)}catch{}const j=x(d.current??b);f.current=null,d.current=null,l(!1),i(j)};a.useEffect(()=>{c||(d.current=null,f.current=null)},[c]);const S=c?d.current??b:b;return s.jsxs("aside",{ref:g,className:Te("relative flex h-full overflow-hidden border-l border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-l-0",n),style:{width:`${S}px`,minWidth:`${S}px`,maxWidth:`${S}px`,"--oc-right-sidebar-width":`${c?S:y}px`,overflowX:"clip",transitionProperty:c?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||b===0,children:[t&&s.jsx("div",{className:Te("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:h,onPointerMove:N,onPointerUp:w,onPointerCancel:w,role:"separator","aria-orientation":"vertical","aria-label":r("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:Te("relative z-10 flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-right-sidebar-width)"},"aria-hidden":!t,children:t?e:null})]})},Xc=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent});function Xu(t){const e=gt.c(120),{t:n}=Tt(),{open:r,onOpenChange:o,target:i,projectDirectory:c,submitting:l,onConfirm:u}=t,m=l===void 0?!1:l,d=cs(ox),f=cs(ix),g=Sf(rx),x=cs(nx),p=cs(sx),y=cs(tx),b=cs(ex),h=cs(Zg);let N;e[0]!==h||e[1]!==y||e[2]!==p||e[3]!==b?(N=()=>Xc({providerID:p,modelID:y,variant:b,agent:h}),e[0]=h,e[1]=y,e[2]=p,e[3]=b,e[4]=N):N=e[4];const[w,S]=a.useState(N);let v,j;e[5]!==g||e[6]!==f||e[7]!==d||e[8]!==r||e[9]!==c?(v=()=>{r&&(d({directory:c,source:"todoSendDialog"}),f({directory:c}),g())},j=[r,d,f,g,c],e[5]=g,e[6]=f,e[7]=d,e[8]=r,e[9]=c,e[10]=v,e[11]=j):(v=e[10],j=e[11]),a.useEffect(v,j);let k,D;e[12]!==h||e[13]!==y||e[14]!==p||e[15]!==b||e[16]!==r?(k=()=>{r&&S(Xc({providerID:p,modelID:y,variant:b,agent:h}))},D=[r,p,y,b,h],e[12]=h,e[13]=y,e[14]=p,e[15]=b,e[16]=r,e[17]=k,e[18]=D):(k=e[17],D=e[18]),a.useEffect(k,D);let T,C;e[19]!==w.modelID||e[20]!==w.providerID||e[21]!==r||e[22]!==x?(T=()=>{if(!r||x.length===0)return;const Be=x.find(K=>K.id===w.providerID)??x[0],se=Array.isArray(Be?.models)?Be.models:[],O=se.some(K=>K.id===w.modelID),A=se[0]?.id??"";Be?.id===w.providerID&&O||S(K=>({...K,providerID:Be?.id??"",modelID:O?K.modelID:A,variant:""}))},C=[r,x,w.providerID,w.modelID],e[19]=w.modelID,e[20]=w.providerID,e[21]=r,e[22]=x,e[23]=T,e[24]=C):(T=e[23],C=e[24]),a.useEffect(T,C);const P=Xg;let E;if(e[25]!==w.modelID||e[26]!==w.providerID||e[27]!==x){let Be;e[29]!==w.providerID?(Be=O=>O.id===w.providerID,e[29]=w.providerID,e[30]=Be):Be=e[30],E=x.find(Be)?.models?.find(O=>O.id===w.modelID),e[25]=w.modelID,e[26]=w.providerID,e[27]=x,e[28]=E}else E=e[28];const M=E;let H;e[31]!==M?(H=M?.variants?Object.keys(M.variants):[],e[31]=M,e[32]=H):H=e[32];const R=H,_=R.length>0;let z,V;e[33]!==w.variant||e[34]!==_?(z=()=>{_||!w.variant||S(Qg)},V=[_,w.variant],e[33]=w.variant,e[34]=_,e[35]=z,e[36]=V):(z=e[35],V=e[36]),a.useEffect(z,V);let F;e[37]!==w.modelID||e[38]!==w.providerID?(F=w.providerID.trim().length>0&&w.modelID.trim().length>0,e[37]=w.modelID,e[38]=w.providerID,e[39]=F):F=e[39];const te=F;let Z;e[40]!==te||e[41]!==w||e[42]!==u||e[43]!==m?(Z=()=>{!te||m||u(w)},e[40]=te,e[41]=w,e[42]=u,e[43]=m,e[44]=Z):Z=e[44];const ne=Z;let U,ie;e[45]!==ne||e[46]!==r?(U=()=>{if(!r)return;const Be=se=>{(se.metaKey||se.ctrlKey)&&se.key==="Enter"&&(se.preventDefault(),ne())};return window.addEventListener("keydown",Be),()=>window.removeEventListener("keydown",Be)},ie=[r,ne],e[45]=ne,e[46]=r,e[47]=U,e[48]=ie):(U=e[47],ie=e[48]),a.useEffect(U,ie);let oe;e[49]!==n||e[50]!==i?(oe=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=oe):oe=e[51];const ge=oe;let je;e[52]!==o||e[53]!==m?(je=Be=>{m||o(Be)},e[52]=o,e[53]=m,e[54]=je):je=e[54];let Se;e[55]!==ge?(Se=s.jsx(Xs,{children:s.jsx(Ys,{children:ge})}),e[55]=ge,e[56]=Se):Se=e[56];let re;e[57]!==n?(re=n("chat.modelControls.model"),e[57]=n,e[58]=re):re=e[58];let L;e[59]!==re?(L=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:re}),e[59]=re,e[60]=L):L=e[60];let $;e[61]===Symbol.for("react.memo_cache_sentinel")?($=(Be,se)=>{S(O=>({...O,providerID:Be,modelID:se,variant:""}))},e[61]=$):$=e[61];let q;e[62]!==w.modelID||e[63]!==w.providerID?(q=s.jsx(Su,{providerId:w.providerID,modelId:w.modelID,className:"max-w-[320px] justify-between",dropdownPortalToBody:!0,onChange:$}),e[62]=w.modelID,e[63]=w.providerID,e[64]=q):q=e[64];let he;e[65]!==L||e[66]!==q?(he=s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[L,q]}),e[65]=L,e[66]=q,e[67]=he):he=e[67];let de;e[68]!==n?(de=n("sessions.scheduledTasks.editor.thinkingLevel.label"),e[68]=n,e[69]=de):de=e[69];let we;e[70]!==de?(we=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:de}),e[70]=de,e[71]=we):we=e[71];const be=!_;let De;e[72]===Symbol.for("react.memo_cache_sentinel")?(De=Be=>S(se=>({...se,variant:Be})),e[72]=De):De=e[72];let le;e[73]!==w.variant||e[74]!==be||e[75]!==R?(le=s.jsx(Nf,{value:w.variant,options:R,disabled:be,onChange:De}),e[73]=w.variant,e[74]=be,e[75]=R,e[76]=le):le=e[76];let ke;e[77]!==we||e[78]!==le?(ke=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[we,le]}),e[77]=we,e[78]=le,e[79]=ke):ke=e[79];let ue;e[80]!==n?(ue=n("sessions.scheduledTasks.editor.agent.label"),e[80]=n,e[81]=ue):ue=e[81];let ve;e[82]!==ue?(ve=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:ue}),e[82]=ue,e[83]=ve):ve=e[83];let G;e[84]===Symbol.for("react.memo_cache_sentinel")?(G=Be=>S(se=>({...se,agent:Be})),e[84]=G):G=e[84];let Ae;e[85]!==w.agent?(Ae=s.jsx(Nu,{agentName:w.agent,filter:P,dropdownPortalToBody:!0,onChange:G}),e[85]=w.agent,e[86]=Ae):Ae=e[86];let ce;e[87]!==ve||e[88]!==Ae?(ce=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ve,Ae]}),e[87]=ve,e[88]=Ae,e[89]=ce):ce=e[89];let fe;e[90]!==he||e[91]!==ke||e[92]!==ce?(fe=s.jsxs("div",{className:"flex flex-col gap-4",children:[he,ke,ce]}),e[90]=he,e[91]=ke,e[92]=ce,e[93]=fe):fe=e[93];let Ee;e[94]!==o?(Ee=()=>o(!1),e[94]=o,e[95]=Ee):Ee=e[95];let me;e[96]!==n?(me=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[96]=n,e[97]=me):me=e[97];let B;e[98]!==m||e[99]!==Ee||e[100]!==me?(B=s.jsx(ze,{variant:"ghost",size:"sm",onClick:Ee,disabled:m,children:me}),e[98]=m,e[99]=Ee,e[100]=me,e[101]=B):B=e[101];const ye=!te||m;let Oe;e[102]!==m||e[103]!==n?(Oe=n(m?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[102]=m,e[103]=n,e[104]=Oe):Oe=e[104];let Q;e[105]!==ne||e[106]!==ye||e[107]!==Oe?(Q=s.jsx(ze,{size:"sm",onClick:ne,disabled:ye,children:Oe}),e[105]=ne,e[106]=ye,e[107]=Oe,e[108]=Q):Q=e[108];let Me;e[109]!==B||e[110]!==Q?(Me=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[B,Q]}),e[109]=B,e[110]=Q,e[111]=Me):Me=e[111];let Re;e[112]!==Se||e[113]!==fe||e[114]!==Me?(Re=s.jsxs(Gs,{className:"max-w-md overflow-visible",children:[Se,fe,Me]}),e[112]=Se,e[113]=fe,e[114]=Me,e[115]=Re):Re=e[115];let Ne;return e[116]!==r||e[117]!==je||e[118]!==Re?(Ne=s.jsx(Ks,{open:r,onOpenChange:je,children:Re}),e[116]=r,e[117]=je,e[118]=Re,e[119]=Ne):Ne=e[119],Ne}function Qg(t){return{...t,variant:""}}function Xg(t){return ku(t.mode)}function Zg(t){return t.currentAgentName||""}function ex(t){return t.currentVariant||""}function tx(t){return t.currentModelId}function sx(t){return t.currentProviderId}function nx(t){return t.providers}function rx(t){return t.loadAgents}function ix(t){return t.loadAgents}function ox(t){return t.loadProviders}const vl=5,Zu=15,Bo=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},ax=(t,e)=>{const n=Bo(e);return Math.max(n*vl,Math.min(n*Zu,n*t))},lx=async(t,e)=>{const n=await If(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},cx=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Zc=t=>[...t.filter(e=>!e.completed),...t.filter(e=>e.completed)],ed=(t,e)=>{const n=t.findIndex(r=>r.completed);return n===-1?[...t,e]:[...t.slice(0,n),e,...t.slice(n)]},dx=t=>{const e=gt.c(20),{id:n,children:r}=t;let o;e[0]!==n?(o={id:n},e[0]=n,e[1]=o):o=e[1];const{attributes:i,listeners:c,setNodeRef:l,setActivatorNodeRef:u,transform:m,transition:d,isDragging:f}=Rl(o);let g;e[2]!==m?(g=Ml.Transform.toString(m),e[2]=m,e[3]=g):g=e[3];let x;e[4]!==g||e[5]!==d?(x={transform:g,transition:d},e[4]=g,e[5]=d,e[6]=x):x=e[6];const p=f&&"opacity-60";let y;e[7]!==p?(y=Te(p),e[7]=p,e[8]=y):y=e[8];let b;e[9]!==i||e[10]!==r||e[11]!==f||e[12]!==c||e[13]!==u?(b=r({attributes:i,listeners:c,setActivatorNodeRef:u,isDragging:f}),e[9]=i,e[10]=r,e[11]=f,e[12]=c,e[13]=u,e[14]=b):b=e[14];let h;return e[15]!==l||e[16]!==x||e[17]!==y||e[18]!==b?(h=s.jsx("li",{ref:l,style:x,className:y,children:b}),e[15]=l,e[16]=x,e[17]=y,e[18]=b,e[19]=h):h=e[19],h},ux=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:o})=>{const{t:i}=Tt(),[c,l]=a.useState(!1),[u,m]=a.useState(""),[d,f]=a.useState([]),[g,x]=a.useState(""),[p,y]=a.useState(null),[b,h]=a.useState(()=>new Set),[N,w]=a.useState([]),[S,v]=a.useState(null),[j,k]=a.useState(!1),[D,T]=a.useState(0),C=a.useRef(!1),P=a.useRef(""),E=Fe(O=>O.todoPanelHeight),M=Fe(O=>O.setTodoPanelHeight),H=Fe(O=>O.notesPanelHeight),R=Fe(O=>O.setNotesPanelHeight),[_,z]=a.useState(!1),V=a.useRef(0),F=a.useRef(E),te=vt(O=>O.currentSessionId),Z=vt(O=>O.createSession),ne=vt(O=>O.initializeNewOpenChamberSession),U=vt(O=>O.sendMessage),ie=vt(O=>O.setCurrentSession),oe=ei(O=>O.setPendingInputText),ge=sn(O=>O.currentDirectory),je=Fe(O=>O.openContextPanelTab),Se=Fe(O=>O.setActiveMainTab),re=Fe(O=>O.setSessionSwitcherOpen),L=Fe(O=>O.padding),$=a.useCallback(async(O,A)=>{if(!t)return!1;const K=await kf(t,{notes:O,todos:A});return K||ae.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),K},[t,i]);a.useEffect(()=>{if(!t){m(""),f([]),w([]),x(""),h(new Set);return}let O=!1;return l(!0),(async()=>{try{const A=await Cf(t),K=await Promise.all(A.plans.map(pe=>lx(pe,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(O)return;m(A.notes),f(Zc(A.todos)),w(K),P.current=A.notes,C.current=!0,x(""),h(new Set)}catch{O||(ae.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),m(""),f([]),w([]),P.current="",C.current=!0)}finally{O||l(!1)}})(),()=>{O=!0}},[D,t,i]),a.useEffect(()=>{if(!t)return;const O=A=>{const K=A.detail;K?.projectId&&K.projectId!==t.id||T(pe=>pe+1)};return window.addEventListener("openchamber:project-plan-saved",O),window.addEventListener("openchamber:project-notes-updated",O),()=>{window.removeEventListener("openchamber:project-plan-saved",O),window.removeEventListener("openchamber:project-notes-updated",O)}},[t]),a.useEffect(()=>{if(d.length<7)return;const O=ax(d.length,L),A=Bo(L)*vl;(E<A||E>O)&&M(O)},[d.length,L,E,M]),a.useEffect(()=>{if(!_)return;const O=K=>{const pe=K.clientY-V.current,_e=Math.min(Bo(L)*Zu,Math.max(Bo(L)*vl,F.current+pe));M(_e)},A=()=>{z(!1)};return window.addEventListener("pointermove",O),window.addEventListener("pointerup",A,{once:!0}),window.addEventListener("pointercancel",A,{once:!0}),()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",A),window.removeEventListener("pointercancel",A)}},[_,L,M]);const q=a.useCallback(O=>{z(!0),V.current=O.clientY,F.current=E,O.preventDefault()},[E]),he=a.useCallback(()=>{P.current=u,$(u,d)},[u,$,d]);a.useEffect(()=>{if(!t||!C.current||u===P.current)return;const O=window.setTimeout(()=>{P.current=u,$(u,d)},400);return()=>{window.clearTimeout(O)}},[u,$,t,d]);const de=a.useCallback(()=>{const O=g.trim();if(!O)return;const A=ed(d,{id:cx(),text:O.slice(0,No),completed:!1,createdAt:Date.now()});f(A),x(""),$(u,A)},[g,u,$,d]),we=a.useCallback(O=>{h(A=>{const K=new Set(A);return K.has(O)?K.delete(O):K.add(O),K})},[]),be=a.useCallback((O,A)=>{const K=d.find(Le=>Le.id===O);if(!K||K.completed===A)return;const pe=d.filter(Le=>Le.id!==O),_e={...K,completed:A},We=A?[...pe,_e]:ed(pe,_e);f(We),$(u,We)},[u,$,d]),De=a.useCallback(O=>{const A=d.filter(K=>K.id!==O);f(A),$(u,A)},[u,$,d]),le=a.useCallback(()=>{const O=d.filter(A=>!A.completed);O.length!==d.length&&(f(O),$(u,O))},[u,$,d]),ke=a.useCallback(O=>{const{active:A,over:K}=O;if(!K||A.id===K.id)return;const pe=d.findIndex(Le=>Le.id===A.id),_e=d.findIndex(Le=>Le.id===K.id);if(pe===-1||_e===-1)return;const We=Zc(fu(d,pe,_e));f(We),$(u,We)},[u,$,d]),ue=qo(ro(Yo,{activationConstraint:{distance:8}})),ve=g.slice(0,No),G=d.reduce((O,A)=>O+(A.completed?1:0),0),Ae=a.useCallback(()=>{Se("chat"),re(!1)},[Se,re]),ce=a.useCallback((O,A)=>{!t||p||v({kind:"session",todoId:O,todoText:A})},[t,p]),fe=a.useCallback(O=>{if(!te){ae.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Ae();const A=`\`\`\`md
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-hYm-4PtP.js","assets/vendor-.bun-TPgXvEwq.js","assets/vendor--V65Sl9C2.css","assets/index-D9t9eCUC.js","assets/index-BDH6F8f2.css","assets/TerminalView-CePdcScA.js","assets/NewWorktreeDialog-C6394QE9.js","assets/mobileLayoutPreference-Dio-WWkI.js","assets/SessionSwitcherDropdown-BMN9gaXo.js","assets/SettingsWindow-DXEjjH2f.js","assets/MultiRunWindow-DXXoYCBh.js","assets/OnboardingScreen-CLXmHHBW.js"])))=>i.map(i=>d[i]);
2
+ import{j as s,c as pt,R as a,b as Ni,I as hu,e as Rl,L as pu,H as et,N as gu,u as qo,g as no,k as Yo,D as Jo,m as Qo,S as il,v as ol,o as Ml,C as Fl,T as xu,X as qr,Y as Zm,F as ef,$ as tf,a0 as sf,a1 as nf,a2 as rf,a3 as of,a4 as af,a5 as al,a6 as lf,i as cf,s as df,_ as Ui,a7 as hc,a8 as pc,a9 as gc,G as uf}from"./vendor-.bun-TPgXvEwq.js";import{d as mf,b as Fs,e as ff,a as Xr,f as ll,h as hf,r as Ll,g as Li,s as bu,i as pf}from"./index-D9t9eCUC.js";import{u as Tt,z as tn,H as I,m as Pe,ai as Ot,aj as _t,ak as Bt,al as ua,am as or,an as uo,ao as xc,ap as zt,aq as gf,ar as Xo,o as ar,t as ae,as as sn,at as On,au as nn,av as rn,aw as yu,ax as bo,a as Gn,ay as Pr,T as Fe,az as wi,aA as bc,aB as xf,aC as mo,aD as wu,aE as vu,R as ls,y as jt,aF as bf,a6 as ju,x as Zr,w as Ol,D as Ms,U as vi,aG as _l,aH as Su,aI as Hi,aJ as yf,aK as yc,aL as wf,aM as vf,aN as jf,aO as Nu,aP as Sf,aQ as Nf,aR as ku,V as Bl,aS as hi,aT as kf,aU as Vl,aV as pi,aW as $l,aX as Lo,$ as on,aY as Cf,aZ as Cu,a_ as Af,a$ as Au,b0 as Du,b1 as Qs,b2 as Ys,B as ze,b3 as Gs,b4 as Ks,b5 as ti,b6 as Df,b7 as If,b8 as No,b9 as Tn,ba as Iu,bb as Pu,bc as zl,bd as Pf,be as Tf,bf as wc,bg as vc,bh as gi,I as kn,bi as ji,bj as Ef,bk as vs,bl as ma,bm as fa,bn as ha,bo as pa,bp as Yr,bq as ei,br as Rf,bs as Mf,bt as dn,bu as Ff,bv as Lf,bw as Of,bx as _f,by as Bf,k as Oi,bz as ga,bA as Vf,bB as $f,bC as zf,bD as Wf,bE as Uf,bF as Hf,bG as Gf,bH as _n,bI as zn,bJ as Wn,bK as En,bL as Un,bM as qs,bN as Dr,bO as Kf,v as fo,M as xa,S as ba,bP as qf,bQ as sr,bR as Yf,b as si,d as Wl,c as ya,bS as Jf,bT as Tu,bU as Qf,bV as Xf,e as Ul,bW as Zf,f as _s,bX as wa,bY as Ir,j as eh,bZ as th,b_ as Ta,b$ as Eu,c0 as Ru,c1 as Hl,c2 as va,c3 as Nn,F as xr,c4 as Gl,X as Hn,c5 as Si,c6 as cl,c7 as dl,l as _i,c8 as Mu,c9 as sh,p as Tr,q as jc,r as Sc,ca as nh,cb as Fu,cc as rh,n as Nc,J as ih,cd as Ea,ce as Kl,cf as Lu,cg as oh,ch as ah,ci as yo,cj as ql,ck as lh,cl as ja,cm as Yl,cn as Ou,co as ko,cp as ch,cq as xi,cr as dh,cs as _u,ct as uh,cu as mh,cv as kc,cw as Bu,cx as Vu,cy as $u,E as Jl,P as Sa,G as Na,N as ul,cz as Ql,cA as fh,cB as os,cC as ho,cD as Bi,cE as Pi,cF as Zo,cG as Cc,cH as Fn,K as hh,L as ph,cI as gh,cJ as ro,cK as xh,cL as zu,cM as bh,cN as yh,cO as ml,cP as wh,cQ as vh,cR as jh,cS as Ac,cT as Sh,cU as Nh,cV as kh,cW as Xl,cX as Wu,cY as Ch,cZ as Ah,c_ as Dh,c$ as Ih,d0 as Ph,d1 as Dc,d2 as Th,d3 as Eh,d4 as Rh,d5 as Mh,d6 as Fh,O as Lh,d7 as Oh,d8 as _h,Q as Bh,d9 as Vh,A as $h,C as zh,da as Wh,db as Uh,dc as Hh,dd as Gh,de as Kh,df as qh,dg as Yh,dh as Jh,di as Qh,dj as Xh,dk as Ic,dl as Zh,dm as ep,dn as tp,dp as wo,dq as sp,dr as Pc,ds as np,dt as Oo,du as _o,dv as rp,dw as ip,dx as op,dy as ap,dz as lp,dA as cp,dB as dp,dC as up,dD as mp,dE as fp,dF as Tc,dG as Ec,dH as Rc,dI as Mc,dJ as hp,dK as pp,W as Fc,Y as gp,dL as xp,Z as bp,_ as yp,dM as wp,dN as vp,a0 as Lc,a1 as Oc,a2 as _c,dO as jp,a3 as Uu,a4 as Hu,ab as Sp,ac as Np,ad as kp,ae as Cp,af as Ap,ag as Dp,ah as Ip,a7 as Pp,a8 as Tp,a9 as Ep,aa as Rp}from"./useAppFontEffects-hYm-4PtP.js";import{I as Bc,f as Mp,g as to,h as Vc,i as Fp,j as $c,n as Lp,k as zc,t as Wr,r as Op,l as Ra,m as po,o as ea,p as Jr,q as ta,s as Gu,v as Ku,U as sa,w as na,x as Vi,y as vo,z as $i,A as qu,B as rr,E as _p,Q as Bp,F as Vp,G as $p,H as zp,J as Yu,P as Zl,K as Wp,L as Up,C as Hp,a as Gp,M as Ju,O as Qu,R as fl,T as hl,V as pl,W as Kp,X as qp,Y as Ti,N as Yp,D as Jp,e as Qp,d as gl,Z as Xp,_ as Zp,$ as eg,u as tg,a0 as sg}from"./NewWorktreeDialog-C6394QE9.js";import{S as ng,C as rg,W as ig,u as Ma}from"./SessionSwitcherDropdown-BMN9gaXo.js";function Xu(t){const{drafts:e,editingDraftId:n,commentText:r,selection:o,isDragging:i,fileLabel:c,newWidgetId:l,mapDraftToRange:u,onSave:m,onCancel:d,onEdit:f,onDelete:g}=t,x=[];for(const p of e){const y=u(p);if(p.id===n){x.push({afterLine:y.end,id:`edit-${p.id}`,content:s.jsx(Bc,{initialText:r,fileLabel:c,lineRange:y,isEditing:!0,onSave:m,onCancel:d},`edit-${p.id}`)});continue}x.push({afterLine:y.end,id:`card-${p.id}`,content:s.jsx(Mp,{draft:p,onEdit:()=>f(p),onDelete:()=>g(p)},`card-${p.id}`)})}if(o&&!n&&!i){const p={...o,start:Math.min(o.start,o.end),end:Math.max(o.start,o.end)};x.push({afterLine:p.end,id:l,content:s.jsx(Bc,{initialText:r,fileLabel:c,lineRange:p,isEditing:!1,onSave:m,onCancel:d},l)})}return x}function Wc(t){const e=pt.c(14);let n,r,o,i;e[0]!==t?({size:o,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=i):(n=e[1],r=e[2],o=e[3],i=e[4]);const c=typeof o=="number"?`${o}px`:o,l=typeof o=="number"?`${o}px`:o;let u;e[5]!==i||e[6]!==c||e[7]!==l?(u={width:c,height:l,...i},e[5]=i,e[6]=c,e[7]=l,e[8]=u):u=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=m):m=e[9];let d;return e[10]!==n||e[11]!==r||e[12]!==u?(d=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:u,...r,children:m}),e[10]=n,e[11]=r,e[12]=u,e[13]=d):d=e[13],d}const og=(t,e)=>{if(!t)return e("mcpDropdown.status.unknown");switch(t.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:t.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:t.error||""});default:return t.status}},ag=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Zu=({active:t,className:e})=>{const{t:n}=Tt(),o=tn(h=>h.currentDirectory)??null,i=to(h=>h.getStatusForDirectory(o)),c=to(h=>h.refresh),l=to(h=>h.connect),u=to(h=>h.disconnect),m=Vc(h=>h.mcpServers),d=Vc(h=>h.loadMcpConfigs),[f,g]=a.useState(!1),[x,p]=a.useState(null);a.useEffect(()=>{c({directory:o,silent:!0})},[c,o]),a.useEffect(()=>{d({force:!0})},[d]),a.useEffect(()=>{t&&Promise.all([c({directory:o,silent:!0}),d({force:!0})])},[t,c,o,d]);const y=a.useMemo(()=>{const h=new Set(Object.keys(i));for(const N of m)N?.name&&h.add(N.name);return Array.from(h).sort((N,w)=>N.localeCompare(w))},[m,i]),b=a.useCallback(h=>{if(h?.preventDefault(),f)return;g(!0);const N=new Promise(w=>setTimeout(w,500));Promise.all([c({directory:o}),N]).finally(()=>{g(!1)})},[f,c,o]);return s.jsxs("div",{className:Pe("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),o&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:o.split("/").pop()||o})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:f,onClick:b,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:Pe("h-4 w-4",f&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[y.map(h=>{const N=i[h],w=ag(N),S=N?.status==="connected",v=x===h,j=og(N,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:Pe("h-2 w-2 rounded-full flex-shrink-0",w==="success"&&"bg-status-success",w==="error"&&"bg-status-error",w==="warning"&&"bg-status-warning",w==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Bt,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:h})]})}),s.jsx(Fp,{checked:S,disabled:v,className:"data-[checked]:bg-status-info",onCheckedChange:async k=>{p(h);try{k?await l(h,o):await u(h,o)}finally{p(null)}}})]},h)}),y.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},Qr=[{id:"finder",label:"Finder",appName:"Finder"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm"},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"xcode",label:"Xcode",appName:"Xcode"},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"zed",label:"Zed",appName:"Zed"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"kiro",label:"Kiro",appName:"Kiro"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],xl="finder",bl=new Set(["finder","terminal"]),ec=t=>typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32"&&t.id==="finder"?{...t,label:"Explorer",appName:"File Explorer"}:t,yl=t=>{if(!t)return null;const e=Qr.find(n=>n.id===t)??null;return e?ec(e):null},Fa=()=>Qr.filter(t=>bl.has(t.id)).map(t=>({...ec(t)})),lg=()=>{if(typeof window>"u")return xl;const t=window.localStorage.getItem("openInAppId");return t&&yl(t)?t:xl};let La=!1,ki=!1,Ur=!1,Hr=0,io=null;const Uc=()=>{io&&(clearTimeout(io),io=null)},pr=Ni()((t,e)=>({selectedAppId:lg(),availableApps:Fa(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(La||typeof window>"u")return;La=!0;const n=(u,m=!0)=>{if(!Array.isArray(u)||u.length===0){t({availableApps:Fa(),hasLoadedApps:m});return}const d=new Set(u.map(p=>p.name)),f=new Map(u.map(p=>[p.name,p.iconDataUrl??void 0])),x=Qr.filter(p=>d.has(p.appName)||bl.has(p.id)).map(p=>({...ec(p),iconDataUrl:f.get(p.appName)}));t({availableApps:x,hasLoadedApps:!0})},r=async u=>{if(!or()||!uo()||ki||e().hasLoadedApps&&!u)return;const d=Qr.map(f=>f.appName);Uc(),ki=!0,Ur=!1,t({isScanning:!0});try{const{apps:f,success:g,hasCache:x,isCacheStale:p}=await xc(d,u),y=g&&!x&&f.length===0&&Hr<3;if(t({isCacheStale:x?p:!1}),n(f,g?!y:!1),g){if(y){const h=[800,1600,3200][Hr]??3200;Hr+=1,Ur=!0,io=setTimeout(()=>{r()},h);return}Hr=0,Ur=!1;return}if(Hr<3){const h=[1e3,3e3,7e3][Hr]??7e3;Hr+=1,Ur=!0,io=setTimeout(()=>{r()},h)}}finally{ki=!1,Ur||t({isScanning:!1})}};r();const o=u=>{const m=u.detail,d=m&&typeof m.openInAppId=="string"&&m.openInAppId.length>0&&yl(m.openInAppId)?m.openInAppId:null;d&&(window.localStorage.setItem("openInAppId",d),t({selectedAppId:d}))},i=()=>{r()},c=u=>{const m=u.detail;Array.isArray(m)&&(Hr=3,Ur=!1,t({isScanning:!1,isCacheStale:!1}),n(m))};window.addEventListener("openchamber:settings-synced",o),window.addEventListener("openchamber:app-ready",i),window.addEventListener("openchamber:installed-apps-updated",c),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(La||e().initialize(),!or()||!uo()||ki||e().hasLoadedApps&&!n)return;const o=Qr.map(i=>i.appName);Uc(),n&&t({hasLoadedApps:!1}),ki=!0,Ur=!1,t({isScanning:!0});try{const{apps:i,hasCache:c,isCacheStale:l}=await xc(o,n),u=new Set(i.map(g=>g.name)),m=new Map(i.map(g=>[g.name,g.iconDataUrl??void 0])),f=Qr.filter(g=>u.has(g.appName)||bl.has(g.id)).map(g=>({...g,iconDataUrl:m.get(g.appName)}));t({availableApps:f.length>0?f:Fa(),hasLoadedApps:f.length>0,isCacheStale:c?l:!1})}finally{ki=!1,Ur||t({isScanning:!1})}},selectApp:async n=>{yl(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ua({openInAppId:n}))}})),cg="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",dg="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",Oa=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__!=="win32"?cg:t.id==="terminal"?dg:void 0}),Hc=t=>{const e=pt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[i,c]=a.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const u=l,m=r||o;if(m&&!i){let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=()=>c(!0),e[2]=g):g=e[2];let x;return e[3]!==m?(x=s.jsx("img",{src:m,alt:"",className:"h-4 w-4 rounded-sm",onError:g}),e[3]=m,e[4]=x):x=e[4],x}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=Pe("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let f;return e[6]!==u?(f=s.jsx("span",{className:d,children:u}),e[6]=u,e[7]=f):f=e[7],f},ug=t=>{const e=pt.c(75),{directory:n,className:r}=t,{t:o}=Tt(),i=pr(mg),c=pr(fg),l=pr(hg),u=pr(pg),m=pr(gg),d=pr(xg),f=pr(bg);let g,x;e[0]!==m?(g=()=>{m()},x=[m],e[0]=m,e[1]=g,e[2]=x):(g=e[1],x=e[2]),a.useEffect(g,x);const p=or()&&uo();let y;e:{let re;e[3]!==c||e[4]!==i?(re=c.find(K=>K.id===i)??c.find(yg)??c[0]??Qr[0],e[3]=c,e[4]=i,e[5]=re):re=e[5];const L=re;if(L){let K;e[6]!==L?(K=Oa(L),e[6]=L,e[7]=K):K=e[7],y=K;break e}let $;e[8]===Symbol.for("react.memo_cache_sentinel")?($=Oa(Qr[0]),e[8]=$):$=e[8],y=$}const b=y;if(!p||!n||c.length===0)return null;let h;e[9]!==n?(h=async re=>{await gf(n,re.id,re.appName)||await Xo(n,re.appName)},e[9]=n,e[10]=h):h=e[10];const N=h;let w;e[11]!==N||e[12]!==f?(w=async re=>{await f(re.id),await N(re)},e[11]=N,e[12]=f,e[13]=w):w=e[13];const S=w;let v;e[14]!==n||e[15]!==o?(v=async()=>{(await ar(n)).ok&&ae.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=v):v=e[16];const j=v;let k;e[17]!==r?(k=Pe("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=k):k=e[18];let A;e[19]!==N||e[20]!==b?(A=()=>{N(b)},e[19]=N,e[20]=b,e[21]=A):A=e[21];const T=u&&"animate-pulse";let C;e[22]!==T?(C=Pe("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",T),e[22]=T,e[23]=C):C=e[23];let P;e[24]!==b.label||e[25]!==o?(P=o("openInApp.actions.openInAria",{app:b.label}),e[24]=b.label,e[25]=o,e[26]=P):P=e[26];let E;e[27]!==b.fallbackIconDataUrl||e[28]!==b.iconDataUrl||e[29]!==b.label?(E=s.jsx(Hc,{label:b.label,iconDataUrl:b.iconDataUrl,fallbackIconDataUrl:b.fallbackIconDataUrl}),e[27]=b.fallbackIconDataUrl,e[28]=b.iconDataUrl,e[29]=b.label,e[30]=E):E=e[30];let M;e[31]!==C||e[32]!==P||e[33]!==E||e[34]!==A?(M=s.jsx("button",{type:"button",onClick:A,className:C,"aria-label":P,children:E}),e[31]=C,e[32]=P,e[33]=E,e[34]=A,e[35]=M):M=e[35];let H;e[36]===Symbol.for("react.memo_cache_sentinel")?(H=Pe("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=H):H=e[36];let R;e[37]!==o?(R=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=R):R=e[38];let _;e[39]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=_):_=e[39];let z;e[40]!==R?(z=s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",className:H,"aria-label":R,children:_})}),e[40]=R,e[41]=z):z=e[41];let V;e[42]!==j?(V=()=>{j()},e[42]=j,e[43]=V):V=e[43];let F;e[44]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(I,{name:"file-copy",className:"h-4 w-4"}),e[44]=F):F=e[44];let te;e[45]!==o?(te=o("openInApp.actions.copyPath"),e[45]=o,e[46]=te):te=e[46];let Z;e[47]!==te?(Z=s.jsx("span",{className:"typography-ui-label text-foreground",children:te}),e[47]=te,e[48]=Z):Z=e[48];let ne;e[49]!==V||e[50]!==Z?(ne=s.jsxs(zt,{className:"flex items-center gap-2",onClick:V,children:[F,Z]}),e[49]=V,e[50]=Z,e[51]=ne):ne=e[51];let U;e[52]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(On,{}),e[52]=U):U=e[52];let ie;if(e[53]!==c||e[54]!==S||e[55]!==b.id){let re;e[57]!==S||e[58]!==b.id?(re=L=>{const $=Oa(L);return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{S(L)},children:[s.jsx(Hc,{label:L.label,iconDataUrl:L.iconDataUrl,fallbackIconDataUrl:$.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:L.label}),b.id===L.id?s.jsx(I,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},L.id)},e[57]=S,e[58]=b.id,e[59]=re):re=e[59],ie=c.map(re),e[53]=c,e[54]=S,e[55]=b.id,e[56]=ie}else ie=e[56];let oe;e[60]!==l||e[61]!==d||e[62]!==o?(oe=l?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{d(!0)},children:[s.jsx(I,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("openInApp.actions.refreshApps")})]}):null,e[60]=l,e[61]=d,e[62]=o,e[63]=oe):oe=e[63];let pe;e[64]!==ne||e[65]!==ie||e[66]!==oe?(pe=s.jsxs(nn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[ne,U,ie,oe]}),e[64]=ne,e[65]=ie,e[66]=oe,e[67]=pe):pe=e[67];let je;e[68]!==z||e[69]!==pe?(je=s.jsxs(rn,{children:[z,pe]}),e[68]=z,e[69]=pe,e[70]=je):je=e[70];let Se;return e[71]!==M||e[72]!==je||e[73]!==k?(Se=s.jsxs("div",{className:k,children:[M,je]}),e[71]=M,e[72]=je,e[73]=k,e[74]=Se):Se=e[74],Se};function mg(t){return t.selectedAppId}function fg(t){return t.availableApps}function hg(t){return t.isCacheStale}function pg(t){return t.isScanning}function gg(t){return t.initialize}function xg(t){return t.loadInstalledApps}function bg(t){return t.selectApp}function yg(t){return t.id===xl}const wg=1e6,vg="terminal-store";let Gc=!1;const _a=t=>typeof t=="object"&&t!==null,jg=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function In(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const Ba=(t,e)=>({id:t,terminalSessionId:null,lifecycle:"idle",label:e,iconKey:null,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Va=t=>({tabs:[t],activeTabId:t.id}),fr=(t,e)=>t.tabs.findIndex(n=>n.id===e),Hs=Ni()(hu(Rl((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=In(n);r&&t(o=>{if(o.sessions.has(r))return o;const i=new Map(o.sessions),c=`tab-${o.nextTabId}`,l=Ba(c,"Terminal");return i.set(r,Va(l)),{sessions:i,nextTabId:o.nextTabId+1}})},getDirectoryState:n=>{const r=In(n);return e().sessions.get(r)},getActiveTab:n=>{const r=In(n),o=e().sessions.get(r);if(!o)return;const i=o.activeTabId;return i?o.tabs.find(c=>c.id===i)??o.tabs[0]:o.tabs[0]},createTab:n=>{const r=In(n);if(!r)return"tab-invalid";const o=`tab-${e().nextTabId}`;return t(i=>{const c=new Map(i.sessions),l=c.get(r),u=i.nextTabId+1,d=`Terminal ${(l?.tabs.length??0)+1}`,f=Ba(o,d);return l?c.set(r,{...l,tabs:[...l.tabs,f]}):c.set(r,Va(f)),{sessions:c,nextTabId:u}}),o},setActiveTab:(n,r)=>{const o=In(n);t(i=>{const c=new Map(i.sessions),l=c.get(o);return!l||l.activeTabId===r||fr(l,r)<0?i:(c.set(o,{...l,activeTabId:r}),{sessions:c})})},setTabLabel:(n,r,o)=>{const i=In(n),c=o.trim();c&&t(l=>{const u=new Map(l.sessions),m=u.get(i);if(!m)return l;const d=fr(m,r);if(d<0||m.tabs[d]?.label===c)return l;const f=[...m.tabs];return f[d]={...f[d],label:c},u.set(i,{...m,tabs:f}),{sessions:u}})},setTabIconKey:(n,r,o)=>{const i=In(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=fr(u,r);if(m<0)return c;const d=o?.trim()||null;if(u.tabs[m]?.iconKey===d)return c;const f=[...u.tabs];return f[m]={...f[m],iconKey:d},l.set(i,{...u,tabs:f}),{sessions:l}})},closeTab:async(n,r)=>{const o=In(n),l=e().sessions.get(o)?.tabs.find(u=>u.id===r)?.terminalSessionId??null;if(l)try{await mf(l)}catch{}t(u=>{const m=new Map(u.sessions),d=m.get(o);if(!d)return u;const f=fr(d,r);if(f<0)return u;const g=d.tabs.filter(b=>b.id!==r),x=Object.fromEntries(Object.entries(u.projectActionRuns).filter(([,b])=>!(b.directory===o&&b.tabId===r))),p=Object.keys(x).length!==Object.keys(u.projectActionRuns).length;if(g.length===0){const b=`tab-${u.nextTabId}`,h=Ba(b,"Terminal");return m.set(o,Va(h)),{sessions:m,nextTabId:u.nextTabId+1,...p?{projectActionRuns:x}:{}}}let y=d.activeTabId;return d.activeTabId===r&&(y=g[Math.min(f,g.length-1)]?.id??g[0]?.id??null),m.set(o,{...d,tabs:g,activeTabId:y}),{sessions:m,...p?{projectActionRuns:x}:{}}})},setTabSessionId:(n,r,o)=>{const i=In(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=fr(u,r);if(m<0)return c;const d=u.tabs[m],f=o!==null&&d.terminalSessionId!==o,g=o?"running":d.terminalSessionId?"exited":d.lifecycle,x={...d,terminalSessionId:o,lifecycle:g,isConnecting:!1,...f?{bufferChunks:[],bufferLength:0}:{}},p=[...u.tabs];return p[m]=x,l.set(i,{...u,tabs:p}),{sessions:l}})},setTabLifecycle:(n,r,o)=>{const i=In(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=fr(u,r);if(m<0)return c;const d=[...u.tabs];return d[m]={...d[m],lifecycle:o,isConnecting:!1},l.set(i,{...u,tabs:d}),{sessions:l}})},setConnecting:(n,r,o)=>{const i=In(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=fr(u,r);if(m<0)return c;const d=[...u.tabs];return d[m]={...d[m],isConnecting:o},l.set(i,{...u,tabs:d}),{sessions:l}})},appendToBuffer:(n,r,o)=>{if(!o)return;const i=In(n);t(c=>{const l=new Map(c.sessions),u=l.get(i);if(!u)return c;const m=fr(u,r);if(m<0)return c;const d=u.tabs[m],f=c.nextChunkId,g={id:f,data:o},x=[...d.bufferChunks,g];let p=d.bufferLength+o.length;for(;p>wg&&x.length>1;){const b=x.shift();if(!b)break;p-=b.data.length}const y=[...u.tabs];return y[m]={...d,bufferChunks:x,bufferLength:p},l.set(i,{...u,tabs:y}),{sessions:l,nextChunkId:f+1}})},setTabPreviewUrl:(n,r,o,i={})=>{const c=In(n);t(l=>{const u=new Map(l.sessions),m=u.get(c);if(!m)return l;const d=fr(m,r);if(d<0)return l;const f=m.tabs[d],g=i.autoOpened??f.previewAutoOpened,x=i.locked??f.previewUrlLocked;if(f.previewUrl===o&&f.previewAutoOpened===g&&f.previewUrlLocked===x)return l;const p=[...m.tabs];return p[d]={...f,previewUrl:o,previewAutoOpened:g,previewUrlLocked:x},u.set(c,{...m,tabs:p}),{sessions:u}})},markPreviewAutoOpened:(n,r)=>{const o=In(n);t(i=>{const c=new Map(i.sessions),l=c.get(o);if(!l)return i;const u=fr(l,r);if(u<0)return i;const m=l.tabs[u];if(!m.previewUrl||m.previewAutoOpened)return i;const d=[...l.tabs];return d[u]={...m,previewAutoOpened:!0},c.set(o,{...l,tabs:d}),{sessions:c}})},setProjectActionRun:n=>{t(r=>{const o=r.projectActionRuns[n.key];return o&&o.directory===n.directory&&o.actionId===n.actionId&&o.tabId===n.tabId&&o.sessionId===n.sessionId&&o.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(o=>{const i=o.projectActionRuns[n];return!i||i.status===r?o:{projectActionRuns:{...o.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const o={...r.projectActionRuns};return delete o[n],{projectActionRuns:o}})},clearBuffer:(n,r)=>{const o=In(n);t(i=>{const c=new Map(i.sessions),l=c.get(o);if(!l)return i;const u=fr(l,r);if(u<0)return i;const m=[...l.tabs];return m[u]={...m[u],bufferChunks:[],bufferLength:0},c.set(o,{...l,tabs:m}),{sessions:c}})},removeDirectory:n=>{const r=In(n);t(o=>{const i=new Map(o.sessions);i.delete(r);const c=Object.fromEntries(Object.entries(o.projectActionRuns).filter(([,l])=>l.directory!==r));return{sessions:i,projectActionRuns:c}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:vg,storage:pu(()=>yu()),partialize:t=>({sessions:Array.from(t.sessions.entries()).map(([e,n])=>[e,{activeTabId:n.activeTabId,tabs:n.tabs.map(r=>({id:r.id,label:r.label,iconKey:r.iconKey,terminalSessionId:r.terminalSessionId,lifecycle:r.lifecycle,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!_a(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let o=0;for(const l of n){if(!Array.isArray(l)||l.length!==2)continue;const[u,m]=l;if(typeof u!="string"||!_a(m))continue;const d=Array.isArray(m.tabs)?m.tabs:[],f=[];for(const p of d){if(!_a(p))continue;const y=typeof p.id=="string"?p.id:null;if(!y)continue;const b=jg(y);b!==null&&(o=Math.max(o,b));const h=typeof p.terminalSessionId=="string"||p.terminalSessionId===null?p.terminalSessionId:null,N=p.lifecycle,w=N==="idle"||N==="running"||N==="exited"?N:h?"running":"idle";f.push({id:y,label:typeof p.label=="string"?p.label:"Terminal",iconKey:typeof p.iconKey=="string"?p.iconKey:null,terminalSessionId:h,lifecycle:w,createdAt:typeof p.createdAt=="number"?p.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(f.length===0)continue;const g=typeof m.activeTabId=="string"?m.activeTabId:null,x=g?f.some(p=>p.id===g):!1;r.set(u,{tabs:f,activeTabId:x?g:f[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,c=Math.max(e.nextTabId,i,o+1);return{...e,sessions:r,nextChunkId:1,nextTabId:c,hasHydrated:!0}}})));if(typeof window<"u"&&!Gc){Gc=!0;const t=Hs.persist,e=()=>{Hs.getState().hasHydrated||Hs.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const Sg=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Ng=["dev","start","preview","serve"];async function kg(t,e,n){if(!t)return null;const r=Dg(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const o=Ig(n);if(o){const i=await Pg(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await Cg(t)){const o=await Ag(),i=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function Cg(t){const e=`${t}/index.html`,n=await ra(e,t);return typeof n=="string"&&n.trim().length>0}async function Ag(){try{const t=await Fs("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Dg(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Ng.some(o=>n.includes(o)))return e}return null}function Ig(t){for(const{pattern:e}of Sg)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Pg(t){const e=await ra(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),o=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(o.startsWith("bun@"))return"bun";if(o.startsWith("pnpm@"))return"pnpm";if(o.startsWith("yarn@"))return"yarn";if(o.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,o]of n){const i=await ra(`${t}/${r}`,t);if(typeof i=="string"&&i.trim().length>0)return o}return"npm"}async function ra(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await Fs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=bo()?.files;if(n?.readFile)try{const r=await n.readFile(t,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await Fs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Tg(t){try{const e=await ra(`${t}/package.json`,t);if(e==null)return null;const r=JSON.parse(e).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const Eg=t=>new Promise(e=>{window.setTimeout(e,t)}),Rg="\x1B",Mg=new RegExp(`${Rg}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Fg=/https?:\/\/[^\s<>'"`]+/gi,Qn="__openchamber_auto_discover_preview__",Lg=15e3,Og=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},_g=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},Bg=t=>{const n=t.replace(Mg,"").match(Fg);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const i of r)try{const c=new URL(i);c.port&&c.port.length>0&&o.push({raw:i,parsed:c})}catch{}if(o.length>0){const i=c=>{const{parsed:l}=c,u=l.hostname.toLowerCase(),m=u==="localhost"||u==="127.0.0.1"||u==="0.0.0.0"||u==="::1",d=l.pathname||"/",f=d.split("/").filter(Boolean).length,g=d==="/"||d==="",x=!!(l.search||l.hash);let p=0;return m&&(p+=50),g&&(p+=30),p-=Math.min(f*5,20),x&&(p-=10),p};return o.sort((c,l)=>i(l)-i(c)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Kc=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:i}=Tt(),{terminal:c,runtime:l}=Gn(),{isMobile:u}=Pr(),m=a.useMemo(()=>or(),[]),d=$c(J=>J.instances),f=$c(J=>J.load),g=Fe(J=>J.setBottomTerminalOpen),x=Fe(J=>J.setActiveMainTab),p=Fe(J=>J.setSettingsPage),y=Fe(J=>J.setSettingsDialogOpen),b=Fe(J=>J.setSettingsProjectsSelectedId),h=Fe(J=>J.openContextPreview),N=Hs(J=>J.sessions),w=Hs(J=>J.ensureDirectory),S=Hs(J=>J.setTabLabel),v=Hs(J=>J.setTabIconKey),j=Hs(J=>J.setActiveTab),k=Hs(J=>J.setConnecting),A=Hs(J=>J.setTabSessionId),T=Hs(J=>J.setTabPreviewUrl),C=Hs(J=>J.projectActionRuns),P=Hs(J=>J.setProjectActionRun),E=Hs(J=>J.updateProjectActionRunStatus),M=Hs(J=>J.removeProjectActionRun),[H,R]=a.useState([]),[_,z]=a.useState(null),[V,F]=a.useState(!1),te=a.useRef({}),Z=a.useRef({}),ne=a.useRef({}),U=a.useRef({}),ie=a.useRef(0),oe=t?.id??null,pe=t?.path??"",je=a.useMemo(()=>oe?{id:oe,path:pe}:null,[oe,pe]);a.useEffect(()=>{m&&f().catch(()=>{})},[m,f]);const Se=a.useCallback(async J=>{await wi(J)},[]),re=a.useCallback(async()=>{if(!je)return;const J=ie.current+1;ie.current=J,F(!0);try{const Me=await bc(je);if(ie.current!==J)return;const Ee=Me.actions;R(Ee),z(Ne=>Ne===Qn||Ne&&Ee.some(Be=>Be.id===Ne)?Ne:null)}catch{if(ie.current!==J)return}finally{ie.current===J&&F(!1)}},[je]),L=a.useMemo(()=>Lp(e||je?.path||""),[e,je?.path]),$=a.useMemo(()=>_?H.find(J=>J.id===_)??null:null,[H,_]),K=a.useMemo(()=>({id:Qn,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),he=!u,de=a.useMemo(()=>he?[K,...H]:H,[H,K,he]);a.useEffect(()=>{re()},[re]),a.useEffect(()=>{if(typeof window>"u")return;const J=Me=>{const Ee=Me.detail;oe&&(Ee?.projectId&&Ee.projectId!==oe||re())};return window.addEventListener(zc,J),()=>{window.removeEventListener(zc,J)}},[re,oe]),a.useEffect(()=>{_&&(_===Qn&&he||H.some(J=>J.id===_)||z(null))},[H,he,_]),a.useEffect(()=>{for(const[J,Me]of Object.entries(C)){const Ne=N.get(Me.directory)?.tabs.find(Be=>Be.id===Me.tabId);(!Ne||Ne.terminalSessionId!==Me.sessionId)&&M(J)}},[C,M,N]),a.useEffect(()=>{for(const[J,Me]of Object.entries(C)){const Ee=Z.current[J]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};Z.current[J]=Ee;const Ne=de.find($e=>$e.id===Me.actionId);if(!Ne)continue;const se=N.get(Me.directory)?.tabs.find($e=>$e.id===Me.tabId);if(!se||!Array.isArray(se.bufferChunks)||se.bufferChunks.length===0)continue;const O=se.bufferChunks.filter($e=>Ee.lastSeenChunkId===null?!0:$e.id>Ee.lastSeenChunkId);if(O.length===0)continue;const D=O.map($e=>$e.data).join(""),Y=`${Ee.tail}${D}`,be=!Ee.openedUrl&&Ne.autoOpenUrl===!0?Bg(Y):null,Oe=O[O.length-1]?.id??Ee.lastSeenChunkId;if(Ee.lastSeenChunkId=Oe,Ee.tail=Y.slice(-512),be)if(Ee.openedUrl=!0,Ee.openInPreview){const $e=C[J];$e&&(T($e.directory,$e.tabId,be,{locked:!1,autoOpened:!1}),$e.status==="waiting-for-preview"&&E(J,"running"),window.clearTimeout(U.current[J]),delete U.current[J],h($e.directory,be))}else Se(be),ae.success(i("projectActions.toast.openedUrlFromOutput"));Z.current[J]=Ee}for(const J of Object.keys(Z.current))C[J]||(delete Z.current[J],window.clearTimeout(U.current[J]),delete U.current[J])},[de,h,Se,C,T,i,N,E]);const we=a.useCallback(async(J,Me={})=>{if(!L)throw new Error(i("projectActions.error.noActiveDirectory"));const Ee=Wr(L,J.id);w(L);const Ne=Hs.getState(),Be=Ne.getDirectoryState(L);let se=te.current[Ee]||null;const O=se?!!Be?.tabs.some(be=>be.id===se):!1;(!se||!O)&&(se=Ne.createTab(L),te.current[Ee]=se),S(L,se,`Action: ${J.name}`),v(L,se,J.icon||"play"),Me.revealTerminal!==!1&&(j(L,se),g(!0),x("terminal"));const Y=Hs.getState().getDirectoryState(L)?.tabs.find(be=>be.id===se);return{key:Ee,tabId:se,sessionId:Y?.terminalSessionId??null}},[w,L,x,j,g,v,S,i]),xe=a.useCallback(async J=>{if(l.isVSCode||!o&&u)return;if(!L){ae.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Me=Wr(L,J.id),Ee=C[Me];if(!(Ee&&Ee.status==="running"))try{const Ne=J.id===Qn?await(async()=>{const[yt,At]=await Promise.all([bc({id:je?.id??"",path:L}),Tg(L)]),mt=await kg(L,yt.actions,At);if(!mt)throw new Error(i("contextPanel.preview.noDevServer"));return{id:Qn,name:i("projectActions.actions.autoDiscover"),command:mt.command,icon:"search",autoOpenUrl:!0,openUrl:mt.previewUrlHint||""}})():J,Be=Ne.autoOpenUrl===!0&&(Ne.openUrl||"").trim().length>0,{key:se,tabId:O,sessionId:D}=await we(Ne,{revealTerminal:!Be&&J.id!==Qn});let Y=D,be=!1;if(!Y){k(L,O,!0);try{Y=(await c.createSession({cwd:L})).sessionId,be=!0,A(L,O,Y)}finally{k(L,O,!1)}}if(!Y)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));be&&await Eg(350),Ne.id===Qn&&(ne.current[se]?.(),k(L,O,!0),ne.current[se]=ff(Y,yt=>{yt.type==="data"&&typeof yt.data=="string"&&yt.data.length>0&&Hs.getState().appendToBuffer(L,O,yt.data),yt.type==="exit"&&(Hs.getState().setTabLifecycle(L,O,"exited"),Hs.getState().setConnecting(L,O,!1),Hs.getState().removeProjectActionRun(se),delete Z.current[se],ne.current[se]?.(),delete ne.current[se],window.clearTimeout(U.current[se]),delete U.current[se])},()=>{Hs.getState().setConnecting(L,O,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Oe=Ne.autoOpenUrl===!0&&m&&(Ne.desktopOpenSshForward||"").trim().length>0,$e=Ne.autoOpenUrl?_g(Ne.openUrl):null,Re=Ne.autoOpenUrl&&m?Op(Ne.desktopOpenSshForward,d):null;P({key:se,directory:L,actionId:Ne.id,tabId:O,sessionId:Y,status:Ne.id===Qn&&!$e?"waiting-for-preview":"running"}),window.clearTimeout(U.current[se]),delete U.current[se],Ne.id===Qn&&!$e&&(U.current[se]=window.setTimeout(()=>{Hs.getState().updateProjectActionRunStatus(se,"running"),delete U.current[se]},Lg)),Re?(T(L,O,null,{locked:!0}),Se(Re),ae.success(i("projectActions.toast.openedForwardedUrl"))):$e?(T(L,O,$e,{locked:!0,autoOpened:!0}),h(L,$e),ae.success(i("projectActions.toast.openedActionUrl"))):Be?(T(L,O,null,{locked:!0}),ae.error(i("projectActions.error.invalidCustomUrlFormat"))):Oe?(T(L,O,null,{locked:!0}),ae.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):T(L,O,null,{locked:!1,autoOpened:!1}),Z.current[se]={lastSeenChunkId:null,openedUrl:!!Re||!!$e||Be,tail:"",openInPreview:Ne.id===Qn};const ot=Og(Ne.command.trim().replace(/\r\n|\r/g,`
3
+ `));await c.sendInput(Y,`${ot}\r`)}catch(Ne){M(Me),delete Z.current[Me],ne.current[Me]?.(),delete ne.current[Me],window.clearTimeout(U.current[Me]),delete U.current[Me],ae.error(Ne instanceof Error?Ne.message:i("projectActions.error.failedToRunAction"))}},[d,we,o,u,m,L,Se,h,C,l.isVSCode,M,k,P,T,A,je?.id,i,c]),De=a.useCallback(async J=>{const Me=Wr(L,J.id),Ee=C[Me];if(!Ee)return;E(Me,"stopping");try{await c.sendInput(Ee.sessionId,"")}catch{}if(await new Promise(se=>{window.setTimeout(se,1e3)}),Hs.getState().getDirectoryState(Ee.directory)?.tabs.find(se=>se.id===Ee.tabId)?.terminalSessionId===Ee.sessionId){if(typeof c.forceKill=="function")try{await c.forceKill({sessionId:Ee.sessionId})}catch{}else try{await c.close(Ee.sessionId)}catch{}A(Ee.directory,Ee.tabId,null)}M(Me),delete Z.current[Me],ne.current[Me]?.(),delete ne.current[Me],window.clearTimeout(U.current[Me]),delete U.current[Me]},[L,C,M,A,c,E]),le=a.useCallback(()=>{const J=$??de[0];if(!J)return;const Me=Wr(L,J.id),Ee=C[Me];if(Ee?.status!=="stopping"){if(Ee){De(J);return}xe(J)}},[de,L,xe,C,$,De]),Ce=a.useCallback((J,Me=!1)=>{if(z(J.id),!Me){xe(J);return}const Ee=Wr(L,J.id),Ne=C[Ee];if(Ne?.status!=="stopping"){if(Ne){De(J);return}xe(J)}},[L,xe,C,De]),ue=a.useCallback(()=>{je?.id&&(b(je.id),p("projects"),y(!0))},[y,p,b,je?.id]);if(l.isVSCode||!o&&u||!je||!L)return null;const ve=$??de[0]??null;if(!ve)return null;const G=ve.icon||"play",Ae=ve.id===Qn?"search":Ra[G]||"play",ce=Wr(L,ve.id),fe=C[ce],Te=fe?.status==="stopping",me=fe?.status==="waiting-for-preview",B=fe?N.get(fe.directory)?.tabs.find(J=>J.id===fe.tabId)?.previewUrl??null:null,ye=!!(fe&&B),_e=()=>{!fe||!B||h(fe.directory,B)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:V||Te,className:Pe("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:le,"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:ve.name}):i("projectActions.actions.runNamedAria",{name:ve.name}),children:Te||me?s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(I,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(I,{name:Ae,className:"h-5 w-5"})}),ye?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.openPreview"),onClick:_e,children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(Bt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(rn,{children:[s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(nn,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:ue,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(On,{}),de.map(J=>{const Me=J.icon||"play",Ee=J.id===Qn?"search":Ra[Me]||"play",Ne=Wr(L,J.id),Be=C[Ne],se=!!Be,O=Be?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{Ce(J,!0)},children:[s.jsx(I,{name:Ee,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:J.name}),O||Be?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):se?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},J.id)})]})]})]}):s.jsxs("div",{className:Pe("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsx("button",{type:"button",onClick:le,disabled:V||Te,className:Pe("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:ve.name}):i("projectActions.actions.runNamedAria",{name:ve.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Te||me?s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(I,{name:Ae,className:"h-4 w-4"})})}),ye?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:_e,className:Pe(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(Bt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(rn,{children:[s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(nn,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:ue,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(On,{}),de.map(J=>{const Me=J.icon||"play",Ee=J.id===Qn?"search":Ra[Me]||"play",Ne=Wr(L,J.id),Be=C[Ne],se=!!Be,O=Be?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{Ce(J,!0)},children:[s.jsx(I,{name:Ee,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:J.name}),O||Be?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):se?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},J.id)})]})]})]})},ka="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:bg-interactive-hover transition-colors",Vg="app-region-no-drag inline-flex h-9 w-9 items-center justify-center gap-2 p-2 rounded-md typography-ui-label font-medium text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:text-foreground hover:bg-interactive-hover transition-colors",Ci=a.memo(function(e){const n=pt.c(17),{visible:r,title:o,ariaLabel:i,onClick:c,className:l,Icon:u,iconClassName:m,pressed:d}=e,f=r===void 0?!0:r,g=d===void 0?!1:d;if(!f)return null;const x=l??ka,p=g&&"bg-interactive-selection text-interactive-selection-foreground";let y;n[0]!==x||n[1]!==p?(y=Pe(x,p),n[0]=x,n[1]=p,n[2]=y):y=n[2];const b=m??"h-[18px] w-[18px]";let h;n[3]!==u||n[4]!==b?(h=s.jsx(I,{name:u,className:b}),n[3]=u,n[4]=b,n[5]=h):h=n[5];let N;n[6]!==i||n[7]!==c||n[8]!==g||n[9]!==y||n[10]!==h?(N=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":i,"aria-pressed":g,className:y,children:h})}),n[6]=i,n[7]=c,n[8]=g,n[9]=y,n[10]=h,n[11]=N):N=n[11];let w;n[12]!==o?(w=s.jsx(Bt,{children:s.jsx("p",{children:o})}),n[12]=o,n[13]=w):w=n[13];let S;return n[14]!==N||n[15]!==w?(S=s.jsxs(Ot,{children:[N,w]}),n[14]=N,n[15]=w,n[16]=S):S=n[16],S}),$g=a.memo(function(e){const n=pt.c(42),{isMobile:r,githubAuthStatus:o,githubAccounts:i,githubAvatarUrl:c,githubLogin:l,isSwitchingGitHubAccount:u,handleGitHubAccountSwitch:m}=e,{t:d}=Tt();if(!o?.connected||r)return null;if(i.length>1){let p;n[0]===Symbol.for("react.memo_cache_sentinel")?(p=Pe(ka,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=p):p=n[0];let y;n[1]!==l||n[2]!==d?(y=l?d("header.github.connectedWithLogin",{login:l}):d("header.github.connected"),n[1]=l,n[2]=d,n[3]=y):y=n[3];let b;n[4]!==c||n[5]!==l||n[6]!==d?(b=c?s.jsx("img",{src:c,alt:l?d("header.github.avatarWithLogin",{login:l}):d("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=c,n[5]=l,n[6]=d,n[7]=b):b=n[7];let h;n[8]!==u||n[9]!==y||n[10]!==b?(h=s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",className:p,title:y,disabled:u,children:b})}),n[8]=u,n[9]=y,n[10]=b,n[11]=h):h=n[11];let N;n[12]!==d?(N=d("header.github.accountsTitle"),n[12]=d,n[13]=N):N=n[13];let w;n[14]!==N?(w=s.jsx(vu,{className:"typography-ui-header font-semibold text-foreground",children:N}),n[14]=N,n[15]=w):w=n[15];let S;n[16]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(On,{}),n[16]=S):S=n[16];let v;if(n[17]!==i||n[18]!==m||n[19]!==u||n[20]!==d){let A;n[22]!==m||n[23]!==u||n[24]!==d?(A=T=>{const C=T.user,P=!!T.current;return s.jsxs(zt,{className:"gap-2",disabled:P||u,onSelect:()=>{P||m(T.id)},children:[C?.avatarUrl?s.jsx("img",{src:C.avatarUrl,alt:C.login?d("header.github.avatarWithLogin",{login:C.login}):d("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(I,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:C?.name?.trim()||C?.login||"GitHub"}),C?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:C.login}):null]}),P?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},T.id)},n[22]=m,n[23]=u,n[24]=d,n[25]=A):A=n[25],v=i.map(A),n[17]=i,n[18]=m,n[19]=u,n[20]=d,n[21]=v}else v=n[21];let j;n[26]!==w||n[27]!==v?(j=s.jsxs(nn,{align:"end",className:"w-64",children:[w,S,v]}),n[26]=w,n[27]=v,n[28]=j):j=n[28];let k;return n[29]!==h||n[30]!==j?(k=s.jsxs(rn,{children:[h,j]}),n[29]=h,n[30]=j,n[31]=k):k=n[31],k}let f;n[32]!==l||n[33]!==d?(f=l?d("header.github.connectedWithLogin",{login:l}):d("header.github.connected"),n[32]=l,n[33]=d,n[34]=f):f=n[34];let g;n[35]!==c||n[36]!==l||n[37]!==d?(g=c?s.jsx("img",{src:c,alt:l?d("header.github.avatarWithLogin",{login:l}):d("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=c,n[36]=l,n[37]=d,n[38]=g):g=n[38];let x;return n[39]!==f||n[40]!==g?(x=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:f,children:g}),n[39]=f,n[40]=g,n[41]=x):x=n[41],x}),zg=a.memo(function(e){const n=pt.c(84),{isDesktopApp:r,currentInstanceLabel:o,compactCurrentInstanceLabel:i,currentInstanceIsLocal:c,isDesktopServicesOpen:l,setIsDesktopServicesOpen:u,refreshCurrentInstanceLabel:m,desktopServicesTab:d,setDesktopServicesTab:f,quotaResultsLength:g,fetchAllQuotas:x,servicesTabItems:p,quotaLastUpdated:y,quotaDisplayMode:b,quotaDisplayTabItems:h,handleDisplayModeChange:N,handleUsageRefresh:w,isQuotaLoading:S,isUsageRefreshSpinning:v,hasRateLimits:j,rateLimitGroups:k,expandedFamilies:A,toggleFamilyExpanded:T,shortcutLabel:C,showDevShutdown:P,isDevShutdownInFlight:E,onDevShutdown:M,remoteUpdateInfo:H,remoteUpdateChecking:R,remoteUpdateError:_,onOpenRemoteUpdate:z,showPredValues:V,timeFormatPreference:F}=e,{t:te}=Tt();let Z;n[0]!==d||n[1]!==x||n[2]!==g||n[3]!==m||n[4]!==u?(Z=Ce=>{u(Ce),Ce&&(m(),d==="usage"&&g===0&&x())},n[0]=d,n[1]=x,n[2]=g,n[3]=m,n[4]=u,n[5]=Z):Z=n[5];let ne;n[6]!==o||n[7]!==r||n[8]!==te?(ne=r?te("header.services.openWithCurrent",{current:o}):te("header.services.open"),n[6]=o,n[7]=r,n[8]=te,n[9]=ne):ne=n[9];const U=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let ie;n[10]!==U?(ie=Pe(ka,U),n[10]=U,n[11]=ie):ie=n[11];let oe;n[12]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(I,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=oe):oe=n[12];let pe;n[13]!==i||n[14]!==r?(pe=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=pe):pe=n[15];let je;n[16]!==ne||n[17]!==ie||n[18]!==pe?(je=s.jsx(_t,{asChild:!0,children:s.jsx(sn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":ne,className:ie,children:[oe,pe]})})}),n[16]=ne,n[17]=ie,n[18]=pe,n[19]=je):je=n[19];let Se;n[20]!==o||n[21]!==r||n[22]!==C||n[23]!==te?(Se=r?te("header.services.tooltip.currentInstanceWithShortcuts",{current:o,toggle:C("toggle_services_menu"),nextTab:C("cycle_services_tab")}):te("header.services.tooltip.servicesWithShortcuts",{toggle:C("toggle_services_menu"),nextTab:C("cycle_services_tab")}),n[20]=o,n[21]=r,n[22]=C,n[23]=te,n[24]=Se):Se=n[24];let re;n[25]!==Se?(re=s.jsx(Bt,{children:s.jsx("p",{children:Se})}),n[25]=Se,n[26]=re):re=n[26];let L;n[27]!==je||n[28]!==re?(L=s.jsxs(Ot,{children:[je,re]}),n[27]=je,n[28]=re,n[29]=L):L=n[29];let $;n[30]!==x||n[31]!==g||n[32]!==f?($=Ce=>{const ue=Ce;f(ue),ue==="usage"&&g===0&&x()},n[30]=x,n[31]=g,n[32]=f,n[33]=$):$=n[33];let K;n[34]!==d||n[35]!==p||n[36]!==$?(K=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(po,{items:p,activeId:d,onSelect:$,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=d,n[35]=p,n[36]=$,n[37]=K):K=n[37];let he;n[38]!==c||n[39]!==d||n[40]!==r||n[41]!==l||n[42]!==z||n[43]!==R||n[44]!==_||n[45]!==H||n[46]!==u||n[47]!==te?(he=r&&d==="instance"?s.jsxs("div",{children:[c?null:s.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:te("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:H?.available?te("header.services.remoteUpdate.available",{version:H.version||""}):R?te("header.services.remoteUpdate.checking"):_||te("header.services.remoteUpdate.upToDate")})]}),H?.available?s.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:z,children:te("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(xf,{embedded:!0,open:l&&d==="instance",onOpenChange:Hg,onHostSwitched:()=>u(!1)})]}):null,n[38]=c,n[39]=d,n[40]=r,n[41]=l,n[42]=z,n[43]=R,n[44]=_,n[45]=H,n[46]=u,n[47]=te,n[48]=he):he=n[48];let de;n[49]!==d||n[50]!==l?(de=d==="mcp"?s.jsx(Zu,{active:l&&d==="mcp"}):null,n[49]=d,n[50]=l,n[51]=de):de=n[51];let we;n[52]!==d||n[53]!==A||n[54]!==N||n[55]!==w||n[56]!==j||n[57]!==S||n[58]!==v||n[59]!==b||n[60]!==h||n[61]!==y||n[62]!==k||n[63]!==V||n[64]!==te||n[65]!==F||n[66]!==T?(we=d==="usage"?s.jsxs("div",{className:"overflow-x-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:te("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:em(y,F)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(po,{items:h,activeId:b,onSelect:Ce=>{N(Ce)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:Pe("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:S||v,"aria-label":te("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:Pe("h-4 w-4",v&&"animate-spin")})})]})]}),j?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:te("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:k.map((Ce,ue)=>{const ve=A[Ce.providerId]??[];return s.jsxs(a.Fragment,{children:[ue>0?s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(mo,{providerId:Ce.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Ce.providerName})]}),Ce.entries.length===0&&(!Ce.modelFamilies||Ce.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Ce.error??te("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Ce.entries.map(G=>{const[Ae,ce]=G,fe=b==="remaining"?ce.remainingPercent:ce.usedPercent,Te=ea(ce.usedPercent,ce.resetAt,ce.windowSeconds,Ae),me=Te?.dailyAllocationPercent!=null?b==="remaining"?100-Jr(Te.elapsedRatio):Jr(Te.elapsedRatio):null,B=ta(ce.valueLabel,fe),ye=Gu(ce.resetAt,ce.resetAfterFormatted??ce.resetAtFormatted,F);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Ku(Ae)}),ye?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:ye}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:B==="-"?"":B})]}),s.jsx(sa,{percent:fe,tonePercent:ce.usedPercent,className:"h-1.5",expectedMarkerPercent:me}),Te&&V?s.jsx(na,{paceInfo:Te,compact:!0}):null]},`${Ce.providerId}-${Ae}`)}),Ce.modelFamilies&&Ce.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:Ce.modelFamilies.map(G=>{const Ae=G.familyId??"other",ce=ve.includes(Ae);return s.jsxs(Vi,{open:ce,onOpenChange:()=>T(Ce.providerId,Ae),children:[s.jsxs(vo,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:G.familyLabel}),ce?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx($i,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:G.models.map(fe=>{const[Te,me]=fe,B=b==="remaining"?me.remainingPercent:me.usedPercent,ye=ea(me.usedPercent,me.resetAt,me.windowSeconds),_e=ye?.dailyAllocationPercent!=null?b==="remaining"?100-Jr(ye.elapsedRatio):Jr(ye.elapsedRatio):null,J=ta(me.valueLabel,B);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:qu(Te)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:J==="-"?"":J})]}),s.jsx(sa,{percent:B,tonePercent:me.usedPercent,className:"h-1.5",expectedMarkerPercent:_e}),ye&&V?s.jsx(na,{paceInfo:ye,compact:!0}):null]},`${Ce.providerId}-${Te}`)})})})]},Ae)})}):null]})]},Ce.providerId)})})]}):null,n[52]=d,n[53]=A,n[54]=N,n[55]=w,n[56]=j,n[57]=S,n[58]=v,n[59]=b,n[60]=h,n[61]=y,n[62]=k,n[63]=V,n[64]=te,n[65]=F,n[66]=T,n[67]=we):we=n[67];let xe;n[68]!==E||n[69]!==M||n[70]!==P||n[71]!==te?(xe=P?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx(zt,{disabled:E,onSelect:()=>{M()},children:te("header.services.shutdownDev")})})]}):null,n[68]=E,n[69]=M,n[70]=P,n[71]=te,n[72]=xe):xe=n[72];let De;n[73]!==K||n[74]!==he||n[75]!==de||n[76]!==we||n[77]!==xe?(De=s.jsxs(nn,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[K,he,de,we,xe]}),n[73]=K,n[74]=he,n[75]=de,n[76]=we,n[77]=xe,n[78]=De):De=n[78];let le;return n[79]!==l||n[80]!==Z||n[81]!==L||n[82]!==De?(le=s.jsxs(rn,{open:l,onOpenChange:Z,children:[L,De]}),n[79]=l,n[80]=Z,n[81]=L,n[82]=De,n[83]=le):le=n[83],le}),Wg=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),Ug=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),i=`${r} ${o}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},em=(t,e)=>{if(!t)return"-";try{return wu(t,e,{fallback:"-"})}catch{return"-"}},Vn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Ai=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,qc=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{const{t:o}=Tt(),i=Fe(ee=>ee.setSessionSwitcherOpen),c=Fe(ee=>ee.toggleSidebar),l=Fe(ee=>ee.toggleBottomTerminal),u=Fe(ee=>ee.toggleRightSidebar),m=Fe(ee=>ee.openContextOverview),d=Fe(ee=>ee.openContextPlan),f=Fe(ee=>ee.openContextBrowser),g=Fe(ee=>ee.closeContextPanel),x=Fe(ee=>ee.contextPanelByDirectory),p=Fe(ee=>ee.activeMainTab),y=Fe(ee=>ee.setActiveMainTab),b=Fe(ee=>ee.shortcutOverrides),h=Fe(ee=>ee.timeFormatPreference),N=ls(ee=>ee.getCurrentModel),w=Gn(),[S,v]=a.useState(!1),j=jt(ee=>ee.getContextUsage),k=jt(ee=>!!ee.newSessionDraft?.open),A=jt(ee=>ee.currentSessionId),T=bf(A??""),C=ju(A??null),P=Zr(ee=>ee.activeSessions),E=Ol(),M=Ms(ee=>ee.activeProjectId?ee.projects.find(it=>it.id===ee.activeProjectId)??null:null),H=a.useMemo(()=>{if(!M)return null;const ee=M.label?.trim();if(ee)return ee;const it=M.path.split(/[\\/]/).filter(Boolean);return it[it.length-1]??null},[M]),R=rr(ee=>ee.results),_=rr(ee=>ee.fetchAllQuotas),z=rr(ee=>ee.isLoading),V=rr(ee=>ee.lastUpdated),F=rr(ee=>ee.displayMode),te=rr(ee=>ee.showPredValues),Z=rr(ee=>ee.dropdownProviderIds),ne=rr(ee=>ee.loadSettings),U=rr(ee=>ee.setDisplayMode),{isMobile:ie}=Pr(),oe=vi(ee=>ee.status),pe=vi(ee=>ee.setStatus),je=a.useRef(null),[Se,re]=a.useState(()=>typeof window>"u"?!1:or()),L=a.useMemo(()=>_l(),[]),$=Su(),[K,he]=a.useState(!1),de=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),we=a.useMemo(()=>typeof window>"u"?!1:!!window.__OPENCHAMBER_ELECTRON__&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),xe=a.useMemo(()=>{if(typeof window>"u")return null;const ee=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof ee=="number"&&Number.isFinite(ee)&&ee>0)return ee;if(typeof navigator>"u")return null;const it=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!it)return null;const wt=Number.parseInt(it[1],10),Vt=Number.parseInt(it[2],10);return Number.isNaN(wt)?null:wt===10?Vt:wt},[]);et.useEffect(()=>{typeof window>"u"||re(or())},[]);const De=N(),le=De&&typeof De.limit=="object"&&De.limit!==null?De.limit:null,Ce=le&&typeof le.context=="number"?le.context:0,ue=le&&typeof le.output=="number"?le.output:0,ve=j(Ce,ue),[G,Ae]=a.useState(null),ce=!A||T;et.useEffect(()=>{if(!A){Ae(ee=>ee===null?ee:null);return}if(ve&&ve.totalTokens>0){Ae(ee=>Wg(ee,ve)?ee:ve);return}ce&&Ae(ee=>ee===null?ee:null)},[ve,A,ce]);const fe=Fe(ee=>ee.isSessionSwitcherOpen),Te=oe?.connected?oe.user?.avatarUrl??null:null,me=oe?.connected?oe.user?.login??null:null,B=oe?.accounts??[],[ye,_e]=a.useState(!1),[J,Me]=a.useState(!1),[Ee,Ne]=a.useState(!1),[Be,se]=a.useState(!1),[O,D]=a.useState("Local"),[Y,be]=a.useState(!0),[Oe,$e]=a.useState(!1),[Re,ot]=a.useState(null),[yt,At]=a.useState(!1),[mt,Le]=a.useState(null),Qe=a.useMemo(()=>Ug(O),[O]),[Ye,rt]=a.useState(Se?"instance":"usage"),[bt,ct]=a.useState("usage");et.useEffect(()=>{!Se&&Ye==="instance"&&rt("usage")},[Ye,Se]);const nt=a.useMemo(()=>Hi(),[]),It=!nt&&p==="chat"&&!!G&&G.totalTokens>0,lt=G&&G.contextLimit>0?Math.min(999,G.totalTokens/G.contextLimit*100):0,kt=a.useCallback(async()=>{if(!(typeof window>"u"||!Se))try{if(uo()){D("Local"),be(!0);return}be(!1);const ee=await yf(),it=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,wt=Xr();if(wt&&yc(wt,it)){D("Local"),be(!0);return}const Vt=ee.hosts.find(ps=>wt?yc(wt,wf(ps)):!1);if(Vt?.label?.trim()){D(vf(Vt.label.trim()));return}D("Instance")}catch{D("Local"),be(!0)}},[Se]);et.useEffect(()=>{kt()},[kt]);const Ke=a.useCallback(async()=>{if(Y){ot(null),Le(null);return}At(!0),Le(null);try{const ee=new URLSearchParams({appType:"web",instanceMode:"remote"}),it=await Fs(`/api/openchamber/update-check?${ee.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!it.ok)throw new Error(`Server responded with ${it.status}`);const wt=await it.json();ot({available:wt.available??!1,version:wt.version,currentVersion:wt.currentVersion??"unknown",body:wt.body,nextSuggestedCheckInSec:typeof wt.nextSuggestedCheckInSec=="number"?wt.nextSuggestedCheckInSec:void 0,packageManager:wt.packageManager,updateCommand:wt.updateCommand})}catch(ee){ot(null),Le(ee instanceof Error?ee.message:o("header.services.remoteUpdate.error"))}finally{At(!1)}},[Y,o]);a.useEffect(()=>{ot(null),Le(null),$e(!1)},[Y,O]),a.useEffect(()=>{if(!Se||Y)return;const ee=3e3,it=3600*1e3;let wt=!1,Vt=null;const ps=us=>{Vt=window.setTimeout(()=>{if(wt||typeof document<"u"&&document.visibilityState!=="visible"){ps(it);return}Ke().finally(()=>{wt||ps(it)})},us)};return ps(ee),()=>{wt=!0,Vt!==null&&window.clearTimeout(Vt)}},[Ke,Y,O,Se]);const tt=a.useCallback(()=>{if(Re?.available){$e(!0);return}Ke()},[Ke,Re?.available]);_p();const We=rr(ee=>ee.selectedModels),gt=rr(ee=>ee.expandedFamilies),He=rr(ee=>ee.toggleFamilyExpanded),st=a.useMemo(()=>{const ee=[];for(const it of Bp){if(!Z.includes(it.id))continue;const wt=R.find(Us=>Us.providerId===it.id),Vt=wt?.usage?.windows??{},ps=wt?.usage?.models,us=Object.entries(Vt),cs={providerId:it.id,providerName:it.name,entries:us,error:wt&&!wt.ok&&wt.configured?wt.error:void 0};if(ps&&Object.keys(ps).length>0){const Us=We[it.id]??[],js=Us.length>0,Mn=Vp(ps,it.id),mn=$p(it.id),Rr=zp(mn);cs.modelFamilies=[];for(const xn of Rr){const Vs=Mn.get(xn.id)??[];if(Vs.length===0)continue;const bn=js?Vs.filter(Zs=>Us.includes(Zs)):Vs;if(bn.length===0)continue;const Ds=[];for(const Zs of bn){const vr=ps[Zs];if(vr?.windows){const jr=Object.entries(vr.windows);jr.length>0&&Ds.push([Zs,jr[0][1]])}}Ds.length>0&&cs.modelFamilies.push({familyId:xn.id,familyLabel:xn.label,models:Ds})}const gn=Mn.get(null)??[],Mr=js?gn.filter(xn=>Us.includes(xn)):gn;if(Mr.length>0){const xn=[];for(const Vs of Mr){const bn=ps[Vs];if(bn?.windows){const Ds=Object.entries(bn.windows);Ds.length>0&&xn.push([Vs,Ds[0][1]])}}xn.length>0&&cs.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:xn})}}(us.length>0||cs.modelFamilies&&cs.modelFamilies.length>0||cs.error)&&ee.push(cs)}return ee},[Z,R,We,o]),Et=st.length>0;a.useEffect(()=>{ne()},[ne]);const at=a.useCallback(async ee=>{U(ee);try{await ua({usageDisplayMode:ee})}catch(it){console.warn("Failed to update usage display mode:",it)}},[U]),dt=a.useCallback(()=>{if(Be)return;se(!0);const ee=new Promise(it=>setTimeout(it,500));Promise.all([_(),ee]).finally(()=>{se(!1)})},[_,Be]),Ht=a.useMemo(()=>A?E.find(ee=>ee.id===A)??P.find(ee=>ee.id===A)??C??jf().find(ee=>ee.id===A)??null:null,[A,C,P,E]),Rt=a.useRef(null),[Wt,qt]=a.useState(0);a.useEffect(()=>{if(!A){Rt.current&&(Rt.current=null,qt(Vt=>Vt+1));return}if(Ht){Rt.current={sessionId:A,session:Ht,expiresAt:Date.now()+2e3};return}const ee=Rt.current;if(!ee||ee.sessionId!==A)return;const it=ee.expiresAt-Date.now();if(it<=0){Rt.current=null,qt(Vt=>Vt+1);return}const wt=window.setTimeout(()=>{Rt.current?.sessionId===A&&(Rt.current=null),qt(Vt=>Vt+1)},it);return()=>{window.clearTimeout(wt)}},[A,Ht]);const Lt=(()=>{if(Ht)return Ht;if(!A)return null;const ee=Rt.current;return ee&&ee.sessionId===A&&ee.expiresAt>Date.now()?ee.session:null})(),Gt=jt(ee=>A?ee.worktreeMetadata.get(A)?.path??"":""),Qt=jt(ee=>A?ee.worktreeMetadata.get(A)?.branch?.trim()??null:null),rs=Nu(ee=>A?ee.getAttachment(A):void 0),Yt=a.useMemo(()=>rs?Sf(rs):null,[rs]),ft=a.useMemo(()=>rs?rs.legacy?"legacy":rs.degraded?"degraded":rs.worktreeStatus==="missing"?"missing":rs.worktreeStatus==="invalid"?"invalid":rs.attentionReason?"attention":null:null,[rs]),Jt=a.useMemo(()=>Vn(Gt||""),[Gt]),ms=a.useMemo(()=>{const ee=typeof Lt?.directory=="string"?Lt.directory:"";return Vn(ee||"")},[Lt?.directory]),Xt=jt(ee=>ee.newSessionDraft?.open?Vn(ee.newSessionDraft.bootstrapPendingDirectory??ee.newSessionDraft.directoryOverride??""):""),ts=a.useMemo(()=>Jt||ms||Xt,[Xt,ms,Jt]),ks=jt(ee=>{const it=Vn(Jt||ms||"");if(!it)return null;for(const wt of ee.availableWorktreesByProject.values()){const ps=wt.find(us=>Vn(us.path)===it)?.branch?.trim();if(ps)return ps}return null}),as=Nf(ts||null)||Qt||ks,$s=a.useMemo(()=>{if(!A)return H??"OpenChamber";const ee=Lt?.title?.trim();return ee&&ee.length>0?ee:"Untitled Session"},[H,Lt?.title,A]),Ut=a.useMemo(()=>ku(Lt?.summary),[Lt?.summary]),Es=a.useMemo(()=>Ut||{additions:0,deletions:0},[Ut]),Ls=Es.additions>0||Es.deletions>0,gs=a.useMemo(()=>Vn(ts||M?.path||""),[M?.path,ts]),Cs=a.useMemo(()=>M?{id:M.id,path:M.path}:null,[M]),Mt=a.useRef(null);a.useEffect(()=>{!Cs||!gs||(Mt.current={projectRef:Cs,directory:gs})},[gs,Cs]);const xt=a.useMemo(()=>Cs&&gs?{projectRef:Cs,directory:gs}:Mt.current,[gs,Cs]),Zt=Bl(ee=>ee.planModeEnabled),Ft=jt(ee=>ee.isSessionPlanAvailable),is=Zt&&A?Ft(A):!1,es=is,fs=a.useRef("");a.useEffect(()=>{if(!Zt){Fe.getState().activeMainTab==="plan"&&Fe.getState().setActiveMainTab("chat");return}if(!A)return;const ee=`${A||"none"}:${ms||"none"}:${Lt?.time?.created||0}:${Lt?.slug||"none"}`;fs.current!==ee&&(fs.current=ee),!is&&Fe.getState().activeMainTab==="plan"&&Fe.getState().setActiveMainTab("chat")},[Zt,is,Lt?.slug,Lt?.time?.created,A,ms]);const W=a.useCallback(async ee=>{if(!(!ee||ye)){_e(!0);try{const it=w.github?await w.github.authActivate(ee):await(async()=>{const wt=await Fs("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:ee})}),Vt=await wt.json().catch(()=>null);if(!wt.ok||!Vt)throw new Error(Vt?.error||wt.statusText);return Vt})();pe(it)}catch(it){console.error("Failed to switch GitHub account:",it)}finally{_e(!1)}}},[ye,w.github,pe]),Ge=a.useCallback(()=>{if(typeof document>"u")return;const ee=document.activeElement;if(!ee)return;const it=ee.tagName;(it==="INPUT"||it==="TEXTAREA"||it==="SELECT"||ee.isContentEditable)&&ee.blur()},[]),Xe=a.useCallback(()=>{if(ie){Ge(),i(!fe);return}c()},[Ge,ie,fe,i,c]),ht=a.useCallback(ee=>{const it=ee.currentTarget.getBoundingClientRect();hi("desktop_show_app_menu",{x:it.left,y:it.bottom}).catch(wt=>{console.warn("[header] failed to open app menu",wt)})},[]),Nt=a.useCallback(()=>{hi("desktop_open_draft_mini_chat_window",{directory:Vn(ts||M?.path||""),projectId:M?.id??null,apiBaseUrl:Xr(),clientToken:ll()}).catch(ee=>{console.warn("[header] failed to open draft mini chat window",ee)})},[M?.id,M?.path,ts]),ut=a.useCallback(()=>{if(k){Nt();return}A&&hi("desktop_open_session_mini_chat_window",{sessionId:A,directory:Vn(ts||M?.path||""),apiBaseUrl:Xr(),clientToken:ll()}).catch(ee=>{console.warn("[header] failed to open session mini chat window",ee)})},[M?.path,A,Nt,k,ts]),ss=a.useCallback(()=>{const ee=Vn(ts||"");if(!ee)return;const it=x[ee];if(Ai(it)==="context"){g(ee);return}m(ee)},[g,x,m,ts]),bs=a.useMemo(()=>{const ee=Vn(ts||"");if(!ee)return!1;const it=x[ee];return Ai(it)==="context"},[x,ts]),ys=a.useCallback(()=>{const ee=Vn(ts||"");if(!ee)return;const it=x[ee];if(Ai(it)==="plan"){g(ee);return}d(ee)},[g,x,d,ts]),Bs=a.useCallback(()=>{const ee=Vn(ts||"");if(!ee)return;const it=x[ee];if(Ai(it)==="browser"){g(ee);return}f(ee)},[g,x,f,ts]),Rs=a.useMemo(()=>{const ee=Vn(ts||"");if(!ee)return!1;const it=x[ee];return Ai(it)==="plan"},[x,ts]),an=a.useMemo(()=>{const ee=Vn(ts||"");if(!ee)return!1;const it=x[ee];return Ai(it)==="browser"},[x,ts]),Ss=ka,zs=Vg,Ws=a.useMemo(()=>J?"services":n?"sessions":r?"git":p,[p,J,n,r]),hs=a.useCallback(()=>{Me(!1),n&&t&&t(),r&&e&&e(),!t&&fe&&i(!1)},[fe,n,t,e,r,i]),br=a.useCallback(()=>{n||Me(!1),t?.()},[n,t]),Rn=a.useCallback(()=>{r||Me(!1),e?.()},[e,r]),nr=a.useMemo(()=>Se&&de&&!K||$?"pl-[5.5rem]":"pl-3",[Se,K,de,$]);et.useEffect(()=>{if(!Se||!de){he(!1);return}let ee=!1;const it=async()=>{try{const Vt=await hi("desktop_is_window_fullscreen");ee||he(Vt===!0)}catch{ee||he(!1)}},wt=()=>{it()};return it(),window.addEventListener("openchamber:window-resized",wt),()=>{ee=!0,window.removeEventListener("openchamber:window-resized",wt)}},[Se,de]);const Kn=a.useMemo(()=>!Se||!de||xe===null?"":xe>=26?"h-12":xe<=15?"h-14":"",[Se,de,xe]),As=a.useMemo(()=>{if(!(Se&&!we||nt))return{paddingLeft:$?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[Se,$,nt,we]),Xs=a.useCallback(()=>{if(typeof document>"u")return;const ee=je.current?.getBoundingClientRect().height;ee&&document.documentElement.style.setProperty("--oc-header-height",`${ee}px`)},[]);et.useEffect(()=>{if(typeof window>"u")return;Xs();const ee=je.current;if(!ee||typeof ResizeObserver>"u")return()=>{};let it=0;const wt=()=>{it||(it=requestAnimationFrame(()=>{it=0,Xs()}))},Vt=new ResizeObserver(wt);return Vt.observe(ee),window.addEventListener("resize",wt),window.addEventListener("orientationchange",wt),()=>{it&&cancelAnimationFrame(it),Vt.disconnect(),window.removeEventListener("resize",wt),window.removeEventListener("orientationchange",wt)}},[Xs]),et.useEffect(()=>{Xs()},[Xs,ie,Kn]);const Cn=a.useCallback(async ee=>{const it=ee.target;it.closest(".app-region-no-drag")||it.closest("button, a, input, select, textarea")||ee.button===0&&Se&&await kf()},[Se]),un=a.useMemo(()=>{if(ie){const ee=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return es&&ee.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),ee.push({id:"diff",label:o("layout.mainTab.diff"),icon:"diff"},{id:"files",label:o("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:o("layout.mainTab.terminal"),icon:"terminal-box"},{id:"context",label:o("layout.mainTab.context"),icon:"file-list-2"}),ee}return[]},[ie,es,o]),hn=a.useCallback(ee=>Vl(pi(ee,b)),[b]);et.useEffect(()=>{!ie&&(p==="git"||p==="terminal"||p==="diff"||p==="files"||p==="context")&&y("chat")},[p,ie,y]);const ds=a.useMemo(()=>{const ee=[];return Se&&ee.push({value:"instance",label:o("layout.services.instance"),icon:"server"}),ee.push({value:"usage",label:o("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:"plug-2"}),ee},[Se,o]),ws=a.useMemo(()=>ds.map(ee=>({id:ee.value,label:ee.label,icon:s.jsx(I,{name:ee.icon,className:"h-3.5 w-3.5"})})),[ds]),pn=a.useMemo(()=>{if(typeof window>"u"||Se||nt)return!1;const ee=window.location.hostname;return ee==="localhost"||ee==="127.0.0.1"||ee==="::1"},[Se,nt]),Sn=a.useCallback(async()=>{if(S)return;v(!0),Ne(!1);const ee=[];let it=!1;try{try{for(const[,wt]of Hs.getState().sessions.entries())for(const Vt of wt.tabs)Vt.previewUrl&&ee.push(Vt.previewUrl)}catch{}try{await hf({})}catch{}try{(await Fs("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:ee})})).ok?it=!0:it=(await Fs("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{it||v(!1)}},[S,Ne]),Os=a.useMemo(()=>[{value:"usage",label:o("header.services.used")},{value:"remaining",label:o("header.services.remaining")}],[o]),lr=a.useMemo(()=>Os.map(ee=>({id:ee.value,label:ee.label})),[Os]),cr=a.useMemo(()=>[{id:"usage",label:o("layout.services.usage"),icon:s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(I,{name:"command",className:"h-3.5 w-3.5"})}],[o]);et.useEffect(()=>{const ee=it=>{if($l(it)&&!it.shiftKey&&!it.altKey){const wt=parseInt(it.key,10);wt>=1&&wt<=un.length&&(it.preventDefault(),ie&&(Ge(),hs()),y(un[wt-1].id))}};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[Ge,hs,ie,y,un]),et.useEffect(()=>{const ee=it=>{const wt=pi("toggle_services_menu",b);if(Lo(it,wt)){it.preventDefault(),Ee?Ne(!1):(Ne(!0),kt(),Ye==="usage"&&R.length===0&&_());return}const Vt=pi("cycle_services_tab",b);if(Lo(it,Vt)){it.preventDefault();const us=ds.map(Mn=>Mn.value);if(us.length===0)return;const cs=us.indexOf(Ye),Us=cs===-1?0:(cs+1)%us.length,js=us[Us];rt(js),Ne(!0),kt(),js==="usage"&&R.length===0&&_();return}const ps=pi("toggle_context_plan",b);Lo(it,ps)&&(it.preventDefault(),ys())};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[b,Ee,Ye,ds,R.length,_,kt,ys]);const qn=ee=>{const it=p===ee.id,wt=ee.icon==="diff",Vt=wt?null:ee.icon,ps=ee.id==="chat",us=Us=>wt?s.jsx(Wc,{size:Us}):Vt?s.jsx(I,{name:Vt,className:`h-${Us/4} w-${Us/4}`}):null,cs=s.jsxs("button",{type:"button",onClick:()=>y(ee.id),className:Pe("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",it?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",ps&&!ie&&"min-w-[100px] justify-center"),"aria-label":ee.label,"aria-selected":it,role:"tab",children:[ie?us(20):s.jsxs(s.Fragment,{children:[us(16),s.jsx("span",{className:"header-tab-label",children:ee.label})]}),ee.badge!==void 0&&ee.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:ee.badge})]});return s.jsx(a.Fragment,{children:cs},ee.id)},Er=s.jsxs(s.Fragment,{children:[es&&s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.actions.openPlanAria"),onClick:ys,className:Pe(Ss,Rs&&"bg-[var(--interactive-hover)]"),children:s.jsx(I,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Bt,{children:s.jsx("p",{children:o("header.actions.planWithShortcut",{shortcut:hn("toggle_context_plan")})})})]}),s.jsx(ug,{directory:gs,className:"mr-1"}),s.jsx(zg,{isDesktopApp:Se,currentInstanceLabel:O,compactCurrentInstanceLabel:Qe,currentInstanceIsLocal:Y,isDesktopServicesOpen:Ee,setIsDesktopServicesOpen:Ne,refreshCurrentInstanceLabel:kt,desktopServicesTab:Ye,setDesktopServicesTab:rt,quotaResultsLength:R.length,fetchAllQuotas:_,servicesTabItems:ws,quotaLastUpdated:V,quotaDisplayMode:F,showPredValues:te,quotaDisplayTabItems:lr,handleDisplayModeChange:at,handleUsageRefresh:dt,isQuotaLoading:z,isUsageRefreshSpinning:Be,hasRateLimits:Et,rateLimitGroups:st,expandedFamilies:gt,toggleFamilyExpanded:He,shortcutLabel:hn,showDevShutdown:pn,isDevShutdownInFlight:S,onDevShutdown:Sn,remoteUpdateInfo:Re,remoteUpdateChecking:yt,remoteUpdateError:mt,onOpenRemoteUpdate:tt,timeFormatPreference:h}),s.jsx(Ci,{title:o("header.actions.terminalPanelWithShortcut",{shortcut:hn("toggle_terminal")}),ariaLabel:o("header.actions.toggleTerminalPanelAria"),onClick:l,Icon:"terminal-box"}),ie?null:s.jsx(Ci,{title:o("contextPanel.browser.open"),ariaLabel:o("contextPanel.browser.open"),onClick:Bs,pressed:an,Icon:"global"}),s.jsx(Ci,{title:o("header.actions.rightSidebarWithShortcut",{shortcut:hn("toggle_right_sidebar")}),ariaLabel:o("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx($g,{isMobile:ie,githubAuthStatus:oe,githubAccounts:B,githubAvatarUrl:Te,githubLogin:me,isSwitchingGitHubAccount:ye,handleGitHubAccountSwitch:W})]}),dr=L&&(k||!!A),yr=()=>s.jsxs("div",{onMouseDown:Cn,className:Pe("app-region-drag relative flex h-12 select-none items-center pr-3",nr,Kn),style:As,role:"tablist","aria-label":o("header.navigation.mainAria"),children:[we?s.jsx(Ci,{title:o("header.actions.openAppMenu"),ariaLabel:o("header.actions.openAppMenuAria"),onClick:ht,className:`${Ss} shrink-0`,Icon:"menu-2"}):null,s.jsx(Ci,{title:o("header.actions.openSessionsWithShortcut",{shortcut:hn("toggle_sidebar")}),ariaLabel:o("header.actions.openSessionsAria"),onClick:Xe,className:`${Ss} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center pl-3",children:[xt&&s.jsx(Kc,{projectRef:xt.projectRef,directory:xt.directory,className:"mr-2"}),s.jsx(ng,{children:s.jsxs("button",{type:"button","aria-label":o("sessions.switcher.openAria"),className:"app-region-no-drag mr-3 flex min-w-0 flex-col items-start rounded-md px-1 py-0.5 -my-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:k?o("sessions.switcher.draftTitle"):$s}),H||as||!k&&(Ls||ft)?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[H?s.jsx("span",{className:"truncate",children:H}):null,as?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:as})]}):null,!k&&Ls?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Es.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Es.deletions]})]}):null,!k&&ft?s.jsxs("span",{className:Pe("inline-flex min-w-0 items-center gap-0.5",ft==="attention"||ft==="invalid"||ft==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(I,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Yt})]}):null]}):null]})}),un.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:un.map(ee=>qn(ee))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[It&&G?s.jsx(rg,{totalTokens:G.totalTokens,percentage:lt,colorPercentage:G.percentage,contextLimit:G.contextLimit,outputLimit:G.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:ss,pressed:bs,className:dr?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ci,{visible:dr,title:o(k?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(k?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:ut,className:Pe(Ss,It?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),Er,s.jsx(ig,{visible:we})]})]})]}),wr=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:br,className:Pe(zs,Ws==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":o(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(I,{name:"layout-left",className:"h-5 w-5"})}):fe?s.jsx("button",{type:"button",onClick:()=>i(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.backAria"),children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Xe,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.openSessionsAria"),children:s.jsx(I,{name:"play-list-add",className:"h-5 w-5"})}),!t&&fe&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!fe||!!t)&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":o("header.navigation.mainAria"),children:un.map(ee=>{const it=p===ee.id,wt=ee.icon==="diff",Vt=wt?null:ee.icon;return s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{ie&&(Ge(),hs()),y(ee.id)},"aria-label":ee.label,"aria-selected":it,role:"tab",className:Pe(zs,"relative rounded-lg",Ws===ee.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[wt?s.jsx(Wc,{className:"h-5 w-5"}):Vt?s.jsx(I,{name:Vt,className:"h-5 w-5"}):null,ee.badge!==void 0&&ee.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:ee.badge}),ee.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":o("header.changes.availableAria")})]})}),s.jsx(Bt,{children:s.jsx("p",{children:ee.label})})]},ee.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[xt&&s.jsx(Kc,{projectRef:xt.projectRef,directory:xt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(rn,{open:J,onOpenChange:ee=>{ee&&(n&&t&&t(),r&&e&&e()),Me(ee),ee&&R.length===0&&_()},children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:Pe(zs,Ws==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(I,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Bt,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(nn,{align:"end",sideOffset:0,positionerClassName:"!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none",className:"h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(po,{items:cr,activeId:bt,onSelect:ee=>{const it=ee;ct(it),it==="usage"&&R.length===0&&_()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>Me(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":o("header.services.closeAria"),children:s.jsx(I,{name:"close",className:"h-5 w-5"})})]})}),bt==="mcp"&&s.jsx(Zu,{active:J&&bt==="mcp"}),bt==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:o("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:em(V,h)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>at("usage"),className:Pe("typography-ui-label px-1 pb-0.5 transition-colors",F==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>at("remaining"),className:Pe("typography-ui-label px-1 pb-0.5 transition-colors",F==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.remaining")})]}),s.jsx("button",{type:"button",className:Pe("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:dt,disabled:z||Be,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:Pe("h-4 w-4",Be&&"animate-spin")})})]})]})}),!Et&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:o("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:st.map((ee,it)=>s.jsxs(a.Fragment,{children:[it>0?s.jsx("div",{className:"mx-4 my-1 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(mo,{providerId:ee.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:ee.providerName})]}),ee.entries.length===0&&(!ee.modelFamilies||ee.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:ee.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[ee.entries.map(([wt,Vt])=>{const ps=F==="remaining"?Vt.remainingPercent:Vt.usedPercent,us=ea(Vt.usedPercent,Vt.resetAt,Vt.windowSeconds,wt),cs=us?.dailyAllocationPercent!=null?F==="remaining"?100-Jr(us.elapsedRatio):Jr(us.elapsedRatio):null,Us=ta(Vt.valueLabel,ps),js=Gu(Vt.resetAt,Vt.resetAfterFormatted??Vt.resetAtFormatted,h);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Ku(wt)}),js?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:js}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Us==="-"?"":Us})]}),s.jsx(sa,{percent:ps,tonePercent:Vt.usedPercent,className:"h-1.5",expectedMarkerPercent:cs}),us&&te?s.jsx(na,{paceInfo:us,compact:!0}):null]},`${ee.providerId}-${wt}`)}),ee.modelFamilies&&ee.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:ee.modelFamilies.map(wt=>{const ps=(gt[ee.providerId]??[]).includes(wt.familyId??"other");return s.jsxs(Vi,{open:ps,onOpenChange:()=>He(ee.providerId,wt.familyId??"other"),children:[s.jsxs(vo,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:wt.familyLabel}),ps?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx($i,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:wt.models.map(([us,cs])=>{const Us=F==="remaining"?cs.remainingPercent:cs.usedPercent,js=ea(cs.usedPercent,cs.resetAt,cs.windowSeconds),Mn=js?.dailyAllocationPercent!=null?F==="remaining"?100-Jr(js.elapsedRatio):Jr(js.elapsedRatio):null,mn=ta(cs.valueLabel,Us);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:qu(us)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:mn==="-"?"":mn})]}),s.jsx(sa,{percent:Us,tonePercent:cs.usedPercent,className:"h-1.5",expectedMarkerPercent:Mn}),js&&te?s.jsx(na,{paceInfo:js,compact:!0}):null]},`${ee.providerId}-${us}`)})})})]},wt.familyId??"other")})})]})]},ee.providerId))})]})]})})]}),e?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Rn,className:Pe(zs,"relative",Ws==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(I,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Bt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),ur=Pe("header-safe-area relative z-10",ie?"border-b border-border/50 bg-background":"bg-sidebar");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:je,className:ur,style:{"--padding-scale":"1"},children:ie?wr():yr()}),s.jsx(Yu,{open:Oe,onOpenChange:$e,info:Re,downloading:!1,downloaded:!1,progress:null,error:mt,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function Hg(){}const Yc=180,Jc=640,Gg=110,Kg=t=>{const e=pt.c(44),{isOpen:n,isMobile:r,children:o}=t,{t:i}=Tt(),c=Fe(qg),l=Fe(Yg),u=Fe(Jg),m=Fe(Qg),[d,f]=a.useState(null),[g,x]=a.useState(!1),p=a.useRef(null),y=a.useRef(0),b=a.useRef(c||300),h=Math.min(Jc,Math.max(Yc,c||300));let N,w;e[0]!==n?(N=()=>{n||(f(null),x(!1))},w=[n],e[0]=n,e[1]=N,e[2]=w):(N=e[1],w=e[2]),a.useEffect(N,w);let S,v;e[3]!==l||e[4]!==r||e[5]!==n?(S=()=>{if(r||!n||!l)return;const ie=()=>{const je=p.current?.parentElement?.getBoundingClientRect().height;if(!je||je<=0)return;const Se=Math.max(0,Math.round(je));f(re=>re===Se?re:Se)};ie();const oe=p.current?.parentElement;if(!oe)return;const pe=new ResizeObserver(ie);return pe.observe(oe),()=>{pe.disconnect()}},v=[l,r,n],e[3]=l,e[4]=r,e[5]=n,e[6]=S,e[7]=v):(S=e[6],v=e[7]),a.useEffect(S,v);let j,k;if(e[8]!==l||e[9]!==r||e[10]!==g||e[11]!==u||e[12]!==m?(j=()=>{if(r||!g||l)return;const ie=pe=>{const je=y.current-pe.clientY,Se=Math.min(Jc,Math.max(Yc,b.current+je));u(Se)},oe=()=>{x(!1),Fe.getState().bottomTerminalHeight<=Gg&&m(!1)};return window.addEventListener("pointermove",ie),window.addEventListener("pointerup",oe,{once:!0}),()=>{window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",oe)}},k=[l,r,g,u,m],e[8]=l,e[9]=r,e[10]=g,e[11]=u,e[12]=m,e[13]=j,e[14]=k):(j=e[13],k=e[14]),a.useEffect(j,k),r)return null;const A=n?l?Math.max(0,d??h):h:0,T=n&&l;let C;e[15]!==A||e[16]!==l||e[17]!==n?(C=ie=>{!n||l||(x(!0),y.current=ie.clientY,b.current=A,ie.preventDefault())},e[15]=A,e[16]=l,e[17]=n,e[18]=C):C=e[18];const P=C,E=T?"absolute inset-x-0 bottom-0 z-40":"relative",M=g?"transition-none":"transition-[height] duration-300 ease-in-out",H=(!n||T)&&"border-t-0";let R;e[19]!==H||e[20]!==E||e[21]!==M?(R=Pe("flex overflow-hidden border-t border-border bg-sidebar",E,M,H),e[19]=H,e[20]=E,e[21]=M,e[22]=R):R=e[22];let _;e[23]!==A||e[24]!==T?(_=T?{top:0}:{height:`${A}px`,minHeight:`${A}px`,maxHeight:`${A}px`},e[23]=A,e[24]=T,e[25]=_):_=e[25];const z=!n||!l&&A===0;let V;e[26]!==P||e[27]!==l||e[28]!==n||e[29]!==g||e[30]!==i?(V=n&&!l&&s.jsx("div",{className:Pe("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",g&&"bg-[var(--interactive-border)]"),onPointerDown:P,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=P,e[27]=l,e[28]=n,e[29]=g,e[30]=i,e[31]=V):V=e[31];const F=!n&&"pointer-events-none select-none opacity-0";let te;e[32]!==F?(te=Pe("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",F),e[32]=F,e[33]=te):te=e[33];const Z=!n;let ne;e[34]!==o||e[35]!==te||e[36]!==Z?(ne=s.jsx("div",{className:te,"aria-hidden":Z,children:o}),e[34]=o,e[35]=te,e[36]=Z,e[37]=ne):ne=e[37];let U;return e[38]!==R||e[39]!==_||e[40]!==z||e[41]!==V||e[42]!==ne?(U=s.jsxs("section",{ref:p,className:R,style:_,"aria-hidden":z,children:[V,ne]}),e[38]=R,e[39]=_,e[40]=z,e[41]=V,e[42]=ne,e[43]=U):U=e[43],U};function qg(t){return t.bottomTerminalHeight}function Yg(t){return t.isBottomTerminalExpanded}function Jg(t){return t.setBottomTerminalHeight}function Qg(t){return t.setBottomTerminalOpen}const wl=280,Qc=280,Xc=500,Xg=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:o}=Tt(),i=Fe(j=>j.sidebarWidth),c=Fe(j=>j.setSidebarWidth),[l,u]=a.useState(!1),m=a.useRef(0),d=a.useRef(i||wl),f=a.useRef(null),g=a.useRef(null),x=a.useRef(null),p=a.useCallback(j=>Math.min(Xc,Math.max(Qc,j)),[]),y=a.useCallback(j=>{const k=x.current;k&&(k.style.width=`${j}px`,k.style.minWidth=`${j}px`,k.style.maxWidth=`${j}px`,k.style.setProperty("--oc-left-sidebar-width",`${j}px`))},[]);if(a.useEffect(()=>{e&&l&&u(!1)},[e,l]),a.useEffect(()=>{l||(f.current=null,g.current=null)},[l]),e)return null;const b=Math.min(Xc,Math.max(Qc,i||wl)),h=t?b:0,N=j=>{if(t){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}g.current=j.pointerId,u(!0),m.current=j.clientX,d.current=h,f.current=h,y(h),j.preventDefault()}},w=j=>{if(e||!l||g.current!==j.pointerId)return;const k=j.clientX-m.current,A=p(d.current+k);f.current!==A&&(f.current=A,y(A))},S=j=>{if(g.current!==j.pointerId||e)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const k=p(f.current??h);g.current=null,f.current=null,u(!1),c(k)},v=l?f.current??h:h;return s.jsxs("aside",{ref:x,className:Pe("relative flex h-full overflow-hidden border-r border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-r-0",r),style:{width:`${v}px`,minWidth:`${v}px`,maxWidth:`${v}px`,"--oc-left-sidebar-width":`${l?v:b}px`,overflowX:"clip",transitionProperty:l?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||h===0,children:[t&&s.jsx("div",{className:Pe("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",l&&"bg-[var(--interactive-border)]"),onPointerDown:N,onPointerMove:w,onPointerUp:S,onPointerCancel:S,role:"separator","aria-orientation":"vertical","aria-label":o("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:Pe("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",l&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(on,{children:n})})})]})},vl=420,Zc=360,ed=860,Zg=({isOpen:t,children:e,className:n})=>{const{t:r}=Tt(),o=Fe(v=>v.rightSidebarWidth),i=Fe(v=>v.setRightSidebarWidth),[c,l]=a.useState(!1),u=a.useRef(0),m=a.useRef(o||vl),d=a.useRef(null),f=a.useRef(null),g=a.useRef(null),x=a.useCallback(v=>Math.min(ed,Math.max(Zc,v)),[]),p=a.useCallback(v=>{const j=g.current;j&&(j.style.width=`${v}px`,j.style.minWidth=`${v}px`,j.style.maxWidth=`${v}px`,j.style.setProperty("--oc-right-sidebar-width",`${v}px`))},[]),y=Math.min(ed,Math.max(Zc,o||vl)),b=t?y:0,h=v=>{if(t){try{v.currentTarget.setPointerCapture(v.pointerId)}catch{}f.current=v.pointerId,l(!0),u.current=v.clientX,m.current=b,d.current=b,p(b),v.preventDefault()}},N=v=>{if(!c||f.current!==v.pointerId)return;const j=u.current-v.clientX,k=x(m.current+j);d.current!==k&&(d.current=k,p(k))},w=v=>{if(f.current!==v.pointerId)return;try{v.currentTarget.releasePointerCapture(v.pointerId)}catch{}const j=x(d.current??b);f.current=null,d.current=null,l(!1),i(j)};a.useEffect(()=>{c||(d.current=null,f.current=null)},[c]);const S=c?d.current??b:b;return s.jsxs("aside",{ref:g,className:Pe("relative flex h-full overflow-hidden border-l border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-l-0",n),style:{width:`${S}px`,minWidth:`${S}px`,maxWidth:`${S}px`,"--oc-right-sidebar-width":`${c?S:y}px`,overflowX:"clip",transitionProperty:c?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||b===0,children:[t&&s.jsx("div",{className:Pe("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:h,onPointerMove:N,onPointerUp:w,onPointerCancel:w,role:"separator","aria-orientation":"vertical","aria-label":r("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:Pe("relative z-10 flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-right-sidebar-width)"},"aria-hidden":!t,children:t?e:null})]})},td=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent});function tm(t){const e=pt.c(120),{t:n}=Tt(),{open:r,onOpenChange:o,target:i,projectDirectory:c,submitting:l,onConfirm:u}=t,m=l===void 0?!1:l,d=ls(cx),f=ls(lx),g=Cf(ax),x=ls(ox),p=ls(ix),y=ls(rx),b=ls(nx),h=ls(sx);let N;e[0]!==h||e[1]!==y||e[2]!==p||e[3]!==b?(N=()=>td({providerID:p,modelID:y,variant:b,agent:h}),e[0]=h,e[1]=y,e[2]=p,e[3]=b,e[4]=N):N=e[4];const[w,S]=a.useState(N);let v,j;e[5]!==g||e[6]!==f||e[7]!==d||e[8]!==r||e[9]!==c?(v=()=>{r&&(d({directory:c,source:"todoSendDialog"}),f({directory:c}),g())},j=[r,d,f,g,c],e[5]=g,e[6]=f,e[7]=d,e[8]=r,e[9]=c,e[10]=v,e[11]=j):(v=e[10],j=e[11]),a.useEffect(v,j);let k,A;e[12]!==h||e[13]!==y||e[14]!==p||e[15]!==b||e[16]!==r?(k=()=>{r&&S(td({providerID:p,modelID:y,variant:b,agent:h}))},A=[r,p,y,b,h],e[12]=h,e[13]=y,e[14]=p,e[15]=b,e[16]=r,e[17]=k,e[18]=A):(k=e[17],A=e[18]),a.useEffect(k,A);let T,C;e[19]!==w.modelID||e[20]!==w.providerID||e[21]!==r||e[22]!==x?(T=()=>{if(!r||x.length===0)return;const Be=x.find(Y=>Y.id===w.providerID)??x[0],se=Array.isArray(Be?.models)?Be.models:[],O=se.some(Y=>Y.id===w.modelID),D=se[0]?.id??"";Be?.id===w.providerID&&O||S(Y=>({...Y,providerID:Be?.id??"",modelID:O?Y.modelID:D,variant:""}))},C=[r,x,w.providerID,w.modelID],e[19]=w.modelID,e[20]=w.providerID,e[21]=r,e[22]=x,e[23]=T,e[24]=C):(T=e[23],C=e[24]),a.useEffect(T,C);const P=tx;let E;if(e[25]!==w.modelID||e[26]!==w.providerID||e[27]!==x){let Be;e[29]!==w.providerID?(Be=O=>O.id===w.providerID,e[29]=w.providerID,e[30]=Be):Be=e[30],E=x.find(Be)?.models?.find(O=>O.id===w.modelID),e[25]=w.modelID,e[26]=w.providerID,e[27]=x,e[28]=E}else E=e[28];const M=E;let H;e[31]!==M?(H=M?.variants?Object.keys(M.variants):[],e[31]=M,e[32]=H):H=e[32];const R=H,_=R.length>0;let z,V;e[33]!==w.variant||e[34]!==_?(z=()=>{_||!w.variant||S(ex)},V=[_,w.variant],e[33]=w.variant,e[34]=_,e[35]=z,e[36]=V):(z=e[35],V=e[36]),a.useEffect(z,V);let F;e[37]!==w.modelID||e[38]!==w.providerID?(F=w.providerID.trim().length>0&&w.modelID.trim().length>0,e[37]=w.modelID,e[38]=w.providerID,e[39]=F):F=e[39];const te=F;let Z;e[40]!==te||e[41]!==w||e[42]!==u||e[43]!==m?(Z=()=>{!te||m||u(w)},e[40]=te,e[41]=w,e[42]=u,e[43]=m,e[44]=Z):Z=e[44];const ne=Z;let U,ie;e[45]!==ne||e[46]!==r?(U=()=>{if(!r)return;const Be=se=>{(se.metaKey||se.ctrlKey)&&se.key==="Enter"&&(se.preventDefault(),ne())};return window.addEventListener("keydown",Be),()=>window.removeEventListener("keydown",Be)},ie=[r,ne],e[45]=ne,e[46]=r,e[47]=U,e[48]=ie):(U=e[47],ie=e[48]),a.useEffect(U,ie);let oe;e[49]!==n||e[50]!==i?(oe=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=oe):oe=e[51];const pe=oe;let je;e[52]!==o||e[53]!==m?(je=Be=>{m||o(Be)},e[52]=o,e[53]=m,e[54]=je):je=e[54];let Se;e[55]!==pe?(Se=s.jsx(Qs,{children:s.jsx(Ys,{children:pe})}),e[55]=pe,e[56]=Se):Se=e[56];let re;e[57]!==n?(re=n("chat.modelControls.model"),e[57]=n,e[58]=re):re=e[58];let L;e[59]!==re?(L=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:re}),e[59]=re,e[60]=L):L=e[60];let $;e[61]===Symbol.for("react.memo_cache_sentinel")?($=(Be,se)=>{S(O=>({...O,providerID:Be,modelID:se,variant:""}))},e[61]=$):$=e[61];let K;e[62]!==w.modelID||e[63]!==w.providerID?(K=s.jsx(Cu,{providerId:w.providerID,modelId:w.modelID,className:"max-w-[320px] justify-between",dropdownPortalToBody:!0,onChange:$}),e[62]=w.modelID,e[63]=w.providerID,e[64]=K):K=e[64];let he;e[65]!==L||e[66]!==K?(he=s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[L,K]}),e[65]=L,e[66]=K,e[67]=he):he=e[67];let de;e[68]!==n?(de=n("sessions.scheduledTasks.editor.thinkingLevel.label"),e[68]=n,e[69]=de):de=e[69];let we;e[70]!==de?(we=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:de}),e[70]=de,e[71]=we):we=e[71];const xe=!_;let De;e[72]===Symbol.for("react.memo_cache_sentinel")?(De=Be=>S(se=>({...se,variant:Be})),e[72]=De):De=e[72];let le;e[73]!==w.variant||e[74]!==xe||e[75]!==R?(le=s.jsx(Af,{value:w.variant,options:R,disabled:xe,onChange:De}),e[73]=w.variant,e[74]=xe,e[75]=R,e[76]=le):le=e[76];let Ce;e[77]!==we||e[78]!==le?(Ce=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[we,le]}),e[77]=we,e[78]=le,e[79]=Ce):Ce=e[79];let ue;e[80]!==n?(ue=n("sessions.scheduledTasks.editor.agent.label"),e[80]=n,e[81]=ue):ue=e[81];let ve;e[82]!==ue?(ve=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:ue}),e[82]=ue,e[83]=ve):ve=e[83];let G;e[84]===Symbol.for("react.memo_cache_sentinel")?(G=Be=>S(se=>({...se,agent:Be})),e[84]=G):G=e[84];let Ae;e[85]!==w.agent?(Ae=s.jsx(Au,{agentName:w.agent,filter:P,dropdownPortalToBody:!0,onChange:G}),e[85]=w.agent,e[86]=Ae):Ae=e[86];let ce;e[87]!==ve||e[88]!==Ae?(ce=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ve,Ae]}),e[87]=ve,e[88]=Ae,e[89]=ce):ce=e[89];let fe;e[90]!==he||e[91]!==Ce||e[92]!==ce?(fe=s.jsxs("div",{className:"flex flex-col gap-4",children:[he,Ce,ce]}),e[90]=he,e[91]=Ce,e[92]=ce,e[93]=fe):fe=e[93];let Te;e[94]!==o?(Te=()=>o(!1),e[94]=o,e[95]=Te):Te=e[95];let me;e[96]!==n?(me=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[96]=n,e[97]=me):me=e[97];let B;e[98]!==m||e[99]!==Te||e[100]!==me?(B=s.jsx(ze,{variant:"ghost",size:"sm",onClick:Te,disabled:m,children:me}),e[98]=m,e[99]=Te,e[100]=me,e[101]=B):B=e[101];const ye=!te||m;let _e;e[102]!==m||e[103]!==n?(_e=n(m?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[102]=m,e[103]=n,e[104]=_e):_e=e[104];let J;e[105]!==ne||e[106]!==ye||e[107]!==_e?(J=s.jsx(ze,{size:"sm",onClick:ne,disabled:ye,children:_e}),e[105]=ne,e[106]=ye,e[107]=_e,e[108]=J):J=e[108];let Me;e[109]!==B||e[110]!==J?(Me=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[B,J]}),e[109]=B,e[110]=J,e[111]=Me):Me=e[111];let Ee;e[112]!==Se||e[113]!==fe||e[114]!==Me?(Ee=s.jsxs(Gs,{className:"max-w-md overflow-visible",children:[Se,fe,Me]}),e[112]=Se,e[113]=fe,e[114]=Me,e[115]=Ee):Ee=e[115];let Ne;return e[116]!==r||e[117]!==je||e[118]!==Ee?(Ne=s.jsx(Ks,{open:r,onOpenChange:je,children:Ee}),e[116]=r,e[117]=je,e[118]=Ee,e[119]=Ne):Ne=e[119],Ne}function ex(t){return{...t,variant:""}}function tx(t){return Du(t.mode)}function sx(t){return t.currentAgentName||""}function nx(t){return t.currentVariant||""}function rx(t){return t.currentModelId}function ix(t){return t.currentProviderId}function ox(t){return t.providers}function ax(t){return t.loadAgents}function lx(t){return t.loadAgents}function cx(t){return t.loadProviders}const jl=5,sm=15,Bo=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},dx=(t,e)=>{const n=Bo(e);return Math.max(n*jl,Math.min(n*sm,n*t))},ux=async(t,e)=>{const n=await Ef(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},mx=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,sd=t=>[...t.filter(e=>!e.completed),...t.filter(e=>e.completed)],nd=(t,e)=>{const n=t.findIndex(r=>r.completed);return n===-1?[...t,e]:[...t.slice(0,n),e,...t.slice(n)]},fx=t=>{const e=pt.c(20),{id:n,children:r}=t;let o;e[0]!==n?(o={id:n},e[0]=n,e[1]=o):o=e[1];const{attributes:i,listeners:c,setNodeRef:l,setActivatorNodeRef:u,transform:m,transition:d,isDragging:f}=Ml(o);let g;e[2]!==m?(g=Fl.Transform.toString(m),e[2]=m,e[3]=g):g=e[3];let x;e[4]!==g||e[5]!==d?(x={transform:g,transition:d},e[4]=g,e[5]=d,e[6]=x):x=e[6];const p=f&&"opacity-60";let y;e[7]!==p?(y=Pe(p),e[7]=p,e[8]=y):y=e[8];let b;e[9]!==i||e[10]!==r||e[11]!==f||e[12]!==c||e[13]!==u?(b=r({attributes:i,listeners:c,setActivatorNodeRef:u,isDragging:f}),e[9]=i,e[10]=r,e[11]=f,e[12]=c,e[13]=u,e[14]=b):b=e[14];let h;return e[15]!==l||e[16]!==x||e[17]!==y||e[18]!==b?(h=s.jsx("li",{ref:l,style:x,className:y,children:b}),e[15]=l,e[16]=x,e[17]=y,e[18]=b,e[19]=h):h=e[19],h},hx=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:o})=>{const{t:i}=Tt(),[c,l]=a.useState(!1),[u,m]=a.useState(""),[d,f]=a.useState([]),[g,x]=a.useState(""),[p,y]=a.useState(null),[b,h]=a.useState(()=>new Set),[N,w]=a.useState([]),[S,v]=a.useState(null),[j,k]=a.useState(!1),[A,T]=a.useState(0),C=a.useRef(!1),P=a.useRef(""),E=Fe(O=>O.todoPanelHeight),M=Fe(O=>O.setTodoPanelHeight),H=Fe(O=>O.notesPanelHeight),R=Fe(O=>O.setNotesPanelHeight),[_,z]=a.useState(!1),V=a.useRef(0),F=a.useRef(E),te=jt(O=>O.currentSessionId),Z=jt(O=>O.createSession),ne=jt(O=>O.initializeNewOpenChamberSession),U=jt(O=>O.sendMessage),ie=jt(O=>O.setCurrentSession),oe=ti(O=>O.setPendingInputText),pe=tn(O=>O.currentDirectory),je=Fe(O=>O.openContextPanelTab),Se=Fe(O=>O.setActiveMainTab),re=Fe(O=>O.setSessionSwitcherOpen),L=Fe(O=>O.padding),$=a.useCallback(async(O,D)=>{if(!t)return!1;const Y=await Df(t,{notes:O,todos:D});return Y||ae.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),Y},[t,i]);a.useEffect(()=>{if(!t){m(""),f([]),w([]),x(""),h(new Set);return}let O=!1;return l(!0),(async()=>{try{const D=await If(t),Y=await Promise.all(D.plans.map(be=>ux(be,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(O)return;m(D.notes),f(sd(D.todos)),w(Y),P.current=D.notes,C.current=!0,x(""),h(new Set)}catch{O||(ae.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),m(""),f([]),w([]),P.current="",C.current=!0)}finally{O||l(!1)}})(),()=>{O=!0}},[A,t,i]),a.useEffect(()=>{if(!t)return;const O=D=>{const Y=D.detail;Y?.projectId&&Y.projectId!==t.id||T(be=>be+1)};return window.addEventListener("openchamber:project-plan-saved",O),window.addEventListener("openchamber:project-notes-updated",O),()=>{window.removeEventListener("openchamber:project-plan-saved",O),window.removeEventListener("openchamber:project-notes-updated",O)}},[t]),a.useEffect(()=>{if(d.length<7)return;const O=dx(d.length,L),D=Bo(L)*jl;(E<D||E>O)&&M(O)},[d.length,L,E,M]),a.useEffect(()=>{if(!_)return;const O=Y=>{const be=Y.clientY-V.current,Oe=Math.min(Bo(L)*sm,Math.max(Bo(L)*jl,F.current+be));M(Oe)},D=()=>{z(!1)};return window.addEventListener("pointermove",O),window.addEventListener("pointerup",D,{once:!0}),window.addEventListener("pointercancel",D,{once:!0}),()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",D),window.removeEventListener("pointercancel",D)}},[_,L,M]);const K=a.useCallback(O=>{z(!0),V.current=O.clientY,F.current=E,O.preventDefault()},[E]),he=a.useCallback(()=>{P.current=u,$(u,d)},[u,$,d]);a.useEffect(()=>{if(!t||!C.current||u===P.current)return;const O=window.setTimeout(()=>{P.current=u,$(u,d)},400);return()=>{window.clearTimeout(O)}},[u,$,t,d]);const de=a.useCallback(()=>{const O=g.trim();if(!O)return;const D=nd(d,{id:mx(),text:O.slice(0,No),completed:!1,createdAt:Date.now()});f(D),x(""),$(u,D)},[g,u,$,d]),we=a.useCallback(O=>{h(D=>{const Y=new Set(D);return Y.has(O)?Y.delete(O):Y.add(O),Y})},[]),xe=a.useCallback((O,D)=>{const Y=d.find(Re=>Re.id===O);if(!Y||Y.completed===D)return;const be=d.filter(Re=>Re.id!==O),Oe={...Y,completed:D},$e=D?[...be,Oe]:nd(be,Oe);f($e),$(u,$e)},[u,$,d]),De=a.useCallback(O=>{const D=d.filter(Y=>Y.id!==O);f(D),$(u,D)},[u,$,d]),le=a.useCallback(()=>{const O=d.filter(D=>!D.completed);O.length!==d.length&&(f(O),$(u,O))},[u,$,d]),Ce=a.useCallback(O=>{const{active:D,over:Y}=O;if(!Y||D.id===Y.id)return;const be=d.findIndex(Re=>Re.id===D.id),Oe=d.findIndex(Re=>Re.id===Y.id);if(be===-1||Oe===-1)return;const $e=sd(gu(d,be,Oe));f($e),$(u,$e)},[u,$,d]),ue=qo(no(Yo,{activationConstraint:{distance:8}})),ve=g.slice(0,No),G=d.reduce((O,D)=>O+(D.completed?1:0),0),Ae=a.useCallback(()=>{Se("chat"),re(!1)},[Se,re]),ce=a.useCallback((O,D)=>{!t||p||v({kind:"session",todoId:O,todoText:D})},[t,p]),fe=a.useCallback(O=>{if(!te){ae.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Ae();const D=`\`\`\`md
4
4
  ${O}
5
- \`\`\``;oe(A,"append"),ae.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[te,r,Ae,oe,i]),Ee=a.useCallback((O,A)=>{if(!(!t||p)){if(!n){ae.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}v({kind:"worktree",todoId:O,todoText:A})}},[n,t,p,i]),me=a.useCallback(async O=>{if(!t||!S)return;const A=await In("plan.todo.visible",{todo_text:S.todoText}),pe=[{synthetic:!0,text:await In("plan.todo.instructions",{todo_text:S.todoText})}];k(!0),y(S.todoId);try{Ae();let _e=null,We=t.path;if(S.kind==="worktree"){if(!n){ae.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const rt=await Cu(t.path,Au());if(!rt?.id)return;_e=rt.id,We=rt.path}else{const rt=await Z(void 0,t.path,null);if(!rt?.id){ae.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}_e=rt.id,We=rt.directory??t.path,ne(rt.id,cs.getState().agents??[])}if(!_e)return;const Le=$l.getState();Le.saveSessionModelSelection(_e,O.providerID,O.modelID),O.agent.trim()&&(Le.saveSessionAgentSelection(_e,O.agent),Le.saveAgentModelForSession(_e,O.agent,O.providerID,O.modelID),Le.saveAgentModelVariantForSession(_e,O.agent,O.providerID,O.modelID,O.variant||void 0)),ie(_e,We),await U(A,O.providerID,O.modelID,O.agent.trim()||void 0,void 0,void 0,pe,O.variant||void 0),ae.success(S.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),v(null),r?.()}catch(_e){const We=_e instanceof Error?_e.message:void 0;ae.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),We?{description:We}:void 0)}finally{k(!1),y(null)}},[n,Z,ne,r,S,t,Ae,U,ie,i]),B=a.useRef(null),[ye,Oe]=a.useState(!1),[Q,Me]=a.useState(null),Re=a.useCallback(async O=>{if(!(!t||Q)){Me(O);try{if(!await Af(t,O)){ae.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}w(K=>K.filter(pe=>pe.id!==O)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Me(null)}}},[Q,t,i]),Ne=a.useCallback(async()=>{if(!t||ye)return;const O=await Df({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(O.success&&O.path){Oe(!0);try{const A=new URLSearchParams({path:O.path,allowOutsideWorkspace:"true"}),K=await Rs(`/api/fs/read?${A.toString()}`,{cache:"no-store"});if(!K.ok){ae.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const pe=await K.text();if(!pe.trim()){ae.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const _e=O.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await xc(t,pe,_e)){ae.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),ae.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(A){const K=A instanceof Error?A.message:void 0;ae.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),K?{description:K}:void 0)}finally{Oe(!1)}}else O.error==="Native file picker not available"&&B.current?.click()},[ye,t,i]),Be=a.useCallback(async O=>{if(!(!t||!O)){Oe(!0);try{const A=await O.text();if(!A.trim()){ae.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const K=O.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await xc(t,A,K)){ae.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),ae.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(A){const K=A instanceof Error?A.message:void 0;ae.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),K?{description:K}:void 0)}finally{Oe(!1)}}},[t,i]),se=a.useCallback(O=>{const A=t?.path?.trim(),K=ge?.trim()||A;K&&je(K,{mode:"plan",targetPath:O.path,dedupeKey:O.path,label:O.title})},[ge,je,t]);return t?s.jsxs("div",{className:Te("w-full min-w-0 space-y-3 p-3",o),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:i("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[u.length,"/",bc]})]}),s.jsx(fi,{value:u,onChange:O=>m(O.target.value.slice(0,bc)),onBlur:he,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:H,onResizeHeightChange:R,useScrollShadow:!0,scrollShadowSize:56,disabled:c})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:d.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:d.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:d.length})}),s.jsx("button",{type:"button",onClick:le,disabled:c||G===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:i("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[ve.length,"/",No]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(kn,{value:ve,onChange:O=>x(O.target.value.slice(0,No)),onKeyDown:O=>{O.key==="Enter"&&(O.preventDefault(),de())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:c,className:"h-8"}),s.jsx("button",{type:"button",onClick:de,disabled:c||ve.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.addAria"),title:i("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:Te("overflow-y-auto rounded-lg border border-border/60 bg-background/40",_&&"transition-none"),style:d.length<7?void 0:{height:`${E}px`,maxHeight:`${E}px`},children:d.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(Jo,{sensors:ue,collisionDetection:Qo,onDragEnd:ke,children:s.jsx(rl,{items:d.map(O=>O.id),strategy:il,children:s.jsx("ul",{className:"divide-y divide-border/50",children:d.map(O=>{const A=b.has(O.id);return s.jsx(dx,{id:O.id,children:K=>s.jsxs("div",{className:Te("flex gap-1.5 px-2.5 py-1.5",A?"items-start":"items-center"),children:[s.jsx("button",{type:"button",ref:K.setActivatorNodeRef,...K.attributes,...K.listeners,onClick:pe=>{pe.preventDefault(),pe.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.text}),children:s.jsx(I,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(yi,{checked:O.completed,onChange:pe=>be(O.id,pe),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:O.text})})}),s.jsx("button",{type:"button",onClick:()=>we(O.id),className:Te("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-normal text-foreground",A?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",O.completed&&"text-muted-foreground line-through"),title:A?void 0:O.text,"aria-label":A?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:O.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:O.text}),children:O.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>De(O.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(on,{children:[s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",disabled:p===O.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),children:s.jsx(I,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(rn,{align:"end",className:"w-56",children:[s.jsx(zt,{onClick:()=>fe(O.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(zt,{onClick:()=>ce(O.id,O.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(zt,{onClick:()=>{Ee(O.id,O.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},O.id)})})})})}),d.length>=7&&s.jsx("div",{className:Te("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",_&&"bg-[var(--interactive-border)]"),onPointerDown:q,role:"separator","aria-orientation":"horizontal","aria-label":i("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:N.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:N.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:N.length})})]}),s.jsx("input",{ref:B,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:O=>{const A=O.target.files?.[0]??null;Be(A),O.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Ne,disabled:!t||ye,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.plans.importFromFile"),title:i("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:N.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:N.map(O=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>se(O),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:O.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(O.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Re(O.id)},disabled:Q===O.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:i("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":i("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:O.title}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},O.id))})})]}),s.jsx(Xu,{open:S!==null,onOpenChange:O=>{!O&&!j&&v(null)},target:S?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:me})]}):s.jsx("div",{className:Te("w-full min-w-0 p-3",o),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},em=12,mx=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],fx=t=>{const e=gt.c(18),{isActive:n,burstKey:r,className:o,durationMs:i,bursts:c,onComplete:l}=t,u=r===void 0?0:r,m=i===void 0?900:i,d=c===void 0?mx:c,f=et.useRef(!1);let g,x;e[0]!==n||e[1]!==l?(g=()=>{!n&&f.current&&l?.(),n&&(f.current=!0)},x=[n,l],e[0]=n,e[1]=l,e[2]=g,e[3]=x):(g=e[2],x=e[3]),et.useEffect(g,x);let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=Array.from({length:em},hx),e[4]=p):p=e[4];const y=p;if(!n)return null;let b;e[5]!==o?(b=Te("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=b):b=e[6];let h;if(e[7]!==u||e[8]!==d||e[9]!==m){let w;e[11]!==u||e[12]!==m?(w=S=>{const v={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${m}ms`};return s.jsx("div",{className:"firework-burst",style:v,children:y.map((j,k)=>{const D=j.x*S.radius,T=j.y*S.radius,C={"--translate-x":`${D}px`,"--translate-y":`${T}px`,"--particle-delay":`${j.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:C},`${S.id}-${k}-${u}`)})},`${S.id}-${u}`)},e[11]=u,e[12]=m,e[13]=w):w=e[13],h=d.map(w),e[7]=u,e[8]=d,e[9]=m,e[10]=h}else h=e[10];let N;return e[14]!==u||e[15]!==b||e[16]!==h?(N=s.jsx("div",{className:b,"aria-hidden":"true","data-burst-key":u,children:h}),e[14]=u,e[15]=b,e[16]=h,e[17]=N):N=e[17],N};function hx(t,e){const n=Math.PI*2*e/em;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const px=t=>{const e=gt.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,o=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[c,l]=et.useState(i),u=et.useRef(null);let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{u.current&&(window.clearTimeout(u.current),u.current=null)},e[3]=m):m=e[3];const d=m;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{d(),l(gx)},e[4]=f):f=e[4];const g=f;let x;e[5]!==o?(x=()=>{d(),l(xx),u.current=window.setTimeout(()=>{l(bx),u.current=null},o)},e[5]=o,e[6]=x):x=e[6];const p=x;let y,b;e[7]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>d(),b=[d],e[7]=y,e[8]=b):(y=e[7],b=e[8]),et.useEffect(y,b);let h;return e[9]!==c.cycle||e[10]!==c.isActive||e[11]!==p?(h={isActive:c.isActive,burstKey:c.cycle,triggerFireworks:p,dismissFireworks:g},e[9]=c.cycle,e[10]=c.isActive,e[11]=p,e[12]=h):h=e[12],h};function gx(t){return t.isActive?{...t,isActive:!1}:t}function xx(t){return{isActive:!0,cycle:t.cycle+1}}function bx(t){return t.isActive?{...t,isActive:!1}:t}const tm=a.createContext(void 0),yx=t=>{const e=gt.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:i,dismissFireworks:c}=px();let l;e[0]!==c||e[1]!==i?(l={triggerFireworks:i,dismissFireworks:c},e[0]=c,e[1]=i,e[2]=l):l=e[2];const u=l;let m;e[3]!==o||e[4]!==r?(m=s.jsx(fx,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=m):m=e[5];let d;return e[6]!==n||e[7]!==m||e[8]!==u?(d=s.jsxs(tm.Provider,{value:u,children:[n,m]}),e[6]=n,e[7]=m,e[8]=u,e[9]=d):d=e[9],d},wx=()=>{const t=a.useContext(tm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},jl=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},vx=t=>{const e=jl(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function jx(t,e,n){const r=gt.c(5),[o,i]=a.useState();let c,l;return r[0]!==n||r[1]!==t||r[2]!==e?(c=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let u=!1;return(async()=>{const[m,d]=await Promise.all([ws("git rev-parse --absolute-git-dir",t),ws("git rev-parse --show-toplevel",t)]);if(u||!m.success||!d.success)return;const f=jl((m.stdout||"").trim()),g=vx(f);if(!g)return;const x=jl((d.stdout||"").trim());if(!x||x===g)return;const p=n||"",y=x.split("/").filter(Boolean).pop()||x;i({source:"sdk",path:x,projectDirectory:g,branch:p,label:p||y,name:y,worktreeRoot:x,worktreeStatus:"ready",headState:p?"branch":"unborn",worktreeSource:"existing"})})(),()=>{u=!0}},l=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=c,r[4]=l):(c=r[3],l=r[4]),a.useEffect(c,l),e??o}const Rn=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},Wi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),Or=t=>!!t.success,Ca=t=>(t.stdout||"").trim(),pi=t=>(t.stderr||"").trim();async function Sx(t){const n=((await ws("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let o=null;for(const i of n){if(i.startsWith("worktree ")){o&&r.push(o),o={path:i.slice(9).trim(),branchRef:null};continue}o&&i.startsWith("branch ")&&(o.branchRef=i.slice(7).trim())}return o&&r.push(o),r.filter(i=>!!i.path)}async function Nx(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),o=(await Sx(t.repoRoot)).filter(c=>c.branchRef===e).map(c=>c.path).filter(c=>c&&!n.has(c)),i=[];for(const c of o){const l=await ws("git status --porcelain",c);Ca(l)||i.push(c)}return i}async function sm(t,e){for(const n of e)await ws("git reset --hard",n).catch(()=>{})}async function kx(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await ws(`git show-ref --verify --quiet ${Rn(`refs/heads/${n}`)}`,t);if(Or(r))return n;if(n.startsWith("remotes/")){const c=n.slice(8).split("/"),l=c[0]||"origin",u=c.slice(1).join("/");if(u)return await ws(`git branch --track ${Rn(u)} ${Rn(`${l}/${u}`)}`,t),u}const o=await ws(`git show-ref --verify --quiet ${Rn(`refs/remotes/origin/${n}`)}`,t);return Or(o)&&await ws(`git branch --track ${Rn(n)} ${Rn(`origin/${n}`)}`,t),n}async function Qi(t){const e=t.repoRoot,n=t.sourceBranch.trim(),r=t.targetBranch.trim();if(!n||!r)return{repoRoot:e,sourceBranch:n,targetBranch:r,commits:[]};const o=await kx(e,r),i=await ws(`git cherry ${Rn(o)} ${Rn(n)}`,e),c=Wi(i.stdout),l=new Set;for(const f of c){const g=f.match(/^\+\s+([0-9a-f]{7,40})\b/i);g&&l.add(g[1])}const u=await ws(`git rev-list --reverse ${Rn(`${o}..${n}`)}`,e),d=Wi(u.stdout).filter(f=>l.has(f));return{repoRoot:e,sourceBranch:n,targetBranch:o,commits:d}}async function Cx(t,e){const n=await ws('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!Or(n))throw new Error(pi(n)||"Failed to create temp directory parent");const r=await ws('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),o=Ca(r);if(!o)throw new Error(pi(r)||"Failed to create temp directory");const i=await ws(`git worktree add --force ${Rn(o)} ${Rn(e)}`,t);if(!Or(i))throw new Error(pi(i)||"Failed to create temp worktree");return o}async function ia(t,e){await ws(`git worktree remove --force ${Rn(e)}`,t).catch(()=>{}),await ws("git worktree prune",t).catch(()=>{})}async function Ax(t){const e=await ws("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Ca(e);if(!n)return;await ws("git fetch",t);const r=await ws(`git merge --ff-only ${Rn(n)}`,t);if(!Or(r))throw new Error(pi(r)||"Fast-forward failed")}async function oa(t){const e=await ws("git status --porcelain",t),n=await ws("git diff --name-only --diff-filter=U",t),r=await ws("git diff",t),o=await ws("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await ws("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:Wi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:o.stdout||o.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function Dx(t){return oa(t)}async function Ix(t){const e=await ws("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return Or(e)}async function Px(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await Cx(t.repoRoot,t.targetBranch);let n=[];try{await Ax(e);const r=await ws("git status --porcelain",e);if(Ca(r))throw new Error("Target branch has local changes; abort integration and retry");const o=await Nx({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],c=await ws(`git cherry-pick ${Rn(i)}`,e);if(Or(c)){n.shift();continue}const l=await ws("git diff --name-only --diff-filter=U",e);if(Wi(l.stdout).length>0){const m=await oa(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:o,remainingCommits:n,currentCommit:i},details:m}}throw new Error(pi(c)||"Cherry-pick failed")}return await ia(t.repoRoot,e),await sm(t.repoRoot,o).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await ia(t.repoRoot,e).catch(()=>{}),r}}async function Tx(t){await ws("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await ia(t.repoRoot,t.tempWorktreePath)}async function Ex(t){const e=await ws("git cherry-pick --continue",t.tempWorktreePath);if(!Or(e)){const i=await ws("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(Wi(i.stdout).length>0){const l=await oa(t.tempWorktreePath);return{kind:"conflict",state:t,details:l}}throw new Error(pi(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const o=[...r];for(;o.length>0;){const i=o[0],c=await ws(`git cherry-pick ${Rn(i)}`,n);if(Or(c)){o.shift();continue}const l=await ws("git diff --name-only --diff-filter=U",n);if(Wi(l.stdout).length>0){const m=await oa(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:o,currentCommit:i},details:m}}throw new Error(pi(c)||"Cherry-pick failed")}return await ia(t.repoRoot,t.tempWorktreePath),await sm(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Rx=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:o,refreshKey:i,onRefresh:c})=>{const{t:l}=Tt(),u=vt(F=>F.currentSessionId),m=Fe(F=>F.setActiveMainTab),[d,f]=et.useState(!1),g=et.useRef(null),[x,p]=et.useState(o);et.useEffect(()=>{p(o)},[o]),et.useEffect(()=>{if(d){const F=setTimeout(()=>{g.current?.focus()},0);return()=>clearTimeout(F)}},[d]);const y=!!(t&&e&&x&&x!=="HEAD"&&e!==x),[b,h]=et.useState({kind:"idle"}),[N,w]=et.useState(!1),[S,v]=et.useState([]),j=et.useMemo(()=>u?`openchamber.integrate.conflict:${u}`:null,[u]);et.useEffect(()=>{if(!j||typeof window>"u")return;const F=window.localStorage.getItem(j);if(!F)return;let te=!1;try{const Z=JSON.parse(F);if(!Z?.tempWorktreePath||Z.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const ne=await Ix(Z.tempWorktreePath).catch(()=>!1);if(te)return;if(!ne){window.localStorage.removeItem(j);return}const U=await Dx(Z.tempWorktreePath).catch(()=>null);te||U&&h({kind:"conflict",state:Z,details:U})})()}catch{window.localStorage.removeItem(j)}return()=>{te=!0}},[j,t]),et.useEffect(()=>{if(!y){h({kind:"idle"});return}let F=!1;return h({kind:"loading"}),(async()=>{try{const te=await Qi({repoRoot:t,sourceBranch:e,targetBranch:x});if(F)return;if(h({kind:"ready",plan:te}),te.commits.length>0){const U=te.commits.slice(-50).reverse().map(je=>JSON.stringify(je)).join(" "),oe=((await ws(`git show -s --format=%H%x09%h%x09%s ${U}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),ge=[];for(const je of oe){const[Se,re,L]=je.split(" ");!Se||!re||ge.push({sha:Se,short:re,subject:L||""})}F||(v(ge),w(!1))}else F||(v([]),w(!1))}catch{F||h({kind:"idle"})}})(),()=>{F=!0}},[y,t,e,x,i]);const k=et.useCallback(F=>{u&&vt.getState().setWorktreeMetadata(u,{...n,createdFromBranch:F})},[u,n]),D=vt(F=>F.openNewSessionDraft),T=et.useCallback(async F=>{const te=await In("git.integrate.cherrypick.resolve.visible",{current_commit:F.state.currentCommit,target_branch:F.state.targetBranch}),Z=await In("git.integrate.cherrypick.resolve.instructions",{repo_root:F.state.repoRoot,temp_worktree_path:F.state.tempWorktreePath,source_branch:F.state.sourceBranch,target_branch:F.state.targetBranch,current_commit:F.state.currentCommit}),ne=`Cherry-pick conflict context (JSON)
6
- ${JSON.stringify({repoRoot:F.state.repoRoot,tempWorktreePath:F.state.tempWorktreePath,sourceBranch:F.state.sourceBranch,targetBranch:F.state.targetBranch,currentCommit:F.state.currentCommit,remainingCommits:F.state.remainingCommits,statusPorcelain:F.details.statusPorcelain,unmergedFiles:F.details.unmergedFiles,currentPatchMeta:F.details.currentPatchMeta,currentPatch:F.details.currentPatch,diff:F.details.diff},null,2)}`;return{visibleText:te,instructionsText:Z,payloadText:ne}},[]),C=ei(F=>F.setPendingInputText),P=ei(F=>F.setPendingSyntheticParts),E=et.useCallback(async(F,te)=>{const Z=await T(F);if(te){D({directoryOverride:F.state.tempWorktreePath,initialPrompt:Z.visibleText,syntheticParts:[{text:Z.instructionsText,synthetic:!0},{text:Z.payloadText,synthetic:!0}]}),m("chat");return}if(!u){ae.error(l("gitView.integrate.noActiveSession"),{description:l("gitView.integrate.noActiveSessionDescription")});return}C(Z.visibleText,"replace"),P([{text:Z.instructionsText,synthetic:!0},{text:Z.payloadText,synthetic:!0}]),m("chat")},[u,m,T,D,C,P,l]),M=et.useCallback(async()=>{if(b.kind==="ready"){if(b.plan.commits.length===0){ae.message(l("gitView.integrate.noCommitsToMoveToast"));return}h({kind:"running",plan:b.plan});try{const F=await Px(b.plan);if(F.kind==="success"){ae.success(l("gitView.integrate.commitsMovedToast"),{description:F.moved===1?l("gitView.integrate.commitsMovedDescriptionSingle",{count:F.moved,branch:b.plan.targetBranch}):l("gitView.integrate.commitsMovedDescriptionPlural",{count:F.moved,branch:b.plan.targetBranch})});const te=await Qi(b.plan);h({kind:"ready",plan:te}),c?.();return}F.kind==="conflict"&&(ae.error(l("gitView.integrate.cherryPickConflictToast"),{description:l("gitView.integrate.cherryPickConflictDescription")}),h({kind:"conflict",state:F.state,details:F.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(F.state)))}catch(F){const te=F instanceof Error?F.message:String(F);ae.error(l("gitView.integrate.failedToMoveToast"),{description:te});const Z=await Qi({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(Z?{kind:"ready",plan:Z}:{kind:"idle"})}}},[b,c,t,e,x,j,l]),H=et.useCallback(async()=>{if(b.kind==="conflict")try{await Tx(b.state),ae.message(l("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const F=await Qi({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(F?{kind:"ready",plan:F}:{kind:"idle"})}},[b,t,e,x,j,l]),R=et.useCallback(async()=>{if(b.kind==="conflict")try{const F=await Ex(b.state);if(F.kind==="success"){ae.success(l("gitView.integrate.cherryPickFinishedToast"));const te=await Qi({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(te?{kind:"ready",plan:te}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),c?.();return}F.kind==="conflict"&&(h({kind:"conflict",state:F.state,details:F.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(F.state)))}catch(F){const te=F instanceof Error?F.message:String(F);ae.error(l("gitView.integrate.cherryPickContinueFailedToast"),{description:te})}},[b,t,e,x,c,j,l]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(I,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:l("gitView.integrate.title")}),b.kind==="ready"&&b.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:l("gitView.integrate.toMoveCount",{count:b.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:b.kind==="loading"||b.kind==="running"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",x]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(on,{open:d,onOpenChange:f,children:[s.jsx(nn,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"sm",className:"gap-1.5",children:[l("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:x}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(rn,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(ma,{className:"h-full min-h-0",children:[s.jsx(fa,{ref:g,placeholder:l("gitView.branch.searchPlaceholder"),onKeyDown:F=>F.stopPropagation()}),s.jsxs(ha,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(pa,{children:l("gitView.branch.empty")}),s.jsx(qr,{heading:l("gitView.branch.localBranches"),children:r.map(F=>s.jsx(Zr,{value:F,onSelect:()=>{p(F),k(F),f(!1)},children:F},F))})]})]})})]}),b.kind==="ready"?s.jsx(ze,{size:"sm",onClick:()=>{M()},disabled:!y||b.plan.commits.length===0,children:l("gitView.integrate.move")}):b.kind==="loading"?s.jsx(ze,{size:"sm",variant:"outline",disabled:!0,children:l("gitView.integrate.checking")}):b.kind==="running"?s.jsx(ze,{size:"sm",variant:"outline",disabled:!0,children:l("gitView.integrate.moving")}):null]}),b.kind==="ready"&&b.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.integrate.noCommitsToMove")}),b.kind==="ready"&&b.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[l("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",b.plan.commits.length,")"]})]}),S.length>0&&b.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>w(F=>!F),className:"typography-micro text-muted-foreground hover:text-foreground",children:l(N?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(N?S:S.slice(0,5)).map(F=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:F.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:F.subject||F.sha})]},F.sha)),S.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.integrate.previewUnavailable")}),b.plan.commits.length>S.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:l("gitView.integrate.showingFirstCommits",{count:S.length})})]})]}),b.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:l("gitView.integrate.conflictsInFiles",{count:b.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[l("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:b.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[b.details.unmergedFiles.slice(0,6).map(F=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:F},F)),b.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:l("gitView.integrate.moreFiles",{count:b.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ze,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{H()},children:l("gitView.operation.abort")}),s.jsxs(ze,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!u,onClick:()=>{E({state:b.state,details:b.details},!1)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),l("gitView.integrate.currentSession")]}),s.jsxs(ze,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{E({state:b.state,details:b.details},!0)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),l("gitView.integrate.newSession")]}),s.jsx(ze,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:l("gitView.operation.continue")})]})]})]})]})},Mx=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:o=!1,uncommittedFileCount:i,onChanged:c})=>{const{t:l}=Tt(),[u,m]=a.useState([]),[d,f]=a.useState(!1),[g,x]=a.useState(""),[p,y]=a.useState(""),[b,h]=a.useState(null),[N,w]=a.useState({}),S=a.useCallback(async()=>{if(n){f(!0);try{const C=await Pf(n);m(C.stashes),w({})}catch(C){ae.error(C instanceof Error?C.message:l("gitView.stashes.toast.loadFailed"))}finally{f(!1)}}},[n,l]);a.useEffect(()=>{t&&S()},[S,t]),a.useEffect(()=>{if(!t||!n||u.length===0)return;let C=!1;const P=u.map(E=>E.ref);return Tf(n,P).then(E=>{C||w(E.counts)}).catch(()=>{}),()=>{C=!0}},[n,t,u]);const v=a.useMemo(()=>{const C=g.trim().toLowerCase();return C?u.filter(P=>`${P.ref} ${P.message} ${P.relativeTime}`.toLowerCase().includes(C)):u},[g,u]),j=a.useCallback(async C=>{await S(),await c?.(C)},[S,c]),k=async()=>{if(!(!n||b)){h("create");try{const C=await Ef(n,{message:p.trim()||void 0});C.created?(ae.success(l("gitView.stashes.toast.created")),y("")):ae.info(l("gitView.stashes.toast.noChanges")),await j({affectsIndex:!!(C.created&&o)})}catch(C){ae.error(C instanceof Error?C.message:l("gitView.stashes.toast.createFailed"))}finally{h(null)}}},D=async(C,P)=>{if(!(!n||b)&&!(P==="drop"&&!window.confirm(l("gitView.stashes.confirm.drop",{ref:C.ref})))){h(`${P}:${C.ref}`);try{P==="apply"&&await Rf(n,{ref:C.ref}),P==="pop"&&await Mf(n,{ref:C.ref}),P==="drop"&&await Ff(n,{ref:C.ref});const E=P==="apply"?"gitView.stashes.toast.applySuccess":P==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";ae.success(l(E)),await j({affectsIndex:P!=="drop"})}catch(E){const M=P==="apply"?"gitView.stashes.toast.applyFailed":P==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";ae.error(E instanceof Error?E.message:l(M)),await j({affectsIndex:P!=="drop"})}finally{h(null)}}},T=b!==null;return s.jsx(Ks,{open:t,onOpenChange:e,children:s.jsxs(Gs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(Xs,{children:[s.jsxs(Ys,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"archive-stack",className:"h-5 w-5"}),l("gitView.stashes.title")]}),s.jsx(cn,{children:l("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(kn,{value:p,onChange:C=>y(C.target.value),placeholder:l("gitView.stashes.messagePlaceholder"),disabled:T||!r,className:"flex-1"}),s.jsxs(ze,{onClick:k,disabled:!r||T||!n,children:[b==="create"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"inbox-archive",className:"size-4"}),l("gitView.stashes.actions.stashCurrentWithCount",{count:i})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:l("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(I,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(kn,{value:g,onChange:C=>x(C.target.value),placeholder:l("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:d?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(I,{name:"loader-4",className:"size-5 animate-spin"})}):v.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:l(g?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):v.map((C,P)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:C.message||l("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{children:P===0&&!g.trim()?l("gitView.stashes.latestLabel"):l("gitView.stashes.itemNumber",{number:P+1})})}),s.jsx(_t,{sideOffset:6,children:C.ref})]})," · ",C.relativeTime," · ",typeof N[C.ref]=="number"?l("gitView.stashes.fileCount",{count:N[C.ref]}):l("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(Va,{label:l("gitView.stashes.actions.apply"),loading:b===`apply:${C.ref}`,onClick:()=>D(C,"apply"),disabled:T,children:s.jsx(I,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(Va,{label:l("gitView.stashes.actions.pop"),loading:b===`pop:${C.ref}`,onClick:()=>D(C,"pop"),disabled:T,children:s.jsx(I,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(Va,{label:l("gitView.stashes.actions.drop"),loading:b===`drop:${C.ref}`,onClick:()=>D(C,"drop"),disabled:T,destructive:!0,children:s.jsx(I,{name:"delete-bin",className:"size-4"})})]})]},C.ref))})]})})},Va=t=>{const e=gt.c(17),{label:n,loading:r,disabled:o,destructive:i,onClick:c,children:l}=t,u=r||void 0,m=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let d;e[0]!==m?(d=Te("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",m),e[0]=m,e[1]=d):d=e[1];let f;e[2]!==l||e[3]!==r?(f=r?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):l,e[2]=l,e[3]=r,e[4]=f):f=e[4];let g;e[5]!==o||e[6]!==n||e[7]!==c||e[8]!==u||e[9]!==d||e[10]!==f?(g=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":u,className:d,onClick:c,disabled:o,children:f})}),e[5]=o,e[6]=n,e[7]=c,e[8]=u,e[9]=d,e[10]=f,e[11]=g):g=e[11];let x;e[12]!==n?(x=s.jsx(_t,{sideOffset:6,children:n}),e[12]=n,e[13]=x):x=e[13];let p;return e[14]!==g||e[15]!==x?(p=s.jsxs(Lt,{children:[g,x]}),e[14]=g,e[15]=x,e[16]=p):p=e[16],p},Fx=t=>{const e=gt.c(16),{onOpenStashes:n}=t,{t:r}=Tt();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(I,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=o):o=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let c;e[3]!==i?(c=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=c):c=e[4];let l;e[5]!==r?(l=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=l):l=e[6];let u;e[7]!==l?(u=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:l}),e[7]=l,e[8]=u):u=e[8];let m;e[9]!==n||e[10]!==r?(m=n?s.jsxs(ze,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(I,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=m):m=e[11];let d;return e[12]!==c||e[13]!==u||e[14]!==m?(d=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[o,c,u,m]}),e[12]=c,e[13]=u,e[14]=m,e[15]=d):d=e[15],d},Hr=8,Lx=t=>{const e=gt.c(18),{laned:n,totalLanes:r,isExpanded:o}=t,{lane:i,color:c,connectors:l}=n,m=Math.max(r,i+1)*Hr+Hr/2,d=a.useRef(null),f=a.useRef(null);let g;e[0]!==c||e[1]!==l||e[2]!==i||e[3]!==m?(g=()=>{const h=d.current,N=f.current;if(!h||!N)return;const w=h.offsetHeight;if(w===0)return;const S=window.devicePixelRatio||1;N.width=m*S,N.height=w*S;const v=N.getContext("2d");if(!v)return;v.scale(S,S),v.clearRect(0,0,m,w);const j=w/2,k=i*Hr+Hr/2,D=getComputedStyle(N),T=D.getPropertyValue("--surface-muted-foreground").trim()||D.color,C=M=>{if(!M.startsWith("var("))return M;const H=M.slice(4,-1).trim();return D.getPropertyValue(H).trim()||T},P=[...l].sort(_x);for(const M of P){const H=M.fromLane*Hr+Hr/2,R=M.toLane*Hr+Hr/2,_=M.type==="passing"?.72:M.type==="branch-out"||M.type==="merge-in"?.95:1;v.beginPath(),v.strokeStyle=C(M.color),v.globalAlpha=_,v.lineWidth=1.25,v.lineCap="round";e:switch(M.type){case"passing":case"commit-lane":{v.moveTo(H,0),v.lineTo(H,w);break e}case"top-stub":{v.moveTo(H,0),v.lineTo(H,j);break e}case"bottom-stub":{v.moveTo(H,j),v.lineTo(H,w);break e}case"branch-out":{const z=(j+w)/2;v.moveTo(k,j),v.bezierCurveTo(k,z,R,z,R,w);break e}case"merge-in":{const z=j/2;v.moveTo(H,0),v.bezierCurveTo(H,z,k,z,k,j);break e}default:continue}v.stroke(),v.globalAlpha=1}const E=D.getPropertyValue("--background").trim()||D.getPropertyValue("--surface-background").trim();v.beginPath(),v.arc(k,j,4,0,Math.PI*2),v.fillStyle=C(c),v.fill(),v.beginPath(),v.arc(k,j,5,0,Math.PI*2),v.strokeStyle=E||T,v.lineWidth=2,v.stroke()},e[0]=c,e[1]=l,e[2]=i,e[3]=m,e[4]=g):g=e[4];let x;e[5]!==c||e[6]!==l||e[7]!==o||e[8]!==i||e[9]!==n||e[10]!==r||e[11]!==m?(x=[n,i,c,l,r,o,m],e[5]=c,e[6]=l,e[7]=o,e[8]=i,e[9]=n,e[10]=r,e[11]=m,e[12]=x):x=e[12],a.useLayoutEffect(g,x);let p;e[13]!==m?(p={width:m,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=m,e[14]=p):p=e[14];let y;e[15]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("canvas",{ref:f,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=y):y=e[15];let b;return e[16]!==p?(b=s.jsx("div",{ref:d,style:p,children:y}),e[16]=p,e[17]=b):b=e[17],b};function Ox(t){return t==="branch-out"||t==="merge-in"}function _x(t,e){const n=Ox;return(n(t.type)?1:0)-(n(e.type)?1:0)}const td=15e3,sd=500,nd=12,rd=8*1024*1024,id=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),od=t=>{if(t.size<=nd){let o=0;for(const i of t.values())o+=id(i);if(o<=rd)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[o,i]of e){if(n.size>=nd)continue;const c=id(i);r+c>rd&&n.size>0||(n.set(o,i),r+=c)}return new Map(Array.from(n.entries()).reverse())};function ad(t,e){const n=new Date(t);return Number.isNaN(n.getTime())?t:ga(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Bx(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function Vx(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const $x=a.memo(({entry:t,mode:e="history",laned:n,totalLanes:r,isExpanded:o,onToggle:i,files:c,isLoadingFiles:l,onCopyHash:u,directory:m,onConflict:d,onActionSuccess:f})=>{const{t:g}=Tt(),x=Fe(U=>U.timeFormatPreference),p=e==="graph",[y,b]=a.useState(null),[h,N]=a.useState(!1),[w,S]=a.useState(""),[v,j]=a.useState(null),[k,D]=a.useState(new Set),[T,C]=a.useState(new Map),[P,E]=a.useState(new Set),M=async()=>{if(m){b("checkout");try{await Wf(m,t.hash),ae.success(g("gitView.history.actions.detachedHead")),f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},H=async()=>{if(!(!m||!w.trim())){b("createBranch");try{await Of(m,w.trim(),t.hash),N(!1),S(""),f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},R=async()=>{if(m){b("cherryPick");try{const U=await zf(m,t.hash);U.conflict?d?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"cherry-pick"}):f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},_=async()=>{if(m){b("revert");try{const U=await $f(m,t.hash);U.conflict?d?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"revert"}):f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},z=async(U,ie=!1)=>{if(!(!m||y!==null)){b("reset");try{await _f(m,t.hash,U,ie),f?.()}catch(oe){ae.error(String(oe.message))}finally{b(null)}}},V=async()=>{if(!v)return;const U=v;switch(j(null),U){case"checkout":return M();case"cherryPick":return R();case"revert":return _();case"merge":return F();case"rebase":return te();case"resetSoft":return z("soft");case"resetMixed":return z("mixed");case"resetHard":return z("hard",!0)}},F=async()=>{if(m){b("merge");try{const U=await Vf(m,{branch:t.hash});U.conflict?d?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"merge"}):f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},te=async()=>{if(m){b("rebase");try{const U=await Bf(m,{onto:t.hash});U.conflict?d?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"rebase"}):f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},Z=a.useCallback(async U=>{const ie=U.path;if(!m){C(oe=>new Map(oe).set(ie,"error"));return}C(oe=>od(new Map(oe).set(ie,"loading")));try{const oe=Lf(m,t.hash,U.path,!1),ge=new Promise((Se,re)=>{setTimeout(()=>re(new Error(`Timed out after ${td}ms`)),td)}),je=await Promise.race([oe,ge]);C(Se=>od(new Map(Se).set(ie,je)))}catch{C(oe=>new Map(oe).set(ie,"error"))}},[m,t.hash]),ne=a.useCallback(async U=>{const ie=U.path;if(U.changeType==="R"||U.isBinary){D(Se=>{const re=new Set(Se);return re.has(ie)?re.delete(ie):re.add(ie),re});return}const oe=T.get(ie);if(k.has(ie)&&oe&&oe!=="error"){D(Se=>{const re=new Set(Se);return re.delete(ie),re});return}D(Se=>{const re=new Set(Se);return re.add(ie),re}),!(oe&&oe!=="error"||U.insertions+U.deletions>sd&&!P.has(ie))&&await Z(U)},[T,P,Z,k]);return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:i,className:Te("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",p?"hover:bg-[var(--interactive-hover)]/40":o?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[p&&n&&r!==void 0?s.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:s.jsx(Lx,{laned:n,totalLanes:r,isExpanded:o})}):s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[p?(()=>{const U=Vx(t.refs);return U.length>0?s.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:U.map(ie=>s.jsx("span",{className:Te("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",ie.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":ie.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:ie.label},ie.label))}):null})():null,s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:t.message}),s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[s.jsx("span",{className:"truncate min-w-[3ch]",title:t.author_name,children:t.author_name}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("span",{className:"truncate min-w-0",title:ad(t.date,x),children:ad(t.date,x)})]}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("code",{className:"shrink-0 font-mono",children:t.hash.slice(0,8)}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:U=>{U.stopPropagation(),u(t.hash)},children:s.jsx(I,{name:"file-copy",className:"size-3"})})}),s.jsx(_t,{sideOffset:8,children:g("gitView.history.copySha")})]})]})]})]}),o&&s.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[p&&v?s.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:g(`gitView.history.actions.${v}Confirm`)}),s.jsxs(ze,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:y!==null,onClick:U=>{U.stopPropagation(),V()},children:[y!==null?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.confirmButton")]}),s.jsx(ze,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:y!==null,onClick:U=>{U.stopPropagation(),j(null)},children:g("gitView.history.actions.cancelButton")})]}):p?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("checkout")},children:g("gitView.history.actions.checkout")}),h?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("input",{autoFocus:!0,value:w,onChange:U=>S(U.target.value),onKeyDown:U=>{U.key==="Enter"&&H(),U.key==="Escape"&&(N(!1),S(""))},placeholder:g("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),s.jsxs(ze,{variant:"outline",size:"xs",className:"h-6",disabled:!w.trim()||y!==null,onClick:U=>{U.stopPropagation(),H()},children:[y==="createBranch"?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.createBranchConfirm")]})]}):s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",onClick:U=>{U.stopPropagation(),N(!0)},children:g("gitView.history.actions.createBranch")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("cherryPick")},children:g("gitView.history.actions.cherryPick")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("revert")},children:g("gitView.history.actions.revert")}),s.jsxs(on,{children:[s.jsx(nn,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>U.stopPropagation(),children:[y==="reset"?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.reset")]})}),s.jsx(rn,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(U=>s.jsx(zt,{disabled:y!==null,onSelect:ie=>{ie.stopPropagation(),j(`reset${U.charAt(0).toUpperCase()+U.slice(1)}`)},children:g(`gitView.history.actions.reset${U.charAt(0).toUpperCase()+U.slice(1)}`)},U))})]}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("merge")},children:g("gitView.history.actions.merge")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("rebase")},children:g("gitView.history.actions.rebase")})]}):null,l?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:g("gitView.history.loadingFiles")})]}):c.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:g("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:c.map(U=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>ne(U),className:Te("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",k.has(U.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:Te("font-semibold w-3 text-center shrink-0",Bx(U.changeType)),children:U.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:U.path,children:U.path}),!U.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",U.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",U.deletions]})]}),U.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:g("gitView.history.binary")}),s.jsx(I,{name:k.has(U.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),k.has(U.path)&&s.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:U.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.renamedNoDiff")}):U.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.binaryNoDiff")}):(()=>{const ie=U.insertions+U.deletions;if(!P.has(U.path)&&ie>sd)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:g("gitView.history.largeDiffTitle",{count:ie})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:g("gitView.history.largeDiffDescription")}),s.jsx(ze,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{E(ge=>new Set(ge).add(U.path)),Z(U)},children:g("gitView.history.renderDiffAnyway")})]});const oe=T.get(U.path);return oe==="loading"||oe===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.loadingDiff")}):oe==="error"?s.jsx("button",{type:"button",onClick:()=>ne(U),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:g("gitView.history.diffError")}):s.jsx(Xl,{original:oe.original,modified:oe.modified,language:_i(U.path)||"",fileName:U.path,renderSideBySide:!1,layout:"inline"})})()})]},U.path))})]})]})}),ld=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function Co(t){return ld[t%ld.length]}function zx(t){if(t.length===0)return[];const e=[],n=[];for(let r=0;r<t.length;r++){const o=t[r],i=[];for(let x=0;x<e.length;x++)e[x]===o.hash&&i.push(x);let c=i.length>0?i[0]:-1;if(c===-1){const x=e.indexOf(null);x!==-1?c=x:(c=e.length,e.push(null))}const l=i.slice(1),u=Co(c),m=e[c]===o.hash,d=o.parents.length>0;d?e[c]=o.parents[0]:e[c]=null;const f=[];for(let x=1;x<o.parents.length;x++){const p=o.parents[x],y=e.indexOf(p);if(y!==-1)f.push(y);else{const b=e.indexOf(null),h=b!==-1?b:e.length;e[h]=p,h===e.length&&e.push(p),f.push(h)}}const g=[];m&&d?g.push({fromLane:c,toLane:c,color:u,type:"commit-lane"}):m&&!d?g.push({fromLane:c,toLane:c,color:u,type:"top-stub"}):!m&&d&&g.push({fromLane:c,toLane:c,color:u,type:"bottom-stub"});for(const x of l)g.push({fromLane:x,toLane:c,color:Co(x),type:"merge-in"}),e[x]=null;for(const x of f)g.push({fromLane:c,toLane:x,color:Co(x),type:"branch-out"});for(let x=0;x<e.length;x++)e[x]!==null&&x!==c&&(f.includes(x)||g.push({fromLane:x,toLane:x,color:Co(x),type:"passing"}));n.push({commit:o,lane:c,color:u,connectors:g})}return n}const Wx=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Ux=t=>{const e=gt.c(84),{mode:n,log:r,isLogLoading:o,logMaxCount:i,onLogMaxCountChange:c,expandedCommitHashes:l,onToggleCommit:u,commitFilesMap:m,loadingCommitHashes:d,onCopyHash:f,directory:g,showHeader:x,contentMaxHeightClassName:p,branchDivider:y,onConflict:b,onActionSuccess:h}=t,N=n===void 0?"history":n,w=x===void 0?!0:x,S=p===void 0?"max-h-[50vh]":p,v=y===void 0?null:y,{t:j}=Tt(),[k,D]=a.useState(!0),T=N==="graph";let C;e[0]!==T||e[1]!==r?(C=T&&r?zx(r.all):[],e[0]=T,e[1]=r,e[2]=C):C=e[2];const P=C;let E;e[3]!==P?(E=Math.max(1,...P.map(Hx)),e[3]=P,e[4]=E):E=e[4];const M=E;let H;e[5]!==P?(H=new Map(P.map(Gx)),e[5]=P,e[6]=H):H=e[6];const R=H;if(!r)return null;const _=v!==null&&v.insertBeforeIndex>0&&v.insertBeforeIndex<r.all.length,z=v!==null&&v.insertBeforeIndex===r.all.length,V=_||z;let F;e[7]!==v||e[8]!==_||e[9]!==z||e[10]!==r.all?(F=_?r.all.slice(0,v.insertBeforeIndex):z?r.all:[],e[7]=v,e[8]=_,e[9]=z,e[10]=r.all,e[11]=F):F=e[11];const te=F;let Z;if(e[12]!==v||e[13]!==m||e[14]!==S||e[15]!==g||e[16]!==l||e[17]!==_||e[18]!==V||e[19]!==T||e[20]!==o||e[21]!==R||e[22]!==d||e[23]!==r.all||e[24]!==i||e[25]!==M||e[26]!==N||e[27]!==h||e[28]!==b||e[29]!==f||e[30]!==c||e[31]!==u||e[32]!==j||e[33]!==te){const $=_?r.all.slice(v.insertBeforeIndex):[];let q;e[35]!==v?.direction?(q=v?.direction==="down"?s.jsx(I,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"}),e[35]=v?.direction,e[36]=q):q=e[36];const he=q;let de;e[37]!==m||e[38]!==g||e[39]!==l||e[40]!==T||e[41]!==R||e[42]!==d||e[43]!==M||e[44]!==N||e[45]!==h||e[46]!==b||e[47]!==f||e[48]!==u?(de=le=>s.jsx("ul",{className:"divide-y divide-border/60",children:le.map(ke=>s.jsx($x,{entry:ke,mode:N,laned:T?R.get(ke.hash):void 0,totalLanes:T?M:void 0,isExpanded:l.has(ke.hash),onToggle:()=>u(ke.hash),files:m.get(ke.hash)??[],isLoadingFiles:d.has(ke.hash),onCopyHash:f,directory:g,onConflict:b,onActionSuccess:h},ke.hash))}),e[37]=m,e[38]=g,e[39]=l,e[40]=T,e[41]=R,e[42]=d,e[43]=M,e[44]=N,e[45]=h,e[46]=b,e[47]=f,e[48]=u,e[49]=de):de=e[49];const we=de;let be;e[50]!==o||e[51]!==r.all.length||e[52]!==i||e[53]!==c||e[54]!==j?(be=r.all.length>=i?s.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:s.jsx(ze,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(i+25),disabled:o,className:"px-3 text-muted-foreground hover:text-foreground",children:o?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"loader-4",className:"size-3 animate-spin"}),j("gitView.history.loadingMore")]}):j("gitView.history.loadMore")})}):null,e[50]=o,e[51]=r.all.length,e[52]=i,e[53]=c,e[54]=j,e[55]=be):be=e[55];const De=be;Z=s.jsx(Fn,{outerClassName:`min-h-0 ${S}`,className:"h-full w-full",children:r.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:j("gitView.history.noCommits")})}):V&&v?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-0",children:[te.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:we(te)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:v.branchName,children:v.branchName}),he]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),$.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:we($)}):null]}),De]}):s.jsxs(s.Fragment,{children:[we(r.all),De]})}),e[12]=v,e[13]=m,e[14]=S,e[15]=g,e[16]=l,e[17]=_,e[18]=V,e[19]=T,e[20]=o,e[21]=R,e[22]=d,e[23]=r.all,e[24]=i,e[25]=M,e[26]=N,e[27]=h,e[28]=b,e[29]=f,e[30]=c,e[31]=u,e[32]=j,e[33]=te,e[34]=Z}else Z=e[34];const ne=Z;if(!w){if(V){let q;return e[56]!==ne?(q=s.jsx("section",{className:"h-full min-h-0",children:ne}),e[56]=ne,e[57]=q):q=e[57],q}let $;return e[58]!==ne?($=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ne}),e[58]=ne,e[59]=$):$=e[59],$}let U;e[60]!==j?(U=j("gitView.history.title"),e[60]=j,e[61]=U):U=e[61];let ie;e[62]!==U?(ie=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:U}),e[62]=U,e[63]=ie):ie=e[63];let oe;e[64]!==o||e[65]!==k||e[66]!==i||e[67]!==c||e[68]!==j?(oe=k&&s.jsx("div",{onClick:Kx,onPointerDown:qx,children:s.jsxs(Bn,{value:String(i),onValueChange:$=>c(Number($)),disabled:o,children:[s.jsx(Vn,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:o,children:s.jsx(Pn,{placeholder:j("gitView.history.commitsPlaceholder")})}),s.jsx($n,{children:Wx.map($=>s.jsx(qs,{value:String($.value),children:j($.labelKey)},$.value))})]})}),e[64]=o,e[65]=k,e[66]=i,e[67]=c,e[68]=j,e[69]=oe):oe=e[69];let ge;e[70]!==k?(ge=k?s.jsx(I,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=k,e[71]=ge):ge=e[71];let je;e[72]!==oe||e[73]!==ge?(je=s.jsxs("div",{className:"flex items-center gap-2",children:[oe,ge]}),e[72]=oe,e[73]=ge,e[74]=je):je=e[74];let Se;e[75]!==ie||e[76]!==je?(Se=s.jsxs(jo,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[ie,je]}),e[75]=ie,e[76]=je,e[77]=Se):Se=e[77];let re;e[78]!==ne?(re=s.jsx(zi,{children:ne}),e[78]=ne,e[79]=re):re=e[79];let L;return e[80]!==k||e[81]!==Se||e[82]!==re?(L=s.jsxs($i,{open:k,onOpenChange:D,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[Se,re]}),e[80]=k,e[81]=Se,e[82]=re,e[83]=L):L=e[83],L};function Hx(t){return t.lane+1}function Gx(t){return[t.commit.hash,t]}function Kx(t){return t.stopPropagation()}function qx(t){return t.stopPropagation()}const nm=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),o=new Array(t.length);let i=0;const c=async()=>{for(;;){const l=i;if(i+=1,l>=t.length)return;o[l]=await n(t[l])}};return await Promise.all(Array.from({length:r},()=>c())),o},Yx=9e4,Jx=15e3,Qx=5*6e4,Xx=[2e3,5e3],Zx=6e4,eb=2*6e4,tb=5*6e4,sb=4,nb=720*6e4,rb="openchamber.github-pr-status",ib=t=>t==="closed"||t==="merged",ob=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},ao=(t,e,n)=>`${t}::${e}`,Ao=new Map,Do=new Map,Xi=new Set,cd=new Map,no=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),aa=t=>t?.params?.directory&&t.params.branch?{directory:t.params.directory,branch:t.params.branch,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null}:!t?.identity?.directory||!t.identity.branch?null:t.identity,ec=t=>{const e=aa(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},rm=(t,e)=>Object.entries(t).filter(([,n])=>ec(n)===e).map(([n])=>n),ab=(t,e)=>{const n=e.remoteName??t.params?.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null;return{...t,params:t.params?{...t.params,...e,remoteName:n}:{...e,remoteName:n},identity:{directory:e.directory,branch:e.branch,remoteName:n}}},Io=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},lb=(t,e,n)=>{const r=rm(t,e),o=r.map(u=>Io(t[u])).filter(u=>!!u);if(o.length===0)return null;const i=Io(t[n]);if(i&&ec(t[n])===e)return i;const c=r.map(u=>t[u]).find(u=>!!(u?.resolvedRemoteName&&Io(u)));if(c)return Io(c);const l=o.find(u=>!!u.remoteName);return l||(o[0]??null)},cb=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:aa(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),db=t=>({...no(),status:t?.status??null,isInitialStatusResolved:t?.isInitialStatusResolved??!1,lastRefreshAt:t?.lastRefreshAt??0,lastDiscoveryPollAt:t?.lastDiscoveryPollAt??0,identity:t?.identity??null,resolvedRemoteName:t?.resolvedRemoteName??t?.status?.resolvedRemoteName??null}),er=vi()(El((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:no()}})},setParams:(n,r)=>{t(o=>{const i=o.entries[n]??no();return{entries:{...o.entries,[n]:ab(i,r)}}})},startWatching:n=>{if(t(i=>{const c=i.entries[n]??no();return{entries:{...i.entries,[n]:{...c,watchers:c.watchers+1}}}}),Ao.has(n))return;const r=i=>{const c=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const u=e().entries[n];!u||u.watchers<=0||u.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},i),l=Do.get(n)??[];l.push(c),Do.set(n,l)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),Xx.forEach(i=>r(i));const o=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const i=e().entries[n];if(!i||i.watchers<=0)return;if(!!!i.status?.pr){const m=Date.now();if(m-i.lastDiscoveryPollAt<Qx)return;t(d=>{const f=d.entries[n];return f?{entries:{...d.entries,[n]:{...f,lastDiscoveryPollAt:m}}}:d}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(ib(i.status?.pr?.state))return;const l=Date.now()-i.lastRefreshAt,u=ob(i.status)?Zx:i.status?.checks&&i.status.checks.state!=="pending"?tb:eb;l<u||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},Jx);Ao.set(n,o)},stopWatching:n=>{t(c=>{const l=c.entries[n];if(!l)return c;const u=Math.max(0,l.watchers-1);return{entries:{...c.entries,[n]:{...l,watchers:u}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const o=Ao.get(n);typeof o=="number"&&window.clearInterval(o),Ao.delete(n);const i=Do.get(n);i&&i.length>0&&i.forEach(c=>{window.clearTimeout(c)}),Do.delete(n)},refresh:async(n,r)=>{const o=e(),i=o.entries[n],c=ec(i);if(!i||!c)return;const l=rm(o.entries,c),u=l.some(f=>!!o.entries[f]?.status?.pr);if(r?.onlyExistingPr&&!u)return;const m=cd.get(c)??0;if(!r?.force&&Date.now()-m<Yx||Xi.has(c))return;const d=lb(o.entries,c,n);if(d){if(Xi.add(c),cd.set(c,Date.now()),t(f=>{const g={...f.entries};return l.forEach(x=>{const p=g[x];p&&(g[x]={...p,lastRefreshAt:Date.now(),isLoading:r?.silent?p.isLoading:!0,error:null})}),{entries:g}}),d.githubAuthChecked&&d.githubConnected===!1){t(f=>{const g={...f.entries};return l.forEach(x=>{const p=g[x];p&&(g[x]={...p,status:{connected:!1},error:null,isLoading:r?.silent?p.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?p.isInitialStatusResolved:!0})}),{entries:g}}),Xi.delete(c);return}if(!d.github?.prStatus){t(f=>{const g={...f.entries};return l.forEach(x=>{const p=g[x];p&&(g[x]={...p,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?p.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?p.isInitialStatusResolved:!0})}),{entries:g}}),Xi.delete(c);return}try{t(g=>({...g,activeRequestCount:g.activeRequestCount+1,totalRequestCount:g.totalRequestCount+1}));const f=await d.github.prStatus(d.directory,d.branch,d.remoteName??void 0,{force:r?.force});t(g=>{const x={...g.entries};return l.forEach(p=>{const y=x[p];if(!y)return;const b=y.status?.pr,h=f.pr,w=!!(h&&b&&h.number===b.number&&(!h.body||!h.body.trim())&&typeof b.body=="string"&&b.body.trim().length>0)&&h&&b?.body?{...f,pr:{...h,body:b.body}}:f,S=w.resolvedRemoteName??y.resolvedRemoteName??d.remoteName??null,v=aa(y)??{directory:d.directory,branch:d.branch,remoteName:d.remoteName??null};x[p]={...y,status:w,error:null,isLoading:r?.silent?y.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?y.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...v,remoteName:S??v.remoteName??null}}}),{entries:x}})}catch(f){const g=f instanceof Error?f.message:String(f);t(x=>{const p={...x.entries};return l.forEach(y=>{const b=p[y];b&&(p[y]={...b,error:g||"Failed to load PR status",isLoading:r?.silent?b.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?b.isInitialStatusResolved:!0})}),{entries:p}})}finally{Xi.delete(c),t(f=>({...f,activeRequestCount:Math.max(0,f.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const o=Array.from(new Set(n.map(i=>{const c=i.directory.trim(),l=i.branch.trim();return!c||!l?null:ao(c,l,i.remoteName??null)}).filter(i=>!!i)));await nm(o,sb,i=>e().refresh(i,r))},updateStatus:(n,r)=>{t(o=>{const i=o.entries[n]??no();return{entries:{...o.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:rb,storage:mu(()=>Dr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=aa(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<nb}).map(([e,n])=>[e,cb(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([o,i])=>[o,db(i)]))}}})),ub=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",o=e.mergeable===!1||r==="blocked"||r==="dirty";return n||o?"blocked":"open"},mb=t=>{const e=ub(t.status??null),n=t.status?.pr;return!e||!n?.number?null:{number:n.number,visualState:e,prState:n.state,draft:!!n.draft,title:typeof n.title=="string"&&n.title.trim().length>0?n.title:null,url:typeof n.url=="string"&&n.url.trim().length>0?n.url:null,base:typeof n.base=="string"&&n.base.trim().length>0?n.base:null,head:typeof n.head=="string"&&n.head.trim().length>0?n.head:null,checks:t.status?.checks?{state:t.status.checks.state,total:t.status.checks.total,success:t.status.checks.success,failure:t.status.checks.failure,pending:t.status.checks.pending}:null,canMerge:typeof t.status?.canMerge=="boolean"?t.status.canMerge:null,mergeableState:typeof n.mergeableState=="string"?n.mergeableState:null,repo:t.status?.repo?{owner:t.status.repo.owner,repo:t.status.repo.repo}:null}},fb=t=>`${t.number}:${t.visualState}:${t.prState}:${t.draft}:${t.title??""}:${t.url??""}:${t.base??""}:${t.head??""}:${t.canMerge??""}:${t.mergeableState??""}:${t.checks?.state??""}:${t.checks?.total??""}:${t.checks?.success??""}:${t.checks?.failure??""}:${t.checks?.pending??""}:${t.repo?.owner??""}:${t.repo?.repo??""}`;let $a=new Map,dd=new Map;const hb=t=>{const e=gt.c(2);let n;return e[0]!==t?(n=r=>{const o=new Map,i=new Map;for(const c of t){const l=r.entries[c];if(!l)continue;const u=mb(l);if(!u)continue;const m=fb(u);o.set(c,m),i.set(c,u)}if(o.size===$a.size){let c=!0;for(const[l,u]of o)if($a.get(l)!==u){c=!1;break}if(c)return dd}return $a=o,dd=i,i},e[0]=t,e[1]=n):n=e[1],er(n)},pb=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},gb=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",o=e.mergeable===!1||r==="blocked"||r==="dirty";return n||o?"blocked":"open"},xb=[2e3,5e3],ud=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),Gr=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},bb=(t,e)=>{const n=Gr(t);if(!n||n.includes("->"))return"";if(e){const o=`${e}/`;return n.startsWith(o)?n.slice(o.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},yb=(t,e)=>`${t}::${e}`,tc=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},za=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(c=>c.name===n);if(i)return i}const r=tc(e.trackingBranch);if(r){const i=r==="origin"?t.find(l=>l.name==="upstream"):null;if(i)return i;const c=t.find(l=>l.name===r);if(c)return c}const o=t.find(i=>i.name==="origin");return o||(t[0]??null)},wb=t=>t.startsWith("pr-"),vb=(t,e)=>{const n=tc(e),r=new Map(t.map(c=>[c.name,c])),o=[],i=c=>{c&&(o.some(l=>l.name===c.name)||o.push(c))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(c=>!wb(c.name)).forEach(c=>i(c)),t.forEach(c=>i(c)),o},Wa=new Map,Ua=xi;function jb(t,e){const[n,r]=a.useState(null),[o,i]=a.useState([]),c=a.useRef(null);return a.useEffect(()=>{r(null),i([])},[t]),a.useEffect(()=>{if(!t||!e?.repoUpstream||c.current===t)return;c.current=t;let l=!1;return(async()=>{try{const u=await e.repoUpstream(t);if(l||!u?.isFork||!u.upstream||(r(u.upstream),!e.repoBranches))return;try{const m=await e.repoBranches(u.upstream.owner,u.upstream.repo);l||i(m)}catch{}}catch{}})(),()=>{l=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:o}}const Sb=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:i=[],onGeneratedDescription:c})=>{const{t:l}=Tt(),u=Fe(W=>W.timeFormatPreference),{github:m}=Wn(),d=bi(W=>W.status),f=bi(W=>W.hasChecked),g=Fe(W=>W.setSettingsDialogOpen),x=Fe(W=>W.setSettingsPage),p=Fe(W=>W.setActiveMainTab),y=vt(W=>W.currentSessionId),{isMobile:b,hasTouchInput:h}=Pr(),N=a.useCallback(()=>{x("github"),g(!0)},[g,x]),w=a.useMemo(()=>yb(t,e),[t,e]),S=a.useMemo(()=>Wa.get(w)??null,[w]),v=er(W=>W.ensureEntry),j=er(W=>W.setParams),k=er(W=>W.startWatching),D=er(W=>W.stopWatching),T=er(W=>W.refresh),C=er(W=>W.updateStatus),[P,E]=a.useState(()=>S?.title??ud(e)),[M,H]=a.useState(()=>S?.body??""),[R,_]=a.useState(()=>S?.draft??!1),[z,V]=a.useState(()=>S?.additionalContext??""),[F,te]=a.useState(()=>{const W=typeof S?.targetBaseBranch=="string"?Gr(S.targetBaseBranch):"";return W||Gr(n)}),[Z,ne]=a.useState("squash"),[U,ie]=a.useState(!1),[oe,ge]=a.useState(!1),[je,Se]=a.useState(!1),[re,L]=a.useState(!1),[$,q]=a.useState(!1),[he,de]=a.useState(!1),[we,be]=a.useState(null),[De,le]=a.useState(""),[ke,ue]=a.useState(""),[ve,G]=a.useState(!1),[Ae,ce]=a.useState(!1),[fe,Ee]=a.useState(()=>za(o,{selectedRemoteName:S?.selectedRemoteName,trackingBranch:r})),[me,B]=a.useState(!1),{detectedUpstream:ye,upstreamBranches:Oe}=jb(t,m);a.useEffect(()=>{B(!1)},[t]);const Q=o.some(W=>W.name==="upstream"),Re=!!(t&&e&&n&&(e!==n||(Q||ye!==null))),Ne=a.useMemo(()=>ao(t,e),[t,e]),Be=er(W=>W.entries[Ne]),se=Be?.isLoading??!1,O=Be?.status??null,A=Be?.error??null,K=Be?.isInitialStatusResolved??!1,pe=a.useMemo(()=>{const W=me?null:fe?.name?.trim()||null,qe=new Set;for(const Ct of i){const ut=bb(Ct,W);!ut||ut==="HEAD"||qe.add(ut)}if(me)for(const Ct of Oe)Ct&&Ct!=="HEAD"&&qe.add(Ct);const Qe=Gr(n);Qe&&Qe!=="HEAD"&&qe.add(Qe);const ht=Gr(F);return ht&&ht!=="HEAD"&&qe.add(ht),Array.from(qe).sort((Ct,ut)=>Ct.localeCompare(ut))},[n,i,fe?.name,F,Oe,me]);a.useEffect(()=>{if(o.length===0){fe&&Ee(null);return}(!fe||!o.some(W=>W.name===fe.name))&&Ee(za(o,{selectedRemoteName:S?.selectedRemoteName,trackingBranch:r}))},[S?.selectedRemoteName,o,fe,r]),a.useEffect(()=>{const W=Gr(n);if(!F&&W){te(W);return}if(pe.length!==0&&!pe.includes(F)){const qe=pe.includes(W)?W:pe[0];qe&&te(qe)}},[pe,n,F]);const[_e,We]=a.useState(!1),[Le,rt]=a.useState(null),[yt,Dt]=a.useState(!1),[st,Pe]=a.useState(new Set),[tt,Ye]=a.useState(!1),[nt,ft]=a.useState(null),[mt,ot]=a.useState(!1),It=a.useRef(new Set),dt=a.useRef(null),bt=a.useRef(!1),He=a.useRef(new Set),Ze=a.useRef([]);a.useEffect(()=>{ye&&!Q&&B(!0)},[ye,Q]),a.useEffect(()=>{me&&ye?.defaultBranch&&te(ye.defaultBranch)},[me,ye?.defaultBranch]);const Ue=O?.pr??null,jt=Ue?`${t}#${Ue.number}`:null,Ge=!!(jt&&we===jt);a.useEffect(()=>{if(!m?.prContext||!Ue||typeof Ue.body=="string"&&Ue.body.length>0)return;const W=`${t}#${Ue.number}`;if(It.current.has(W))return;It.current.add(W),be(W);let qe=!1;return m.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1}).then(Qe=>{if(qe)return;const ht=Qe?.pr;ht&&C(Ne,Ct=>!Ct?.pr||Ct.pr.number!==Ue.number?Ct:{...Ct,pr:{...Ct.pr,body:ht.body||""}})}).catch(()=>{}).finally(()=>{qe||be(Qe=>Qe===W?null:Qe)}),()=>{qe=!0}},[t,m,Ue,Ne,C]),a.useEffect(()=>{if(!Ue){de(!1),le(""),ue(""),dt.current=null;return}const W=dt.current!==null&&dt.current!==Ue.number;W&&de(!1),(!he||W)&&(le(Ue.title||""),ue(Ue.body||"")),dt.current=Ue.number},[he,Ue]);const it=a.useCallback(async()=>{if(!m?.prContext){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(Ue){We(!0),Pe(new Set),Dt(!0);try{const W=await m.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!0});rt(W)}catch(W){const qe=W instanceof Error?W.message:String(W);ae.error(l("gitView.pr.toast.loadCheckDetailsFailed"),{description:qe})}finally{Dt(!1)}}},[t,m,Ue,l]),Et=a.useCallback(async()=>{if(!m?.prContext){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(Ue){Ye(!0),ot(!0);try{const W=await m.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1});ft(W)}catch(W){const qe=W instanceof Error?W.message:String(W);ae.error(l("gitView.pr.toast.loadCommentsFailed"),{description:qe})}finally{ot(!1)}}},[t,m,Ue,l]),lt=a.useCallback(W=>{if(!W)return"";const qe=Date.parse(W);return Number.isFinite(qe)?ga(qe,u,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):W},[u]),ct=a.useMemo(()=>{const W=d?.user?.login;return typeof W=="string"?W.trim():""},[d]),Bt=a.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),Ft=a.useCallback(W=>{const qe=ct.toLowerCase(),Qe=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return W.replace(Qe,(ht,Ct,ut)=>{const ts=`@${ut}`,js=ut.toLowerCase();return`${Ct}[${ts}](https://github.com/${js}${qe&&js===qe?"?oc-self-mention=1":""})`})},[ct]),qt=a.useMemo(()=>{const W=(nt?.issueComments??[]).map(ht=>({id:`issue-${ht.id}`,body:ht.body||"",authorName:ht.author?.name||ht.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:ht.author?.login||null,avatarUrl:ht.author?.avatarUrl||null,createdAt:ht.createdAt,context:l("gitView.pr.comments.generalContext"),path:null,line:null})),qe=(nt?.reviewComments??[]).map(ht=>({id:`review-${ht.id}`,body:ht.body||"",authorName:ht.author?.name||ht.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:ht.author?.login||null,avatarUrl:ht.author?.avatarUrl||null,createdAt:ht.createdAt,context:l("gitView.pr.comments.reviewContext"),path:ht.path||null,line:ht.line??null})),Qe=[...W,...qe];return Qe.sort((ht,Ct)=>{const ut=ht.createdAt?Date.parse(ht.createdAt):0,ts=Ct.createdAt?Date.parse(Ct.createdAt):0,js=Number.isFinite(ut)?ut:0,xs=Number.isFinite(ts)?ts:0;return js-xs}),Qe},[nt,l]),Ut=a.useCallback(()=>{if(!y)return ae.error(l("gitView.pr.toast.noActiveSession"),{description:l("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:W,currentModelId:qe,currentAgentName:Qe,currentVariant:ht}=cs.getState(),Ct=$l.getState().lastUsedProvider,ut=W||Ct?.providerID,ts=qe||Ct?.modelID;return!ut||!ts?(ae.error(l("gitView.pr.toast.noModelSelected")),null):{sessionId:y,providerID:ut,modelID:ts,currentAgentName:Qe??null,currentVariant:ht??null}},[y,l]),At=a.useCallback((W,qe,Qe,ht)=>{vt.getState().sendMessage(qe,W.providerID,W.modelID,W.currentAgentName??void 0,void 0,void 0,[{text:Qe,synthetic:!0},{text:ht,synthetic:!0}],W.currentVariant??void 0).catch(Ct=>{const ut=Ct instanceof Error?Ct.message:String(Ct);ae.error(l("gitView.pr.toast.sendMessageFailed"),{description:ut})})},[l]),Xt=a.useCallback(W=>{const qe=W.status||"unknown",Qe=W.conclusion??void 0,ht=Qe?`${qe} / ${Qe}`:qe,Ct=W.app?.name||W.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:W.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Ct?`${Ct} · ${ht}`:ht})]}),W.detailsUrl?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:W.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),W.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:W.output.title}):null,W.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:W.output.summary}):null,W.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:W.output.text}):null,Array.isArray(W.annotations)&&W.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",W.annotations.length>20?` (showing 20/${W.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:W.annotations.slice(0,20).map((ut,ts)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro text-[var(--status-error)]",children:[ut.title||ut.level||"Issue",ut.path?` · ${ut.path}`:"",typeof ut.startLine=="number"?`:${ut.startLine}`:"",typeof ut.endLine=="number"&&ut.endLine!==ut.startLine?`-${ut.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:ut.message}),ut.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:ut.rawDetails}):null]},`${ut.path||"file"}:${ut.startLine||ts}:${ts}`))})]}):null,W.job?.steps&&W.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:W.job.steps.map((ut,ts)=>{const js=(ut.conclusion||"").toLowerCase(),xs=js&&!["success","neutral","skipped"].includes(js),Bs=`${W.id??"run"}:${W.job?.jobId??"job"}:${ut.number??ts}:${ut.name}`,Ts=st.has(Bs);return xs?s.jsxs($i,{open:Ts,children:[s.jsxs("button",{type:"button",onClick:()=>{Pe(dn=>{const Ds=new Set(dn);return Ds.has(Bs)?Ds.delete(Bs):Ds.add(Bs),Ds})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(xs?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Ts?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:ut.name}),ut.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:ut.conclusion}):null]}),s.jsx(zi,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof ut.number=="number"?s.jsxs("div",{children:[l("gitView.pr.checks.stepLabel"),": ",ut.number]}):null,ut.status?s.jsxs("div",{children:[l("gitView.pr.checks.statusLabel"),": ",ut.status]}):null,ut.conclusion?s.jsxs("div",{children:[l("gitView.pr.checks.conclusionLabel"),": ",ut.conclusion]}):null,ut.startedAt?s.jsxs("div",{children:[l("gitView.pr.checks.startedLabel"),": ",lt(ut.startedAt)]}):null,ut.completedAt?s.jsxs("div",{children:[l("gitView.pr.checks.completedLabel"),": ",lt(ut.completedAt)]}):null]})})]},Bs):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:ut.name}),ut.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:ut.conclusion}):null]},Bs)})})]}):null]})},[st,lt,l]),ls=a.useCallback(async()=>{if(p("chat"),!m?.prContext){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ue)return;const W=Ut();if(W)try{const qe=await m.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!0}),ht=(qe.checkRuns??[]).filter(xs=>{const Bs=typeof xs.conclusion=="string"?xs.conclusion.toLowerCase():"";return Bs?!["success","neutral","skipped"].includes(Bs):!1});if(ht.length===0){ae.message(l("gitView.pr.toast.noFailedChecks"));return}const Ct=await In("github.pr.checks.review.visible"),ut=await In("github.pr.checks.review.instructions"),ts=ht.flatMap(xs=>(Array.isArray(xs.annotations)?xs.annotations:[]).map(Ts=>({run:xs.name,level:Ts.level,title:Ts.title,path:Ts.path,startLine:Ts.startLine,endLine:Ts.endLine,message:Ts.message,rawDetails:Ts.rawDetails}))),js=`GitHub PR failed checks (JSON)
7
- ${JSON.stringify({repo:qe.repo??null,pr:qe.pr??null,failedChecks:ht,failedAnnotations:ts},null,2)}`;At(W,Ct,ut,js)}catch(qe){const Qe=qe instanceof Error?qe.message:String(qe);ae.error(l("gitView.pr.toast.loadChecksFailed"),{description:Qe})}},[t,At,m,Ue,Ut,p,l]),es=a.useCallback(async()=>{if(p("chat"),!m?.prContext){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ue)return;const W=Ut();if(W)try{const qe=await m.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1}),Qe=qe.issueComments??[],ht=qe.reviewComments??[];if(Qe.length+ht.length===0){ae.message(l("gitView.pr.toast.noPrComments"));return}const ut=await In("github.pr.comments.review.visible"),ts=await In("github.pr.comments.review.instructions"),js=`GitHub PR comments (JSON)
8
- ${JSON.stringify({repo:qe.repo??null,pr:qe.pr??null,issueComments:Qe,reviewComments:ht},null,2)}`;At(W,ut,ts,js)}catch(qe){const Qe=qe instanceof Error?qe.message:String(qe);ae.error(l("gitView.pr.toast.loadPrCommentsFailed"),{description:Qe})}},[t,At,m,Ue,Ut,p,l]),Gt=a.useCallback(async W=>{Ye(!1),p("chat");const qe=Ut();if(!qe)return;const Qe=await In("github.pr.comment.single.visible"),ht=await In("github.pr.comment.single.instructions"),Ct=`GitHub PR comment (JSON)
9
- ${JSON.stringify({repo:nt?.repo??null,pr:nt?.pr??Ue??null,comment:W},null,2)}`;At(qe,Qe,ht,Ct)},[nt,At,Ue,Ut,p]),pt=a.useCallback(async W=>{await T(Ne,W)},[Ne,T]),Yt=a.useCallback(()=>{Ze.current.forEach(W=>{window.clearTimeout(W)}),Ze.current=xb.map(W=>window.setTimeout(()=>{pt({force:!0,silent:!0,markInitialResolved:!0})},W))},[pt]);a.useEffect(()=>{if(!m?.prStatus||!Re||o.length<=1||bt.current||O?.pr)return;const W=`${w}::${fe?.name??""}`;if(He.current.has(W))return;He.current.add(W);const qe=vb(o,r).filter(Ct=>Ct.name!==fe?.name);if(qe.length===0)return;let Qe=!1;return(async()=>{for(const Ct of qe){if(Qe)return;try{if(!(await m.prStatus(t,e,Ct.name))?.pr)continue;if(Qe)return;Ee(ts=>ts?.name===Ct.name?ts:Ct);return}catch{}}})(),()=>{Qe=!0}},[e,Re,t,m,o,fe?.name,w,O?.pr,r]),a.useEffect(()=>{v(Ne),j(Ne,{directory:t,branch:e,remoteName:fe?.name??null,canShow:Re,github:m,githubAuthChecked:f,githubConnected:d?.connected??null})},[e,Re,t,v,m,f,d?.connected,Ne,fe?.name,j]),a.useEffect(()=>(k(Ne),()=>{D(Ne)}),[Ne,k,D]),a.useEffect(()=>{const W=Wa.get(w)??null;E(W?.title??ud(e)),H(W?.body??""),_(W?.draft??!1),te(W?.targetBaseBranch?Gr(W.targetBaseBranch):Gr(n));const qe=za(o,{selectedRemoteName:W?.selectedRemoteName,trackingBranch:r});Ee(Qe=>Qe?.name===qe?.name?Qe:qe)},[n,e,o,w,r]),a.useEffect(()=>{pt({markInitialResolved:!0})},[Ne,pt]),a.useEffect(()=>{!Re||!fe?.name||pt({force:!0,silent:!0,markInitialResolved:!0})},[Re,pt,fe?.name]),a.useEffect(()=>{const W=O?.resolvedRemoteName?.trim();if(!W||bt.current)return;const qe=o.find(Qe=>Qe.name===W);qe&&Ee(Qe=>Qe?.name===qe.name?Qe:qe)},[o,O?.resolvedRemoteName]),a.useEffect(()=>{const W=O?.pr?.state==="closed"||O?.pr?.state==="merged",qe=Be?.lastRefreshAt??0,Qe=Date.now()-qe>6e4,ht=!W&&Qe,Ct=()=>{ht&&pt({force:!0,silent:!0})},ut=()=>{document.visibilityState==="visible"&&ht&&pt({force:!0,silent:!0})};return window.addEventListener("focus",Ct),document.addEventListener("visibilitychange",ut),()=>{window.removeEventListener("focus",Ct),document.removeEventListener("visibilitychange",ut)}},[pt,O?.pr?.state,Be?.lastRefreshAt]),a.useEffect(()=>{f&&d?.connected===!1&&pt({force:!0,silent:!0,markInitialResolved:!0})},[f,d,pt]),a.useEffect(()=>{!t||!e||Wa.set(w,{title:P,body:M,draft:R,additionalContext:z,targetBaseBranch:F,selectedRemoteName:fe?.name})},[w,P,M,R,z,F,fe?.name,t,e]),a.useEffect(()=>{const W=Ze.current;return()=>{W.forEach(qe=>{window.clearTimeout(qe)}),Ze.current=[]}},[]);const us=a.useCallback(async()=>{if(!U&&t){ie(!0);try{const qe={base:me&&ye?.defaultBranchSha?ye.defaultBranchSha:F,head:e};z&&(qe.context=z);const Qe=await Uf(t,qe);Qe.title?.trim()&&E(Qe.title.trim()),Qe.body?.trim()&&H(Qe.body.trim()),c?.()}catch(W){const qe=W instanceof Error?W.message:String(W);ae.error(l("gitView.pr.toast.generateDescriptionFailed"),{description:qe})}finally{ie(!1)}}},[z,e,ye?.defaultBranchSha,t,U,c,F,l,me]),Jt=a.useCallback(async()=>{if(!m?.prCreate){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}const W=P.trim();if(!W){ae.error(l("gitView.pr.toast.titleRequired"));return}const qe=F.trim();if(!qe){ae.error(l("gitView.pr.toast.baseBranchRequired"));return}if(!me&&qe===e){ae.error(l("gitView.pr.toast.baseMustDifferFromHead"));return}ge(!0);try{const Qe=tc(r),ht=me&&ye,Ct=await m.prCreate({directory:t,title:W,head:e,base:qe,...M.trim()?{body:M}:{},draft:R,...ht?{targetRepo:{owner:ye.owner,repo:ye.repo},headRemote:"origin"}:{...fe?{remote:fe.name}:{},...Qe&&Qe!==fe?.name?{headRemote:Qe}:{}}});ae.success(l("gitView.pr.toast.prCreated")),C(Ne,ut=>ut&&{...ut,pr:Ct}),await pt({force:!0}),Yt()}catch(Qe){const ht=Qe instanceof Error?Qe.message:String(Qe);ae.error(l("gitView.pr.toast.createPrFailed"),{description:ht})}finally{ge(!1)}},[M,e,ye,t,R,m,Ne,pt,Yt,fe,F,P,r,C,me,l]),ss=a.useCallback(async W=>{if(!m?.prMerge){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}L(!0);try{const qe=await m.prMerge({directory:t,number:W.number,method:Z});qe.merged?ae.success(l("gitView.pr.toast.prMerged")):ae.message(l("gitView.pr.toast.prNotMerged"),{description:qe.message||l("gitView.pr.notMergeable")}),await pt({force:!0}),Yt()}catch(qe){const Qe=qe instanceof Error?qe.message:String(qe);ae.error(l("gitView.pr.toast.mergeFailed"),{description:Qe}),W.url&&Ua(W.url)}finally{L(!1)}},[t,m,Z,pt,Yt,l]),hs=a.useCallback(async W=>{if(!m?.prReady){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}q(!0);try{await m.prReady({directory:t,number:W.number}),ae.success(l("gitView.pr.toast.markedReady")),await pt({force:!0}),Yt()}catch(qe){const Qe=qe instanceof Error?qe.message:String(qe);ae.error(l("gitView.pr.toast.markReadyFailed"),{description:Qe}),W.url&&Ua(W.url)}finally{q(!1)}},[t,m,pt,Yt,l]),Wt=a.useCallback(async W=>{if(!m?.prUpdate){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}const qe=De.trim();if(!qe){ae.error(l("gitView.pr.toast.titleRequired"));return}Se(!0);try{const Qe=await m.prUpdate({directory:t,number:W.number,title:qe,body:ke});C(Ne,ht=>ht&&{...ht,pr:{...ht.pr??W,...Qe}}),de(!1),ae.success(l("gitView.pr.toast.prUpdated")),await pt({force:!0}),Yt()}catch(Qe){const ht=Qe instanceof Error?Qe.message:String(Qe);ae.error(l("gitView.pr.toast.updatePrFailed"),{description:ht})}finally{Se(!1)}},[t,ke,De,m,Ne,pt,Yt,C,l]);if(!Re)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:l("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pullRequest.availableOnFeatureBranches")})]})});const gs=O?.repo?.url||null,Ms=me&&ye?.url?ye.url:gs,Vt=O?.checks??null,vs=!!O?.canMerge,Ps=!!O?.connected,Ns=f&&O?.connected===!1,As=gb(O),Rt=As?`var(--pr-${As})`:"var(--status-info)",xt=As==="draft"?"git-pr-draft":As==="merged"?"git-merge":As==="closed"?"git-close-pull-request":"git-pull-request",Kt=Ue?[`${Ue.state}${Ue.draft?" (draft)":""}`,Ue.mergeable===!1?l("gitView.pr.notMergeable"):null,Ue.state==="open"&&typeof Ue.mergeableState=="string"&&Ue.mergeableState&&Ue.mergeableState!=="unknown"?Ue.mergeableState:null].filter(Boolean).join(" · "):"",Ht=Vt?Vt.total>0?`${Vt.success}/${Vt.total} ${l("gitView.pr.checks.label")}`:`${Vt.state} ${l("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[Ue?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{Ua(Ue.url)},"aria-label":l("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(I,{name:xt,className:"size-4 shrink-0",style:{color:Rt}})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(I,{name:xt,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:l("gitView.pullRequest.title")}),Ue?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",Ue.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[se?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:se,onClick:()=>{pt({force:!0})},"aria-label":l("gitView.pr.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.refresh")})})]})]})]}),Ue?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:Rt},children:Kt}),Vt?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${pb(Vt.state)}`}),Ht]}):null,r&&fe&&r.split("/")[0]!==fe.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",fe.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Ns?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.githubNotConnected")}),s.jsx(ze,{variant:"outline",size:"sm",onClick:N,className:"w-fit",children:l("gitView.pr.actions.openSettings")})]}):null,A?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:A}),Ms?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:Ms,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!Ue&&!K&&!A&&!Ns?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),l("gitView.pr.checkingStatus")]}):Ue?s.jsx("div",{className:"flex flex-col gap-2",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[he?s.jsxs("div",{className:"space-y-2",children:[s.jsx(kn,{value:De,onChange:W=>le(W.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h}),s.jsx(fi,{value:ke,onChange:W=>ue(W.target.value),className:"min-h-[120px] bg-background/80",placeholder:l("gitView.pr.placeholder.description"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:Ue.title}),Ue.body?.trim()?s.jsx(ho,{content:Ue.body,className:"typography-markdown-body text-muted-foreground break-words mt-1"}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:l(Ge?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),vs&&Ue.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.draftMustBeReady")}):null,vs?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.noMergePermission")})]}),s.jsxs("div",{className:"order-first w-full flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Ue.state==="open"?he?s.jsxs(s.Fragment,{children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{de(!1),le(Ue.title||""),ue(Ue.body||"")},disabled:je,"aria-label":l("gitView.pr.actions.cancelEditingAria"),children:s.jsx(I,{name:"close",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>Wt(Ue),disabled:je||!De.trim(),"aria-label":l("gitView.pr.actions.savePrAria"),children:je?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>de(!0),"aria-label":l("gitView.pr.actions.editPrAria"),children:s.jsx(I,{name:"edit",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.editPr")})})]}):null,Vt?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:it,disabled:yt,"aria-label":l("gitView.pr.actions.openChecksAria"),children:yt?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"information",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.openChecks")})})]}):null,Vt?.failure?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:ls,"aria-label":l("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(I,{name:"error-warning",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Et,"aria-label":l("gitView.pr.actions.openCommentsAria"),children:s.jsx(I,{name:"chat-4",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.openComments")})})]}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:es,"aria-label":l("gitView.pr.actions.shareCommentsAria"),children:s.jsx(I,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.shareComments")})})]}),vs&&Ue.draft&&Ue.state==="open"?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>hs(Ue),disabled:$||re||je||he,"aria-label":l("gitView.pr.actions.markReadyAria"),children:$?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:vs?s.jsxs(s.Fragment,{children:[s.jsxs(Bn,{value:Z,onValueChange:W=>ne(W),disabled:re||Ue.state!=="open",children:[s.jsx(Vn,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(Pn,{})}),s.jsxs($n,{children:[s.jsx(qs,{value:"squash",children:l("gitView.pr.mergeMethod.squash")}),s.jsx(qs,{value:"merge",children:l("gitView.pr.mergeMethod.merge")}),s.jsx(qs,{value:"rebase",children:l("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ss(Ue),disabled:re||$||Ue.state!=="open"||Ue.draft||je||he,"aria-label":l("gitView.pr.actions.mergePrAria"),children:re?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"})})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.mergePr")})})]})]}):null})]})]})}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",F," ",s.jsxs("span",{className:"opacity-60",children:["(",me&&ye?"upstream":"remote",")"]})]})]}),Ms?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:Ms,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),l("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.title")}),s.jsx(kn,{value:P,onChange:W=>E(W.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.baseBranch")}),pe.length>0?s.jsxs(Bn,{value:F,onValueChange:te,children:[s.jsx(Vn,{className:"h-9",children:s.jsx(Pn,{placeholder:l("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx($n,{children:pe.map(W=>s.jsx(qs,{value:W,children:W},W))})]}):s.jsx(kn,{value:F,onChange:W=>te(W.target.value),placeholder:l("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.description")}),s.jsx(fi,{value:M,onChange:W=>H(W.target.value),className:"min-h-[110px]",placeholder:l("gitView.pr.placeholder.whatChanged"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":R,onClick:()=>_(W=>!W),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),_(qe=>!qe))},children:[s.jsx(yi,{size:"sm",checked:R,onChange:W=>_(W),ariaLabel:l("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:l("gitView.pr.field.draft")})]}),b?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.optional")}),s.jsx(ze,{variant:"outline",size:"sm",onClick:()=>ce(!0),children:z.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),z.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:l("gitView.pr.additionalContext.added")})})]}):s.jsxs($i,{open:ve,onOpenChange:G,children:[s.jsxs(jo,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:ve?l("gitView.pr.actions.hide"):z.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),s.jsx(zi,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(fi,{value:z,onChange:W=>V(W.target.value),className:"min-h-[100px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(xa,{open:Ae,onClose:()=>ce(!1),title:l("gitView.pr.additionalContext.title"),footer:s.jsx(ze,{size:"sm",onClick:()=>ce(!1),className:"w-full",children:l("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(fi,{value:z,onChange:W=>V(W.target.value),className:"min-h-[200px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ze,{variant:"outline",size:"sm",onClick:us,disabled:U||oe,children:[U?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),l("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(ze,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Jt,disabled:oe||!Ps||!F.trim()||!me&&F.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:oe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:l("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(Ks,{open:_e,onOpenChange:We,children:s.jsxs(Gs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(Xs,{children:[s.jsxs(Ys,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),l("gitView.pr.checkDetails.title")]}),s.jsx(cn,{children:Ue?l("gitView.pr.numberLabel",{number:Ue.number}):l("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[yt?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),l("gitView.loading.loading")]}):null,yt?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(Le?.checkRuns)&&Le?.checkRuns.length>0?Le.checkRuns.map((W,qe)=>{const Qe=`${W.id??"run"}:${W.job?.jobId??"job"}:${W.name}:${qe}`;return s.jsx("div",{className:"p-1",children:Xt(W)},Qe)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:l("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(Ks,{open:tt,onOpenChange:Ye,children:s.jsxs(Gs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(Xs,{children:s.jsxs(Ys,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),l("gitView.pr.comments.title"),Ue?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.numberLabel",{number:Ue.number})}):null]})}),s.jsxs(ba,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[mt?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),l("gitView.loading.loading")]}):null,mt?null:s.jsx("div",{className:"space-y-4",children:qt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:qt.map((W,qe)=>{const Qe=(W.authorName||"?").charAt(0).toUpperCase(),ht=qe===qt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[ht?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:W.avatarUrl?s.jsx("img",{src:W.avatarUrl,alt:W.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Qe})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[W.authorName,W.authorLogin&&W.authorLogin!==W.authorName?` · @${W.authorLogin}`:""]}),W.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:lt(W.createdAt)}):null,s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsxs(ze,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{Gt(W)},"aria-label":l("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(I,{name:"ai-generate-2",className:"size-3.5"}),l("gitView.pr.actions.sendToAgent")]})}),s.jsx(_t,{children:s.jsx("p",{children:l("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[W.context,W.path?` · ${W.path}`:"",W.line?`:${W.line}`:""]}),s.jsx(ho,{content:Ft(W.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Bt].filter(Boolean).join(" ")})]})]},W.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:l("gitView.pr.comments.empty")})})]})]})})]})},Nb=t=>{const e=gt.c(150),{open:n,onOpenChange:r,conflictFiles:o,directory:i,operation:c,onAbort:l,onClearState:u}=t;let m;e[0]!==o?(m=o===void 0?[]:o,e[0]=o,e[1]=m):m=e[1];const d=m,{t:f}=Tt(),g=vt(kb),x=vt(Cb),p=ei(Ab),y=ei(Db),b=Fe(Ib),[h,N]=a.useState(!1),[w,S]=a.useState(null),[v,j]=a.useState(null);let k,D;e[2]!==i||e[3]!==n||e[4]!==f?(k=()=>{!n||!i||(N(!0),j(null),S(null),Hf(i).then(me=>{S(me)}).catch(me=>{const B=me instanceof Error?me.message:f("gitView.conflict.loadFailed");j(B)}).finally(()=>{N(!1)}))},D=[n,i,f],e[2]=i,e[3]=n,e[4]=f,e[5]=k,e[6]=D):(k=e[5],D=e[6]),a.useEffect(k,D);let T;e[7]!==w||e[8]!==i||e[9]!==c?(T=async()=>{if(!w)return null;const me=c==="merge"?"merge":"rebase",B=w.headInfo||(c==="merge"?"MERGE_HEAD":"REBASE_HEAD"),ye=c==="merge"?"git commit --no-edit":"git rebase --continue",Oe=await In("git.conflict.resolve.visible",{operation_label:me,head_ref:B}),Q=await In("git.conflict.resolve.instructions",{operation_label:me,directory:i,operation:c,head_info:w.headInfo||"N/A",continue_cmd:ye}),Me=`${me} conflict context (JSON)
10
- ${JSON.stringify({directory:i,operation:w.operation,headInfo:w.headInfo,statusPorcelain:w.statusPorcelain,unmergedFiles:w.unmergedFiles,diff:w.diff},null,2)}`;return{visibleText:Oe,instructionsText:Q,payloadText:Me}},e[7]=w,e[8]=i,e[9]=c,e[10]=T):T=e[10];const C=T;let P;e[11]!==l||e[12]!==r?(P=()=>{l(),r(!1)},e[11]=l,e[12]=r,e[13]=P):P=e[13];const E=P;let M;e[14]!==u||e[15]!==r?(M=()=>{u?.(),r(!1)},e[14]=u,e[15]=r,e[16]=M):M=e[16];const H=M;let R;e[17]!==C||e[18]!==x||e[19]!==u||e[20]!==r||e[21]!==b||e[22]!==p||e[23]!==y||e[24]!==f?(R=async()=>{const me=await C();if(!me){ae.error(f("gitView.conflict.noDetailsAvailable"));return}if(!x){ae.error(f("gitView.conflict.noActiveSession"),{description:f("gitView.conflict.noActiveSessionDescription")});return}p(me.visibleText,"replace"),y([{text:me.instructionsText,synthetic:!0},{text:me.payloadText,synthetic:!0}]),b("chat"),u?.(),r(!1)},e[17]=C,e[18]=x,e[19]=u,e[20]=r,e[21]=b,e[22]=p,e[23]=y,e[24]=f,e[25]=R):R=e[25];const _=R;let z;e[26]!==C||e[27]!==i||e[28]!==u||e[29]!==r||e[30]!==g||e[31]!==b||e[32]!==f?(z=async()=>{const me=await C();if(!me){ae.error(f("gitView.conflict.noDetailsAvailable"));return}g({directoryOverride:i,initialPrompt:me.visibleText,syntheticParts:[{text:me.instructionsText,synthetic:!0},{text:me.payloadText,synthetic:!0}]}),b("chat"),u?.(),r(!1)},e[26]=C,e[27]=i,e[28]=u,e[29]=r,e[30]=g,e[31]=b,e[32]=f,e[33]=z):z=e[33];const V=z;let F,te,Z,ne,U,ie,oe,ge,je,Se,re,L,$,q,he,de,we,be,De,le,ke,ue;if(e[34]!==w||e[35]!==d||e[36]!==x||e[37]!==E||e[38]!==H||e[39]!==_||e[40]!==V||e[41]!==h||e[42]!==v||e[43]!==r||e[44]!==n||e[45]!==c||e[46]!==f){const me=f(c==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),B=w?.unmergedFiles||d;Z=Ks,ke=n,ue=r,te=Gs,le="max-w-md w-[calc(100vw-2rem)]",q="flex flex-col gap-4 overflow-hidden";let ye;e[69]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx(I,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=ye):ye=e[69];const Oe=s.jsxs("div",{className:"flex items-center gap-2",children:[ye,s.jsx(Ys,{children:f("gitView.conflict.detectedTitle",{operation:me})})]});let Q;e[70]!==c||e[71]!==f?(Q=f("gitView.conflict.detectedDescription",{operation:c}),e[70]=c,e[71]=f,e[72]=Q):Q=e[72];let Me;e[73]!==Q?(Me=s.jsx(cn,{children:Q}),e[73]=Q,e[74]=Me):Me=e[74],e[75]!==Oe||e[76]!==Me?(he=s.jsxs(Xs,{children:[Oe,Me]}),e[75]=Oe,e[76]=Me,e[77]=he):he=e[77],e[78]!==h||e[79]!==f?(de=h&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:f("gitView.conflict.loading")})]}),e[78]=h,e[79]=f,e[80]=de):de=e[80],e[81]!==v||e[82]!==f?(we=v&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:f("gitView.conflict.errorLoadingDetails",{message:v})}),e[81]=v,e[82]=f,e[83]=we):we=e[83],e[84]!==B||e[85]!==f?(be=B.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:B.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:B.map(Pb)})})]}),e[84]=B,e[85]=f,e[86]=be):be=e[86],e[87]!==w||e[88]!==f?(De=w?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:w.headInfo})]}),e[87]=w,e[88]=f,e[89]=De):De=e[89],re="flex flex-col gap-2 pt-2";let Re;e[90]!==V?(Re=()=>{V()},e[90]=V,e[91]=Re):Re=e[91];const Ne=h||!w;let Be;e[92]!==h?(Be=h?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"}),e[92]=h,e[93]=Be):Be=e[93];let se;e[94]!==f?(se=f("gitView.conflict.resolveNewSession"),e[94]=f,e[95]=se):se=e[95],e[96]!==Re||e[97]!==Ne||e[98]!==Be||e[99]!==se?(L=s.jsxs(ze,{variant:"default",onClick:Re,disabled:Ne,className:"w-full gap-2",children:[Be,se]}),e[96]=Re,e[97]=Ne,e[98]=Be,e[99]=se,e[100]=L):L=e[100];let O;e[101]!==_?(O=()=>{_()},e[101]=_,e[102]=O):O=e[102];const A=h||!w||!x;let K;e[103]!==h?(K=h?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"chat-1",className:"size-4"}),e[103]=h,e[104]=K):K=e[104];let pe;e[105]!==f?(pe=f("gitView.conflict.resolveCurrentSession"),e[105]=f,e[106]=pe):pe=e[106],e[107]!==O||e[108]!==A||e[109]!==K||e[110]!==pe?($=s.jsxs(ze,{variant:"outline",onClick:O,disabled:A,className:"w-full gap-2",children:[K,pe]}),e[107]=O,e[108]=A,e[109]=K,e[110]=pe,e[111]=$):$=e[111],je="flex gap-2 pt-1";let _e;e[112]!==f?(_e=f("gitView.conflict.continueLater"),e[112]=f,e[113]=_e):_e=e[113],e[114]!==H||e[115]!==_e?(Se=s.jsx(ze,{variant:"ghost",size:"sm",onClick:H,className:"flex-1",children:_e}),e[114]=H,e[115]=_e,e[116]=Se):Se=e[116],F=ze,ne="destructive",U="sm",ie=E,oe="flex-1",ge=f("gitView.conflict.abortOperation",{operation:me}),e[34]=w,e[35]=d,e[36]=x,e[37]=E,e[38]=H,e[39]=_,e[40]=V,e[41]=h,e[42]=v,e[43]=r,e[44]=n,e[45]=c,e[46]=f,e[47]=F,e[48]=te,e[49]=Z,e[50]=ne,e[51]=U,e[52]=ie,e[53]=oe,e[54]=ge,e[55]=je,e[56]=Se,e[57]=re,e[58]=L,e[59]=$,e[60]=q,e[61]=he,e[62]=de,e[63]=we,e[64]=be,e[65]=De,e[66]=le,e[67]=ke,e[68]=ue}else F=e[47],te=e[48],Z=e[49],ne=e[50],U=e[51],ie=e[52],oe=e[53],ge=e[54],je=e[55],Se=e[56],re=e[57],L=e[58],$=e[59],q=e[60],he=e[61],de=e[62],we=e[63],be=e[64],De=e[65],le=e[66],ke=e[67],ue=e[68];let ve;e[117]!==F||e[118]!==ne||e[119]!==U||e[120]!==ie||e[121]!==oe||e[122]!==ge?(ve=s.jsx(F,{variant:ne,size:U,onClick:ie,className:oe,children:ge}),e[117]=F,e[118]=ne,e[119]=U,e[120]=ie,e[121]=oe,e[122]=ge,e[123]=ve):ve=e[123];let G;e[124]!==je||e[125]!==Se||e[126]!==ve?(G=s.jsxs("div",{className:je,children:[Se,ve]}),e[124]=je,e[125]=Se,e[126]=ve,e[127]=G):G=e[127];let Ae;e[128]!==re||e[129]!==L||e[130]!==$||e[131]!==G?(Ae=s.jsxs("div",{className:re,children:[L,$,G]}),e[128]=re,e[129]=L,e[130]=$,e[131]=G,e[132]=Ae):Ae=e[132];let ce;e[133]!==q||e[134]!==he||e[135]!==de||e[136]!==we||e[137]!==be||e[138]!==De||e[139]!==Ae?(ce=s.jsxs("div",{className:q,children:[he,de,we,be,De,Ae]}),e[133]=q,e[134]=he,e[135]=de,e[136]=we,e[137]=be,e[138]=De,e[139]=Ae,e[140]=ce):ce=e[140];let fe;e[141]!==te||e[142]!==le||e[143]!==ce?(fe=s.jsx(te,{className:le,children:ce}),e[141]=te,e[142]=le,e[143]=ce,e[144]=fe):fe=e[144];let Ee;return e[145]!==Z||e[146]!==ke||e[147]!==ue||e[148]!==fe?(Ee=s.jsx(Z,{open:ke,onOpenChange:ue,children:fe}),e[145]=Z,e[146]=ke,e[147]=ue,e[148]=fe,e[149]=Ee):Ee=e[149],Ee};function kb(t){return t.openNewSessionDraft}function Cb(t){return t.currentSessionId}function Ab(t){return t.setPendingInputText}function Db(t){return t.setPendingSyntheticParts}function Ib(t){return t.setActiveMainTab}function Pb(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const Tb=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:o})=>{const{t:i}=Tt(),[c,l]=a.useState(!0),[u,m]=a.useState(!1),d=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),f=async()=>{m(!0);try{await o(c),e(!1)}catch(x){const p=x instanceof Error?x.message:`Failed to ${n}`;ae.error(p)}finally{m(!1)}},g=()=>{u||e(!1)};return s.jsx(Ks,{open:t,onOpenChange:u?void 0:e,children:s.jsxs(Gs,{className:"max-w-md",children:[s.jsxs(Xs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(Ys,{children:i("gitView.stash.title")})]}),s.jsx(cn,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),c&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(yi,{checked:c,onChange:l,disabled:u,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!u&&l(!c),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(tr,{className:"gap-2",children:[s.jsx(ze,{variant:"ghost",size:"sm",onClick:g,disabled:u,children:i("gitView.common.cancel")}),s.jsx(ze,{variant:"default",size:"sm",onClick:f,disabled:u,className:"gap-1.5",children:u?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:d})})]})]})})},Eb=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:o,hasUnresolvedConflicts:i=!1,isLoading:c=!1})=>{const{t:l}=Tt(),[u,m]=a.useState(null),d=t&&t.head,f=e&&(e.headName||e.onto),g=d?"merge":f?"rebase":null;if(!g)return null;const x=async()=>{m("continue");try{await n()}finally{m(null)}},p=async()=>{m("abort");try{await r()}finally{m(null)}},y=u!==null,b=l(g==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),h=g==="merge"?"git-merge":"git-branch";let N="";return t?N=t.message?l("gitView.operation.mergingMessage",{message:t.message}):l("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(N=e.headName?l("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):l("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(I,{name:h,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:l("gitView.operation.inProgressTitle",{operation:b})}),N&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:N})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&o&&s.jsxs(ze,{variant:"outline",size:"sm",onClick:o,disabled:y||c,className:"gap-1.5",children:[s.jsx(I,{name:"sparkling",className:"size-4"}),l("gitView.operation.resolveWithAi")]}),u!=="continue"&&s.jsxs(ze,{variant:"ghost",size:"sm",onClick:p,disabled:y||c,className:"gap-1.5",children:[u==="abort"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"close",className:"size-4"}),l("gitView.operation.abort")]}),!i&&s.jsxs(ze,{variant:"default",size:"sm",onClick:x,disabled:y||c,className:"gap-1.5",children:[u==="continue"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"}),l("gitView.operation.continue")]})]}),i&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:l("gitView.operation.resolveConflictsHint")})]})})},Rb=t=>{const e=gt.c(104),{currentBranch:n,localBranches:r,remoteBranches:o,onMerge:i,onRebase:c,disabled:l,isOperating:u,operationLogs:m,onOperationComplete:d,mode:f,defaultTargetBranch:g}=t,x=l===void 0?!1:l,p=u===void 0?!1:u,y=m===void 0?[]:m,b=f===void 0?"dialog":f,{t:h}=Tt(),[N,w]=a.useState(!1),[S,v]=a.useState("merge"),[j,k]=a.useState(null),[D,T]=a.useState(!1),[C,P]=a.useState(""),E=a.useRef(null),M=a.useRef(null),H=x||p,R=n||h("gitView.branch.currentBranchFallback"),_=y.length>0&&y.every(Mb),z=y.some(Fb);let V;e[0]===Symbol.for("react.memo_cache_sentinel")?(V=()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},e[0]=V):V=e[0],a.useEffect(V,[y]);let F;if(e[1]!==C||e[2]!==n||e[3]!==r||e[4]!==o){e:{const O=C.toLowerCase();let A;e[6]!==o?(A=new Set(o.map(Lb).filter(Boolean)),e[6]=o,e[7]=A):A=e[7];const K=A;let pe;e[8]!==n||e[9]!==K?(pe=We=>We!==n&&!K.has(We),e[8]=n,e[9]=K,e[10]=pe):pe=e[10];const _e=r.filter(pe);if(!O){F=_e;break e}F=_e.filter(We=>We.toLowerCase().includes(O))}e[1]=C,e[2]=n,e[3]=r,e[4]=o,e[5]=F}else F=e[5];const te=F;let Z;if(e[11]!==C||e[12]!==o){e:{const O=C.toLowerCase();if(!O){Z=o;break e}Z=o.filter(A=>A.toLowerCase().includes(O))}e[11]=C,e[12]=o,e[13]=Z}else Z=e[13];const ne=Z;let U;e[14]!==g||e[15]!==r||e[16]!==o?(U=()=>g&&(o.includes(g)||r.includes(g))?g:null,e[14]=g,e[15]=r,e[16]=o,e[17]=U):U=e[17];const ie=U;let oe;e[18]!==ie||e[19]!==w?(oe=()=>{w(!0),k(ie()),v("merge"),P("")},e[18]=ie,e[19]=w,e[20]=oe):oe=e[20];const ge=oe;let je;e[21]===Symbol.for("react.memo_cache_sentinel")?(je=O=>{k(O),T(!1),P("")},e[21]=je):je=e[21];const Se=je;let re;e[22]!==i||e[23]!==c||e[24]!==S||e[25]!==j?(re=()=>{j&&(S==="merge"?i(j):c(j))},e[22]=i,e[23]=c,e[24]=S,e[25]=j,e[26]=re):re=e[26];const L=re;let $;e[27]!==p||e[28]!==w?($=()=>{p||(k(null),v("merge"),P(""),w(!1))},e[27]=p,e[28]=w,e[29]=$):$=e[29];const q=$,he=()=>{p&&!_||(_&&d?.(),k(null),v("merge"),P(""),w(!1))};let de,we;e[30]!==D?(de=()=>{D||P("")},we=[D],e[30]=D,e[31]=de,e[32]=we):(de=e[31],we=e[32]),a.useEffect(de,we);let be,De;e[33]!==b||e[34]!==ie||e[35]!==j?(be=()=>{b!=="inline"||j||k(ie())},De=[b,ie,j],e[33]=b,e[34]=ie,e[35]=j,e[36]=be,e[37]=De):(be=e[36],De=e[37]),a.useEffect(be,De);const ue=p?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:M,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:y.map(Ob)})}),_?b==="dialog"?s.jsx(tr,{children:s.jsx(ze,{variant:"default",size:"sm",onClick:he,children:h(z?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(ze,{variant:"default",size:"sm",onClick:he,children:h(z?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>v("merge"),className:Te("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-merge",className:Te("size-4",S==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Te("typography-ui-label",S==="merge"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>v("rebase"),className:Te("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-branch",className:Te("size-4",S==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Te("typography-ui-label",S==="rebase"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?h("gitView.branch.branchToMergeInto",{branch:R}):h("gitView.branch.branchToRebaseOnto")}),s.jsxs(on,{open:D,onOpenChange:T,modal:!1,children:[s.jsx(nn,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:Te("truncate",!j&&"text-muted-foreground"),children:j||h("gitView.branch.selectBranch")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(rn,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(ma,{className:"h-full min-h-0",children:[s.jsx(fa,{ref:E,placeholder:h("gitView.branch.searchPlaceholder"),value:C,onValueChange:P,onKeyDown:_b}),s.jsxs(ha,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(pa,{children:h("gitView.branch.empty")}),te.length>0&&s.jsx(qr,{heading:h("gitView.branch.localBranches"),children:te.map(O=>s.jsx(Zr,{onSelect:()=>Se(O),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`local-${O}`))}),te.length>0&&ne.length>0?s.jsx(Gf,{}):null,ne.length>0&&s.jsx(qr,{heading:h("gitView.branch.remoteBranches"),children:ne.map(O=>s.jsx(Zr,{onSelect:()=>Se(O),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`remote-${O}`))})]})]})})]})]}),j?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})," ",h("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})]}):s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})," ",h("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,b==="dialog"?s.jsxs(tr,{className:"gap-2 pt-1",children:[s.jsx(ze,{variant:"ghost",size:"sm",onClick:q,children:h("gitView.common.cancel")}),s.jsx(ze,{variant:"default",size:"sm",onClick:L,disabled:!j,className:"gap-1.5",children:S==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-merge",className:"size-4"}),h("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-branch",className:"size-4"}),h("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ze,{variant:"destructive",size:"sm",onClick:q,disabled:H,children:h("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(ze,{variant:"default",size:"sm",onClick:L,disabled:H||!j,children:h(S==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(b==="inline"){let O;e[38]!==h?(O=h("gitView.branch.updateTitle"),e[38]=h,e[39]=O):O=e[39];let A;e[40]!==O?(A=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:O}),e[40]=O,e[41]=A):A=e[41];let K;e[42]!==h?(K=h("gitView.branch.updateDescriptionPrefix"),e[42]=h,e[43]=K):K=e[43];let pe;e[44]!==R?(pe=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=pe):pe=e[45];let _e;e[46]!==K||e[47]!==pe?(_e=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[K," ",pe,"."]}),e[46]=K,e[47]=pe,e[48]=_e):_e=e[48];let We;e[49]!==A||e[50]!==_e?(We=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[A,_e]})}),e[49]=A,e[50]=_e,e[51]=We):We=e[51];let Le;e[52]!==ue?(Le=s.jsx("div",{className:"pt-3",children:ue}),e[52]=ue,e[53]=Le):Le=e[53];let rt;return e[54]!==We||e[55]!==Le?(rt=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[We,Le]}),e[54]=We,e[55]=Le,e[56]=rt):rt=e[56],rt}let ve;e[57]!==p?(ve=p?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"}),e[57]=p,e[58]=ve):ve=e[58];let G;e[59]!==h?(G=h("gitView.branch.mergeRebase"),e[59]=h,e[60]=G):G=e[60];let Ae;e[61]!==G?(Ae=s.jsx("span",{children:G}),e[61]=G,e[62]=Ae):Ae=e[62];let ce;e[63]!==ge||e[64]!==H||e[65]!==ve||e[66]!==Ae?(ce=s.jsx(Ot,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ge,disabled:H,children:[ve,Ae]})}),e[63]=ge,e[64]=H,e[65]=ve,e[66]=Ae,e[67]=ce):ce=e[67];let fe;e[68]!==h?(fe=h("gitView.branch.mergeRebaseTooltip"),e[68]=h,e[69]=fe):fe=e[69];let Ee;e[70]!==fe?(Ee=s.jsx(_t,{sideOffset:8,children:fe}),e[70]=fe,e[71]=Ee):Ee=e[71];let me;e[72]!==ce||e[73]!==Ee?(me=s.jsxs(Lt,{children:[ce,Ee]}),e[72]=ce,e[73]=Ee,e[74]=me):me=e[74];let B;e[75]!==he||e[76]!==w?(B=O=>{O?w(!0):he()},e[75]=he,e[76]=w,e[77]=B):B=e[77];let ye;e[78]!==h?(ye=h("gitView.branch.updateTitle"),e[78]=h,e[79]=ye):ye=e[79];let Oe;e[80]!==ye?(Oe=s.jsx(Ys,{children:ye}),e[80]=ye,e[81]=Oe):Oe=e[81];let Q;e[82]!==z||e[83]!==p||e[84]!==S||e[85]!==_||e[86]!==h||e[87]!==R?(Q=p?h(_?z?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":S==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[h("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R}),"."]}),e[82]=z,e[83]=p,e[84]=S,e[85]=_,e[86]=h,e[87]=R,e[88]=Q):Q=e[88];let Me;e[89]!==Q?(Me=s.jsx(cn,{children:Q}),e[89]=Q,e[90]=Me):Me=e[90];let Re;e[91]!==Oe||e[92]!==Me?(Re=s.jsxs(Xs,{children:[Oe,Me]}),e[91]=Oe,e[92]=Me,e[93]=Re):Re=e[93];let Ne;e[94]!==ue||e[95]!==Re?(Ne=s.jsxs(Gs,{className:"max-w-md",children:[Re,ue]}),e[94]=ue,e[95]=Re,e[96]=Ne):Ne=e[96];let Be;e[97]!==N||e[98]!==B||e[99]!==Ne?(Be=s.jsx(Ks,{open:N,onOpenChange:B,children:Ne}),e[97]=N,e[98]=B,e[99]=Ne,e[100]=Be):Be=e[100];let se;return e[101]!==me||e[102]!==Be?(se=s.jsxs(s.Fragment,{children:[me,Be]}),e[101]=me,e[102]=Be,e[103]=se):se=e[103],se};function Mb(t){return t.status==="done"||t.status==="error"}function Fb(t){return t.status==="error"}function Lb(t){return t.slice(t.indexOf("/")+1)}function Ob(t,e){return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"mt-0.5 shrink-0",children:[t.status==="running"&&s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(I,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(I,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:Te("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function _b(t){return t.stopPropagation()}const Bb=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:o})=>{const i=[];let c=!1;return{enqueue:u=>{const m=i[i.length-1];if(m?.directory===u.directory&&m.direction===u.direction){u.paths.forEach(d=>m.paths.add(d));return}i.push(u)},flush:()=>{if(c)return;const u=i.shift();if(!u)return;c=!0;const m={directory:u.directory,direction:u.direction,paths:Array.from(u.paths),rollback:u.rollback};(async()=>{try{await t(m),e(m)}catch(d){n(m,d)}finally{r(m.paths),c=!1,i.length>0&&o()}})()},clear:()=>{i.length=0},size:()=>i.length,isRunning:()=>c}},md="oc.git.actionTab",Vb=15e3,$b=t=>t==="commit"||t==="branch"||t==="pr",im="gitmojiCache",zb=1e3*60*60*24*7,om="1",Wb=40,Ub=20,Hb="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",fd={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},am=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Gb=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(im);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==om||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(am),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Kb=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:om};localStorage.setItem(im,JSON.stringify(e))}catch{return}},qb=t=>Date.now()-t.fetchedAt<zb,Yb=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,o=n.match(r);if(o){const l=o[1],u=fd[l];if(u)return e.find(m=>m.code===u)||null}const i=n.split(" ")[0],c=fd[i];return c&&e.find(l=>l.code===c)||null},hd=new Map,Lr=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),pd=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Jb=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},Sl=()=>{const{t}=Tt(),{git:e}=Wn(),n=ti(),[r,o]=a.useState(null),[i,c]=a.useState(!1),l=vt(J=>J.currentSessionId),u=vt(J=>J.newSessionDraft),m=vt(J=>J.setDraftBootstrapPendingDirectory),d=vt(J=>J.worktreeMetadata),f=vt(J=>J.availableWorktrees),g=Lr(n),x=a.useMemo(()=>{if(!g)return;const J=f.find(xe=>Lr(xe.path)===g);if(J)return J;for(const xe of d.values())if(Lr(xe.path)===g)return xe},[f,g,d]),p=a.useMemo(()=>{if(l)return d.get(l)??x;if(u?.open)return x},[l,x,u?.open,d]),{profiles:y,globalIdentity:b,defaultGitIdentityId:h,loadProfiles:N,loadGlobalIdentity:w,loadDefaultGitIdentityId:S}=Vp(hu(J=>({profiles:J.profiles,globalIdentity:J.globalIdentity,defaultGitIdentityId:J.defaultGitIdentityId,loadProfiles:J.loadProfiles,loadGlobalIdentity:J.loadGlobalIdentity,loadDefaultGitIdentityId:J.loadDefaultGitIdentityId}))),v=zl(n??null),j=ya(n??null),k=vu(J=>l?J.getAttachment(l):void 0),D=k?Kf(k):[],T=k&&!k.degraded&&!k.legacy?k.worktreeRoot??void 0:void 0,C=jx(n,p,j?.current??void 0),P=Du(n??null),E=qf(n??null),M=Yf(n??null),H=Wl(n??null),R=Jf(n??null),_=_s(J=>J.setActiveDirectory),z=_s(J=>J.fetchAll),V=_s(J=>J.ensureAll),F=_s(J=>J.fetchStatus),te=_s(J=>J.fetchBranches),Z=_s(J=>J.fetchLog),ne=_s(J=>J.setLogMaxCount),U=_s(J=>J.fetchIdentity),ie=_s(J=>J.prefetchDiffs),oe=_s(J=>J.moveStatusPathsOptimistically),ge=_s(J=>J.restoreStatus),je=_s(J=>J.bumpIndexRevision),Se=Fe(J=>J.isMobile),re=Fe(J=>J.openContextDiff),L=Fe(J=>J.navigateToDiff),$=Fe(J=>J.setRightSidebarOpen),q=a.useRef(null),he=a.useRef(null),de=a.useRef(null),we=a.useRef(null),be=a.useCallback(()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null)},[]),De=a.useCallback(J=>{be(),he.current=window.setTimeout(()=>{he.current=null,Lr(J)===Lr(n)&&F(J,e,{silent:!0})},Vb)},[be,n,F,e]);a.useEffect(()=>be,[be]);const le=a.useCallback(()=>{de.current!==null&&(window.clearTimeout(de.current),de.current=null)},[]),ke=a.useCallback(()=>{de.current===null&&(de.current=window.setTimeout(()=>{de.current=null,we.current?.()},0))},[]),ue=a.useCallback(async(J,xe,Ce)=>{if(xe==="stage"){if(e.stageGitFiles){await e.stageGitFiles(J,Ce);return}await Promise.all(Ce.map($e=>e.stageGitFile(J,$e)));return}if(e.unstageGitFiles){await e.unstageGitFiles(J,Ce);return}await Promise.all(Ce.map($e=>e.unstageGitFile(J,$e)))},[e]),ve=a.useMemo(()=>Bb({runMutation:({directory:J,direction:xe,paths:Ce})=>ue(J,xe,Ce),onMutationComplete:({directory:J})=>{je(J),De(J)},onMutationError:({directory:J,direction:xe,rollback:Ce},$e)=>{Ce?.(),je(J),De(J);const wt=t(xe==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");ae.error($e instanceof Error?$e.message:wt)},onPathsComplete:J=>{It(xe=>{const Ce=new Set(xe);return J.forEach($e=>Ce.delete($e)),Ce})},scheduleFlush:ke}),[je,ue,ke,De,t]);a.useEffect(()=>(we.current=ve.flush,()=>{we.current=null}),[ve]),a.useEffect(()=>()=>ve.clear(),[ve]),a.useEffect(()=>le,[le]),a.useEffect(()=>{if(!n){o(null),c(!1);return}let J=!1,xe=null;const Ce=async()=>{try{const $e=await Xf(n);if(J)return;o($e.status),$e.status==="pending"&&(xe=window.setTimeout(()=>{Ce()},500))}catch{J||o(null)}};return Ce(),()=>{J=!0,xe!==null&&window.clearTimeout(xe)}},[n]),a.useEffect(()=>{const J=q.current;q.current=r,!(!n||!e)&&(J==="pending"&&r==="ready"&&(c(!0),z(n,e).finally(()=>{window.setTimeout(()=>{c(!1)},1200)})),r==="failed"&&(m(null),c(!1)))},[n,z,e,m,r]);const G=Lr(u?.bootstrapPendingDirectory??null),Ae=!!(n&&G&&G===Lr(n)),fe=!!(n&&(r==="pending"||Ae))||i,Ee=a.useMemo(()=>n?hd.get(n)??null:null,[n]),me=cs(J=>J.settingsGitmojiEnabled),[B,ye]=a.useState(null);a.useEffect(()=>{const J=T||C?.projectDirectory;if(!J){ye(null);return}let xe=!1;return wa(J).then(Ce=>{if(xe)return;const $e=Ce.trim();ye($e&&$e!=="HEAD"?$e:null)}).catch(()=>{xe||ye(null)}),()=>{xe=!0}},[T,C?.projectDirectory]);const[Oe,Q]=a.useState(Ee?.commitMessage??""),[Me,Re]=a.useState([]),[Ne,Be]=a.useState(!1),se=a.useRef(null),[O,A]=a.useState(null),[K,pe]=a.useState(!1),[_e,We]=a.useState(null),[Le,rt]=a.useState(25),[yt,Dt]=a.useState(!1),{triggerFireworks:st}=wx(),Pe=a.useRef(new Map),tt=a.useRef(0),Ye=a.useCallback(()=>{tt.current+=1,Dt(!0)},[]),nt=a.useCallback(()=>{tt.current=Math.max(0,tt.current-1),tt.current===0&&Dt(!1)},[]),[ft,mt]=a.useState(new Set),[ot,It]=a.useState(new Set),[dt,bt]=a.useState(!1),[He,Ze]=a.useState(0),[Ue,jt]=a.useState(!1),[Ge,it]=a.useState(Ee?.generatedHighlights??[]),Et=ot.size>0||ve.size()>0||ve.isRunning(),lt=a.useCallback(()=>{const J=se.current;J&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{J.scrollTo({top:J.scrollHeight,behavior:"smooth"})})})},[]),ct=T||C?.projectDirectory||null,Bt=j?.current||null,Ft=a.useMemo(()=>{const J=j?.tracking;return J?J.startsWith("origin/"):!0},[j?.tracking]),qt=a.useMemo(()=>{const J=C?.createdFromBranch,xe=typeof J=="string"?J.trim():"",Ce=typeof j?.current=="string"?j.current.trim():"",$e=typeof B=="string"?B.trim():"";return xe?xe===Ce&&xe.startsWith("opencode/")&&$e.length>0&&$e!==xe?$e:xe:$e||Ce||"HEAD"},[C?.createdFromBranch,j,B]),Ut=a.useCallback(()=>{it([])},[]),[At,Xt]=a.useState(new Set),[ls,es]=a.useState(new Map),[Gt,pt]=a.useState(new Set),[Yt,us]=a.useState(null),[Jt,ss]=a.useState(null),[hs,Wt]=a.useState([]),[gs,Ms]=a.useState(""),[Vt,vs]=a.useState(null),Ps=a.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(I,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(I,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[Ns,As]=a.useState(()=>{if(typeof window>"u")return"commit";const J=window.localStorage.getItem(md);return J==="worktree"?"branch":$b(J)?J:"commit"}),[Rt,xt]=a.useState([]),[Kt,Ht]=a.useState(null),[ns,rs]=a.useState(null),[ds,W]=a.useState([]),[qe,Qe]=a.useState(!1),[ht,Ct]=a.useState([]),[ut,ts]=a.useState("merge"),[js,xs]=a.useState(null),[Bs,Ts]=a.useState(!1),[dn,Ds]=a.useState(100),Vs=a.useMemo(()=>l?`openchamber.conflict:${l}`:null,[l]),Us=a.useCallback((J,xe,Ce)=>{if(!Vs||typeof window>"u")return;const $e={directory:J,conflictFiles:xe,operation:Ce};window.localStorage.setItem(Vs,JSON.stringify($e))},[Vs]),bs=a.useCallback(()=>{!Vs||typeof window>"u"||window.localStorage.removeItem(Vs)},[Vs]);a.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(md,Ns)},[Ns]),a.useEffect(()=>{if(!Vs||typeof window>"u"||!n)return;const J=window.localStorage.getItem(Vs);if(J)try{const xe=JSON.parse(J);if(xe.directory!==n){window.localStorage.removeItem(Vs);return}Ct(xe.conflictFiles??[]),ts(xe.operation??"merge"),Qe(!0)}catch{window.localStorage.removeItem(Vs)}},[Vs,n]);const[wr,yn]=a.useState(!1),[ks,ln]=a.useState("merge"),[Tn,un]=a.useState(""),Un=a.useCallback(J=>{cr(J).then(xe=>{if(xe.ok){ae.success(t("gitView.toast.commitHashCopied"));return}ae.error(t("gitView.toast.copyFailed"))})},[t]),wn=a.useCallback(J=>{Xt(xe=>{const Ce=new Set(xe);return Ce.has(J)?Ce.delete(J):Ce.add(J),Ce})},[]);a.useEffect(()=>{if(!n||!e)return;const J=Array.from(At).filter(xe=>!ls.has(xe)&&!Gt.has(xe));if(J.length!==0){pt(xe=>{const Ce=new Set(xe);for(const $e of J)Ce.add($e);return Ce});for(const xe of J)e.getCommitFiles(n,xe).then(Ce=>{es($e=>new Map($e).set(xe,Ce.files))}).catch(Ce=>{console.error("Failed to fetch commit files:",Ce),es($e=>new Map($e).set(xe,[]))}).finally(()=>{pt(Ce=>{const $e=new Set(Ce);return $e.delete(xe),$e})})}},[At,n,e,ls,Gt]),a.useEffect(()=>{n&&hd.set(n,{directory:n,commitMessage:Oe,generatedHighlights:Ge})},[Oe,n,Ge]),a.useEffect(()=>{N(),w(),S()},[N,w,S]),a.useEffect(()=>{if(!n||!e?.getRemoteUrl){ss(null);return}e.getRemoteUrl(n).then(ss).catch(()=>ss(null))},[n,e]);const zs=a.useCallback(async()=>{if(!n||!e?.getRemotes){xt([]);return}try{const J=await e.getRemotes(n);xt(J)}catch{xt([])}},[n,e]);a.useEffect(()=>{zs()},[zs]),a.useEffect(()=>{if(!me){Wt([]);return}let J=!1;const xe=Gb();return xe&&(Wt(xe.gitmojis),qb(xe))?()=>{J=!0}:((async()=>{try{const $e=await fetch(Hb);if(!$e.ok)throw new Error(`Failed to load gitmojis: ${$e.statusText}`);const wt=await $e.json(),Nt=Array.isArray(wt.gitmojis)?wt.gitmojis.filter(am):[];J||(Wt(Nt),Kb(Nt))}catch($e){J||console.warn("Failed to load gitmoji list:",$e)}})(),()=>{J=!0})},[me]),a.useEffect(()=>{n&&(_(n),V(n,e))},[n,_,V,e]),a.useEffect(()=>{if(n)return Ir.onGitRefreshHint(J=>{Lr(J.directory)===Lr(n)&&F(n,e)})},[n,F,e]);const is=a.useCallback(async(J=!0)=>{if(n)try{await Promise.all([F(n,e),te(n,e)])}catch(xe){if(J){const Ce=xe instanceof Error?xe.message:t("gitView.toast.refreshRepositoryFailed");ae.error(Ce)}}},[n,e,F,te,t]),Fs=a.useCallback(async()=>{n&&await Z(n,e,Le)},[n,e,Z,Le]),dr=a.useCallback(async()=>{n&&await U(n,e)},[n,e,U]);a.useEffect(()=>{if(!n||!e?.hasLocalIdentity||v!==!0)return;const J=typeof h=="string"?h.trim():"";if(!J||J==="global"||Pe.current.get(n)===J)return;let Ce=!1;return(async()=>{try{const wt=await e.hasLocalIdentity?.(n);if(Ce||wt===!0)return;Ye(),await e.setGitIdentity(n,J),Pe.current.set(n,J),await dr()}catch(wt){console.warn("Failed to auto-apply default git identity:",wt)}finally{Ce||nt()}})(),()=>{Ce=!0}},[Ye,n,h,nt,e,v,dr]);const Cn=a.useMemo(()=>{if(!j)return[];const J=j.files??[],xe=new Map;for(const Ce of J)xe.set(Ce.path,Ce);return Array.from(xe.values()).sort((Ce,$e)=>Ce.path.localeCompare($e.path))},[j]),$s=a.useMemo(()=>Cn.filter(pd),[Cn]),Hn=a.useMemo(()=>Cn.filter(Jb),[Cn]);a.useEffect(()=>{if(!n||Cn.length===0)return;const J=[],xe=new Set,Ce=wt=>{!wt||xe.has(wt)||(xe.add(wt),J.push(wt))};if($s.forEach(wt=>Ce(wt.path)),Me.forEach(Ce),Cn.slice(0,Ub).forEach(wt=>Ce(wt.path)),J.length===0)return;const $e=window.setTimeout(()=>{ie(n,e,J,{maxFiles:Wb})},120);return()=>{window.clearTimeout($e)}},[Cn,n,e,ie,$s,Me]);const vr=J=>J?.pushed[0]?.remote||j?.tracking?.split("/")[0]||ms.find(xe=>xe.name==="origin")?.name||ms[0]?.name||"origin",Er=async(J,xe)=>{if(n){A(J);try{const Ce=$e=>{const wt=`${$e.name}/`,Nt=j?.tracking?.startsWith(wt)?j.tracking.slice(wt.length):void 0;return{remote:$e.name,branch:Nt,rebase:!0}};if(J==="fetch"){if(!xe)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:xe.name}),ae.success(t("gitView.toast.fetchedFromRemote",{name:xe.name}))}else if(J==="pull"){if(!xe)throw new Error("No remote available for pull");const $e=await e.gitPull(n,Ce(xe));ae.success($e.files.length===1?t("gitView.toast.pulledFilesSingle",{count:$e.files.length,name:xe.name}):t("gitView.toast.pulledFilesPlural",{count:$e.files.length,name:xe.name}))}else if(J==="push"){const $e=await e.gitPush(n);ae.success(t("gitView.toast.pushedToUpstream",{name:vr($e)}))}else if(J==="sync"){if(!xe)throw new Error("No remote available for sync");let $e=0,wt=!1;await e.gitFetch(n,{remote:xe.name});const Nt=await e.getGitStatus(n);if((Nt.behind??0)>0){if((Nt.files?.length??0)>0){ae.error(t("gitView.toast.commitOrStashBeforeSync"));return}$e=(await e.gitPull(n,Ce(xe))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),wt=!0),$e>0&&wt?ae.success($e===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:$e,name:xe.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:$e,name:xe.name})):$e>0?ae.success($e===1?t("gitView.toast.pulledFilesSingle",{count:$e,name:xe.name}):t("gitView.toast.pulledFilesPlural",{count:$e,name:xe.name})):wt?ae.success(t("gitView.toast.pushedToUpstream",{name:xe.name})):ae.success(t("gitView.toast.alreadyUpToDate"))}await is(!1),await Fs()}catch(Ce){const $e=Ce instanceof Error?Ce.message:t("gitView.toast.syncActionFailed",{action:J==="sync"?t("gitView.sync.syncChanges"):J==="pull"?t("gitView.sync.pull"):J});ae.error($e)}finally{A(null)}}},jr=a.useCallback(async J=>{if(!n)return;const xe=J.name.trim();if(!xe){ae.error(t("gitView.toast.remoteNameRequired"));return}if(xe==="origin"){ae.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Ht(xe);try{await e.removeRemote(n,{remote:xe}),ae.success(t("gitView.toast.removedRemote",{name:xe})),await Promise.all([is(!1),zs()])}catch(Ce){const $e=Ce instanceof Error?Ce.message:`Failed to remove ${xe}`;ae.error($e)}finally{Ht(null)}},[n,e,zs,is,t]),sr=async(J={})=>{if(!n)return;if(!Oe.trim()){ae.error(t("gitView.toast.enterCommitMessage"));return}const xe=$s.map($e=>$e.path).sort();if(xe.length===0){ae.error(t("gitView.toast.stageFileToCommit"));return}const Ce=J.pushAfter?"commitAndPush":"commit";We(Ce);try{if(await e.createGitCommit(n,Oe.trim(),{files:xe,stageFiles:[]}),je(n),ae.success(t("gitView.toast.commitCreated")),Q(""),Ut(),await is(),J.pushAfter){const $e=await e.gitPush(n);ae.success(t("gitView.toast.pushedToUpstream",{name:vr($e)})),st(),await is(!1)}else await is(!1);await Fs(),Ze($e=>$e+1)}catch($e){const wt=$e instanceof Error?$e.message:t("gitView.toast.createCommitFailed");ae.error(wt)}finally{We(null),J.pushAfter&&A(null)}},nr=a.useCallback(async()=>{if(!n)return;const J=$s.map(xe=>xe.path).sort();if(J.length===0){ae.error(t("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:J.length}),jt(!0);try{const{message:xe}=await Qf(n,J),Ce=xe.subject?.trim()??"",$e=Array.isArray(xe.highlights)?xe.highlights:[];if(Ce){let wt=Ce;if(me&&hs.length>0){const Nt=Yb(Ce,hs);if(Nt){const{code:Ss,emoji:Os}=Nt;!Ce.startsWith(Ss)&&!Ce.startsWith(Os)&&(wt=`${Ss} ${Ce}`)}}Q(wt)}it($e),lt()}catch(xe){console.error("[git-generation][browser] GitView generate handler failed",{message:xe instanceof Error?xe.message:String(xe),error:xe});const Ce=xe instanceof Error?xe.message:t("gitView.toast.generateCommitMessageFailed");ae.error(Ce)}finally{jt(!1)}},[n,$s,me,hs,lt,t]),Sr=J=>J.reason==="attention"?`${J.attentionReason} in progress`:J.reason==="missing"?"worktree is missing":"worktree is invalid",Rr=async(J,xe)=>{if(!n||!j)return;const Ce=Pa(k);if(Ce.length>0){ae.error(t("gitView.toast.cannotCreateBranch",{reason:Sr(Ce[0])}));return}const $e=j.current??null,wt=xe?.name??"origin";try{await e.createBranch(n,J,$e??"HEAD"),ae.success(t("gitView.toast.createdBranch",{name:J})),await e.checkoutBranch(n,J);let Nt=!1;try{await e.gitPush(n,{remote:wt,branch:J,options:["--set-upstream"]}),Nt=!0}catch(Ss){const Os=Ss instanceof Error?Ss.message:`Unable to push new branch to ${wt}.`;ae.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Os]})})}await is(),await Fs(),Nt&&ae.success(t("gitView.toast.upstreamSet",{branch:J,remote:wt}))}catch(Nt){const Ss=Nt instanceof Error?Nt.message:t("gitView.toast.createBranchFailed");throw ae.error(Ss),Nt}},ee=async(J,xe)=>{if(!n)return;const Ce=Pa(k);if(Ce.length>0){ae.error(t("gitView.toast.cannotRenameBranch",{reason:Sr(Ce[0])}));return}try{await e.renameBranch(n,J,xe),ae.success(t("gitView.toast.renamedBranch",{oldName:J,newName:xe})),await is(),await Fs()}catch($e){const wt=$e instanceof Error?$e.message:t("gitView.toast.renameBranchFailed",{oldName:J,newName:xe});ae.error(wt)}},at=async J=>{if(!n)return;const xe=Pa(k);if(xe.length>0){ae.error(t("gitView.toast.cannotCheckout",{reason:Sr(xe[0])}));return}const Ce=J.replace(/^remotes\//,"");if(j?.current!==Ce)try{await e.checkoutBranch(n,Ce),ae.success(t("gitView.toast.checkedOut",{name:Ce})),await is(),await Fs()}catch($e){const wt=$e instanceof Error?$e.message:t("gitView.toast.checkoutFailed",{name:Ce});ae.error(wt)}},St=async J=>{if(n){Ye();try{await e.setGitIdentity(n,J.id),ae.success(t("gitView.toast.appliedIdentity",{name:J.name})),await dr()}catch(xe){const Ce=xe instanceof Error?xe.message:t("gitView.toast.applyIdentityFailed");ae.error(Ce)}finally{nt()}}},$t=a.useMemo(()=>P?.all?P.all.filter(J=>!J.startsWith("remotes/")).sort():[],[P]),fs=a.useMemo(()=>P?.all?P.all.filter(J=>J.startsWith("remotes/")).map(J=>J.replace(/^remotes\//,"")).sort():[],[P]),ms=a.useMemo(()=>{if(Rt.length>0)return Rt;const J=new Set,xe=j?.tracking?.trim();xe&&xe.includes("/")&&J.add(xe.split("/")[0]);for(const Ce of fs){const $e=Ce.indexOf("/");$e>0&&J.add(Ce.slice(0,$e))}return J.size===0&&Jt&&J.add("origin"),Array.from(J).map(Ce=>({name:Ce,fetchUrl:Jt??"",pushUrl:Jt??""}))},[Rt,fs,Jt,j?.tracking]),Qt=a.useMemo(()=>{const J=new Set(ms.map(wt=>wt.name)),xe=wt=>{if(!wt)return"";let Nt=wt.trim();if(!Nt||Nt==="HEAD")return"";if($t.includes(Nt))return Nt;Nt.startsWith("refs/heads/")&&(Nt=Nt.slice(11)),Nt.startsWith("heads/")&&(Nt=Nt.slice(6)),Nt.startsWith("remotes/")&&(Nt=Nt.slice(8));const Ss=Nt.indexOf("/");if(Ss>0){const Os=Nt.slice(0,Ss);if(J.has(Os)){const qn=Nt.slice(Ss+1).trim();qn&&(Nt=qn)}}return Nt},Ce=xe(typeof C?.createdFromBranch=="string"?C.createdFromBranch:"");if(Ce)return Ce;const $e=xe(typeof B=="string"?B:"");return $e||($t.includes("main")?"main":$t.includes("master")?"master":$t.includes("develop")?"develop":"main")},[ms,$t,B,C?.createdFromBranch]),Ws=a.useMemo(()=>ms.map(Ce=>Ce.name).map(Ce=>`${Ce}/${Qt}`).find(Ce=>fs.includes(Ce))??Qt,[Qt,ms,fs]),Is=a.useMemo(()=>{const J=new Map;b&&J.set(b.id,b);let xe=null;if(Jt)try{let Ce=Jt.trim();Ce.startsWith("git@")&&(Ce=`https://${Ce.slice(4).replace(":","/")}`),Ce.endsWith(".git")&&(Ce=Ce.slice(0,-4));const $e=new URL(Ce);xe=$e.hostname+$e.pathname}catch{}for(const Ce of y){if(Ce.authType!=="token"){J.set(Ce.id,Ce);continue}const $e=Ce.host;if(!$e){J.set(Ce.id,Ce);continue}if(!$e.includes("/")){J.set(Ce.id,Ce);continue}xe&&xe===$e&&J.set(Ce.id,Ce)}return Array.from(J.values())},[y,b,Jt]),Gn=a.useMemo(()=>{if(M?.userName&&M?.userEmail){const J=y.find(xe=>xe.userName===M.userName&&xe.userEmail===M.userEmail);return J||(b&&b.userName===M.userName&&b.userEmail===M.userEmail?b:{id:"local-config",name:M.userName,userName:M.userName,userEmail:M.userEmail,sshKey:M.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return b??null},[M,y,b]),ur=$s.length,_r=H||O!==null||_e!==null,pn=j?.current??null,Ln=!!(C&&ct&&Bt&&Ft),mn=!!(n&&pn),ps=!!pn,Zs=Ln&&ct&&Bt&&C?{repoRoot:ct,sourceBranch:Bt,worktreeMetadata:C}:null,vn=a.useMemo(()=>!mn||!n||!pn?null:{directory:n,branch:pn},[mn,pn,n]);a.useEffect(()=>{if(!n||!e||!E?.all?.length||!pn||!Qt||pn===Qt){us(null);return}let J=!1;return(async()=>{try{const Ce=await e.getGitLog(n,{from:Qt,to:"HEAD",maxCount:Le});if(J)return;const $e=new Set((Ce?.all??[]).map(Nt=>Nt.hash).filter(Nt=>typeof Nt=="string"&&Nt.length>0));if($e.size===0){us(null);return}const wt=E.all.findIndex(Nt=>!$e.has(Nt.hash));if(wt===0){us(null);return}if(wt===-1){us({insertBeforeIndex:E.all.length,branchName:pn,direction:"up"});return}us({insertBeforeIndex:wt,branchName:pn,direction:"up"})}catch{J||us(null)}})(),()=>{J=!0}},[Qt,pn,n,e,E,Le]),a.useEffect(()=>{xs(null)},[n]),a.useEffect(()=>{if(Vt!=="graph"||!n){Vt!=="graph"&&xs(null);return}let J=!1;return Ts(!0),e.getGitLog(n,{maxCount:dn,all:!0}).then(xe=>{J||xs(xe)}).catch(xe=>{console.error("Failed to fetch graph log:",xe)}).finally(()=>{J||Ts(!1)}),()=>{J=!0}},[Vt,n,dn,e]);const jn=a.useCallback((J,xe)=>{if(!n||J.length===0)return;const Ce=Array.from(new Set(J));It(wt=>{const Nt=new Set(wt);return Ce.forEach(Ss=>Nt.add(Ss)),Nt});const $e=oe(n,Ce,xe);ve.enqueue({directory:n,direction:xe,paths:new Set(Ce),rollback:()=>ge(n,$e)}),ke()},[n,ve,oe,ge,ke]),Kn=a.useCallback(async J=>{if(n){mt(xe=>{const Ce=new Set(xe);return Ce.add(J),Ce});try{await e.revertGitFile(n,J,{scope:"working"}),ae.success(t("gitView.toast.revertedFile",{path:J})),await is(!1)}catch(xe){const Ce=xe instanceof Error?xe.message:t("gitView.toast.revertFailed");ae.error(Ce)}finally{mt(xe=>{const Ce=new Set(xe);return Ce.delete(J),Ce})}}},[n,is,e,t]),Nr=a.useCallback(async J=>{if(!n||J.length===0||dt)return;const xe=Array.from(new Set(J)),Ce=new Set($s.map(Nt=>Nt.path)),$e=xe.some(Nt=>Ce.has(Nt));bt(!0),mt(Nt=>{const Ss=new Set(Nt);return xe.forEach(Os=>Ss.add(Os)),Ss});const wt=[];try{if(await Promise.all(xe.map(async Nt=>{try{await e.revertGitFile(n,Nt)}catch(Ss){wt.push({path:Nt,message:Ss instanceof Error?Ss.message:t("gitView.toast.revertFailed")})}})),$e&&wt.length<xe.length&&je(n),await is(!1),wt.length===0)ae.success(xe.length===1?t("gitView.toast.revertedFilesSingle",{count:xe.length}):t("gitView.toast.revertedFilesPlural",{count:xe.length}));else if(wt.length===xe.length)ae.error(wt[0]?.message||t("gitView.toast.revertFailed"));else{const Nt=xe.length-wt.length;ae.warning(Nt===1?t("gitView.toast.revertedSomeSingle",{success:Nt,failed:wt.length}):t("gitView.toast.revertedSomePlural",{success:Nt,failed:wt.length}))}}finally{mt(Nt=>{const Ss=new Set(Nt);return xe.forEach(Os=>Ss.delete(Os)),Ss}),bt(!1)}},[je,n,e,dt,is,$s,t]),en=a.useCallback((J,xe)=>{if(n&&!Se){re(n,J,xe);return}L(J,xe),Se&&$(!1)},[n,Se,L,re,$]),kr=a.useCallback(()=>pe(!0),[]),qi=a.useMemo(()=>{const J=[];return $s.length>0&&J.push({id:"staged",title:t("gitView.changes.stagedTitle"),entries:$s,actionSymbol:"-",actionAllLabel:t("gitView.changes.unstageAllAria"),getActionLabel:xe=>t("gitView.changes.unstageFileAria",{path:xe}),onActionFile:xe=>{jn([xe],"unstage")},onActionAll:xe=>{jn(xe,"unstage")},onViewDiff:xe=>en(xe,!0),onRevertFile:Kn,showRevertActions:!1,accent:!0}),Hn.length>0&&J.push({id:"unstaged",title:t("gitView.changes.title"),entries:Hn,actionSymbol:"+",actionAllLabel:t("gitView.changes.stageAllAria"),getActionLabel:xe=>t("gitView.changes.stageFileAria",{path:xe}),onActionFile:xe=>{jn([xe],"stage")},onActionAll:xe=>{jn(xe,"stage")},onViewDiff:xe=>en(xe,!1),onRevertFile:Kn}),J},[Kn,en,jn,$s,t,Hn]),ji=a.useCallback(J=>{if(J.length===0)return;const xe=J.map(Ce=>Ce.trim()).filter(Boolean);if(xe.length===0){Ut();return}Q(Ce=>{const $e=Ce.trim(),wt=$e.length>0?`
11
-
12
- `:"";return`${$e}${wt}${xe.join(`
13
- `)}`.trim()}),Ut()},[Ut]),Yi=a.useCallback((J,xe)=>{const Ce=xe||J;Q($e=>{const wt=$e.trimStart();return wt.startsWith(J)||xe&&wt.startsWith(xe)?$e:`${Ce.endsWith(" ")?Ce:`${Ce} `}${$e}`.trimStart()}),Ms(""),Be(!1)},[]),si=a.useCallback(J=>{const xe=J instanceof Error?J.message.toLowerCase():"";return xe.includes("uncommitted changes")||xe.includes("local changes")||xe.includes("your local changes would be overwritten")||xe.includes("please commit your changes or stash them")||xe.includes("cannot rebase: you have unstaged changes")||xe.includes("error: cannot pull with rebase")},[]),rr=a.useCallback((J,xe)=>{W(Ce=>[...Ce,{message:J,status:xe,timestamp:Date.now()}])},[]),gn=a.useCallback((J,xe)=>{W(Ce=>{if(Ce.length===0)return Ce;const $e=[...Ce];return $e[$e.length-1]={...$e[$e.length-1],status:J,...xe?{message:xe}:{}},$e})},[]),Br=a.useCallback(()=>{W([])},[]),Mr=a.useCallback(()=>{W([]),rs(null)},[]),Js=a.useCallback(J=>{const xe=J.trim(),Ce=new Set(ms.map(wt=>wt.name)),$e=xe.indexOf("/");if($e>0){const wt=xe.slice(0,$e),Nt=xe.slice($e+1);if(Ce.has(wt)&&Nt)return{branch:xe,remote:wt,remoteBranch:Nt}}for(const wt of ms){const Nt=`${wt.name}/${xe}`;if(fs.includes(Nt))return{branch:Nt,remote:wt.name,remoteBranch:xe}}return{branch:xe,remote:null,remoteBranch:null}},[ms,fs]),mr=a.useCallback(async J=>{if(!n)return;rs("merge"),Br();const xe=j?.current,Ce=Js(J);try{Ce.remote&&Ce.remoteBranch&&(rr(`Fetching ${Ce.remote}/${Ce.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:Ce.remote,branch:Ce.remoteBranch}),gn("done",`Fetched ${Ce.remote}/${Ce.remoteBranch}`)),rr(`Merging ${Ce.branch} into ${xe}...`,"running");const $e=await e.merge(n,{branch:Ce.branch});$e.conflict?(gn("error","Merge conflicts detected"),Ct($e.conflictFiles??[]),ts("merge"),Qe(!0),Us(n,$e.conflictFiles??[],"merge")):(gn("done",`Merged ${Ce.branch} into ${xe}`),bs(),rr("Refreshing repository status...","running"),await is(),await Fs(),gn("done","Repository status updated"))}catch($e){if(si($e))gn("error","Uncommitted changes detected"),ln("merge"),un(Ce.branch),yn(!0);else{const wt=$e instanceof Error?$e.message:`Failed to merge ${Ce.branch}`;gn("error",wt)}}},[n,e,j,Js,is,Fs,si,Us,bs,rr,gn,Br]),Si=a.useCallback(async J=>{if(!n)return;rs("rebase"),Br();const xe=j?.current,Ce=Js(J);try{Ce.remote&&Ce.remoteBranch&&(rr(`Fetching ${Ce.remote}/${Ce.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:Ce.remote,branch:Ce.remoteBranch}),gn("done",`Fetched ${Ce.remote}/${Ce.remoteBranch}`)),rr(`Rebasing ${xe} onto ${Ce.branch}...`,"running");const $e=await e.rebase(n,{onto:Ce.branch});$e.conflict?(gn("error","Rebase conflicts detected"),Ct($e.conflictFiles??[]),ts("rebase"),Qe(!0),Us(n,$e.conflictFiles??[],"rebase")):(gn("done",`Rebased ${xe} onto ${Ce.branch}`),bs(),rr("Refreshing repository status...","running"),await is(),await Fs(),gn("done","Repository status updated"))}catch($e){if(si($e))gn("error","Uncommitted changes detected"),ln("rebase"),un(Ce.branch),yn(!0);else{const wt=$e instanceof Error?$e.message:`Failed to rebase onto ${Ce.branch}`;gn("error",wt)}}},[n,e,j,Js,is,Fs,si,Us,bs,rr,gn,Br]),Cr=a.useCallback(async()=>{if(n)try{ut==="merge"?(await e.abortMerge(n),ae.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),ae.success(t("gitView.toast.rebaseAborted"))),bs(),await is(),await Fs()}catch(J){const xe=J instanceof Error?J.message:`Failed to abort ${ut}`;ae.error(xe)}},[n,e,ut,is,Fs,bs,t]),fr=a.useMemo(()=>j?.files?j.files.some(J=>J.index==="U"||J.working_dir==="U"||J.index==="A"&&J.working_dir==="A"||J.index==="D"&&J.working_dir==="D"):!1,[j?.files]),Vr=a.useCallback(async()=>{if(n)try{const J=!!j?.mergeInProgress?.head,xe=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(J){const Ce=await e.continueMerge(n);Ce.conflict?(Ct(Ce.conflictFiles??[]),ts("merge"),Qe(!0),Us(n,Ce.conflictFiles??[],"merge"),ae.error(t("gitView.toast.mergeConflictsDetected"))):(bs(),ae.success(t("gitView.toast.mergeCompleted")),await is(),await Fs())}else if(xe){const Ce=await e.continueRebase(n);Ce.conflict?(Ct(Ce.conflictFiles??[]),ts("rebase"),Qe(!0),Us(n,Ce.conflictFiles??[],"rebase"),ae.error(t("gitView.toast.rebaseConflictsDetected"))):(bs(),ae.success(t("gitView.toast.rebaseStepCompleted")),await is(),await Fs())}}catch(J){const xe=J instanceof Error?J.message:t("gitView.toast.continueOperationFailed");ae.error(xe)}},[n,e,j,is,Fs,Us,bs,t]),Ls=a.useCallback(async()=>{if(n)try{!!j?.mergeInProgress?.head?(await e.abortMerge(n),ae.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),ae.success(t("gitView.toast.rebaseAborted"))),bs(),await is(),await Fs()}catch(J){const xe=J instanceof Error?J.message:t("gitView.toast.abortOperationFailed");ae.error(xe)}},[n,e,j,is,Fs,bs,t]),xn=a.useCallback(()=>{if(!n)return;const xe=!!j?.mergeInProgress?.head?"merge":"rebase",Ce=j?.files?.filter($e=>$e.index==="U"||$e.working_dir==="U").map($e=>$e.path)??[];Ce.length>0&&Ct(Ce),ts(xe),Qe(!0)},[n,j]),hr=a.useCallback(async J=>{if(!n)return;const xe=j?.current,Ce=ks,$e=Tn,wt=(j?.files??[]).some(pd);try{await e.stash(n,{message:`Auto-stash before ${Ce} with ${$e}`,includeUntracked:!0}),wt&&je(n)}catch(Os){const qn=Os instanceof Error?Os.message:"Failed to stash changes";ae.error(qn);return}let Nt=!1,Ss=!1;try{if(Ce==="merge"){const Os=await e.merge(n,{branch:$e});Os.conflict?(Ss=!0,Ct(Os.conflictFiles??[]),ts("merge"),Qe(!0)):(Nt=!0,ae.success(t("gitView.toast.mergedIntoBranch",{branch:$e,currentBranch:xe||""})))}else{const Os=await e.rebase(n,{onto:$e});Os.conflict?(Ss=!0,Ct(Os.conflictFiles??[]),ts("rebase"),Qe(!0)):(Nt=!0,ae.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:xe||"",branch:$e})))}if(J&&Nt)try{await e.stashPop(n),je(n),ae.success(t("gitView.toast.stashedRestored"))}catch(Os){const qn=Os instanceof Error?Os.message:t("gitView.toast.restoreStashFailed");ae.error(qn)}else J&&Ss&&ae.info(t("gitView.toast.restoreStashManually"));await is(),await Fs()}catch(Os){if(J)try{await e.stashPop(n),je(n)}catch{}throw Os}},[je,n,e,j,ks,Tn,is,Fs,t]),ni=a.useCallback(J=>{rt(J),n&&(ne(n,J),Z(n,e,J))},[n,Z,e,ne]),ri=a.useCallback(J=>{Ds(J)},[]),$r=a.useCallback(()=>{vs(null),n&&(F(n,e),te(n,e),Z(n,e,Le))},[n,F,te,Z,Le,e]),Qs=a.useCallback(J=>{if(J.conflict){if(J.operation==="cherry-pick"||J.operation==="revert"){ae.error(t("gitView.history.actions.conflictToastTitle"),{description:t("gitView.history.actions.conflictToastDescription",{files:J.conflictFiles?.join(", ")??"unknown files"})}),n&&(F(n,e),te(n,e),Z(n,e,Le));return}Ct(J.conflictFiles??[]),ts(J.operation),Qe(!0),n&&Us(n,J.conflictFiles??[],J.operation)}},[t,Ct,ts,Qe,Us,n,F,te,Z,Le,e]);return n?v===null||v===!0&&!j?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):v===!1?fe?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.notGitRepositoryDescription")}),D.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:Te("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx($p,{status:j,localBranches:$t,remoteBranches:fs,branchInfo:P?.branches,syncAction:O,remotes:ms,onFetch:J=>Er("fetch",J),onSync:J=>Er("sync",J),onRemoveRemote:jr,removingRemoteName:Kt,onCheckoutBranch:at,onCreateBranch:Rr,onRenameBranch:ee,activeIdentityProfile:Gn,availableIdentities:Is,onSelectIdentity:St,isApplyingIdentity:yt,isWorktreeMode:!!C,onOpenHistory:()=>vs("history"),onOpenGraph:()=>vs("graph"),onOpenStashes:kr,actionTabItems:Ps,activeActionTab:Ns,onSelectActionTab:J=>As(J)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(Eb,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:Vr,onAbort:Ls,onResolveWithAI:xn,hasUnresolvedConflicts:fr,isLoading:H}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:Te("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Fn,{as:ba,ref:se,outerClassName:"flex-1 min-h-0",className:Te("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[Ns==="commit"?s.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(Cn?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(zp,{groups:qi,diffStats:j?.diffStats,revertingPaths:ft,isRevertingAll:dt,onVisiblePathsChange:Re,onRevertAll:Nr})}),s.jsx(Wp,{stagedCount:ur,commitMessage:Oe,onCommitMessageChange:Q,generatedHighlights:Ge,onInsertHighlights:ji,onGenerateMessage:nr,isGeneratingMessage:Ue,onCommit:()=>sr({pushAfter:!1}),onCommitAndPush:()=>sr({pushAfter:!0}),commitAction:_e,hasPendingIndexMutation:Et,gitmojiEnabled:me,onOpenGitmojiPicker:()=>Be(!0)})]}):s.jsx(Fx,{onOpenStashes:()=>pe(!0)})}):null,Ns==="branch"?s.jsx("div",{className:"space-y-4",children:ps?s.jsxs(s.Fragment,{children:[s.jsx(Rb,{mode:"inline",currentBranch:j?.current,localBranches:$t,remoteBranches:fs,defaultTargetBranch:Ws,onMerge:mr,onRebase:Si,disabled:_r,isOperating:ns!==null,operationLogs:ds,onOperationComplete:Mr}),Zs?s.jsx(Rx,{repoRoot:Zs.repoRoot,sourceBranch:Zs.sourceBranch,worktreeMetadata:Zs.worktreeMetadata,localBranches:$t,defaultTargetBranch:qt,refreshKey:He,onRefresh:()=>{n&&(F(n,e),te(n,e),Z(n,e,Le))}},Zs.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,Ns==="pr"?s.jsx("div",{className:"space-y-4",children:vn?s.jsx(Sb,{directory:vn.directory,branch:vn.branch,baseBranch:Qt,trackingBranch:j?.tracking??void 0,remotes:Rt,remoteBranches:fs,onGeneratedDescription:lt}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:t("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(Ks,{open:Vt!==null,onOpenChange:J=>{J||vs(null)},children:s.jsxs(Gs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Xs,{children:[s.jsx(Ys,{children:t(Vt==="graph"?"gitView.graph.title":"gitView.history.title")}),s.jsx(cn,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(Ux,{mode:Vt==="graph"?"graph":"history",log:Vt==="graph"?js??E:E,isLogLoading:Vt==="graph"&&Bs||R,logMaxCount:Vt==="graph"?dn:Le,onLogMaxCountChange:Vt==="graph"?ri:ni,expandedCommitHashes:At,onToggleCommit:wn,commitFilesMap:ls,loadingCommitHashes:Gt,onCopyHash:Un,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Vt==="graph"?null:Yt,onConflict:Vt==="graph"?Qs:void 0,onActionSuccess:Vt==="graph"?$r:void 0})})]})}),s.jsx(Mx,{open:K,onOpenChange:pe,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,hasStagedChanges:$s.length>0,uncommittedFileCount:j?.files?.length??0,onChanged:async J=>{n&&J?.affectsIndex&&je(n),await is(!1),await Fs()}}),s.jsx(Ks,{open:Ne,onOpenChange:Be,children:s.jsxs(Gs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Xs,{className:"px-4 pt-4",children:s.jsx(Ys,{children:t("gitView.gitmoji.title")})}),s.jsxs(ma,{className:"h-[420px]",children:[s.jsx(fa,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:gs,onValueChange:Ms}),s.jsxs(ha,{children:[s.jsx(pa,{children:t("gitView.gitmoji.empty")}),s.jsx(qr,{children:(hs.length===0?[]:hs.filter(J=>{const xe=gs.trim().toLowerCase();return xe?J.emoji.includes(xe)||J.code.toLowerCase().includes(xe)||J.description.toLowerCase().includes(xe):!0})).map(J=>s.jsxs(Zr,{onSelect:()=>Yi(J.emoji,J.code),children:[s.jsx("span",{className:"text-lg",children:J.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:J.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:J.description})]},J.code))})]})]})]})}),n&&s.jsx(Nb,{open:qe,onOpenChange:Qe,conflictFiles:ht,directory:n,operation:ut,onAbort:Cr,onClearState:bs}),s.jsx(Tb,{open:wr,onOpenChange:yn,operation:ks,targetBranch:Tn,onConfirm:hr})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:t("gitView.empty.selectSessionOrDirectory")})})},Nl=5e3,Qb=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},Xb=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},Zb=async(t,e)=>{if(t.readFile)return(await t.readFile(e,{allowOutsideWorkspace:!0,optional:!0})).content??"";const n=new URLSearchParams({path:e,allowOutsideWorkspace:"true",optional:"true"}),r=await Rs(`/api/fs/read?${n.toString()}`,{cache:"no-store"});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to read file")}return r.text()},sc=async(t,e)=>{try{const n=await Zb(t,e);return Qb(n,Nl)>Nl?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:Xb(n)}}},nc=t=>t==="too-large"?`File is too large to open (>${Nl.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",ey=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Dn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},lm=(t,e)=>{const n=Dn(e),r=Dn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},ty=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),sy=new Set(["node_modules"]),ny=t=>sy.has(t),ry=t=>{const e=Dn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},cm=(t,e)=>s.jsx(yr,{filePath:t,extension:e}),iy=t=>{const e=gt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let i;return e[1]!==o?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=i):i=e[2],i},oy=t=>{const e=gt.c(63),{node:n,root:r,isExpanded:o,isActive:i,status:c,badge:l,permissions:u,downloadFile:m,contextMenuPath:d,setContextMenuPath:f,onSelect:g,onToggle:x,onRevealPath:p,onOpenDialog:y}=t,{t:b}=Tt(),h=n.type==="directory",{canRename:N,canCreateFile:w,canCreateFolder:S,canDelete:v,canReveal:j}=u;let k;e[0]!==w||e[1]!==S||e[2]!==v||e[3]!==N||e[4]!==j||e[5]!==n.path||e[6]!==f?(k=ie=>{!N&&!w&&!S&&!v&&!j||(ie?.preventDefault(),f(n.path))},e[0]=w,e[1]=S,e[2]=v,e[3]=N,e[4]=j,e[5]=n.path,e[6]=f,e[7]=k):k=e[7];const D=k;let T;e[8]!==h||e[9]!==n||e[10]!==g||e[11]!==x?(T=()=>{h?x(n.path):g(n)},e[8]=h,e[9]=n,e[10]=g,e[11]=x,e[12]=T):T=e[12];const C=T;let P;e[13]!==n.path||e[14]!==f?(P=ie=>{ie.stopPropagation(),f(n.path)},e[13]=n.path,e[14]=f,e[15]=P):P=e[15];const E=P;let M;e[16]!==n.path||e[17]!==r?(M=ie=>{const oe=lm(r,n.path);!oe||oe==="."||(ie.dataTransfer.setData("application/x-openchamber-file-path",oe),ie.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=M):M=e[18];const H=M,R=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let _;e[19]!==R?(_=Te("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",R,"cursor-grab active:cursor-grabbing"),e[19]=R,e[20]=_):_=e[20];let z;e[21]!==h||e[22]!==o||e[23]!==n.extension||e[24]!==n.path?(z=h?o?s.jsx(I,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):cm(n.path,n.extension),e[21]=h,e[22]=o,e[23]=n.extension,e[24]=n.path,e[25]=z):z=e[25];let V;e[26]!==n.name||e[27]!==n.path?(V=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[26]=n.name,e[27]=n.path,e[28]=V):V=e[28];let F;e[29]!==h||e[30]!==c?(F=!h&&c&&s.jsx(iy,{status:c}),e[29]=h,e[30]=c,e[31]=F):F=e[31];let te;e[32]!==l||e[33]!==h?(te=h&&l&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[l.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",l.modified]}),l.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",l.added]})]}),e[32]=l,e[33]=h,e[34]=te):te=e[34];let Z;e[35]!==D||e[36]!==H||e[37]!==C||e[38]!==te||e[39]!==_||e[40]!==z||e[41]!==V||e[42]!==F?(Z=s.jsxs("button",{type:"button",onClick:C,onContextMenu:D,draggable:!0,onDragStart:H,className:_,children:[z,V,F,te]}),e[35]=D,e[36]=H,e[37]=C,e[38]=te,e[39]=_,e[40]=z,e[41]=V,e[42]=F,e[43]=Z):Z=e[43];let ne;e[44]!==w||e[45]!==S||e[46]!==v||e[47]!==N||e[48]!==j||e[49]!==d||e[50]!==m||e[51]!==E||e[52]!==h||e[53]!==n||e[54]!==y||e[55]!==p||e[56]!==f||e[57]!==b?(ne=(N||w||S||v||j)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(on,{open:d===n.path,onOpenChange:ie=>f(ie?n.path:null),children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(nn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:E,title:b("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":b("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:b("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsxs(rn,{align:"end",side:"bottom",onCloseAutoFocus:()=>f(null),children:[N&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),y("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.rename")]}),s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),cr(n.path).then(oe=>{if(oe.ok){ae.success(b("sidebarFilesTree.toast.pathCopied"));return}ae.error(b("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.copyPath")]}),!h&&m&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),m(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.save")]}),j&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),p(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",b(Hl())]}),h&&(w||S)&&s.jsxs(s.Fragment,{children:[s.jsx(Mn,{}),w&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),y("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.newFile")]}),S&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),y("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.newFolder")]})]}),v&&s.jsxs(s.Fragment,{children:[s.jsx(Mn,{}),s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),y("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=w,e[45]=S,e[46]=v,e[47]=N,e[48]=j,e[49]=d,e[50]=m,e[51]=E,e[52]=h,e[53]=n,e[54]=y,e[55]=p,e[56]=f,e[57]=b,e[58]=ne):ne=e[58];let U;return e[59]!==D||e[60]!==Z||e[61]!==ne?(U=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:D,children:[Z,ne]}),e[59]=D,e[60]=Z,e[61]=ne,e[62]=U):U=e[62],U},ay=()=>{const t=gt.c(251),{t:e}=Tt(),{files:n}=Wn(),r=ti()??"";let o;t[0]!==r?(o=Dn(r.trim()),t[0]=r,t[1]=o):o=t[1];const i=o,c=Iu(),l=Pu(),u=Ul(ly),m=Fe(cy),d=ya(r),[f,g]=a.useState(""),x=va(f,200),p=a.useRef(null);let y;t[2]===Symbol.for("react.memo_cache_sentinel")?(y=[],t[2]=y):y=t[2];const[b,h]=a.useState(y),[N,w]=a.useState(!1);let S;t[3]===Symbol.for("react.memo_cache_sentinel")?(S={},t[3]=S):S=t[3];const[v,j]=a.useState(S);let k;t[4]===Symbol.for("react.memo_cache_sentinel")?(k={},t[4]=k):k=t[4];const[D,T]=a.useState(k);let C;t[5]===Symbol.for("react.memo_cache_sentinel")?(C=new Set,t[5]=C):C=t[5];const P=a.useRef(C);let E;t[6]===Symbol.for("react.memo_cache_sentinel")?(E=new Set,t[6]=E):E=t[6];const M=a.useRef(E);let H;t[7]===Symbol.for("react.memo_cache_sentinel")?(H=[],t[7]=H):H=t[7];const R=H;let _;t[8]===Symbol.for("react.memo_cache_sentinel")?(_=[],t[8]=_):_=t[8];const z=_;let V;t[9]!==i?(V=Rt=>i?Rt.byRoot[i]?.expandedPaths??R:R,t[9]=i,t[10]=V):V=t[10];const F=Nn(V);let te;t[11]!==i?(te=Rt=>i?Rt.byRoot[i]?.selectedPath??null:null,t[11]=i,t[12]=te):te=t[12];const Z=Nn(te),ne=Nn(dy),U=Nn(uy),ie=Nn(my),oe=Nn(fy);let ge;t[13]!==i?(ge=Rt=>i?Rt.contextPanelByDirectory[i]?.tabs??z:z,t[13]=i,t[14]=ge):ge=t[14];const je=Fe(ge);let Se;t[15]!==je?(Se=new Set(je.map(hy).filter(py).map(gy)),t[15]=je,t[16]=Se):Se=t[16];const re=Se,[L,$]=a.useState(null),[q,he]=a.useState(null),[de,we]=a.useState(null),[be,De]=a.useState(""),[le,ke]=a.useState(!1),ue=!!n.writeFile,ve=!!n.createDirectory,G=!!n.rename,Ae=!!n.delete,ce=!!n.revealPath;let fe;t[17]!==ue||t[18]!==ve||t[19]!==Ae||t[20]!==G||t[21]!==ce?(fe={canRename:G,canCreateFile:ue,canCreateFolder:ve,canDelete:Ae,canReveal:ce},t[17]=ue,t[18]=ve,t[19]=Ae,t[20]=G,t[21]=ce,t[22]=fe):fe=t[22];const Ee=fe;let me;t[23]!==n||t[24]!==e?(me=Rt=>{n.revealPath&&n.revealPath(Rt).catch(()=>{ae.error(e("sidebarFilesTree.toast.revealFailed"))})},t[23]=n,t[24]=e,t[25]=me):me=t[25];const B=me;let ye;t[26]===Symbol.for("react.memo_cache_sentinel")?(ye=(Rt,xt)=>{he(Rt),we(xt),De(Rt==="rename"&&xt.name||""),ke(!1)},t[26]=ye):ye=t[26];const Oe=ye;let Q;t[27]!==l||t[28]!==c?(Q=(Rt,xt)=>{const Kt=xt.filter(xy).filter(Ht=>c||!Ht.name.startsWith(".")).filter(Ht=>l||!ny(Ht.name)).map(Ht=>{const ns=Ht.name,rs=Dn(Ht.path||""),ds=rs?ty(rs)?rs:Dn(`${Rt}/${rs}`):Dn(`${Rt}/${ns}`),W=Ht.isDirectory?"directory":"file",qe=W==="file"&&ns.includes(".")?ns.split(".").pop()?.toLowerCase():void 0;return{name:ns,path:ds,type:W,extension:qe}});return ey(Kt)},t[27]=l,t[28]=c,t[29]=Q):Q=t[29];const Me=Q;let Re;t[30]!==n||t[31]!==Me||t[32]!==l?(Re=async Rt=>{const xt=Dn(Rt.trim());if(!xt||P.current.has(xt)||M.current.has(xt))return;M.current=new Set(M.current),M.current.add(xt);const Kt=!l;await(n.listDirectory?n.listDirectory(xt,{respectGitignore:Kt}).then(yy):zn.listLocalDirectory(xt,{respectGitignore:Kt}).then(vy)).then(ns=>{const rs=Me(xt,ns);P.current=new Set(P.current),P.current.add(xt),T(ds=>{if(!ds[xt])return ds;const W={...ds};return delete W[xt],W}),j(ds=>({...ds,[xt]:rs}))}).catch(ns=>{const rs=ns instanceof Error?ns.message:String(ns??"");console.error("Failed to load sidebar directory:",ns),T(ds=>({...ds,[xt]:rs}))}).finally(()=>{M.current=new Set(M.current),M.current.delete(xt)})},t[30]=n,t[31]=Me,t[32]=l,t[33]=Re):Re=t[33];const Ne=Re;let Be;t[34]!==Ne||t[35]!==i?(Be=async()=>{i&&(P.current=new Set,M.current=new Set,T({}),j(jy),await Ne(i))},t[34]=Ne,t[35]=i,t[36]=Be):Be=t[36];const se=Be;let O;t[37]!==Ne||t[38]!==se?(O=async Rt=>{if(!Rt){await se();return}const xt=Dn(Rt);P.current=new Set(P.current),P.current.delete(xt),M.current=new Set(M.current),M.current.delete(xt),await Ne(xt)},t[37]=Ne,t[38]=se,t[39]=O):O=t[39];const A=O;let K;t[40]!==Ne||t[41]!==i?(K=()=>{i&&(P.current=new Set,M.current=new Set,T({}),j(Sy),Ne(i))},t[40]=Ne,t[41]=i,t[42]=K):K=t[42];let pe;t[43]!==Ne||t[44]!==i||t[45]!==l||t[46]!==c?(pe=[Ne,i,c,l],t[43]=Ne,t[44]=i,t[45]=l,t[46]=c,t[47]=pe):pe=t[47],a.useEffect(K,pe);let _e,We;t[48]!==F||t[49]!==Ne||t[50]!==i?(_e=()=>{if(!i||F.length===0)return;const Rt=F.map(Ny).filter(Kt=>!!Kt&&Kt!==i&&Kt.startsWith(`${i}/`)&&!P.current.has(Kt)&&!M.current.has(Kt)).sort(ky);if(Rt.length===0)return;let xt=!1;return(async()=>{for(let Kt=0;Kt<Rt.length&&!xt;Kt=Kt+3,Kt){const Ht=Rt.slice(Kt,Kt+3);await Promise.all(Ht.map(ns=>Ne(ns)))}})(),()=>{xt=!0}},We=[F,Ne,i],t[48]=F,t[49]=Ne,t[50]=i,t[51]=_e,t[52]=We):(_e=t[51],We=t[52]),a.useEffect(_e,We);let Le,rt;t[53]!==r||t[54]!==x||t[55]!==u||t[56]!==l||t[57]!==c?(Le=()=>{if(!r){h([]),w(!1);return}const Rt=x.trim();if(!Rt){h([]),w(!1);return}let xt=!1;return w(!0),u(r,Rt,150,{includeHidden:c,respectGitignore:!l,type:"file"}).then(Kt=>{if(xt)return;const ns=Kt.filter(rs=>l||!ry(rs.path)).map(Cy);h(ns)}).catch(()=>{xt||h([])}).finally(()=>{xt||w(!1)}),()=>{xt=!0}},rt=[r,x,u,c,l],t[53]=r,t[54]=x,t[55]=u,t[56]=l,t[57]=c,t[58]=Le,t[59]=rt):(Le=t[58],rt=t[59]),a.useEffect(Le,rt);let yt;t[60]!==d||t[61]!==re||t[62]!==i?(yt=Rt=>{if(re.has(Rt))return"open";if(d?.files){const xt=Rt.startsWith(i+"/")?Rt.slice(i.length+1):Rt,Kt=d.files.find(Ht=>Ht.path===xt);if(Kt){if(Kt.index==="A"||Kt.working_dir==="?")return"git-added";if(Kt.index==="D")return"git-deleted";if(Kt.index==="M"||Kt.working_dir==="M")return"git-modified"}}return null},t[60]=d,t[61]=re,t[62]=i,t[63]=yt):yt=t[63];const Dt=yt;let st;t[64]!==d||t[65]!==i?(st=Rt=>{if(!d?.files)return null;const xt=Rt.startsWith(i+"/")?Rt.slice(i.length+1):Rt,Kt=xt?`${xt}/`:"";let Ht=0,ns=0;for(const rs of d.files)rs.path.startsWith(Kt)&&((rs.index==="M"||rs.working_dir==="M")&&Ht++,(rs.index==="A"||rs.working_dir==="?")&&ns++);return Ht+ns>0?{modified:Ht,added:ns}:null},t[64]=d,t[65]=i,t[66]=st):st=t[66];const Pe=st;let tt;t[67]!==U||t[68]!==n||t[69]!==m||t[70]!==i||t[71]!==ne?(tt=async Rt=>{if(!i)return;const xt=await sc(n,Rt.path);if(!xt.ok){ae.error(nc(xt.reason));return}ne(i,Rt.path),U(i,Rt.path),m(i,Rt.path)},t[67]=U,t[68]=n,t[69]=m,t[70]=i,t[71]=ne,t[72]=tt):tt=t[72];const Ye=tt;let nt;t[73]!==Ne||t[74]!==i||t[75]!==oe?(nt=async Rt=>{const xt=Dn(Rt);i&&(oe(i,xt),P.current.has(xt)||await Ne(xt))},t[73]=Ne,t[74]=i,t[75]=oe,t[76]=nt):nt=t[76];const ft=nt;let mt;t[77]!==q||t[78]!==de||t[79]!==be||t[80]!==n||t[81]!==A||t[82]!==ie||t[83]!==i||t[84]!==Z||t[85]!==ne||t[86]!==e?(mt=async Rt=>{if(Rt?.preventDefault(),!de||!q)return;ke(!0);const xt=()=>ke(!1),Kt=()=>he(null);if(q==="createFile"){if(!be.trim()){ae.error(e("sidebarFilesTree.toast.filenameRequired")),xt();return}if(!n.writeFile){ae.error(e("sidebarFilesTree.toast.writeNotSupported")),xt();return}const Ht=de.path,ns=Ht?`${Ht}/`:"",rs=Dn(`${ns}${be.trim()}`);await n.writeFile(rs,"").then(async ds=>{ds.success&&(ae.success(e("sidebarFilesTree.toast.fileCreated")),await A(Ht)),Kt()}).catch(()=>ae.error(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(q==="createFolder"){if(!be.trim()){ae.error(e("sidebarFilesTree.toast.folderNameRequired")),xt();return}const Ht=de.path,ns=Ht?`${Ht}/`:"",rs=Dn(`${ns}${be.trim()}`);await n.createDirectory(rs).then(async ds=>{ds.success&&(ae.success(e("sidebarFilesTree.toast.folderCreated")),await A(Ht)),Kt()}).catch(()=>ae.error(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(q==="rename"){if(!be.trim()){ae.error(e("sidebarFilesTree.toast.nameRequired")),xt();return}if(!n.rename){ae.error(e("sidebarFilesTree.toast.renameNotSupported")),xt();return}const Ht=de.path,ns=Ht.split("/").slice(0,-1).join("/"),rs=ns?`${ns}/`:"",ds=Dn(`${rs}${be.trim()}`);await n.rename(Ht,ds).then(async W=>{W.success&&(ae.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await A(ns),i&&ie(i,Ht),(Z===Ht||Z&&Z.startsWith(`${Ht}/`))&&ne(i,null)),Kt()}).catch(()=>ae.error(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(q==="delete"){if(!n.delete){ae.error(e("sidebarFilesTree.toast.deleteNotSupported")),xt();return}const Ht=de.path,ns=Ht.split("/").slice(0,-1).join("/");await n.delete(Ht).then(async rs=>{rs.success&&(ae.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await A(ns),i&&ie(i,Ht),(Z===Ht||Z&&Z.startsWith(Ht+"/"))&&ne(i,null)),Kt()}).catch(()=>ae.error(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}xt()},t[77]=q,t[78]=de,t[79]=be,t[80]=n,t[81]=A,t[82]=ie,t[83]=i,t[84]=Z,t[85]=ne,t[86]=e,t[87]=mt):mt=t[87];const ot=mt;let It,dt,bt,He,Ze,Ue,jt;if(t[88]!==ue||t[89]!==ve||t[90]!==v||t[91]!==L||t[92]!==r||t[93]!==F||t[94]!==Ee||t[95]!==n.downloadFile||t[96]!==Dt||t[97]!==Pe||t[98]!==Ye||t[99]!==B||t[100]!==D||t[101]!==se||t[102]!==i||t[103]!==f||t[104]!==b||t[105]!==N||t[106]!==Z||t[107]!==e||t[108]!==ft){let Rt=function(Ds,Vs){const Us=v[Ds]??[];return Us.map((bs,wr)=>{const yn=bs.type==="directory",ks=yn&&F.includes(bs.path),ln=Z===bs.path,Tn=wr===Us.length-1;return s.jsxs("li",{className:"relative",children:[Vs>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Tn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(oy,{node:bs,root:i,isExpanded:ks,isActive:ln,status:yn?void 0:Dt(bs.path),badge:yn?Pe(bs.path):void 0,permissions:Ee,downloadFile:n.downloadFile,contextMenuPath:L,setContextMenuPath:$,onSelect:Ye,onToggle:ft,onRevealPath:B,onOpenDialog:Oe}),yn&&ks&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Rt(bs.path,Vs+1)})]},bs.path)})};const xt=!!(i&&v[i]),Kt=i?D[i]:null;Ue="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let Ht;t[116]===Symbol.for("react.memo_cache_sentinel")?(Ht=s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[116]=Ht):Ht=t[116];let ns;t[117]===Symbol.for("react.memo_cache_sentinel")?(ns=Ds=>g(Ds.target.value),t[117]=ns):ns=t[117];let rs;t[118]!==e?(rs=e("sidebarFilesTree.search.placeholder"),t[118]=e,t[119]=rs):rs=t[119];let ds;t[120]!==f||t[121]!==rs?(ds=s.jsx(kn,{ref:p,value:f,onChange:ns,placeholder:rs,className:"h-8 pl-8 pr-8 typography-meta"}),t[120]=f,t[121]=rs,t[122]=ds):ds=t[122];let W;t[123]!==f||t[124]!==e?(W=f.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{g(""),p.current?.focus()},children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,t[123]=f,t[124]=e,t[125]=W):W=t[125];let qe;t[126]!==ds||t[127]!==W?(qe=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Ht,ds,W]}),t[126]=ds,t[127]=W,t[128]=qe):qe=t[128];let Qe;t[129]!==ue||t[130]!==r||t[131]!==e?(Qe=ue&&s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Oe("createFile",{path:r,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),"aria-label":e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFileTitle")})]}),t[129]=ue,t[130]=r,t[131]=e,t[132]=Qe):Qe=t[132];let ht;t[133]!==ve||t[134]!==r||t[135]!==e?(ht=ve&&s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Oe("createFolder",{path:r,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),"aria-label":e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFolderTitle")})]}),t[133]=ve,t[134]=r,t[135]=e,t[136]=ht):ht=t[136];let Ct;t[137]!==se?(Ct=()=>{se()},t[137]=se,t[138]=Ct):Ct=t[138];let ut;t[139]!==e?(ut=e("sidebarFilesTree.actions.refreshTitle"),t[139]=e,t[140]=ut):ut=t[140];let ts;t[141]!==e?(ts=e("sidebarFilesTree.actions.refreshTitle"),t[141]=e,t[142]=ts):ts=t[142];let js;t[143]===Symbol.for("react.memo_cache_sentinel")?(js=s.jsx(I,{name:"refresh",className:"h-4 w-4"}),t[143]=js):js=t[143];let xs;t[144]!==Ct||t[145]!==ut||t[146]!==ts?(xs=s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:Ct,className:"h-8 w-8 p-0 flex-shrink-0",title:ut,"aria-label":ts,children:js})})}),t[144]=Ct,t[145]=ut,t[146]=ts,t[147]=xs):xs=t[147];let Bs;t[148]!==e?(Bs=e("sidebarFilesTree.actions.refreshTitle"),t[148]=e,t[149]=Bs):Bs=t[149];let Ts;t[150]!==Bs?(Ts=s.jsx(_t,{side:"bottom",sideOffset:6,children:Bs}),t[150]=Bs,t[151]=Ts):Ts=t[151];let dn;t[152]!==xs||t[153]!==Ts?(dn=s.jsxs(Lt,{children:[xs,Ts]}),t[152]=xs,t[153]=Ts,t[154]=dn):dn=t[154],t[155]!==qe||t[156]!==Qe||t[157]!==ht||t[158]!==dn?(jt=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[qe,Qe,ht,dn]}),t[155]=qe,t[156]=Qe,t[157]=ht,t[158]=dn,t[159]=jt):jt=t[159],It=Fn,He="flex-1 min-h-0",Ze="p-2",dt="flex flex-col",bt=N?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):b.length>0?b.map(Ds=>{const Vs=Z===Ds.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Ye(Ds),draggable:!0,onDragStart:Us=>{const bs=Ds.relativePath||lm(i??"",Ds.path);!bs||bs==="."||(Us.dataTransfer.setData("application/x-openchamber-file-path",bs),Us.dataTransfer.effectAllowed="copy")},className:Te("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",Vs?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:Ds.path,children:[cm(Ds.path,Ds.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:Ds.relativePath??Ds.path})]})},Ds.path)}):Kt?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:Kt}),s.jsxs(ze,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{se()},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),e("sidebarFilesTree.actions.refreshTitle")]})]}):xt&&i?Rt(i,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=ue,t[89]=ve,t[90]=v,t[91]=L,t[92]=r,t[93]=F,t[94]=Ee,t[95]=n.downloadFile,t[96]=Dt,t[97]=Pe,t[98]=Ye,t[99]=B,t[100]=D,t[101]=se,t[102]=i,t[103]=f,t[104]=b,t[105]=N,t[106]=Z,t[107]=e,t[108]=ft,t[109]=It,t[110]=dt,t[111]=bt,t[112]=He,t[113]=Ze,t[114]=Ue,t[115]=jt}else It=t[109],dt=t[110],bt=t[111],He=t[112],Ze=t[113],Ue=t[114],jt=t[115];let Ge;t[160]!==dt||t[161]!==bt?(Ge=s.jsx("ul",{className:dt,children:bt}),t[160]=dt,t[161]=bt,t[162]=Ge):Ge=t[162];let it;t[163]!==It||t[164]!==He||t[165]!==Ze||t[166]!==Ge?(it=s.jsx(It,{outerClassName:He,className:Ze,children:Ge}),t[163]=It,t[164]=He,t[165]=Ze,t[166]=Ge,t[167]=it):it=t[167];const Et=!!q;let lt;t[168]===Symbol.for("react.memo_cache_sentinel")?(lt=Rt=>!Rt&&he(null),t[168]=lt):lt=t[168];let ct;t[169]!==q||t[170]!==e?(ct=q==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[169]=q,t[170]=e,t[171]=ct):ct=t[171];let Bt;t[172]!==q||t[173]!==e?(Bt=q==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[172]=q,t[173]=e,t[174]=Bt):Bt=t[174];let Ft;t[175]!==q||t[176]!==e?(Ft=q==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[175]=q,t[176]=e,t[177]=Ft):Ft=t[177];let qt;t[178]!==q||t[179]!==e?(qt=q==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[178]=q,t[179]=e,t[180]=qt):qt=t[180];let Ut;t[181]!==ct||t[182]!==Bt||t[183]!==Ft||t[184]!==qt?(Ut=s.jsxs(Ys,{children:[ct,Bt,Ft,qt]}),t[181]=ct,t[182]=Bt,t[183]=Ft,t[184]=qt,t[185]=Ut):Ut=t[185];let At;t[186]!==q||t[187]!==de?.path||t[188]!==e?(At=q==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:de?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[186]=q,t[187]=de?.path,t[188]=e,t[189]=At):At=t[189];let Xt;t[190]!==q||t[191]!==de?.path||t[192]!==e?(Xt=q==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:de?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[190]=q,t[191]=de?.path,t[192]=e,t[193]=Xt):Xt=t[193];let ls;t[194]!==q||t[195]!==de?.name||t[196]!==e?(ls=q==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:de?.name??""}),t[194]=q,t[195]=de?.name,t[196]=e,t[197]=ls):ls=t[197];let es;t[198]!==q||t[199]!==de?.name||t[200]!==e?(es=q==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:de?.name??""}),t[198]=q,t[199]=de?.name,t[200]=e,t[201]=es):es=t[201];let Gt;t[202]!==At||t[203]!==Xt||t[204]!==ls||t[205]!==es?(Gt=s.jsxs(cn,{children:[At,Xt,ls,es]}),t[202]=At,t[203]=Xt,t[204]=ls,t[205]=es,t[206]=Gt):Gt=t[206];let pt;t[207]!==Ut||t[208]!==Gt?(pt=s.jsxs(Xs,{children:[Ut,Gt]}),t[207]=Ut,t[208]=Gt,t[209]=pt):pt=t[209];let Yt;t[210]!==q||t[211]!==be||t[212]!==ot||t[213]!==e?(Yt=q!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(kn,{value:be,onChange:Rt=>De(Rt.target.value),placeholder:e(q==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:Rt=>{Rt.key==="Enter"&&ot()},autoFocus:!0})}),t[210]=q,t[211]=be,t[212]=ot,t[213]=e,t[214]=Yt):Yt=t[214];let us;t[215]===Symbol.for("react.memo_cache_sentinel")?(us=()=>he(null),t[215]=us):us=t[215];let Jt;t[216]!==e?(Jt=e("sidebarFilesTree.dialog.cancel"),t[216]=e,t[217]=Jt):Jt=t[217];let ss;t[218]!==le||t[219]!==Jt?(ss=s.jsx(ze,{variant:"outline",onClick:us,disabled:le,children:Jt}),t[218]=le,t[219]=Jt,t[220]=ss):ss=t[220];const hs=q==="delete"?"destructive":"default";let Wt;t[221]!==ot?(Wt=()=>{ot()},t[221]=ot,t[222]=Wt):Wt=t[222];let gs;t[223]!==q||t[224]!==be||t[225]!==le?(gs=le||q!=="delete"&&!be.trim(),t[223]=q,t[224]=be,t[225]=le,t[226]=gs):gs=t[226];let Ms;t[227]!==q||t[228]!==le||t[229]!==e?(Ms=le?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e(q==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[227]=q,t[228]=le,t[229]=e,t[230]=Ms):Ms=t[230];let Vt;t[231]!==hs||t[232]!==Wt||t[233]!==gs||t[234]!==Ms?(Vt=s.jsx(ze,{variant:hs,onClick:Wt,disabled:gs,children:Ms}),t[231]=hs,t[232]=Wt,t[233]=gs,t[234]=Ms,t[235]=Vt):Vt=t[235];let vs;t[236]!==ss||t[237]!==Vt?(vs=s.jsxs(tr,{children:[ss,Vt]}),t[236]=ss,t[237]=Vt,t[238]=vs):vs=t[238];let Ps;t[239]!==pt||t[240]!==Yt||t[241]!==vs?(Ps=s.jsxs(Gs,{children:[pt,Yt,vs]}),t[239]=pt,t[240]=Yt,t[241]=vs,t[242]=Ps):Ps=t[242];let Ns;t[243]!==Et||t[244]!==Ps?(Ns=s.jsx(Ks,{open:Et,onOpenChange:lt,children:Ps}),t[243]=Et,t[244]=Ps,t[245]=Ns):Ns=t[245];let As;return t[246]!==Ue||t[247]!==jt||t[248]!==it||t[249]!==Ns?(As=s.jsxs("section",{className:Ue,children:[jt,it,Ns]}),t[246]=Ue,t[247]=jt,t[248]=it,t[249]=Ns,t[250]=As):As=t[250],As};function ly(t){return t.searchFiles}function cy(t){return t.openContextFile}function dy(t){return t.setSelectedPath}function uy(t){return t.addOpenPath}function my(t){return t.removeOpenPathsByPrefix}function fy(t){return t.toggleExpandedPath}function hy(t){return t.mode==="file"?t.targetPath:null}function py(t){return typeof t=="string"&&t.length>0}function gy(t){return Dn(t)}function xy(t){return t&&typeof t.name=="string"&&t.name.length>0}function by(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function yy(t){return t.entries.map(by)}function wy(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function vy(t){return t.map(wy)}function jy(t){return Object.keys(t).length===0?t:{}}function Sy(t){return Object.keys(t).length===0?t:{}}function Ny(t){return Dn(t)}function ky(t,e){return t.split("/").length-e.split("/").length}function Cy(t){return{name:t.name,path:Dn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function Ay(t,e){const n=gt.c(6),{git:r}=Wn(),o=_s(Dy);let i,c;n[0]!==t||n[1]!==o||n[2]!==r||n[3]!==e?(i=()=>{if(!t||!r||!e)return;o(t,r);const l=setInterval(()=>{typeof document<"u"&&document.hidden||o(t,r)},1e4);return()=>clearInterval(l)},c=[t,r,e,o],n[0]=t,n[1]=o,n[2]=r,n[3]=e,n[4]=i,n[5]=c):(i=n[4],c=n[5]),a.useEffect(i,c)}function Dy(t){return t.ensureStatus}const dm=()=>{const t=gt.c(17),e=Es(Py),n=Es(Ty),r=sn(Ey),o=_s(Ry);let i;e:{if(e){let p;t[0]!==e||t[1]!==n?(p=n.find(y=>y.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=p):p=t[2],i=p;break e}i=n[0]??null}const c=i;let l;e:{if(!c){l=null;break e}let p;t[3]!==c.id||t[4]!==c.path?(p={id:c.id,path:c.path},t[3]=c.id,t[4]=c.path,t[5]=p):p=t[5],l=p}const u=l;let m;e:{if(!c){m=null;break e}let p;t[6]!==c.label||t[7]!==c.path||t[8]!==r?(p=c.label?.trim()||wi(c.path,r)||c.path,t[6]=c.label,t[7]=c.path,t[8]=r,t[9]=p):p=t[9],m=p}const d=m;let f;e:{if(!c){f=!1;break e}let p;t[10]!==c.path||t[11]!==o?(p=o.get(c.path)?.isGitRepo,t[10]=c.path,t[11]=o,t[12]=p):p=t[12],f=p===!0}const g=f;let x;return t[13]!==g||t[14]!==d||t[15]!==u?(x=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(ux,{projectRef:u,projectLabel:d,canCreateWorktree:g})}),t[13]=g,t[14]=d,t[15]=u,t[16]=x):x=t[16],x},Iy=()=>{const t=gt.c(38),{t:e}=Tt(),n=Fe(My),r=Fe(Fy),o=Fe(Ly),i=ti();Ay(i,o);let c;t[0]!==e?(c=e("layout.rightSidebar.git"),t[0]=e,t[1]=c):c=t[1];let l;t[2]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=l):l=t[2];let u;t[3]!==c?(u={id:"git",label:c,icon:l},t[3]=c,t[4]=u):u=t[4];let m;t[5]!==e?(m=e("layout.rightSidebar.files"),t[5]=e,t[6]=m):m=t[6];let d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(I,{name:"folder-3",className:"h-3.5 w-3.5"}),t[7]=d):d=t[7];let f;t[8]!==m?(f={id:"files",label:m,icon:d},t[8]=m,t[9]=f):f=t[9];let g;t[10]!==e?(g=e("layout.rightSidebar.context"),t[10]=e,t[11]=g):g=t[11];let x;t[12]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(I,{name:"file-list-2",className:"h-3.5 w-3.5"}),t[12]=x):x=t[12];let p;t[13]!==g?(p={id:"context",label:g,icon:x},t[13]=g,t[14]=p):p=t[14];let y;t[15]!==u||t[16]!==f||t[17]!==p?(y=[u,f,p],t[15]=u,t[16]=f,t[17]=p,t[18]=y):y=t[18];const b=y;let h;t[19]!==r?(h=D=>r(D),t[19]=r,t[20]=h):h=t[20];let N;t[21]!==n||t[22]!==h||t[23]!==b?(N=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(go,{items:b,activeId:n,onSelect:h,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=h,t[23]=b,t[24]=N):N=t[24];let w;t[25]!==n?(w=n==="git"&&s.jsx(Sl,{}),t[25]=n,t[26]=w):w=t[26];let S;t[27]!==n?(S=n==="files"&&s.jsx(ay,{}),t[27]=n,t[28]=S):S=t[28];let v;t[29]!==n?(v=n==="context"&&s.jsx(dm,{}),t[29]=n,t[30]=v):v=t[30];let j;t[31]!==w||t[32]!==S||t[33]!==v?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[w,S,v]}),t[31]=w,t[32]=S,t[33]=v,t[34]=j):j=t[34];let k;return t[35]!==N||t[36]!==j?(k=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[N,j]}),t[35]=N,t[36]=j,t[37]=k):k=t[37],k};function Py(t){return t.activeProjectId}function Ty(t){return t.projects}function Ey(t){return t.homeDirectory}function Ry(t){return t.directories}function My(t){return t.rightSidebarTab}function Fy(t){return t.setRightSidebarTab}function Ly(t){return t.isRightSidebarOpen}const Oy=1100,kl=15e3,gd=500,_y=t=>t<=6?t:t<=12?6:t<=25?4:2,um=a.memo(()=>{const t=gt.c(4),{t:e}=Tt();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),mm={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},By=mm.M,Vo=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],Vy=t=>{const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"},fm=t=>{const e=Vy(t);return mm[e]??By},$y=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},zy=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Wy=t=>!!t.working_dir?.trim()||t.index==="?",Uy=(t,e)=>Zf(t,e),xd=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),bd=(t,e)=>{const n=t.split(`
5
+ \`\`\``;oe(D,"append"),ae.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[te,r,Ae,oe,i]),Te=a.useCallback((O,D)=>{if(!(!t||p)){if(!n){ae.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}v({kind:"worktree",todoId:O,todoText:D})}},[n,t,p,i]),me=a.useCallback(async O=>{if(!t||!S)return;const D=await Tn("plan.todo.visible",{todo_text:S.todoText}),be=[{synthetic:!0,text:await Tn("plan.todo.instructions",{todo_text:S.todoText})}];k(!0),y(S.todoId);try{Ae();let Oe=null,$e=t.path;if(S.kind==="worktree"){if(!n){ae.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const ot=await Iu(t.path,Pu());if(!ot?.id)return;Oe=ot.id,$e=ot.path}else{const ot=await Z(void 0,t.path,null);if(!ot?.id){ae.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Oe=ot.id,$e=ot.directory??t.path,ne(ot.id,ls.getState().agents??[])}if(!Oe)return;const Re=zl.getState();Re.saveSessionModelSelection(Oe,O.providerID,O.modelID),O.agent.trim()&&(Re.saveSessionAgentSelection(Oe,O.agent),Re.saveAgentModelForSession(Oe,O.agent,O.providerID,O.modelID),Re.saveAgentModelVariantForSession(Oe,O.agent,O.providerID,O.modelID,O.variant||void 0)),ie(Oe,$e),await U(D,O.providerID,O.modelID,O.agent.trim()||void 0,void 0,void 0,be,O.variant||void 0),ae.success(S.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),v(null),r?.()}catch(Oe){const $e=Oe instanceof Error?Oe.message:void 0;ae.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),$e?{description:$e}:void 0)}finally{k(!1),y(null)}},[n,Z,ne,r,S,t,Ae,U,ie,i]),B=a.useRef(null),[ye,_e]=a.useState(!1),[J,Me]=a.useState(null),Ee=a.useCallback(async O=>{if(!(!t||J)){Me(O);try{if(!await Pf(t,O)){ae.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}w(Y=>Y.filter(be=>be.id!==O)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Me(null)}}},[J,t,i]),Ne=a.useCallback(async()=>{if(!t||ye)return;const O=await Tf({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(O.success&&O.path){_e(!0);try{const D=new URLSearchParams({path:O.path,allowOutsideWorkspace:"true"}),Y=await Fs(`/api/fs/read?${D.toString()}`,{cache:"no-store"});if(!Y.ok){ae.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const be=await Y.text();if(!be.trim()){ae.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Oe=O.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await wc(t,be,Oe)){ae.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),ae.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(D){const Y=D instanceof Error?D.message:void 0;ae.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Y?{description:Y}:void 0)}finally{_e(!1)}}else O.error==="Native file picker not available"&&B.current?.click()},[ye,t,i]),Be=a.useCallback(async O=>{if(!(!t||!O)){_e(!0);try{const D=await O.text();if(!D.trim()){ae.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Y=O.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await wc(t,D,Y)){ae.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),ae.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(D){const Y=D instanceof Error?D.message:void 0;ae.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Y?{description:Y}:void 0)}finally{_e(!1)}}},[t,i]),se=a.useCallback(O=>{const D=t?.path?.trim(),Y=pe?.trim()||D;Y&&je(Y,{mode:"plan",targetPath:O.path,dedupeKey:O.path,label:O.title})},[pe,je,t]);return t?s.jsxs("div",{className:Pe("w-full min-w-0 space-y-3 p-3",o),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:i("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[u.length,"/",vc]})]}),s.jsx(gi,{value:u,onChange:O=>m(O.target.value.slice(0,vc)),onBlur:he,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:H,onResizeHeightChange:R,useScrollShadow:!0,scrollShadowSize:56,disabled:c})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:d.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:d.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:d.length})}),s.jsx("button",{type:"button",onClick:le,disabled:c||G===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:i("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[ve.length,"/",No]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(kn,{value:ve,onChange:O=>x(O.target.value.slice(0,No)),onKeyDown:O=>{O.key==="Enter"&&(O.preventDefault(),de())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:c,className:"h-8"}),s.jsx("button",{type:"button",onClick:de,disabled:c||ve.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.addAria"),title:i("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:Pe("overflow-y-auto rounded-lg border border-border/60 bg-background/40",_&&"transition-none"),style:d.length<7?void 0:{height:`${E}px`,maxHeight:`${E}px`},children:d.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(Jo,{sensors:ue,collisionDetection:Qo,onDragEnd:Ce,children:s.jsx(il,{items:d.map(O=>O.id),strategy:ol,children:s.jsx("ul",{className:"divide-y divide-border/50",children:d.map(O=>{const D=b.has(O.id);return s.jsx(fx,{id:O.id,children:Y=>s.jsxs("div",{className:Pe("flex gap-1.5 px-2.5 py-1.5",D?"items-start":"items-center"),children:[s.jsx("button",{type:"button",ref:Y.setActivatorNodeRef,...Y.attributes,...Y.listeners,onClick:be=>{be.preventDefault(),be.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.text}),children:s.jsx(I,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(ji,{checked:O.completed,onChange:be=>xe(O.id,be),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:O.text})})}),s.jsx("button",{type:"button",onClick:()=>we(O.id),className:Pe("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-normal text-foreground",D?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",O.completed&&"text-muted-foreground line-through"),title:D?void 0:O.text,"aria-label":D?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:O.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:O.text}),children:O.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>De(O.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(rn,{children:[s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",disabled:p===O.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),children:s.jsx(I,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(nn,{align:"end",className:"w-56",children:[s.jsx(zt,{onClick:()=>fe(O.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(zt,{onClick:()=>ce(O.id,O.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(zt,{onClick:()=>{Te(O.id,O.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},O.id)})})})})}),d.length>=7&&s.jsx("div",{className:Pe("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",_&&"bg-[var(--interactive-border)]"),onPointerDown:K,role:"separator","aria-orientation":"horizontal","aria-label":i("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:N.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:N.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:N.length})})]}),s.jsx("input",{ref:B,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:O=>{const D=O.target.files?.[0]??null;Be(D),O.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Ne,disabled:!t||ye,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.plans.importFromFile"),title:i("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:N.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:N.map(O=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>se(O),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:O.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(O.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Ee(O.id)},disabled:J===O.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:i("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":i("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:O.title}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},O.id))})})]}),s.jsx(tm,{open:S!==null,onOpenChange:O=>{!O&&!j&&v(null)},target:S?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:me})]}):s.jsx("div",{className:Pe("w-full min-w-0 p-3",o),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},nm=12,px=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],gx=t=>{const e=pt.c(18),{isActive:n,burstKey:r,className:o,durationMs:i,bursts:c,onComplete:l}=t,u=r===void 0?0:r,m=i===void 0?900:i,d=c===void 0?px:c,f=et.useRef(!1);let g,x;e[0]!==n||e[1]!==l?(g=()=>{!n&&f.current&&l?.(),n&&(f.current=!0)},x=[n,l],e[0]=n,e[1]=l,e[2]=g,e[3]=x):(g=e[2],x=e[3]),et.useEffect(g,x);let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=Array.from({length:nm},xx),e[4]=p):p=e[4];const y=p;if(!n)return null;let b;e[5]!==o?(b=Pe("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=b):b=e[6];let h;if(e[7]!==u||e[8]!==d||e[9]!==m){let w;e[11]!==u||e[12]!==m?(w=S=>{const v={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${m}ms`};return s.jsx("div",{className:"firework-burst",style:v,children:y.map((j,k)=>{const A=j.x*S.radius,T=j.y*S.radius,C={"--translate-x":`${A}px`,"--translate-y":`${T}px`,"--particle-delay":`${j.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:C},`${S.id}-${k}-${u}`)})},`${S.id}-${u}`)},e[11]=u,e[12]=m,e[13]=w):w=e[13],h=d.map(w),e[7]=u,e[8]=d,e[9]=m,e[10]=h}else h=e[10];let N;return e[14]!==u||e[15]!==b||e[16]!==h?(N=s.jsx("div",{className:b,"aria-hidden":"true","data-burst-key":u,children:h}),e[14]=u,e[15]=b,e[16]=h,e[17]=N):N=e[17],N};function xx(t,e){const n=Math.PI*2*e/nm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const bx=t=>{const e=pt.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,o=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[c,l]=et.useState(i),u=et.useRef(null);let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{u.current&&(window.clearTimeout(u.current),u.current=null)},e[3]=m):m=e[3];const d=m;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{d(),l(yx)},e[4]=f):f=e[4];const g=f;let x;e[5]!==o?(x=()=>{d(),l(wx),u.current=window.setTimeout(()=>{l(vx),u.current=null},o)},e[5]=o,e[6]=x):x=e[6];const p=x;let y,b;e[7]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>d(),b=[d],e[7]=y,e[8]=b):(y=e[7],b=e[8]),et.useEffect(y,b);let h;return e[9]!==c.cycle||e[10]!==c.isActive||e[11]!==p?(h={isActive:c.isActive,burstKey:c.cycle,triggerFireworks:p,dismissFireworks:g},e[9]=c.cycle,e[10]=c.isActive,e[11]=p,e[12]=h):h=e[12],h};function yx(t){return t.isActive?{...t,isActive:!1}:t}function wx(t){return{isActive:!0,cycle:t.cycle+1}}function vx(t){return t.isActive?{...t,isActive:!1}:t}const rm=a.createContext(void 0),jx=t=>{const e=pt.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:i,dismissFireworks:c}=bx();let l;e[0]!==c||e[1]!==i?(l={triggerFireworks:i,dismissFireworks:c},e[0]=c,e[1]=i,e[2]=l):l=e[2];const u=l;let m;e[3]!==o||e[4]!==r?(m=s.jsx(gx,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=m):m=e[5];let d;return e[6]!==n||e[7]!==m||e[8]!==u?(d=s.jsxs(rm.Provider,{value:u,children:[n,m]}),e[6]=n,e[7]=m,e[8]=u,e[9]=d):d=e[9],d},Sx=()=>{const t=a.useContext(rm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Sl=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Nx=t=>{const e=Sl(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function kx(t,e,n){const r=pt.c(5),[o,i]=a.useState();let c,l;return r[0]!==n||r[1]!==t||r[2]!==e?(c=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let u=!1;return(async()=>{const[m,d]=await Promise.all([vs("git rev-parse --absolute-git-dir",t),vs("git rev-parse --show-toplevel",t)]);if(u||!m.success||!d.success)return;const f=Sl((m.stdout||"").trim()),g=Nx(f);if(!g)return;const x=Sl((d.stdout||"").trim());if(!x||x===g)return;const p=n||"",y=x.split("/").filter(Boolean).pop()||x;i({source:"sdk",path:x,projectDirectory:g,branch:p,label:p||y,name:y,worktreeRoot:x,worktreeStatus:"ready",headState:p?"branch":"unborn",worktreeSource:"existing"})})(),()=>{u=!0}},l=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=c,r[4]=l):(c=r[3],l=r[4]),a.useEffect(c,l),e??o}const Ln=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},zi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),Br=t=>!!t.success,Ca=t=>(t.stdout||"").trim(),bi=t=>(t.stderr||"").trim();async function Cx(t){const n=((await vs("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let o=null;for(const i of n){if(i.startsWith("worktree ")){o&&r.push(o),o={path:i.slice(9).trim(),branchRef:null};continue}o&&i.startsWith("branch ")&&(o.branchRef=i.slice(7).trim())}return o&&r.push(o),r.filter(i=>!!i.path)}async function Ax(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),o=(await Cx(t.repoRoot)).filter(c=>c.branchRef===e).map(c=>c.path).filter(c=>c&&!n.has(c)),i=[];for(const c of o){const l=await vs("git status --porcelain",c);Ca(l)||i.push(c)}return i}async function im(t,e){for(const n of e)await vs("git reset --hard",n).catch(()=>{})}async function Dx(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await vs(`git show-ref --verify --quiet ${Ln(`refs/heads/${n}`)}`,t);if(Br(r))return n;if(n.startsWith("remotes/")){const c=n.slice(8).split("/"),l=c[0]||"origin",u=c.slice(1).join("/");if(u)return await vs(`git branch --track ${Ln(u)} ${Ln(`${l}/${u}`)}`,t),u}const o=await vs(`git show-ref --verify --quiet ${Ln(`refs/remotes/origin/${n}`)}`,t);return Br(o)&&await vs(`git branch --track ${Ln(n)} ${Ln(`origin/${n}`)}`,t),n}async function Ji(t){const e=t.repoRoot,n=t.sourceBranch.trim(),r=t.targetBranch.trim();if(!n||!r)return{repoRoot:e,sourceBranch:n,targetBranch:r,commits:[]};const o=await Dx(e,r),i=await vs(`git cherry ${Ln(o)} ${Ln(n)}`,e),c=zi(i.stdout),l=new Set;for(const f of c){const g=f.match(/^\+\s+([0-9a-f]{7,40})\b/i);g&&l.add(g[1])}const u=await vs(`git rev-list --reverse ${Ln(`${o}..${n}`)}`,e),d=zi(u.stdout).filter(f=>l.has(f));return{repoRoot:e,sourceBranch:n,targetBranch:o,commits:d}}async function Ix(t,e){const n=await vs('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!Br(n))throw new Error(bi(n)||"Failed to create temp directory parent");const r=await vs('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),o=Ca(r);if(!o)throw new Error(bi(r)||"Failed to create temp directory");const i=await vs(`git worktree add --force ${Ln(o)} ${Ln(e)}`,t);if(!Br(i))throw new Error(bi(i)||"Failed to create temp worktree");return o}async function ia(t,e){await vs(`git worktree remove --force ${Ln(e)}`,t).catch(()=>{}),await vs("git worktree prune",t).catch(()=>{})}async function Px(t){const e=await vs("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Ca(e);if(!n)return;await vs("git fetch",t);const r=await vs(`git merge --ff-only ${Ln(n)}`,t);if(!Br(r))throw new Error(bi(r)||"Fast-forward failed")}async function oa(t){const e=await vs("git status --porcelain",t),n=await vs("git diff --name-only --diff-filter=U",t),r=await vs("git diff",t),o=await vs("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await vs("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:zi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:o.stdout||o.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function Tx(t){return oa(t)}async function Ex(t){const e=await vs("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return Br(e)}async function Rx(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await Ix(t.repoRoot,t.targetBranch);let n=[];try{await Px(e);const r=await vs("git status --porcelain",e);if(Ca(r))throw new Error("Target branch has local changes; abort integration and retry");const o=await Ax({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],c=await vs(`git cherry-pick ${Ln(i)}`,e);if(Br(c)){n.shift();continue}const l=await vs("git diff --name-only --diff-filter=U",e);if(zi(l.stdout).length>0){const m=await oa(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:o,remainingCommits:n,currentCommit:i},details:m}}throw new Error(bi(c)||"Cherry-pick failed")}return await ia(t.repoRoot,e),await im(t.repoRoot,o).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await ia(t.repoRoot,e).catch(()=>{}),r}}async function Mx(t){await vs("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await ia(t.repoRoot,t.tempWorktreePath)}async function Fx(t){const e=await vs("git cherry-pick --continue",t.tempWorktreePath);if(!Br(e)){const i=await vs("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(zi(i.stdout).length>0){const l=await oa(t.tempWorktreePath);return{kind:"conflict",state:t,details:l}}throw new Error(bi(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const o=[...r];for(;o.length>0;){const i=o[0],c=await vs(`git cherry-pick ${Ln(i)}`,n);if(Br(c)){o.shift();continue}const l=await vs("git diff --name-only --diff-filter=U",n);if(zi(l.stdout).length>0){const m=await oa(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:o,currentCommit:i},details:m}}throw new Error(bi(c)||"Cherry-pick failed")}return await ia(t.repoRoot,t.tempWorktreePath),await im(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Lx=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:o,refreshKey:i,onRefresh:c})=>{const{t:l}=Tt(),u=jt(F=>F.currentSessionId),m=Fe(F=>F.setActiveMainTab),[d,f]=et.useState(!1),g=et.useRef(null),[x,p]=et.useState(o);et.useEffect(()=>{p(o)},[o]),et.useEffect(()=>{if(d){const F=setTimeout(()=>{g.current?.focus()},0);return()=>clearTimeout(F)}},[d]);const y=!!(t&&e&&x&&x!=="HEAD"&&e!==x),[b,h]=et.useState({kind:"idle"}),[N,w]=et.useState(!1),[S,v]=et.useState([]),j=et.useMemo(()=>u?`openchamber.integrate.conflict:${u}`:null,[u]);et.useEffect(()=>{if(!j||typeof window>"u")return;const F=window.localStorage.getItem(j);if(!F)return;let te=!1;try{const Z=JSON.parse(F);if(!Z?.tempWorktreePath||Z.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const ne=await Ex(Z.tempWorktreePath).catch(()=>!1);if(te)return;if(!ne){window.localStorage.removeItem(j);return}const U=await Tx(Z.tempWorktreePath).catch(()=>null);te||U&&h({kind:"conflict",state:Z,details:U})})()}catch{window.localStorage.removeItem(j)}return()=>{te=!0}},[j,t]),et.useEffect(()=>{if(!y){h({kind:"idle"});return}let F=!1;return h({kind:"loading"}),(async()=>{try{const te=await Ji({repoRoot:t,sourceBranch:e,targetBranch:x});if(F)return;if(h({kind:"ready",plan:te}),te.commits.length>0){const U=te.commits.slice(-50).reverse().map(je=>JSON.stringify(je)).join(" "),oe=((await vs(`git show -s --format=%H%x09%h%x09%s ${U}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),pe=[];for(const je of oe){const[Se,re,L]=je.split(" ");!Se||!re||pe.push({sha:Se,short:re,subject:L||""})}F||(v(pe),w(!1))}else F||(v([]),w(!1))}catch{F||h({kind:"idle"})}})(),()=>{F=!0}},[y,t,e,x,i]);const k=et.useCallback(F=>{u&&jt.getState().setWorktreeMetadata(u,{...n,createdFromBranch:F})},[u,n]),A=jt(F=>F.openNewSessionDraft),T=et.useCallback(async F=>{const te=await Tn("git.integrate.cherrypick.resolve.visible",{current_commit:F.state.currentCommit,target_branch:F.state.targetBranch}),Z=await Tn("git.integrate.cherrypick.resolve.instructions",{repo_root:F.state.repoRoot,temp_worktree_path:F.state.tempWorktreePath,source_branch:F.state.sourceBranch,target_branch:F.state.targetBranch,current_commit:F.state.currentCommit}),ne=`Cherry-pick conflict context (JSON)
6
+ ${JSON.stringify({repoRoot:F.state.repoRoot,tempWorktreePath:F.state.tempWorktreePath,sourceBranch:F.state.sourceBranch,targetBranch:F.state.targetBranch,currentCommit:F.state.currentCommit,remainingCommits:F.state.remainingCommits,statusPorcelain:F.details.statusPorcelain,unmergedFiles:F.details.unmergedFiles,currentPatchMeta:F.details.currentPatchMeta,currentPatch:F.details.currentPatch,diff:F.details.diff},null,2)}`;return{visibleText:te,instructionsText:Z,payloadText:ne}},[]),C=ti(F=>F.setPendingInputText),P=ti(F=>F.setPendingSyntheticParts),E=et.useCallback(async(F,te)=>{const Z=await T(F);if(te){A({directoryOverride:F.state.tempWorktreePath,initialPrompt:Z.visibleText,syntheticParts:[{text:Z.instructionsText,synthetic:!0},{text:Z.payloadText,synthetic:!0}]}),m("chat");return}if(!u){ae.error(l("gitView.integrate.noActiveSession"),{description:l("gitView.integrate.noActiveSessionDescription")});return}C(Z.visibleText,"replace"),P([{text:Z.instructionsText,synthetic:!0},{text:Z.payloadText,synthetic:!0}]),m("chat")},[u,m,T,A,C,P,l]),M=et.useCallback(async()=>{if(b.kind==="ready"){if(b.plan.commits.length===0){ae.message(l("gitView.integrate.noCommitsToMoveToast"));return}h({kind:"running",plan:b.plan});try{const F=await Rx(b.plan);if(F.kind==="success"){ae.success(l("gitView.integrate.commitsMovedToast"),{description:F.moved===1?l("gitView.integrate.commitsMovedDescriptionSingle",{count:F.moved,branch:b.plan.targetBranch}):l("gitView.integrate.commitsMovedDescriptionPlural",{count:F.moved,branch:b.plan.targetBranch})});const te=await Ji(b.plan);h({kind:"ready",plan:te}),c?.();return}F.kind==="conflict"&&(ae.error(l("gitView.integrate.cherryPickConflictToast"),{description:l("gitView.integrate.cherryPickConflictDescription")}),h({kind:"conflict",state:F.state,details:F.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(F.state)))}catch(F){const te=F instanceof Error?F.message:String(F);ae.error(l("gitView.integrate.failedToMoveToast"),{description:te});const Z=await Ji({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(Z?{kind:"ready",plan:Z}:{kind:"idle"})}}},[b,c,t,e,x,j,l]),H=et.useCallback(async()=>{if(b.kind==="conflict")try{await Mx(b.state),ae.message(l("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const F=await Ji({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(F?{kind:"ready",plan:F}:{kind:"idle"})}},[b,t,e,x,j,l]),R=et.useCallback(async()=>{if(b.kind==="conflict")try{const F=await Fx(b.state);if(F.kind==="success"){ae.success(l("gitView.integrate.cherryPickFinishedToast"));const te=await Ji({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(te?{kind:"ready",plan:te}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),c?.();return}F.kind==="conflict"&&(h({kind:"conflict",state:F.state,details:F.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(F.state)))}catch(F){const te=F instanceof Error?F.message:String(F);ae.error(l("gitView.integrate.cherryPickContinueFailedToast"),{description:te})}},[b,t,e,x,c,j,l]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(I,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:l("gitView.integrate.title")}),b.kind==="ready"&&b.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:l("gitView.integrate.toMoveCount",{count:b.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:b.kind==="loading"||b.kind==="running"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",x]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(rn,{open:d,onOpenChange:f,children:[s.jsx(sn,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"sm",className:"gap-1.5",children:[l("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:x}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(nn,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(ma,{className:"h-full min-h-0",children:[s.jsx(fa,{ref:g,placeholder:l("gitView.branch.searchPlaceholder"),onKeyDown:F=>F.stopPropagation()}),s.jsxs(ha,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(pa,{children:l("gitView.branch.empty")}),s.jsx(Yr,{heading:l("gitView.branch.localBranches"),children:r.map(F=>s.jsx(ei,{value:F,onSelect:()=>{p(F),k(F),f(!1)},children:F},F))})]})]})})]}),b.kind==="ready"?s.jsx(ze,{size:"sm",onClick:()=>{M()},disabled:!y||b.plan.commits.length===0,children:l("gitView.integrate.move")}):b.kind==="loading"?s.jsx(ze,{size:"sm",variant:"outline",disabled:!0,children:l("gitView.integrate.checking")}):b.kind==="running"?s.jsx(ze,{size:"sm",variant:"outline",disabled:!0,children:l("gitView.integrate.moving")}):null]}),b.kind==="ready"&&b.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.integrate.noCommitsToMove")}),b.kind==="ready"&&b.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[l("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",b.plan.commits.length,")"]})]}),S.length>0&&b.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>w(F=>!F),className:"typography-micro text-muted-foreground hover:text-foreground",children:l(N?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(N?S:S.slice(0,5)).map(F=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:F.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:F.subject||F.sha})]},F.sha)),S.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.integrate.previewUnavailable")}),b.plan.commits.length>S.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:l("gitView.integrate.showingFirstCommits",{count:S.length})})]})]}),b.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:l("gitView.integrate.conflictsInFiles",{count:b.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[l("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:b.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[b.details.unmergedFiles.slice(0,6).map(F=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:F},F)),b.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:l("gitView.integrate.moreFiles",{count:b.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ze,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{H()},children:l("gitView.operation.abort")}),s.jsxs(ze,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!u,onClick:()=>{E({state:b.state,details:b.details},!1)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),l("gitView.integrate.currentSession")]}),s.jsxs(ze,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{E({state:b.state,details:b.details},!0)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),l("gitView.integrate.newSession")]}),s.jsx(ze,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:l("gitView.operation.continue")})]})]})]})]})},Ox=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:o=!1,uncommittedFileCount:i,onChanged:c})=>{const{t:l}=Tt(),[u,m]=a.useState([]),[d,f]=a.useState(!1),[g,x]=a.useState(""),[p,y]=a.useState(""),[b,h]=a.useState(null),[N,w]=a.useState({}),S=a.useCallback(async()=>{if(n){f(!0);try{const C=await Rf(n);m(C.stashes),w({})}catch(C){ae.error(C instanceof Error?C.message:l("gitView.stashes.toast.loadFailed"))}finally{f(!1)}}},[n,l]);a.useEffect(()=>{t&&S()},[S,t]),a.useEffect(()=>{if(!t||!n||u.length===0)return;let C=!1;const P=u.map(E=>E.ref);return Mf(n,P).then(E=>{C||w(E.counts)}).catch(()=>{}),()=>{C=!0}},[n,t,u]);const v=a.useMemo(()=>{const C=g.trim().toLowerCase();return C?u.filter(P=>`${P.ref} ${P.message} ${P.relativeTime}`.toLowerCase().includes(C)):u},[g,u]),j=a.useCallback(async C=>{await S(),await c?.(C)},[S,c]),k=async()=>{if(!(!n||b)){h("create");try{const C=await Ff(n,{message:p.trim()||void 0});C.created?(ae.success(l("gitView.stashes.toast.created")),y("")):ae.info(l("gitView.stashes.toast.noChanges")),await j({affectsIndex:!!(C.created&&o)})}catch(C){ae.error(C instanceof Error?C.message:l("gitView.stashes.toast.createFailed"))}finally{h(null)}}},A=async(C,P)=>{if(!(!n||b)&&!(P==="drop"&&!window.confirm(l("gitView.stashes.confirm.drop",{ref:C.ref})))){h(`${P}:${C.ref}`);try{P==="apply"&&await Lf(n,{ref:C.ref}),P==="pop"&&await Of(n,{ref:C.ref}),P==="drop"&&await _f(n,{ref:C.ref});const E=P==="apply"?"gitView.stashes.toast.applySuccess":P==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";ae.success(l(E)),await j({affectsIndex:P!=="drop"})}catch(E){const M=P==="apply"?"gitView.stashes.toast.applyFailed":P==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";ae.error(E instanceof Error?E.message:l(M)),await j({affectsIndex:P!=="drop"})}finally{h(null)}}},T=b!==null;return s.jsx(Ks,{open:t,onOpenChange:e,children:s.jsxs(Gs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(Qs,{children:[s.jsxs(Ys,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"archive-stack",className:"h-5 w-5"}),l("gitView.stashes.title")]}),s.jsx(dn,{children:l("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(kn,{value:p,onChange:C=>y(C.target.value),placeholder:l("gitView.stashes.messagePlaceholder"),disabled:T||!r,className:"flex-1"}),s.jsxs(ze,{onClick:k,disabled:!r||T||!n,children:[b==="create"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"inbox-archive",className:"size-4"}),l("gitView.stashes.actions.stashCurrentWithCount",{count:i})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:l("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(I,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(kn,{value:g,onChange:C=>x(C.target.value),placeholder:l("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:d?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(I,{name:"loader-4",className:"size-5 animate-spin"})}):v.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:l(g?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):v.map((C,P)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:C.message||l("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{children:P===0&&!g.trim()?l("gitView.stashes.latestLabel"):l("gitView.stashes.itemNumber",{number:P+1})})}),s.jsx(Bt,{sideOffset:6,children:C.ref})]})," · ",C.relativeTime," · ",typeof N[C.ref]=="number"?l("gitView.stashes.fileCount",{count:N[C.ref]}):l("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx($a,{label:l("gitView.stashes.actions.apply"),loading:b===`apply:${C.ref}`,onClick:()=>A(C,"apply"),disabled:T,children:s.jsx(I,{name:"inbox-unarchive",className:"size-4"})}),s.jsx($a,{label:l("gitView.stashes.actions.pop"),loading:b===`pop:${C.ref}`,onClick:()=>A(C,"pop"),disabled:T,children:s.jsx(I,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx($a,{label:l("gitView.stashes.actions.drop"),loading:b===`drop:${C.ref}`,onClick:()=>A(C,"drop"),disabled:T,destructive:!0,children:s.jsx(I,{name:"delete-bin",className:"size-4"})})]})]},C.ref))})]})})},$a=t=>{const e=pt.c(17),{label:n,loading:r,disabled:o,destructive:i,onClick:c,children:l}=t,u=r||void 0,m=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let d;e[0]!==m?(d=Pe("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",m),e[0]=m,e[1]=d):d=e[1];let f;e[2]!==l||e[3]!==r?(f=r?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):l,e[2]=l,e[3]=r,e[4]=f):f=e[4];let g;e[5]!==o||e[6]!==n||e[7]!==c||e[8]!==u||e[9]!==d||e[10]!==f?(g=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":u,className:d,onClick:c,disabled:o,children:f})}),e[5]=o,e[6]=n,e[7]=c,e[8]=u,e[9]=d,e[10]=f,e[11]=g):g=e[11];let x;e[12]!==n?(x=s.jsx(Bt,{sideOffset:6,children:n}),e[12]=n,e[13]=x):x=e[13];let p;return e[14]!==g||e[15]!==x?(p=s.jsxs(Ot,{children:[g,x]}),e[14]=g,e[15]=x,e[16]=p):p=e[16],p},_x=t=>{const e=pt.c(16),{onOpenStashes:n}=t,{t:r}=Tt();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(I,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=o):o=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let c;e[3]!==i?(c=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=c):c=e[4];let l;e[5]!==r?(l=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=l):l=e[6];let u;e[7]!==l?(u=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:l}),e[7]=l,e[8]=u):u=e[8];let m;e[9]!==n||e[10]!==r?(m=n?s.jsxs(ze,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(I,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=m):m=e[11];let d;return e[12]!==c||e[13]!==u||e[14]!==m?(d=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[o,c,u,m]}),e[12]=c,e[13]=u,e[14]=m,e[15]=d):d=e[15],d},Gr=8,Bx=t=>{const e=pt.c(18),{laned:n,totalLanes:r,isExpanded:o}=t,{lane:i,color:c,connectors:l}=n,m=Math.max(r,i+1)*Gr+Gr/2,d=a.useRef(null),f=a.useRef(null);let g;e[0]!==c||e[1]!==l||e[2]!==i||e[3]!==m?(g=()=>{const h=d.current,N=f.current;if(!h||!N)return;const w=h.offsetHeight;if(w===0)return;const S=window.devicePixelRatio||1;N.width=m*S,N.height=w*S;const v=N.getContext("2d");if(!v)return;v.scale(S,S),v.clearRect(0,0,m,w);const j=w/2,k=i*Gr+Gr/2,A=getComputedStyle(N),T=A.getPropertyValue("--surface-muted-foreground").trim()||A.color,C=M=>{if(!M.startsWith("var("))return M;const H=M.slice(4,-1).trim();return A.getPropertyValue(H).trim()||T},P=[...l].sort($x);for(const M of P){const H=M.fromLane*Gr+Gr/2,R=M.toLane*Gr+Gr/2,_=M.type==="passing"?.72:M.type==="branch-out"||M.type==="merge-in"?.95:1;v.beginPath(),v.strokeStyle=C(M.color),v.globalAlpha=_,v.lineWidth=1.25,v.lineCap="round";e:switch(M.type){case"passing":case"commit-lane":{v.moveTo(H,0),v.lineTo(H,w);break e}case"top-stub":{v.moveTo(H,0),v.lineTo(H,j);break e}case"bottom-stub":{v.moveTo(H,j),v.lineTo(H,w);break e}case"branch-out":{const z=(j+w)/2;v.moveTo(k,j),v.bezierCurveTo(k,z,R,z,R,w);break e}case"merge-in":{const z=j/2;v.moveTo(H,0),v.bezierCurveTo(H,z,k,z,k,j);break e}default:continue}v.stroke(),v.globalAlpha=1}const E=A.getPropertyValue("--background").trim()||A.getPropertyValue("--surface-background").trim();v.beginPath(),v.arc(k,j,4,0,Math.PI*2),v.fillStyle=C(c),v.fill(),v.beginPath(),v.arc(k,j,5,0,Math.PI*2),v.strokeStyle=E||T,v.lineWidth=2,v.stroke()},e[0]=c,e[1]=l,e[2]=i,e[3]=m,e[4]=g):g=e[4];let x;e[5]!==c||e[6]!==l||e[7]!==o||e[8]!==i||e[9]!==n||e[10]!==r||e[11]!==m?(x=[n,i,c,l,r,o,m],e[5]=c,e[6]=l,e[7]=o,e[8]=i,e[9]=n,e[10]=r,e[11]=m,e[12]=x):x=e[12],a.useLayoutEffect(g,x);let p;e[13]!==m?(p={width:m,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=m,e[14]=p):p=e[14];let y;e[15]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("canvas",{ref:f,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=y):y=e[15];let b;return e[16]!==p?(b=s.jsx("div",{ref:d,style:p,children:y}),e[16]=p,e[17]=b):b=e[17],b};function Vx(t){return t==="branch-out"||t==="merge-in"}function $x(t,e){const n=Vx;return(n(t.type)?1:0)-(n(e.type)?1:0)}const rd=15e3,id=500,od=12,ad=8*1024*1024,ld=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),cd=t=>{if(t.size<=od){let o=0;for(const i of t.values())o+=ld(i);if(o<=ad)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[o,i]of e){if(n.size>=od)continue;const c=ld(i);r+c>ad&&n.size>0||(n.set(o,i),r+=c)}return new Map(Array.from(n.entries()).reverse())};function dd(t,e){const n=new Date(t);return Number.isNaN(n.getTime())?t:ga(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function zx(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function Wx(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const Ux=a.memo(({entry:t,mode:e="history",laned:n,totalLanes:r,isExpanded:o,onToggle:i,files:c,isLoadingFiles:l,onCopyHash:u,directory:m,onConflict:d,onActionSuccess:f})=>{const{t:g}=Tt(),x=Fe(U=>U.timeFormatPreference),p=e==="graph",[y,b]=a.useState(null),[h,N]=a.useState(!1),[w,S]=a.useState(""),[v,j]=a.useState(null),[k,A]=a.useState(new Set),[T,C]=a.useState(new Map),[P,E]=a.useState(new Set),M=async()=>{if(m){b("checkout");try{await Gf(m,t.hash),ae.success(g("gitView.history.actions.detachedHead")),f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},H=async()=>{if(!(!m||!w.trim())){b("createBranch");try{await Vf(m,w.trim(),t.hash),N(!1),S(""),f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},R=async()=>{if(m){b("cherryPick");try{const U=await Hf(m,t.hash);U.conflict?d?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"cherry-pick"}):f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},_=async()=>{if(m){b("revert");try{const U=await Uf(m,t.hash);U.conflict?d?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"revert"}):f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},z=async(U,ie=!1)=>{if(!(!m||y!==null)){b("reset");try{await $f(m,t.hash,U,ie),f?.()}catch(oe){ae.error(String(oe.message))}finally{b(null)}}},V=async()=>{if(!v)return;const U=v;switch(j(null),U){case"checkout":return M();case"cherryPick":return R();case"revert":return _();case"merge":return F();case"rebase":return te();case"resetSoft":return z("soft");case"resetMixed":return z("mixed");case"resetHard":return z("hard",!0)}},F=async()=>{if(m){b("merge");try{const U=await Wf(m,{branch:t.hash});U.conflict?d?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"merge"}):f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},te=async()=>{if(m){b("rebase");try{const U=await zf(m,{onto:t.hash});U.conflict?d?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"rebase"}):f?.()}catch(U){ae.error(String(U.message))}finally{b(null)}}},Z=a.useCallback(async U=>{const ie=U.path;if(!m){C(oe=>new Map(oe).set(ie,"error"));return}C(oe=>cd(new Map(oe).set(ie,"loading")));try{const oe=Bf(m,t.hash,U.path,!1),pe=new Promise((Se,re)=>{setTimeout(()=>re(new Error(`Timed out after ${rd}ms`)),rd)}),je=await Promise.race([oe,pe]);C(Se=>cd(new Map(Se).set(ie,je)))}catch{C(oe=>new Map(oe).set(ie,"error"))}},[m,t.hash]),ne=a.useCallback(async U=>{const ie=U.path;if(U.changeType==="R"||U.isBinary){A(Se=>{const re=new Set(Se);return re.has(ie)?re.delete(ie):re.add(ie),re});return}const oe=T.get(ie);if(k.has(ie)&&oe&&oe!=="error"){A(Se=>{const re=new Set(Se);return re.delete(ie),re});return}A(Se=>{const re=new Set(Se);return re.add(ie),re}),!(oe&&oe!=="error"||U.insertions+U.deletions>id&&!P.has(ie))&&await Z(U)},[T,P,Z,k]);return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:i,className:Pe("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",p?"hover:bg-[var(--interactive-hover)]/40":o?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[p&&n&&r!==void 0?s.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:s.jsx(Bx,{laned:n,totalLanes:r,isExpanded:o})}):s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[p?(()=>{const U=Wx(t.refs);return U.length>0?s.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:U.map(ie=>s.jsx("span",{className:Pe("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",ie.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":ie.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:ie.label},ie.label))}):null})():null,s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:t.message}),s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[s.jsx("span",{className:"truncate min-w-[3ch]",title:t.author_name,children:t.author_name}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("span",{className:"truncate min-w-0",title:dd(t.date,x),children:dd(t.date,x)})]}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("code",{className:"shrink-0 font-mono",children:t.hash.slice(0,8)}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:U=>{U.stopPropagation(),u(t.hash)},children:s.jsx(I,{name:"file-copy",className:"size-3"})})}),s.jsx(Bt,{sideOffset:8,children:g("gitView.history.copySha")})]})]})]})]}),o&&s.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[p&&v?s.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:g(`gitView.history.actions.${v}Confirm`)}),s.jsxs(ze,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:y!==null,onClick:U=>{U.stopPropagation(),V()},children:[y!==null?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.confirmButton")]}),s.jsx(ze,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:y!==null,onClick:U=>{U.stopPropagation(),j(null)},children:g("gitView.history.actions.cancelButton")})]}):p?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("checkout")},children:g("gitView.history.actions.checkout")}),h?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("input",{autoFocus:!0,value:w,onChange:U=>S(U.target.value),onKeyDown:U=>{U.key==="Enter"&&H(),U.key==="Escape"&&(N(!1),S(""))},placeholder:g("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),s.jsxs(ze,{variant:"outline",size:"xs",className:"h-6",disabled:!w.trim()||y!==null,onClick:U=>{U.stopPropagation(),H()},children:[y==="createBranch"?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.createBranchConfirm")]})]}):s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",onClick:U=>{U.stopPropagation(),N(!0)},children:g("gitView.history.actions.createBranch")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("cherryPick")},children:g("gitView.history.actions.cherryPick")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("revert")},children:g("gitView.history.actions.revert")}),s.jsxs(rn,{children:[s.jsx(sn,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>U.stopPropagation(),children:[y==="reset"?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.reset")]})}),s.jsx(nn,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(U=>s.jsx(zt,{disabled:y!==null,onSelect:ie=>{ie.stopPropagation(),j(`reset${U.charAt(0).toUpperCase()+U.slice(1)}`)},children:g(`gitView.history.actions.reset${U.charAt(0).toUpperCase()+U.slice(1)}`)},U))})]}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("merge")},children:g("gitView.history.actions.merge")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:y!==null,onClick:U=>{U.stopPropagation(),j("rebase")},children:g("gitView.history.actions.rebase")})]}):null,l?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:g("gitView.history.loadingFiles")})]}):c.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:g("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:c.map(U=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>ne(U),className:Pe("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",k.has(U.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:Pe("font-semibold w-3 text-center shrink-0",zx(U.changeType)),children:U.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:U.path,children:U.path}),!U.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",U.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",U.deletions]})]}),U.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:g("gitView.history.binary")}),s.jsx(I,{name:k.has(U.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),k.has(U.path)&&s.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:U.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.renamedNoDiff")}):U.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.binaryNoDiff")}):(()=>{const ie=U.insertions+U.deletions;if(!P.has(U.path)&&ie>id)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:g("gitView.history.largeDiffTitle",{count:ie})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:g("gitView.history.largeDiffDescription")}),s.jsx(ze,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{E(pe=>new Set(pe).add(U.path)),Z(U)},children:g("gitView.history.renderDiffAnyway")})]});const oe=T.get(U.path);return oe==="loading"||oe===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.loadingDiff")}):oe==="error"?s.jsx("button",{type:"button",onClick:()=>ne(U),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:g("gitView.history.diffError")}):s.jsx(Zl,{original:oe.original,modified:oe.modified,language:Oi(U.path)||"",fileName:U.path,renderSideBySide:!1,layout:"inline"})})()})]},U.path))})]})]})}),ud=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function Co(t){return ud[t%ud.length]}function Hx(t){if(t.length===0)return[];const e=[],n=[];for(let r=0;r<t.length;r++){const o=t[r],i=[];for(let x=0;x<e.length;x++)e[x]===o.hash&&i.push(x);let c=i.length>0?i[0]:-1;if(c===-1){const x=e.indexOf(null);x!==-1?c=x:(c=e.length,e.push(null))}const l=i.slice(1),u=Co(c),m=e[c]===o.hash,d=o.parents.length>0;d?e[c]=o.parents[0]:e[c]=null;const f=[];for(let x=1;x<o.parents.length;x++){const p=o.parents[x],y=e.indexOf(p);if(y!==-1)f.push(y);else{const b=e.indexOf(null),h=b!==-1?b:e.length;e[h]=p,h===e.length&&e.push(p),f.push(h)}}const g=[];m&&d?g.push({fromLane:c,toLane:c,color:u,type:"commit-lane"}):m&&!d?g.push({fromLane:c,toLane:c,color:u,type:"top-stub"}):!m&&d&&g.push({fromLane:c,toLane:c,color:u,type:"bottom-stub"});for(const x of l)g.push({fromLane:x,toLane:c,color:Co(x),type:"merge-in"}),e[x]=null;for(const x of f)g.push({fromLane:c,toLane:x,color:Co(x),type:"branch-out"});for(let x=0;x<e.length;x++)e[x]!==null&&x!==c&&(f.includes(x)||g.push({fromLane:x,toLane:x,color:Co(x),type:"passing"}));n.push({commit:o,lane:c,color:u,connectors:g})}return n}const Gx=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Kx=t=>{const e=pt.c(84),{mode:n,log:r,isLogLoading:o,logMaxCount:i,onLogMaxCountChange:c,expandedCommitHashes:l,onToggleCommit:u,commitFilesMap:m,loadingCommitHashes:d,onCopyHash:f,directory:g,showHeader:x,contentMaxHeightClassName:p,branchDivider:y,onConflict:b,onActionSuccess:h}=t,N=n===void 0?"history":n,w=x===void 0?!0:x,S=p===void 0?"max-h-[50vh]":p,v=y===void 0?null:y,{t:j}=Tt(),[k,A]=a.useState(!0),T=N==="graph";let C;e[0]!==T||e[1]!==r?(C=T&&r?Hx(r.all):[],e[0]=T,e[1]=r,e[2]=C):C=e[2];const P=C;let E;e[3]!==P?(E=Math.max(1,...P.map(qx)),e[3]=P,e[4]=E):E=e[4];const M=E;let H;e[5]!==P?(H=new Map(P.map(Yx)),e[5]=P,e[6]=H):H=e[6];const R=H;if(!r)return null;const _=v!==null&&v.insertBeforeIndex>0&&v.insertBeforeIndex<r.all.length,z=v!==null&&v.insertBeforeIndex===r.all.length,V=_||z;let F;e[7]!==v||e[8]!==_||e[9]!==z||e[10]!==r.all?(F=_?r.all.slice(0,v.insertBeforeIndex):z?r.all:[],e[7]=v,e[8]=_,e[9]=z,e[10]=r.all,e[11]=F):F=e[11];const te=F;let Z;if(e[12]!==v||e[13]!==m||e[14]!==S||e[15]!==g||e[16]!==l||e[17]!==_||e[18]!==V||e[19]!==T||e[20]!==o||e[21]!==R||e[22]!==d||e[23]!==r.all||e[24]!==i||e[25]!==M||e[26]!==N||e[27]!==h||e[28]!==b||e[29]!==f||e[30]!==c||e[31]!==u||e[32]!==j||e[33]!==te){const $=_?r.all.slice(v.insertBeforeIndex):[];let K;e[35]!==v?.direction?(K=v?.direction==="down"?s.jsx(I,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"}),e[35]=v?.direction,e[36]=K):K=e[36];const he=K;let de;e[37]!==m||e[38]!==g||e[39]!==l||e[40]!==T||e[41]!==R||e[42]!==d||e[43]!==M||e[44]!==N||e[45]!==h||e[46]!==b||e[47]!==f||e[48]!==u?(de=le=>s.jsx("ul",{className:"divide-y divide-border/60",children:le.map(Ce=>s.jsx(Ux,{entry:Ce,mode:N,laned:T?R.get(Ce.hash):void 0,totalLanes:T?M:void 0,isExpanded:l.has(Ce.hash),onToggle:()=>u(Ce.hash),files:m.get(Ce.hash)??[],isLoadingFiles:d.has(Ce.hash),onCopyHash:f,directory:g,onConflict:b,onActionSuccess:h},Ce.hash))}),e[37]=m,e[38]=g,e[39]=l,e[40]=T,e[41]=R,e[42]=d,e[43]=M,e[44]=N,e[45]=h,e[46]=b,e[47]=f,e[48]=u,e[49]=de):de=e[49];const we=de;let xe;e[50]!==o||e[51]!==r.all.length||e[52]!==i||e[53]!==c||e[54]!==j?(xe=r.all.length>=i?s.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:s.jsx(ze,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(i+25),disabled:o,className:"px-3 text-muted-foreground hover:text-foreground",children:o?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"loader-4",className:"size-3 animate-spin"}),j("gitView.history.loadingMore")]}):j("gitView.history.loadMore")})}):null,e[50]=o,e[51]=r.all.length,e[52]=i,e[53]=c,e[54]=j,e[55]=xe):xe=e[55];const De=xe;Z=s.jsx(_n,{outerClassName:`min-h-0 ${S}`,className:"h-full w-full",children:r.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:j("gitView.history.noCommits")})}):V&&v?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-0",children:[te.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:we(te)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:v.branchName,children:v.branchName}),he]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),$.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:we($)}):null]}),De]}):s.jsxs(s.Fragment,{children:[we(r.all),De]})}),e[12]=v,e[13]=m,e[14]=S,e[15]=g,e[16]=l,e[17]=_,e[18]=V,e[19]=T,e[20]=o,e[21]=R,e[22]=d,e[23]=r.all,e[24]=i,e[25]=M,e[26]=N,e[27]=h,e[28]=b,e[29]=f,e[30]=c,e[31]=u,e[32]=j,e[33]=te,e[34]=Z}else Z=e[34];const ne=Z;if(!w){if(V){let K;return e[56]!==ne?(K=s.jsx("section",{className:"h-full min-h-0",children:ne}),e[56]=ne,e[57]=K):K=e[57],K}let $;return e[58]!==ne?($=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ne}),e[58]=ne,e[59]=$):$=e[59],$}let U;e[60]!==j?(U=j("gitView.history.title"),e[60]=j,e[61]=U):U=e[61];let ie;e[62]!==U?(ie=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:U}),e[62]=U,e[63]=ie):ie=e[63];let oe;e[64]!==o||e[65]!==k||e[66]!==i||e[67]!==c||e[68]!==j?(oe=k&&s.jsx("div",{onClick:Jx,onPointerDown:Qx,children:s.jsxs(zn,{value:String(i),onValueChange:$=>c(Number($)),disabled:o,children:[s.jsx(Wn,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:o,children:s.jsx(En,{placeholder:j("gitView.history.commitsPlaceholder")})}),s.jsx(Un,{children:Gx.map($=>s.jsx(qs,{value:String($.value),children:j($.labelKey)},$.value))})]})}),e[64]=o,e[65]=k,e[66]=i,e[67]=c,e[68]=j,e[69]=oe):oe=e[69];let pe;e[70]!==k?(pe=k?s.jsx(I,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=k,e[71]=pe):pe=e[71];let je;e[72]!==oe||e[73]!==pe?(je=s.jsxs("div",{className:"flex items-center gap-2",children:[oe,pe]}),e[72]=oe,e[73]=pe,e[74]=je):je=e[74];let Se;e[75]!==ie||e[76]!==je?(Se=s.jsxs(vo,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[ie,je]}),e[75]=ie,e[76]=je,e[77]=Se):Se=e[77];let re;e[78]!==ne?(re=s.jsx($i,{children:ne}),e[78]=ne,e[79]=re):re=e[79];let L;return e[80]!==k||e[81]!==Se||e[82]!==re?(L=s.jsxs(Vi,{open:k,onOpenChange:A,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[Se,re]}),e[80]=k,e[81]=Se,e[82]=re,e[83]=L):L=e[83],L};function qx(t){return t.lane+1}function Yx(t){return[t.commit.hash,t]}function Jx(t){return t.stopPropagation()}function Qx(t){return t.stopPropagation()}const om=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),o=new Array(t.length);let i=0;const c=async()=>{for(;;){const l=i;if(i+=1,l>=t.length)return;o[l]=await n(t[l])}};return await Promise.all(Array.from({length:r},()=>c())),o},Xx=9e4,Zx=15e3,eb=5*6e4,tb=[2e3,5e3],sb=6e4,nb=2*6e4,rb=5*6e4,ib=4,ob=720*6e4,ab="openchamber.github-pr-status",lb=t=>t==="closed"||t==="merged",cb=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},oo=(t,e,n)=>`${t}::${e}`,Ao=new Map,Do=new Map,Qi=new Set,md=new Map,so=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),aa=t=>t?.params?.directory&&t.params.branch?{directory:t.params.directory,branch:t.params.branch,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null}:!t?.identity?.directory||!t.identity.branch?null:t.identity,tc=t=>{const e=aa(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},am=(t,e)=>Object.entries(t).filter(([,n])=>tc(n)===e).map(([n])=>n),db=(t,e)=>{const n=e.remoteName??t.params?.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null;return{...t,params:t.params?{...t.params,...e,remoteName:n}:{...e,remoteName:n},identity:{directory:e.directory,branch:e.branch,remoteName:n}}},Io=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},ub=(t,e,n)=>{const r=am(t,e),o=r.map(u=>Io(t[u])).filter(u=>!!u);if(o.length===0)return null;const i=Io(t[n]);if(i&&tc(t[n])===e)return i;const c=r.map(u=>t[u]).find(u=>!!(u?.resolvedRemoteName&&Io(u)));if(c)return Io(c);const l=o.find(u=>!!u.remoteName);return l||(o[0]??null)},mb=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:aa(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),fb=t=>({...so(),status:t?.status??null,isInitialStatusResolved:t?.isInitialStatusResolved??!1,lastRefreshAt:t?.lastRefreshAt??0,lastDiscoveryPollAt:t?.lastDiscoveryPollAt??0,identity:t?.identity??null,resolvedRemoteName:t?.resolvedRemoteName??t?.status?.resolvedRemoteName??null}),tr=Ni()(Rl((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:so()}})},setParams:(n,r)=>{t(o=>{const i=o.entries[n]??so();return{entries:{...o.entries,[n]:db(i,r)}}})},startWatching:n=>{if(t(i=>{const c=i.entries[n]??so();return{entries:{...i.entries,[n]:{...c,watchers:c.watchers+1}}}}),Ao.has(n))return;const r=i=>{const c=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const u=e().entries[n];!u||u.watchers<=0||u.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},i),l=Do.get(n)??[];l.push(c),Do.set(n,l)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),tb.forEach(i=>r(i));const o=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const i=e().entries[n];if(!i||i.watchers<=0)return;if(!!!i.status?.pr){const m=Date.now();if(m-i.lastDiscoveryPollAt<eb)return;t(d=>{const f=d.entries[n];return f?{entries:{...d.entries,[n]:{...f,lastDiscoveryPollAt:m}}}:d}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(lb(i.status?.pr?.state))return;const l=Date.now()-i.lastRefreshAt,u=cb(i.status)?sb:i.status?.checks&&i.status.checks.state!=="pending"?rb:nb;l<u||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},Zx);Ao.set(n,o)},stopWatching:n=>{t(c=>{const l=c.entries[n];if(!l)return c;const u=Math.max(0,l.watchers-1);return{entries:{...c.entries,[n]:{...l,watchers:u}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const o=Ao.get(n);typeof o=="number"&&window.clearInterval(o),Ao.delete(n);const i=Do.get(n);i&&i.length>0&&i.forEach(c=>{window.clearTimeout(c)}),Do.delete(n)},refresh:async(n,r)=>{const o=e(),i=o.entries[n],c=tc(i);if(!i||!c)return;const l=am(o.entries,c),u=l.some(f=>!!o.entries[f]?.status?.pr);if(r?.onlyExistingPr&&!u)return;const m=md.get(c)??0;if(!r?.force&&Date.now()-m<Xx||Qi.has(c))return;const d=ub(o.entries,c,n);if(d){if(Qi.add(c),md.set(c,Date.now()),t(f=>{const g={...f.entries};return l.forEach(x=>{const p=g[x];p&&(g[x]={...p,lastRefreshAt:Date.now(),isLoading:r?.silent?p.isLoading:!0,error:null})}),{entries:g}}),d.githubAuthChecked&&d.githubConnected===!1){t(f=>{const g={...f.entries};return l.forEach(x=>{const p=g[x];p&&(g[x]={...p,status:{connected:!1},error:null,isLoading:r?.silent?p.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?p.isInitialStatusResolved:!0})}),{entries:g}}),Qi.delete(c);return}if(!d.github?.prStatus){t(f=>{const g={...f.entries};return l.forEach(x=>{const p=g[x];p&&(g[x]={...p,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?p.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?p.isInitialStatusResolved:!0})}),{entries:g}}),Qi.delete(c);return}try{t(g=>({...g,activeRequestCount:g.activeRequestCount+1,totalRequestCount:g.totalRequestCount+1}));const f=await d.github.prStatus(d.directory,d.branch,d.remoteName??void 0,{force:r?.force});t(g=>{const x={...g.entries};return l.forEach(p=>{const y=x[p];if(!y)return;const b=y.status?.pr,h=f.pr,w=!!(h&&b&&h.number===b.number&&(!h.body||!h.body.trim())&&typeof b.body=="string"&&b.body.trim().length>0)&&h&&b?.body?{...f,pr:{...h,body:b.body}}:f,S=w.resolvedRemoteName??y.resolvedRemoteName??d.remoteName??null,v=aa(y)??{directory:d.directory,branch:d.branch,remoteName:d.remoteName??null};x[p]={...y,status:w,error:null,isLoading:r?.silent?y.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?y.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...v,remoteName:S??v.remoteName??null}}}),{entries:x}})}catch(f){const g=f instanceof Error?f.message:String(f);t(x=>{const p={...x.entries};return l.forEach(y=>{const b=p[y];b&&(p[y]={...b,error:g||"Failed to load PR status",isLoading:r?.silent?b.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?b.isInitialStatusResolved:!0})}),{entries:p}})}finally{Qi.delete(c),t(f=>({...f,activeRequestCount:Math.max(0,f.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const o=Array.from(new Set(n.map(i=>{const c=i.directory.trim(),l=i.branch.trim();return!c||!l?null:oo(c,l,i.remoteName??null)}).filter(i=>!!i)));await om(o,ib,i=>e().refresh(i,r))},updateStatus:(n,r)=>{t(o=>{const i=o.entries[n]??so();return{entries:{...o.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:ab,storage:pu(()=>Dr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=aa(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<ob}).map(([e,n])=>[e,mb(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([o,i])=>[o,fb(i)]))}}})),hb=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",o=e.mergeable===!1||r==="blocked"||r==="dirty";return n||o?"blocked":"open"},pb=t=>{const e=hb(t.status??null),n=t.status?.pr;return!e||!n?.number?null:{number:n.number,visualState:e,prState:n.state,draft:!!n.draft,title:typeof n.title=="string"&&n.title.trim().length>0?n.title:null,url:typeof n.url=="string"&&n.url.trim().length>0?n.url:null,base:typeof n.base=="string"&&n.base.trim().length>0?n.base:null,head:typeof n.head=="string"&&n.head.trim().length>0?n.head:null,checks:t.status?.checks?{state:t.status.checks.state,total:t.status.checks.total,success:t.status.checks.success,failure:t.status.checks.failure,pending:t.status.checks.pending}:null,canMerge:typeof t.status?.canMerge=="boolean"?t.status.canMerge:null,mergeableState:typeof n.mergeableState=="string"?n.mergeableState:null,repo:t.status?.repo?{owner:t.status.repo.owner,repo:t.status.repo.repo}:null}},gb=t=>`${t.number}:${t.visualState}:${t.prState}:${t.draft}:${t.title??""}:${t.url??""}:${t.base??""}:${t.head??""}:${t.canMerge??""}:${t.mergeableState??""}:${t.checks?.state??""}:${t.checks?.total??""}:${t.checks?.success??""}:${t.checks?.failure??""}:${t.checks?.pending??""}:${t.repo?.owner??""}:${t.repo?.repo??""}`;let za=new Map,fd=new Map;const xb=t=>{const e=pt.c(2);let n;return e[0]!==t?(n=r=>{const o=new Map,i=new Map;for(const c of t){const l=r.entries[c];if(!l)continue;const u=pb(l);if(!u)continue;const m=gb(u);o.set(c,m),i.set(c,u)}if(o.size===za.size){let c=!0;for(const[l,u]of o)if(za.get(l)!==u){c=!1;break}if(c)return fd}return za=o,fd=i,i},e[0]=t,e[1]=n):n=e[1],tr(n)},bb=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},yb=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",o=e.mergeable===!1||r==="blocked"||r==="dirty";return n||o?"blocked":"open"},wb=[2e3,5e3],hd=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),Kr=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},vb=(t,e)=>{const n=Kr(t);if(!n||n.includes("->"))return"";if(e){const o=`${e}/`;return n.startsWith(o)?n.slice(o.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},jb=(t,e)=>`${t}::${e}`,sc=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},Wa=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(c=>c.name===n);if(i)return i}const r=sc(e.trackingBranch);if(r){const i=r==="origin"?t.find(l=>l.name==="upstream"):null;if(i)return i;const c=t.find(l=>l.name===r);if(c)return c}const o=t.find(i=>i.name==="origin");return o||(t[0]??null)},Sb=t=>t.startsWith("pr-"),Nb=(t,e)=>{const n=sc(e),r=new Map(t.map(c=>[c.name,c])),o=[],i=c=>{c&&(o.some(l=>l.name===c.name)||o.push(c))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(c=>!Sb(c.name)).forEach(c=>i(c)),t.forEach(c=>i(c)),o},Ua=new Map,Ha=wi;function kb(t,e){const[n,r]=a.useState(null),[o,i]=a.useState([]),c=a.useRef(null);return a.useEffect(()=>{r(null),i([])},[t]),a.useEffect(()=>{if(!t||!e?.repoUpstream||c.current===t)return;c.current=t;let l=!1;return(async()=>{try{const u=await e.repoUpstream(t);if(l||!u?.isFork||!u.upstream||(r(u.upstream),!e.repoBranches))return;try{const m=await e.repoBranches(u.upstream.owner,u.upstream.repo);l||i(m)}catch{}}catch{}})(),()=>{l=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:o}}const Cb=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:i=[],onGeneratedDescription:c})=>{const{t:l}=Tt(),u=Fe(W=>W.timeFormatPreference),{github:m}=Gn(),d=vi(W=>W.status),f=vi(W=>W.hasChecked),g=Fe(W=>W.setSettingsDialogOpen),x=Fe(W=>W.setSettingsPage),p=Fe(W=>W.setActiveMainTab),y=jt(W=>W.currentSessionId),{isMobile:b,hasTouchInput:h}=Pr(),N=a.useCallback(()=>{x("github"),g(!0)},[g,x]),w=a.useMemo(()=>jb(t,e),[t,e]),S=a.useMemo(()=>Ua.get(w)??null,[w]),v=tr(W=>W.ensureEntry),j=tr(W=>W.setParams),k=tr(W=>W.startWatching),A=tr(W=>W.stopWatching),T=tr(W=>W.refresh),C=tr(W=>W.updateStatus),[P,E]=a.useState(()=>S?.title??hd(e)),[M,H]=a.useState(()=>S?.body??""),[R,_]=a.useState(()=>S?.draft??!1),[z,V]=a.useState(()=>S?.additionalContext??""),[F,te]=a.useState(()=>{const W=typeof S?.targetBaseBranch=="string"?Kr(S.targetBaseBranch):"";return W||Kr(n)}),[Z,ne]=a.useState("squash"),[U,ie]=a.useState(!1),[oe,pe]=a.useState(!1),[je,Se]=a.useState(!1),[re,L]=a.useState(!1),[$,K]=a.useState(!1),[he,de]=a.useState(!1),[we,xe]=a.useState(null),[De,le]=a.useState(""),[Ce,ue]=a.useState(""),[ve,G]=a.useState(!1),[Ae,ce]=a.useState(!1),[fe,Te]=a.useState(()=>Wa(o,{selectedRemoteName:S?.selectedRemoteName,trackingBranch:r})),[me,B]=a.useState(!1),{detectedUpstream:ye,upstreamBranches:_e}=kb(t,m);a.useEffect(()=>{B(!1)},[t]);const J=o.some(W=>W.name==="upstream"),Ee=!!(t&&e&&n&&(e!==n||(J||ye!==null))),Ne=a.useMemo(()=>oo(t,e),[t,e]),Be=tr(W=>W.entries[Ne]),se=Be?.isLoading??!1,O=Be?.status??null,D=Be?.error??null,Y=Be?.isInitialStatusResolved??!1,be=a.useMemo(()=>{const W=me?null:fe?.name?.trim()||null,Ge=new Set;for(const Nt of i){const ut=vb(Nt,W);!ut||ut==="HEAD"||Ge.add(ut)}if(me)for(const Nt of _e)Nt&&Nt!=="HEAD"&&Ge.add(Nt);const Xe=Kr(n);Xe&&Xe!=="HEAD"&&Ge.add(Xe);const ht=Kr(F);return ht&&ht!=="HEAD"&&Ge.add(ht),Array.from(Ge).sort((Nt,ut)=>Nt.localeCompare(ut))},[n,i,fe?.name,F,_e,me]);a.useEffect(()=>{if(o.length===0){fe&&Te(null);return}(!fe||!o.some(W=>W.name===fe.name))&&Te(Wa(o,{selectedRemoteName:S?.selectedRemoteName,trackingBranch:r}))},[S?.selectedRemoteName,o,fe,r]),a.useEffect(()=>{const W=Kr(n);if(!F&&W){te(W);return}if(be.length!==0&&!be.includes(F)){const Ge=be.includes(W)?W:be[0];Ge&&te(Ge)}},[be,n,F]);const[Oe,$e]=a.useState(!1),[Re,ot]=a.useState(null),[yt,At]=a.useState(!1),[mt,Le]=a.useState(new Set),[Qe,Ye]=a.useState(!1),[rt,bt]=a.useState(null),[ct,nt]=a.useState(!1),It=a.useRef(new Set),lt=a.useRef(null),kt=a.useRef(!1),Ke=a.useRef(new Set),tt=a.useRef([]);a.useEffect(()=>{ye&&!J&&B(!0)},[ye,J]),a.useEffect(()=>{me&&ye?.defaultBranch&&te(ye.defaultBranch)},[me,ye?.defaultBranch]);const We=O?.pr??null,gt=We?`${t}#${We.number}`:null,He=!!(gt&&we===gt);a.useEffect(()=>{if(!m?.prContext||!We||typeof We.body=="string"&&We.body.length>0)return;const W=`${t}#${We.number}`;if(It.current.has(W))return;It.current.add(W),xe(W);let Ge=!1;return m.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!1}).then(Xe=>{if(Ge)return;const ht=Xe?.pr;ht&&C(Ne,Nt=>!Nt?.pr||Nt.pr.number!==We.number?Nt:{...Nt,pr:{...Nt.pr,body:ht.body||""}})}).catch(()=>{}).finally(()=>{Ge||xe(Xe=>Xe===W?null:Xe)}),()=>{Ge=!0}},[t,m,We,Ne,C]),a.useEffect(()=>{if(!We){de(!1),le(""),ue(""),lt.current=null;return}const W=lt.current!==null&&lt.current!==We.number;W&&de(!1),(!he||W)&&(le(We.title||""),ue(We.body||"")),lt.current=We.number},[he,We]);const st=a.useCallback(async()=>{if(!m?.prContext){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(We){$e(!0),Le(new Set),At(!0);try{const W=await m.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!0});ot(W)}catch(W){const Ge=W instanceof Error?W.message:String(W);ae.error(l("gitView.pr.toast.loadCheckDetailsFailed"),{description:Ge})}finally{At(!1)}}},[t,m,We,l]),Et=a.useCallback(async()=>{if(!m?.prContext){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(We){Ye(!0),nt(!0);try{const W=await m.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!1});bt(W)}catch(W){const Ge=W instanceof Error?W.message:String(W);ae.error(l("gitView.pr.toast.loadCommentsFailed"),{description:Ge})}finally{nt(!1)}}},[t,m,We,l]),at=a.useCallback(W=>{if(!W)return"";const Ge=Date.parse(W);return Number.isFinite(Ge)?ga(Ge,u,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):W},[u]),dt=a.useMemo(()=>{const W=d?.user?.login;return typeof W=="string"?W.trim():""},[d]),Ht=a.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),Rt=a.useCallback(W=>{const Ge=dt.toLowerCase(),Xe=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return W.replace(Xe,(ht,Nt,ut)=>{const ss=`@${ut}`,bs=ut.toLowerCase();return`${Nt}[${ss}](https://github.com/${bs}${Ge&&bs===Ge?"?oc-self-mention=1":""})`})},[dt]),Wt=a.useMemo(()=>{const W=(rt?.issueComments??[]).map(ht=>({id:`issue-${ht.id}`,body:ht.body||"",authorName:ht.author?.name||ht.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:ht.author?.login||null,avatarUrl:ht.author?.avatarUrl||null,createdAt:ht.createdAt,context:l("gitView.pr.comments.generalContext"),path:null,line:null})),Ge=(rt?.reviewComments??[]).map(ht=>({id:`review-${ht.id}`,body:ht.body||"",authorName:ht.author?.name||ht.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:ht.author?.login||null,avatarUrl:ht.author?.avatarUrl||null,createdAt:ht.createdAt,context:l("gitView.pr.comments.reviewContext"),path:ht.path||null,line:ht.line??null})),Xe=[...W,...Ge];return Xe.sort((ht,Nt)=>{const ut=ht.createdAt?Date.parse(ht.createdAt):0,ss=Nt.createdAt?Date.parse(Nt.createdAt):0,bs=Number.isFinite(ut)?ut:0,ys=Number.isFinite(ss)?ss:0;return bs-ys}),Xe},[rt,l]),qt=a.useCallback(()=>{if(!y)return ae.error(l("gitView.pr.toast.noActiveSession"),{description:l("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:W,currentModelId:Ge,currentAgentName:Xe,currentVariant:ht}=ls.getState(),Nt=zl.getState().lastUsedProvider,ut=W||Nt?.providerID,ss=Ge||Nt?.modelID;return!ut||!ss?(ae.error(l("gitView.pr.toast.noModelSelected")),null):{sessionId:y,providerID:ut,modelID:ss,currentAgentName:Xe??null,currentVariant:ht??null}},[y,l]),Lt=a.useCallback((W,Ge,Xe,ht)=>{jt.getState().sendMessage(Ge,W.providerID,W.modelID,W.currentAgentName??void 0,void 0,void 0,[{text:Xe,synthetic:!0},{text:ht,synthetic:!0}],W.currentVariant??void 0).catch(Nt=>{const ut=Nt instanceof Error?Nt.message:String(Nt);ae.error(l("gitView.pr.toast.sendMessageFailed"),{description:ut})})},[l]),Gt=a.useCallback(W=>{const Ge=W.status||"unknown",Xe=W.conclusion??void 0,ht=Xe?`${Ge} / ${Xe}`:Ge,Nt=W.app?.name||W.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:W.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Nt?`${Nt} · ${ht}`:ht})]}),W.detailsUrl?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:W.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),W.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:W.output.title}):null,W.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:W.output.summary}):null,W.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:W.output.text}):null,Array.isArray(W.annotations)&&W.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",W.annotations.length>20?` (showing 20/${W.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:W.annotations.slice(0,20).map((ut,ss)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro text-[var(--status-error)]",children:[ut.title||ut.level||"Issue",ut.path?` · ${ut.path}`:"",typeof ut.startLine=="number"?`:${ut.startLine}`:"",typeof ut.endLine=="number"&&ut.endLine!==ut.startLine?`-${ut.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:ut.message}),ut.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:ut.rawDetails}):null]},`${ut.path||"file"}:${ut.startLine||ss}:${ss}`))})]}):null,W.job?.steps&&W.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:W.job.steps.map((ut,ss)=>{const bs=(ut.conclusion||"").toLowerCase(),ys=bs&&!["success","neutral","skipped"].includes(bs),Bs=`${W.id??"run"}:${W.job?.jobId??"job"}:${ut.number??ss}:${ut.name}`,Rs=mt.has(Bs);return ys?s.jsxs(Vi,{open:Rs,children:[s.jsxs("button",{type:"button",onClick:()=>{Le(an=>{const Ss=new Set(an);return Ss.has(Bs)?Ss.delete(Bs):Ss.add(Bs),Ss})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(ys?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Rs?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:ut.name}),ut.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:ut.conclusion}):null]}),s.jsx($i,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof ut.number=="number"?s.jsxs("div",{children:[l("gitView.pr.checks.stepLabel"),": ",ut.number]}):null,ut.status?s.jsxs("div",{children:[l("gitView.pr.checks.statusLabel"),": ",ut.status]}):null,ut.conclusion?s.jsxs("div",{children:[l("gitView.pr.checks.conclusionLabel"),": ",ut.conclusion]}):null,ut.startedAt?s.jsxs("div",{children:[l("gitView.pr.checks.startedLabel"),": ",at(ut.startedAt)]}):null,ut.completedAt?s.jsxs("div",{children:[l("gitView.pr.checks.completedLabel"),": ",at(ut.completedAt)]}):null]})})]},Bs):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:ut.name}),ut.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:ut.conclusion}):null]},Bs)})})]}):null]})},[mt,at,l]),Qt=a.useCallback(async()=>{if(p("chat"),!m?.prContext){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!We)return;const W=qt();if(W)try{const Ge=await m.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!0}),ht=(Ge.checkRuns??[]).filter(ys=>{const Bs=typeof ys.conclusion=="string"?ys.conclusion.toLowerCase():"";return Bs?!["success","neutral","skipped"].includes(Bs):!1});if(ht.length===0){ae.message(l("gitView.pr.toast.noFailedChecks"));return}const Nt=await Tn("github.pr.checks.review.visible"),ut=await Tn("github.pr.checks.review.instructions"),ss=ht.flatMap(ys=>(Array.isArray(ys.annotations)?ys.annotations:[]).map(Rs=>({run:ys.name,level:Rs.level,title:Rs.title,path:Rs.path,startLine:Rs.startLine,endLine:Rs.endLine,message:Rs.message,rawDetails:Rs.rawDetails}))),bs=`GitHub PR failed checks (JSON)
7
+ ${JSON.stringify({repo:Ge.repo??null,pr:Ge.pr??null,failedChecks:ht,failedAnnotations:ss},null,2)}`;Lt(W,Nt,ut,bs)}catch(Ge){const Xe=Ge instanceof Error?Ge.message:String(Ge);ae.error(l("gitView.pr.toast.loadChecksFailed"),{description:Xe})}},[t,Lt,m,We,qt,p,l]),rs=a.useCallback(async()=>{if(p("chat"),!m?.prContext){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!We)return;const W=qt();if(W)try{const Ge=await m.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!1}),Xe=Ge.issueComments??[],ht=Ge.reviewComments??[];if(Xe.length+ht.length===0){ae.message(l("gitView.pr.toast.noPrComments"));return}const ut=await Tn("github.pr.comments.review.visible"),ss=await Tn("github.pr.comments.review.instructions"),bs=`GitHub PR comments (JSON)
8
+ ${JSON.stringify({repo:Ge.repo??null,pr:Ge.pr??null,issueComments:Xe,reviewComments:ht},null,2)}`;Lt(W,ut,ss,bs)}catch(Ge){const Xe=Ge instanceof Error?Ge.message:String(Ge);ae.error(l("gitView.pr.toast.loadPrCommentsFailed"),{description:Xe})}},[t,Lt,m,We,qt,p,l]),Yt=a.useCallback(async W=>{Ye(!1),p("chat");const Ge=qt();if(!Ge)return;const Xe=await Tn("github.pr.comment.single.visible"),ht=await Tn("github.pr.comment.single.instructions"),Nt=`GitHub PR comment (JSON)
9
+ ${JSON.stringify({repo:rt?.repo??null,pr:rt?.pr??We??null,comment:W},null,2)}`;Lt(Ge,Xe,ht,Nt)},[rt,Lt,We,qt,p]),ft=a.useCallback(async W=>{await T(Ne,W)},[Ne,T]),Jt=a.useCallback(()=>{tt.current.forEach(W=>{window.clearTimeout(W)}),tt.current=wb.map(W=>window.setTimeout(()=>{ft({force:!0,silent:!0,markInitialResolved:!0})},W))},[ft]);a.useEffect(()=>{if(!m?.prStatus||!Ee||o.length<=1||kt.current||O?.pr)return;const W=`${w}::${fe?.name??""}`;if(Ke.current.has(W))return;Ke.current.add(W);const Ge=Nb(o,r).filter(Nt=>Nt.name!==fe?.name);if(Ge.length===0)return;let Xe=!1;return(async()=>{for(const Nt of Ge){if(Xe)return;try{if(!(await m.prStatus(t,e,Nt.name))?.pr)continue;if(Xe)return;Te(ss=>ss?.name===Nt.name?ss:Nt);return}catch{}}})(),()=>{Xe=!0}},[e,Ee,t,m,o,fe?.name,w,O?.pr,r]),a.useEffect(()=>{v(Ne),j(Ne,{directory:t,branch:e,remoteName:fe?.name??null,canShow:Ee,github:m,githubAuthChecked:f,githubConnected:d?.connected??null})},[e,Ee,t,v,m,f,d?.connected,Ne,fe?.name,j]),a.useEffect(()=>(k(Ne),()=>{A(Ne)}),[Ne,k,A]),a.useEffect(()=>{const W=Ua.get(w)??null;E(W?.title??hd(e)),H(W?.body??""),_(W?.draft??!1),te(W?.targetBaseBranch?Kr(W.targetBaseBranch):Kr(n));const Ge=Wa(o,{selectedRemoteName:W?.selectedRemoteName,trackingBranch:r});Te(Xe=>Xe?.name===Ge?.name?Xe:Ge)},[n,e,o,w,r]),a.useEffect(()=>{ft({markInitialResolved:!0})},[Ne,ft]),a.useEffect(()=>{!Ee||!fe?.name||ft({force:!0,silent:!0,markInitialResolved:!0})},[Ee,ft,fe?.name]),a.useEffect(()=>{const W=O?.resolvedRemoteName?.trim();if(!W||kt.current)return;const Ge=o.find(Xe=>Xe.name===W);Ge&&Te(Xe=>Xe?.name===Ge.name?Xe:Ge)},[o,O?.resolvedRemoteName]),a.useEffect(()=>{const W=O?.pr?.state==="closed"||O?.pr?.state==="merged",Ge=Be?.lastRefreshAt??0,Xe=Date.now()-Ge>6e4,ht=!W&&Xe,Nt=()=>{ht&&ft({force:!0,silent:!0})},ut=()=>{document.visibilityState==="visible"&&ht&&ft({force:!0,silent:!0})};return window.addEventListener("focus",Nt),document.addEventListener("visibilitychange",ut),()=>{window.removeEventListener("focus",Nt),document.removeEventListener("visibilitychange",ut)}},[ft,O?.pr?.state,Be?.lastRefreshAt]),a.useEffect(()=>{f&&d?.connected===!1&&ft({force:!0,silent:!0,markInitialResolved:!0})},[f,d,ft]),a.useEffect(()=>{!t||!e||Ua.set(w,{title:P,body:M,draft:R,additionalContext:z,targetBaseBranch:F,selectedRemoteName:fe?.name})},[w,P,M,R,z,F,fe?.name,t,e]),a.useEffect(()=>{const W=tt.current;return()=>{W.forEach(Ge=>{window.clearTimeout(Ge)}),tt.current=[]}},[]);const ms=a.useCallback(async()=>{if(!U&&t){ie(!0);try{const Ge={base:me&&ye?.defaultBranchSha?ye.defaultBranchSha:F,head:e};z&&(Ge.context=z);const Xe=await Kf(t,Ge);Xe.title?.trim()&&E(Xe.title.trim()),Xe.body?.trim()&&H(Xe.body.trim()),c?.()}catch(W){const Ge=W instanceof Error?W.message:String(W);ae.error(l("gitView.pr.toast.generateDescriptionFailed"),{description:Ge})}finally{ie(!1)}}},[z,e,ye?.defaultBranchSha,t,U,c,F,l,me]),Xt=a.useCallback(async()=>{if(!m?.prCreate){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}const W=P.trim();if(!W){ae.error(l("gitView.pr.toast.titleRequired"));return}const Ge=F.trim();if(!Ge){ae.error(l("gitView.pr.toast.baseBranchRequired"));return}if(!me&&Ge===e){ae.error(l("gitView.pr.toast.baseMustDifferFromHead"));return}pe(!0);try{const Xe=sc(r),ht=me&&ye,Nt=await m.prCreate({directory:t,title:W,head:e,base:Ge,...M.trim()?{body:M}:{},draft:R,...ht?{targetRepo:{owner:ye.owner,repo:ye.repo},headRemote:"origin"}:{...fe?{remote:fe.name}:{},...Xe&&Xe!==fe?.name?{headRemote:Xe}:{}}});ae.success(l("gitView.pr.toast.prCreated")),C(Ne,ut=>ut&&{...ut,pr:Nt}),await ft({force:!0}),Jt()}catch(Xe){const ht=Xe instanceof Error?Xe.message:String(Xe);ae.error(l("gitView.pr.toast.createPrFailed"),{description:ht})}finally{pe(!1)}},[M,e,ye,t,R,m,Ne,ft,Jt,fe,F,P,r,C,me,l]),ts=a.useCallback(async W=>{if(!m?.prMerge){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}L(!0);try{const Ge=await m.prMerge({directory:t,number:W.number,method:Z});Ge.merged?ae.success(l("gitView.pr.toast.prMerged")):ae.message(l("gitView.pr.toast.prNotMerged"),{description:Ge.message||l("gitView.pr.notMergeable")}),await ft({force:!0}),Jt()}catch(Ge){const Xe=Ge instanceof Error?Ge.message:String(Ge);ae.error(l("gitView.pr.toast.mergeFailed"),{description:Xe}),W.url&&Ha(W.url)}finally{L(!1)}},[t,m,Z,ft,Jt,l]),ks=a.useCallback(async W=>{if(!m?.prReady){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}K(!0);try{await m.prReady({directory:t,number:W.number}),ae.success(l("gitView.pr.toast.markedReady")),await ft({force:!0}),Jt()}catch(Ge){const Xe=Ge instanceof Error?Ge.message:String(Ge);ae.error(l("gitView.pr.toast.markReadyFailed"),{description:Xe}),W.url&&Ha(W.url)}finally{K(!1)}},[t,m,ft,Jt,l]),$t=a.useCallback(async W=>{if(!m?.prUpdate){ae.error(l("gitView.pr.toast.githubApiUnavailable"));return}const Ge=De.trim();if(!Ge){ae.error(l("gitView.pr.toast.titleRequired"));return}Se(!0);try{const Xe=await m.prUpdate({directory:t,number:W.number,title:Ge,body:Ce});C(Ne,ht=>ht&&{...ht,pr:{...ht.pr??W,...Xe}}),de(!1),ae.success(l("gitView.pr.toast.prUpdated")),await ft({force:!0}),Jt()}catch(Xe){const ht=Xe instanceof Error?Xe.message:String(Xe);ae.error(l("gitView.pr.toast.updatePrFailed"),{description:ht})}finally{Se(!1)}},[t,Ce,De,m,Ne,ft,Jt,C,l]);if(!Ee)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:l("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pullRequest.availableOnFeatureBranches")})]})});const as=O?.repo?.url||null,$s=me&&ye?.url?ye.url:as,Ut=O?.checks??null,Es=!!O?.canMerge,Ls=!!O?.connected,gs=f&&O?.connected===!1,Cs=yb(O),Mt=Cs?`var(--pr-${Cs})`:"var(--status-info)",xt=Cs==="draft"?"git-pr-draft":Cs==="merged"?"git-merge":Cs==="closed"?"git-close-pull-request":"git-pull-request",Zt=We?[`${We.state}${We.draft?" (draft)":""}`,We.mergeable===!1?l("gitView.pr.notMergeable"):null,We.state==="open"&&typeof We.mergeableState=="string"&&We.mergeableState&&We.mergeableState!=="unknown"?We.mergeableState:null].filter(Boolean).join(" · "):"",Ft=Ut?Ut.total>0?`${Ut.success}/${Ut.total} ${l("gitView.pr.checks.label")}`:`${Ut.state} ${l("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[We?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{Ha(We.url)},"aria-label":l("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(I,{name:xt,className:"size-4 shrink-0",style:{color:Mt}})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(I,{name:xt,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:l("gitView.pullRequest.title")}),We?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",We.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[se?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:se,onClick:()=>{ft({force:!0})},"aria-label":l("gitView.pr.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.refresh")})})]})]})]}),We?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:Mt},children:Zt}),Ut?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${bb(Ut.state)}`}),Ft]}):null,r&&fe&&r.split("/")[0]!==fe.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",fe.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[gs?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.githubNotConnected")}),s.jsx(ze,{variant:"outline",size:"sm",onClick:N,className:"w-fit",children:l("gitView.pr.actions.openSettings")})]}):null,D?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:D}),$s?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:$s,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!We&&!Y&&!D&&!gs?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),l("gitView.pr.checkingStatus")]}):We?s.jsx("div",{className:"flex flex-col gap-2",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[he?s.jsxs("div",{className:"space-y-2",children:[s.jsx(kn,{value:De,onChange:W=>le(W.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h}),s.jsx(gi,{value:Ce,onChange:W=>ue(W.target.value),className:"min-h-[120px] bg-background/80",placeholder:l("gitView.pr.placeholder.description"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:We.title}),We.body?.trim()?s.jsx(fo,{content:We.body,className:"typography-markdown-body text-muted-foreground break-words mt-1"}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:l(He?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),Es&&We.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.draftMustBeReady")}):null,Es?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.noMergePermission")})]}),s.jsxs("div",{className:"order-first w-full flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[We.state==="open"?he?s.jsxs(s.Fragment,{children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{de(!1),le(We.title||""),ue(We.body||"")},disabled:je,"aria-label":l("gitView.pr.actions.cancelEditingAria"),children:s.jsx(I,{name:"close",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>$t(We),disabled:je||!De.trim(),"aria-label":l("gitView.pr.actions.savePrAria"),children:je?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>de(!0),"aria-label":l("gitView.pr.actions.editPrAria"),children:s.jsx(I,{name:"edit",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.editPr")})})]}):null,Ut?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:st,disabled:yt,"aria-label":l("gitView.pr.actions.openChecksAria"),children:yt?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"information",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.openChecks")})})]}):null,Ut?.failure?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:Qt,"aria-label":l("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(I,{name:"error-warning",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Et,"aria-label":l("gitView.pr.actions.openCommentsAria"),children:s.jsx(I,{name:"chat-4",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.openComments")})})]}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:rs,"aria-label":l("gitView.pr.actions.shareCommentsAria"),children:s.jsx(I,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.shareComments")})})]}),Es&&We.draft&&We.state==="open"?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>ks(We),disabled:$||re||je||he,"aria-label":l("gitView.pr.actions.markReadyAria"),children:$?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:Es?s.jsxs(s.Fragment,{children:[s.jsxs(zn,{value:Z,onValueChange:W=>ne(W),disabled:re||We.state!=="open",children:[s.jsx(Wn,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(En,{})}),s.jsxs(Un,{children:[s.jsx(qs,{value:"squash",children:l("gitView.pr.mergeMethod.squash")}),s.jsx(qs,{value:"merge",children:l("gitView.pr.mergeMethod.merge")}),s.jsx(qs,{value:"rebase",children:l("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ts(We),disabled:re||$||We.state!=="open"||We.draft||je||he,"aria-label":l("gitView.pr.actions.mergePrAria"),children:re?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"})})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.mergePr")})})]})]}):null})]})]})}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",F," ",s.jsxs("span",{className:"opacity-60",children:["(",me&&ye?"upstream":"remote",")"]})]})]}),$s?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:$s,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),l("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.title")}),s.jsx(kn,{value:P,onChange:W=>E(W.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.baseBranch")}),be.length>0?s.jsxs(zn,{value:F,onValueChange:te,children:[s.jsx(Wn,{className:"h-9",children:s.jsx(En,{placeholder:l("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(Un,{children:be.map(W=>s.jsx(qs,{value:W,children:W},W))})]}):s.jsx(kn,{value:F,onChange:W=>te(W.target.value),placeholder:l("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.description")}),s.jsx(gi,{value:M,onChange:W=>H(W.target.value),className:"min-h-[110px]",placeholder:l("gitView.pr.placeholder.whatChanged"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":R,onClick:()=>_(W=>!W),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),_(Ge=>!Ge))},children:[s.jsx(ji,{size:"sm",checked:R,onChange:W=>_(W),ariaLabel:l("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:l("gitView.pr.field.draft")})]}),b?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.optional")}),s.jsx(ze,{variant:"outline",size:"sm",onClick:()=>ce(!0),children:z.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),z.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:l("gitView.pr.additionalContext.added")})})]}):s.jsxs(Vi,{open:ve,onOpenChange:G,children:[s.jsxs(vo,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:ve?l("gitView.pr.actions.hide"):z.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),s.jsx($i,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(gi,{value:z,onChange:W=>V(W.target.value),className:"min-h-[100px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(xa,{open:Ae,onClose:()=>ce(!1),title:l("gitView.pr.additionalContext.title"),footer:s.jsx(ze,{size:"sm",onClick:()=>ce(!1),className:"w-full",children:l("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(gi,{value:z,onChange:W=>V(W.target.value),className:"min-h-[200px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ze,{variant:"outline",size:"sm",onClick:ms,disabled:U||oe,children:[U?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),l("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(ze,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Xt,disabled:oe||!Ls||!F.trim()||!me&&F.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:oe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:l("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(Ks,{open:Oe,onOpenChange:$e,children:s.jsxs(Gs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(Qs,{children:[s.jsxs(Ys,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),l("gitView.pr.checkDetails.title")]}),s.jsx(dn,{children:We?l("gitView.pr.numberLabel",{number:We.number}):l("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[yt?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),l("gitView.loading.loading")]}):null,yt?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(Re?.checkRuns)&&Re?.checkRuns.length>0?Re.checkRuns.map((W,Ge)=>{const Xe=`${W.id??"run"}:${W.job?.jobId??"job"}:${W.name}:${Ge}`;return s.jsx("div",{className:"p-1",children:Gt(W)},Xe)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:l("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(Ks,{open:Qe,onOpenChange:Ye,children:s.jsxs(Gs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(Qs,{children:s.jsxs(Ys,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),l("gitView.pr.comments.title"),We?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.numberLabel",{number:We.number})}):null]})}),s.jsxs(ba,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[ct?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),l("gitView.loading.loading")]}):null,ct?null:s.jsx("div",{className:"space-y-4",children:Wt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Wt.map((W,Ge)=>{const Xe=(W.authorName||"?").charAt(0).toUpperCase(),ht=Ge===Wt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[ht?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:W.avatarUrl?s.jsx("img",{src:W.avatarUrl,alt:W.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Xe})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[W.authorName,W.authorLogin&&W.authorLogin!==W.authorName?` · @${W.authorLogin}`:""]}),W.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:at(W.createdAt)}):null,s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsxs(ze,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{Yt(W)},"aria-label":l("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(I,{name:"ai-generate-2",className:"size-3.5"}),l("gitView.pr.actions.sendToAgent")]})}),s.jsx(Bt,{children:s.jsx("p",{children:l("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[W.context,W.path?` · ${W.path}`:"",W.line?`:${W.line}`:""]}),s.jsx(fo,{content:Rt(W.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Ht].filter(Boolean).join(" ")})]})]},W.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:l("gitView.pr.comments.empty")})})]})]})})]})},Ab=t=>{const e=pt.c(150),{open:n,onOpenChange:r,conflictFiles:o,directory:i,operation:c,onAbort:l,onClearState:u}=t;let m;e[0]!==o?(m=o===void 0?[]:o,e[0]=o,e[1]=m):m=e[1];const d=m,{t:f}=Tt(),g=jt(Db),x=jt(Ib),p=ti(Pb),y=ti(Tb),b=Fe(Eb),[h,N]=a.useState(!1),[w,S]=a.useState(null),[v,j]=a.useState(null);let k,A;e[2]!==i||e[3]!==n||e[4]!==f?(k=()=>{!n||!i||(N(!0),j(null),S(null),qf(i).then(me=>{S(me)}).catch(me=>{const B=me instanceof Error?me.message:f("gitView.conflict.loadFailed");j(B)}).finally(()=>{N(!1)}))},A=[n,i,f],e[2]=i,e[3]=n,e[4]=f,e[5]=k,e[6]=A):(k=e[5],A=e[6]),a.useEffect(k,A);let T;e[7]!==w||e[8]!==i||e[9]!==c?(T=async()=>{if(!w)return null;const me=c==="merge"?"merge":"rebase",B=w.headInfo||(c==="merge"?"MERGE_HEAD":"REBASE_HEAD"),ye=c==="merge"?"git commit --no-edit":"git rebase --continue",_e=await Tn("git.conflict.resolve.visible",{operation_label:me,head_ref:B}),J=await Tn("git.conflict.resolve.instructions",{operation_label:me,directory:i,operation:c,head_info:w.headInfo||"N/A",continue_cmd:ye}),Me=`${me} conflict context (JSON)
10
+ ${JSON.stringify({directory:i,operation:w.operation,headInfo:w.headInfo,statusPorcelain:w.statusPorcelain,unmergedFiles:w.unmergedFiles,diff:w.diff},null,2)}`;return{visibleText:_e,instructionsText:J,payloadText:Me}},e[7]=w,e[8]=i,e[9]=c,e[10]=T):T=e[10];const C=T;let P;e[11]!==l||e[12]!==r?(P=()=>{l(),r(!1)},e[11]=l,e[12]=r,e[13]=P):P=e[13];const E=P;let M;e[14]!==u||e[15]!==r?(M=()=>{u?.(),r(!1)},e[14]=u,e[15]=r,e[16]=M):M=e[16];const H=M;let R;e[17]!==C||e[18]!==x||e[19]!==u||e[20]!==r||e[21]!==b||e[22]!==p||e[23]!==y||e[24]!==f?(R=async()=>{const me=await C();if(!me){ae.error(f("gitView.conflict.noDetailsAvailable"));return}if(!x){ae.error(f("gitView.conflict.noActiveSession"),{description:f("gitView.conflict.noActiveSessionDescription")});return}p(me.visibleText,"replace"),y([{text:me.instructionsText,synthetic:!0},{text:me.payloadText,synthetic:!0}]),b("chat"),u?.(),r(!1)},e[17]=C,e[18]=x,e[19]=u,e[20]=r,e[21]=b,e[22]=p,e[23]=y,e[24]=f,e[25]=R):R=e[25];const _=R;let z;e[26]!==C||e[27]!==i||e[28]!==u||e[29]!==r||e[30]!==g||e[31]!==b||e[32]!==f?(z=async()=>{const me=await C();if(!me){ae.error(f("gitView.conflict.noDetailsAvailable"));return}g({directoryOverride:i,initialPrompt:me.visibleText,syntheticParts:[{text:me.instructionsText,synthetic:!0},{text:me.payloadText,synthetic:!0}]}),b("chat"),u?.(),r(!1)},e[26]=C,e[27]=i,e[28]=u,e[29]=r,e[30]=g,e[31]=b,e[32]=f,e[33]=z):z=e[33];const V=z;let F,te,Z,ne,U,ie,oe,pe,je,Se,re,L,$,K,he,de,we,xe,De,le,Ce,ue;if(e[34]!==w||e[35]!==d||e[36]!==x||e[37]!==E||e[38]!==H||e[39]!==_||e[40]!==V||e[41]!==h||e[42]!==v||e[43]!==r||e[44]!==n||e[45]!==c||e[46]!==f){const me=f(c==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),B=w?.unmergedFiles||d;Z=Ks,Ce=n,ue=r,te=Gs,le="max-w-md w-[calc(100vw-2rem)]",K="flex flex-col gap-4 overflow-hidden";let ye;e[69]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx(I,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=ye):ye=e[69];const _e=s.jsxs("div",{className:"flex items-center gap-2",children:[ye,s.jsx(Ys,{children:f("gitView.conflict.detectedTitle",{operation:me})})]});let J;e[70]!==c||e[71]!==f?(J=f("gitView.conflict.detectedDescription",{operation:c}),e[70]=c,e[71]=f,e[72]=J):J=e[72];let Me;e[73]!==J?(Me=s.jsx(dn,{children:J}),e[73]=J,e[74]=Me):Me=e[74],e[75]!==_e||e[76]!==Me?(he=s.jsxs(Qs,{children:[_e,Me]}),e[75]=_e,e[76]=Me,e[77]=he):he=e[77],e[78]!==h||e[79]!==f?(de=h&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:f("gitView.conflict.loading")})]}),e[78]=h,e[79]=f,e[80]=de):de=e[80],e[81]!==v||e[82]!==f?(we=v&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:f("gitView.conflict.errorLoadingDetails",{message:v})}),e[81]=v,e[82]=f,e[83]=we):we=e[83],e[84]!==B||e[85]!==f?(xe=B.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:B.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:B.map(Rb)})})]}),e[84]=B,e[85]=f,e[86]=xe):xe=e[86],e[87]!==w||e[88]!==f?(De=w?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:w.headInfo})]}),e[87]=w,e[88]=f,e[89]=De):De=e[89],re="flex flex-col gap-2 pt-2";let Ee;e[90]!==V?(Ee=()=>{V()},e[90]=V,e[91]=Ee):Ee=e[91];const Ne=h||!w;let Be;e[92]!==h?(Be=h?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"}),e[92]=h,e[93]=Be):Be=e[93];let se;e[94]!==f?(se=f("gitView.conflict.resolveNewSession"),e[94]=f,e[95]=se):se=e[95],e[96]!==Ee||e[97]!==Ne||e[98]!==Be||e[99]!==se?(L=s.jsxs(ze,{variant:"default",onClick:Ee,disabled:Ne,className:"w-full gap-2",children:[Be,se]}),e[96]=Ee,e[97]=Ne,e[98]=Be,e[99]=se,e[100]=L):L=e[100];let O;e[101]!==_?(O=()=>{_()},e[101]=_,e[102]=O):O=e[102];const D=h||!w||!x;let Y;e[103]!==h?(Y=h?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"chat-1",className:"size-4"}),e[103]=h,e[104]=Y):Y=e[104];let be;e[105]!==f?(be=f("gitView.conflict.resolveCurrentSession"),e[105]=f,e[106]=be):be=e[106],e[107]!==O||e[108]!==D||e[109]!==Y||e[110]!==be?($=s.jsxs(ze,{variant:"outline",onClick:O,disabled:D,className:"w-full gap-2",children:[Y,be]}),e[107]=O,e[108]=D,e[109]=Y,e[110]=be,e[111]=$):$=e[111],je="flex gap-2 pt-1";let Oe;e[112]!==f?(Oe=f("gitView.conflict.continueLater"),e[112]=f,e[113]=Oe):Oe=e[113],e[114]!==H||e[115]!==Oe?(Se=s.jsx(ze,{variant:"ghost",size:"sm",onClick:H,className:"flex-1",children:Oe}),e[114]=H,e[115]=Oe,e[116]=Se):Se=e[116],F=ze,ne="destructive",U="sm",ie=E,oe="flex-1",pe=f("gitView.conflict.abortOperation",{operation:me}),e[34]=w,e[35]=d,e[36]=x,e[37]=E,e[38]=H,e[39]=_,e[40]=V,e[41]=h,e[42]=v,e[43]=r,e[44]=n,e[45]=c,e[46]=f,e[47]=F,e[48]=te,e[49]=Z,e[50]=ne,e[51]=U,e[52]=ie,e[53]=oe,e[54]=pe,e[55]=je,e[56]=Se,e[57]=re,e[58]=L,e[59]=$,e[60]=K,e[61]=he,e[62]=de,e[63]=we,e[64]=xe,e[65]=De,e[66]=le,e[67]=Ce,e[68]=ue}else F=e[47],te=e[48],Z=e[49],ne=e[50],U=e[51],ie=e[52],oe=e[53],pe=e[54],je=e[55],Se=e[56],re=e[57],L=e[58],$=e[59],K=e[60],he=e[61],de=e[62],we=e[63],xe=e[64],De=e[65],le=e[66],Ce=e[67],ue=e[68];let ve;e[117]!==F||e[118]!==ne||e[119]!==U||e[120]!==ie||e[121]!==oe||e[122]!==pe?(ve=s.jsx(F,{variant:ne,size:U,onClick:ie,className:oe,children:pe}),e[117]=F,e[118]=ne,e[119]=U,e[120]=ie,e[121]=oe,e[122]=pe,e[123]=ve):ve=e[123];let G;e[124]!==je||e[125]!==Se||e[126]!==ve?(G=s.jsxs("div",{className:je,children:[Se,ve]}),e[124]=je,e[125]=Se,e[126]=ve,e[127]=G):G=e[127];let Ae;e[128]!==re||e[129]!==L||e[130]!==$||e[131]!==G?(Ae=s.jsxs("div",{className:re,children:[L,$,G]}),e[128]=re,e[129]=L,e[130]=$,e[131]=G,e[132]=Ae):Ae=e[132];let ce;e[133]!==K||e[134]!==he||e[135]!==de||e[136]!==we||e[137]!==xe||e[138]!==De||e[139]!==Ae?(ce=s.jsxs("div",{className:K,children:[he,de,we,xe,De,Ae]}),e[133]=K,e[134]=he,e[135]=de,e[136]=we,e[137]=xe,e[138]=De,e[139]=Ae,e[140]=ce):ce=e[140];let fe;e[141]!==te||e[142]!==le||e[143]!==ce?(fe=s.jsx(te,{className:le,children:ce}),e[141]=te,e[142]=le,e[143]=ce,e[144]=fe):fe=e[144];let Te;return e[145]!==Z||e[146]!==Ce||e[147]!==ue||e[148]!==fe?(Te=s.jsx(Z,{open:Ce,onOpenChange:ue,children:fe}),e[145]=Z,e[146]=Ce,e[147]=ue,e[148]=fe,e[149]=Te):Te=e[149],Te};function Db(t){return t.openNewSessionDraft}function Ib(t){return t.currentSessionId}function Pb(t){return t.setPendingInputText}function Tb(t){return t.setPendingSyntheticParts}function Eb(t){return t.setActiveMainTab}function Rb(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const Mb=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:o})=>{const{t:i}=Tt(),[c,l]=a.useState(!0),[u,m]=a.useState(!1),d=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),f=async()=>{m(!0);try{await o(c),e(!1)}catch(x){const p=x instanceof Error?x.message:`Failed to ${n}`;ae.error(p)}finally{m(!1)}},g=()=>{u||e(!1)};return s.jsx(Ks,{open:t,onOpenChange:u?void 0:e,children:s.jsxs(Gs,{className:"max-w-md",children:[s.jsxs(Qs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(Ys,{children:i("gitView.stash.title")})]}),s.jsx(dn,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),c&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(ji,{checked:c,onChange:l,disabled:u,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!u&&l(!c),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(sr,{className:"gap-2",children:[s.jsx(ze,{variant:"ghost",size:"sm",onClick:g,disabled:u,children:i("gitView.common.cancel")}),s.jsx(ze,{variant:"default",size:"sm",onClick:f,disabled:u,className:"gap-1.5",children:u?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:d})})]})]})})},Fb=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:o,hasUnresolvedConflicts:i=!1,isLoading:c=!1})=>{const{t:l}=Tt(),[u,m]=a.useState(null),d=t&&t.head,f=e&&(e.headName||e.onto),g=d?"merge":f?"rebase":null;if(!g)return null;const x=async()=>{m("continue");try{await n()}finally{m(null)}},p=async()=>{m("abort");try{await r()}finally{m(null)}},y=u!==null,b=l(g==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),h=g==="merge"?"git-merge":"git-branch";let N="";return t?N=t.message?l("gitView.operation.mergingMessage",{message:t.message}):l("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(N=e.headName?l("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):l("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(I,{name:h,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:l("gitView.operation.inProgressTitle",{operation:b})}),N&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:N})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&o&&s.jsxs(ze,{variant:"outline",size:"sm",onClick:o,disabled:y||c,className:"gap-1.5",children:[s.jsx(I,{name:"sparkling",className:"size-4"}),l("gitView.operation.resolveWithAi")]}),u!=="continue"&&s.jsxs(ze,{variant:"ghost",size:"sm",onClick:p,disabled:y||c,className:"gap-1.5",children:[u==="abort"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"close",className:"size-4"}),l("gitView.operation.abort")]}),!i&&s.jsxs(ze,{variant:"default",size:"sm",onClick:x,disabled:y||c,className:"gap-1.5",children:[u==="continue"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"}),l("gitView.operation.continue")]})]}),i&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:l("gitView.operation.resolveConflictsHint")})]})})},Lb=t=>{const e=pt.c(104),{currentBranch:n,localBranches:r,remoteBranches:o,onMerge:i,onRebase:c,disabled:l,isOperating:u,operationLogs:m,onOperationComplete:d,mode:f,defaultTargetBranch:g}=t,x=l===void 0?!1:l,p=u===void 0?!1:u,y=m===void 0?[]:m,b=f===void 0?"dialog":f,{t:h}=Tt(),[N,w]=a.useState(!1),[S,v]=a.useState("merge"),[j,k]=a.useState(null),[A,T]=a.useState(!1),[C,P]=a.useState(""),E=a.useRef(null),M=a.useRef(null),H=x||p,R=n||h("gitView.branch.currentBranchFallback"),_=y.length>0&&y.every(Ob),z=y.some(_b);let V;e[0]===Symbol.for("react.memo_cache_sentinel")?(V=()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},e[0]=V):V=e[0],a.useEffect(V,[y]);let F;if(e[1]!==C||e[2]!==n||e[3]!==r||e[4]!==o){e:{const O=C.toLowerCase();let D;e[6]!==o?(D=new Set(o.map(Bb).filter(Boolean)),e[6]=o,e[7]=D):D=e[7];const Y=D;let be;e[8]!==n||e[9]!==Y?(be=$e=>$e!==n&&!Y.has($e),e[8]=n,e[9]=Y,e[10]=be):be=e[10];const Oe=r.filter(be);if(!O){F=Oe;break e}F=Oe.filter($e=>$e.toLowerCase().includes(O))}e[1]=C,e[2]=n,e[3]=r,e[4]=o,e[5]=F}else F=e[5];const te=F;let Z;if(e[11]!==C||e[12]!==o){e:{const O=C.toLowerCase();if(!O){Z=o;break e}Z=o.filter(D=>D.toLowerCase().includes(O))}e[11]=C,e[12]=o,e[13]=Z}else Z=e[13];const ne=Z;let U;e[14]!==g||e[15]!==r||e[16]!==o?(U=()=>g&&(o.includes(g)||r.includes(g))?g:null,e[14]=g,e[15]=r,e[16]=o,e[17]=U):U=e[17];const ie=U;let oe;e[18]!==ie||e[19]!==w?(oe=()=>{w(!0),k(ie()),v("merge"),P("")},e[18]=ie,e[19]=w,e[20]=oe):oe=e[20];const pe=oe;let je;e[21]===Symbol.for("react.memo_cache_sentinel")?(je=O=>{k(O),T(!1),P("")},e[21]=je):je=e[21];const Se=je;let re;e[22]!==i||e[23]!==c||e[24]!==S||e[25]!==j?(re=()=>{j&&(S==="merge"?i(j):c(j))},e[22]=i,e[23]=c,e[24]=S,e[25]=j,e[26]=re):re=e[26];const L=re;let $;e[27]!==p||e[28]!==w?($=()=>{p||(k(null),v("merge"),P(""),w(!1))},e[27]=p,e[28]=w,e[29]=$):$=e[29];const K=$,he=()=>{p&&!_||(_&&d?.(),k(null),v("merge"),P(""),w(!1))};let de,we;e[30]!==A?(de=()=>{A||P("")},we=[A],e[30]=A,e[31]=de,e[32]=we):(de=e[31],we=e[32]),a.useEffect(de,we);let xe,De;e[33]!==b||e[34]!==ie||e[35]!==j?(xe=()=>{b!=="inline"||j||k(ie())},De=[b,ie,j],e[33]=b,e[34]=ie,e[35]=j,e[36]=xe,e[37]=De):(xe=e[36],De=e[37]),a.useEffect(xe,De);const ue=p?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:M,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:y.map(Vb)})}),_?b==="dialog"?s.jsx(sr,{children:s.jsx(ze,{variant:"default",size:"sm",onClick:he,children:h(z?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(ze,{variant:"default",size:"sm",onClick:he,children:h(z?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>v("merge"),className:Pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-merge",className:Pe("size-4",S==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Pe("typography-ui-label",S==="merge"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>v("rebase"),className:Pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-branch",className:Pe("size-4",S==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Pe("typography-ui-label",S==="rebase"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?h("gitView.branch.branchToMergeInto",{branch:R}):h("gitView.branch.branchToRebaseOnto")}),s.jsxs(rn,{open:A,onOpenChange:T,modal:!1,children:[s.jsx(sn,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:Pe("truncate",!j&&"text-muted-foreground"),children:j||h("gitView.branch.selectBranch")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(nn,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(ma,{className:"h-full min-h-0",children:[s.jsx(fa,{ref:E,placeholder:h("gitView.branch.searchPlaceholder"),value:C,onValueChange:P,onKeyDown:$b}),s.jsxs(ha,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(pa,{children:h("gitView.branch.empty")}),te.length>0&&s.jsx(Yr,{heading:h("gitView.branch.localBranches"),children:te.map(O=>s.jsx(ei,{onSelect:()=>Se(O),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`local-${O}`))}),te.length>0&&ne.length>0?s.jsx(Yf,{}):null,ne.length>0&&s.jsx(Yr,{heading:h("gitView.branch.remoteBranches"),children:ne.map(O=>s.jsx(ei,{onSelect:()=>Se(O),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`remote-${O}`))})]})]})})]})]}),j?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})," ",h("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})]}):s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})," ",h("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,b==="dialog"?s.jsxs(sr,{className:"gap-2 pt-1",children:[s.jsx(ze,{variant:"ghost",size:"sm",onClick:K,children:h("gitView.common.cancel")}),s.jsx(ze,{variant:"default",size:"sm",onClick:L,disabled:!j,className:"gap-1.5",children:S==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-merge",className:"size-4"}),h("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-branch",className:"size-4"}),h("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ze,{variant:"destructive",size:"sm",onClick:K,disabled:H,children:h("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(ze,{variant:"default",size:"sm",onClick:L,disabled:H||!j,children:h(S==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(b==="inline"){let O;e[38]!==h?(O=h("gitView.branch.updateTitle"),e[38]=h,e[39]=O):O=e[39];let D;e[40]!==O?(D=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:O}),e[40]=O,e[41]=D):D=e[41];let Y;e[42]!==h?(Y=h("gitView.branch.updateDescriptionPrefix"),e[42]=h,e[43]=Y):Y=e[43];let be;e[44]!==R?(be=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=be):be=e[45];let Oe;e[46]!==Y||e[47]!==be?(Oe=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Y," ",be,"."]}),e[46]=Y,e[47]=be,e[48]=Oe):Oe=e[48];let $e;e[49]!==D||e[50]!==Oe?($e=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[D,Oe]})}),e[49]=D,e[50]=Oe,e[51]=$e):$e=e[51];let Re;e[52]!==ue?(Re=s.jsx("div",{className:"pt-3",children:ue}),e[52]=ue,e[53]=Re):Re=e[53];let ot;return e[54]!==$e||e[55]!==Re?(ot=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[$e,Re]}),e[54]=$e,e[55]=Re,e[56]=ot):ot=e[56],ot}let ve;e[57]!==p?(ve=p?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"}),e[57]=p,e[58]=ve):ve=e[58];let G;e[59]!==h?(G=h("gitView.branch.mergeRebase"),e[59]=h,e[60]=G):G=e[60];let Ae;e[61]!==G?(Ae=s.jsx("span",{children:G}),e[61]=G,e[62]=Ae):Ae=e[62];let ce;e[63]!==pe||e[64]!==H||e[65]!==ve||e[66]!==Ae?(ce=s.jsx(_t,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"sm",className:"gap-1.5",onClick:pe,disabled:H,children:[ve,Ae]})}),e[63]=pe,e[64]=H,e[65]=ve,e[66]=Ae,e[67]=ce):ce=e[67];let fe;e[68]!==h?(fe=h("gitView.branch.mergeRebaseTooltip"),e[68]=h,e[69]=fe):fe=e[69];let Te;e[70]!==fe?(Te=s.jsx(Bt,{sideOffset:8,children:fe}),e[70]=fe,e[71]=Te):Te=e[71];let me;e[72]!==ce||e[73]!==Te?(me=s.jsxs(Ot,{children:[ce,Te]}),e[72]=ce,e[73]=Te,e[74]=me):me=e[74];let B;e[75]!==he||e[76]!==w?(B=O=>{O?w(!0):he()},e[75]=he,e[76]=w,e[77]=B):B=e[77];let ye;e[78]!==h?(ye=h("gitView.branch.updateTitle"),e[78]=h,e[79]=ye):ye=e[79];let _e;e[80]!==ye?(_e=s.jsx(Ys,{children:ye}),e[80]=ye,e[81]=_e):_e=e[81];let J;e[82]!==z||e[83]!==p||e[84]!==S||e[85]!==_||e[86]!==h||e[87]!==R?(J=p?h(_?z?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":S==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[h("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R}),"."]}),e[82]=z,e[83]=p,e[84]=S,e[85]=_,e[86]=h,e[87]=R,e[88]=J):J=e[88];let Me;e[89]!==J?(Me=s.jsx(dn,{children:J}),e[89]=J,e[90]=Me):Me=e[90];let Ee;e[91]!==_e||e[92]!==Me?(Ee=s.jsxs(Qs,{children:[_e,Me]}),e[91]=_e,e[92]=Me,e[93]=Ee):Ee=e[93];let Ne;e[94]!==ue||e[95]!==Ee?(Ne=s.jsxs(Gs,{className:"max-w-md",children:[Ee,ue]}),e[94]=ue,e[95]=Ee,e[96]=Ne):Ne=e[96];let Be;e[97]!==N||e[98]!==B||e[99]!==Ne?(Be=s.jsx(Ks,{open:N,onOpenChange:B,children:Ne}),e[97]=N,e[98]=B,e[99]=Ne,e[100]=Be):Be=e[100];let se;return e[101]!==me||e[102]!==Be?(se=s.jsxs(s.Fragment,{children:[me,Be]}),e[101]=me,e[102]=Be,e[103]=se):se=e[103],se};function Ob(t){return t.status==="done"||t.status==="error"}function _b(t){return t.status==="error"}function Bb(t){return t.slice(t.indexOf("/")+1)}function Vb(t,e){return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"mt-0.5 shrink-0",children:[t.status==="running"&&s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(I,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(I,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:Pe("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function $b(t){return t.stopPropagation()}const zb=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:o})=>{const i=[];let c=!1;return{enqueue:u=>{const m=i[i.length-1];if(m?.directory===u.directory&&m.direction===u.direction){u.paths.forEach(d=>m.paths.add(d));return}i.push(u)},flush:()=>{if(c)return;const u=i.shift();if(!u)return;c=!0;const m={directory:u.directory,direction:u.direction,paths:Array.from(u.paths),rollback:u.rollback};(async()=>{try{await t(m),e(m)}catch(d){n(m,d)}finally{r(m.paths),c=!1,i.length>0&&o()}})()},clear:()=>{i.length=0},size:()=>i.length,isRunning:()=>c}},pd="oc.git.actionTab",Wb=15e3,Ub=t=>t==="commit"||t==="branch"||t==="pr",lm="gitmojiCache",Hb=1e3*60*60*24*7,cm="1",Gb=40,Kb=20,qb="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",gd={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},dm=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Yb=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(lm);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==cm||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(dm),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Jb=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:cm};localStorage.setItem(lm,JSON.stringify(e))}catch{return}},Qb=t=>Date.now()-t.fetchedAt<Hb,Xb=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,o=n.match(r);if(o){const l=o[1],u=gd[l];if(u)return e.find(m=>m.code===u)||null}const i=n.split(" ")[0],c=gd[i];return c&&e.find(l=>l.code===c)||null},xd=new Map,_r=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),bd=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Zb=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},Nl=()=>{const{t}=Tt(),{git:e}=Gn(),n=si(),[r,o]=a.useState(null),[i,c]=a.useState(!1),l=jt(Q=>Q.currentSessionId),u=jt(Q=>Q.newSessionDraft),m=jt(Q=>Q.setDraftBootstrapPendingDirectory),d=jt(Q=>Q.worktreeMetadata),f=jt(Q=>Q.availableWorktrees),g=_r(n),x=a.useMemo(()=>{if(!g)return;const Q=f.find(ge=>_r(ge.path)===g);if(Q)return Q;for(const ge of d.values())if(_r(ge.path)===g)return ge},[f,g,d]),p=a.useMemo(()=>{if(l)return d.get(l)??x;if(u?.open)return x},[l,x,u?.open,d]),{profiles:y,globalIdentity:b,defaultGitIdentityId:h,loadProfiles:N,loadGlobalIdentity:w,loadDefaultGitIdentityId:S}=Wp(xu(Q=>({profiles:Q.profiles,globalIdentity:Q.globalIdentity,defaultGitIdentityId:Q.defaultGitIdentityId,loadProfiles:Q.loadProfiles,loadGlobalIdentity:Q.loadGlobalIdentity,loadDefaultGitIdentityId:Q.loadDefaultGitIdentityId}))),v=Wl(n??null),j=ya(n??null),k=Nu(Q=>l?Q.getAttachment(l):void 0),A=k?Jf(k):[],T=k&&!k.degraded&&!k.legacy?k.worktreeRoot??void 0:void 0,C=kx(n,p,j?.current??void 0),P=Tu(n??null),E=Qf(n??null),M=Xf(n??null),H=Ul(n??null),R=Zf(n??null),_=_s(Q=>Q.setActiveDirectory),z=_s(Q=>Q.fetchAll),V=_s(Q=>Q.ensureAll),F=_s(Q=>Q.fetchStatus),te=_s(Q=>Q.fetchBranches),Z=_s(Q=>Q.fetchLog),ne=_s(Q=>Q.setLogMaxCount),U=_s(Q=>Q.fetchIdentity),ie=_s(Q=>Q.prefetchDiffs),oe=_s(Q=>Q.moveStatusPathsOptimistically),pe=_s(Q=>Q.restoreStatus),je=_s(Q=>Q.bumpIndexRevision),Se=Fe(Q=>Q.isMobile),re=Fe(Q=>Q.openContextDiff),L=Fe(Q=>Q.navigateToDiff),$=Fe(Q=>Q.setRightSidebarOpen),K=a.useRef(null),he=a.useRef(null),de=a.useRef(null),we=a.useRef(null),xe=a.useCallback(()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null)},[]),De=a.useCallback(Q=>{xe(),he.current=window.setTimeout(()=>{he.current=null,_r(Q)===_r(n)&&F(Q,e,{silent:!0})},Wb)},[xe,n,F,e]);a.useEffect(()=>xe,[xe]);const le=a.useCallback(()=>{de.current!==null&&(window.clearTimeout(de.current),de.current=null)},[]),Ce=a.useCallback(()=>{de.current===null&&(de.current=window.setTimeout(()=>{de.current=null,we.current?.()},0))},[]),ue=a.useCallback(async(Q,ge,ke)=>{if(ge==="stage"){if(e.stageGitFiles){await e.stageGitFiles(Q,ke);return}await Promise.all(ke.map(Ue=>e.stageGitFile(Q,Ue)));return}if(e.unstageGitFiles){await e.unstageGitFiles(Q,ke);return}await Promise.all(ke.map(Ue=>e.unstageGitFile(Q,Ue)))},[e]),ve=a.useMemo(()=>zb({runMutation:({directory:Q,direction:ge,paths:ke})=>ue(Q,ge,ke),onMutationComplete:({directory:Q})=>{je(Q),De(Q)},onMutationError:({directory:Q,direction:ge,rollback:ke},Ue)=>{ke?.(),je(Q),De(Q);const vt=t(ge==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");ae.error(Ue instanceof Error?Ue.message:vt)},onPathsComplete:Q=>{It(ge=>{const ke=new Set(ge);return Q.forEach(Ue=>ke.delete(Ue)),ke})},scheduleFlush:Ce}),[je,ue,Ce,De,t]);a.useEffect(()=>(we.current=ve.flush,()=>{we.current=null}),[ve]),a.useEffect(()=>()=>ve.clear(),[ve]),a.useEffect(()=>le,[le]),a.useEffect(()=>{if(!n){o(null),c(!1);return}let Q=!1,ge=null;const ke=async()=>{try{const Ue=await th(n);if(Q)return;o(Ue.status),Ue.status==="pending"&&(ge=window.setTimeout(()=>{ke()},500))}catch{Q||o(null)}};return ke(),()=>{Q=!0,ge!==null&&window.clearTimeout(ge)}},[n]),a.useEffect(()=>{const Q=K.current;K.current=r,!(!n||!e)&&(Q==="pending"&&r==="ready"&&(c(!0),z(n,e).finally(()=>{window.setTimeout(()=>{c(!1)},1200)})),r==="failed"&&(m(null),c(!1)))},[n,z,e,m,r]);const G=_r(u?.bootstrapPendingDirectory??null),Ae=!!(n&&G&&G===_r(n)),fe=!!(n&&(r==="pending"||Ae))||i,Te=a.useMemo(()=>n?xd.get(n)??null:null,[n]),me=ls(Q=>Q.settingsGitmojiEnabled),[B,ye]=a.useState(null);a.useEffect(()=>{const Q=T||C?.projectDirectory;if(!Q){ye(null);return}let ge=!1;return wa(Q).then(ke=>{if(ge)return;const Ue=ke.trim();ye(Ue&&Ue!=="HEAD"?Ue:null)}).catch(()=>{ge||ye(null)}),()=>{ge=!0}},[T,C?.projectDirectory]);const[_e,J]=a.useState(Te?.commitMessage??""),[Me,Ee]=a.useState([]),[Ne,Be]=a.useState(!1),se=a.useRef(null),[O,D]=a.useState(null),[Y,be]=a.useState(!1),[Oe,$e]=a.useState(null),[Re,ot]=a.useState(25),[yt,At]=a.useState(!1),{triggerFireworks:mt}=Sx(),Le=a.useRef(new Map),Qe=a.useRef(0),Ye=a.useCallback(()=>{Qe.current+=1,At(!0)},[]),rt=a.useCallback(()=>{Qe.current=Math.max(0,Qe.current-1),Qe.current===0&&At(!1)},[]),[bt,ct]=a.useState(new Set),[nt,It]=a.useState(new Set),[lt,kt]=a.useState(!1),[Ke,tt]=a.useState(0),[We,gt]=a.useState(!1),[He,st]=a.useState(Te?.generatedHighlights??[]),Et=nt.size>0||ve.size()>0||ve.isRunning(),at=a.useCallback(()=>{const Q=se.current;Q&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q.scrollTo({top:Q.scrollHeight,behavior:"smooth"})})})},[]),dt=T||C?.projectDirectory||null,Ht=j?.current||null,Rt=a.useMemo(()=>{const Q=j?.tracking;return Q?Q.startsWith("origin/"):!0},[j?.tracking]),Wt=a.useMemo(()=>{const Q=C?.createdFromBranch,ge=typeof Q=="string"?Q.trim():"",ke=typeof j?.current=="string"?j.current.trim():"",Ue=typeof B=="string"?B.trim():"";return ge?ge===ke&&ge.startsWith("opencode/")&&Ue.length>0&&Ue!==ge?Ue:ge:Ue||ke||"HEAD"},[C?.createdFromBranch,j,B]),qt=a.useCallback(()=>{st([])},[]),[Lt,Gt]=a.useState(new Set),[Qt,rs]=a.useState(new Map),[Yt,ft]=a.useState(new Set),[Jt,ms]=a.useState(null),[Xt,ts]=a.useState(null),[ks,$t]=a.useState([]),[as,$s]=a.useState(""),[Ut,Es]=a.useState(null),Ls=a.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(I,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(I,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[gs,Cs]=a.useState(()=>{if(typeof window>"u")return"commit";const Q=window.localStorage.getItem(pd);return Q==="worktree"?"branch":Ub(Q)?Q:"commit"}),[Mt,xt]=a.useState([]),[Zt,Ft]=a.useState(null),[is,es]=a.useState(null),[fs,W]=a.useState([]),[Ge,Xe]=a.useState(!1),[ht,Nt]=a.useState([]),[ut,ss]=a.useState("merge"),[bs,ys]=a.useState(null),[Bs,Rs]=a.useState(!1),[an,Ss]=a.useState(100),zs=a.useMemo(()=>l?`openchamber.conflict:${l}`:null,[l]),Ws=a.useCallback((Q,ge,ke)=>{if(!zs||typeof window>"u")return;const Ue={directory:Q,conflictFiles:ge,operation:ke};window.localStorage.setItem(zs,JSON.stringify(Ue))},[zs]),hs=a.useCallback(()=>{!zs||typeof window>"u"||window.localStorage.removeItem(zs)},[zs]);a.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(pd,gs)},[gs]),a.useEffect(()=>{if(!zs||typeof window>"u"||!n)return;const Q=window.localStorage.getItem(zs);if(Q)try{const ge=JSON.parse(Q);if(ge.directory!==n){window.localStorage.removeItem(zs);return}Nt(ge.conflictFiles??[]),ss(ge.operation??"merge"),Xe(!0)}catch{window.localStorage.removeItem(zs)}},[zs,n]);const[br,Rn]=a.useState(!1),[nr,Kn]=a.useState("merge"),[As,Xs]=a.useState(""),Cn=a.useCallback(Q=>{ar(Q).then(ge=>{if(ge.ok){ae.success(t("gitView.toast.commitHashCopied"));return}ae.error(t("gitView.toast.copyFailed"))})},[t]),un=a.useCallback(Q=>{Gt(ge=>{const ke=new Set(ge);return ke.has(Q)?ke.delete(Q):ke.add(Q),ke})},[]);a.useEffect(()=>{if(!n||!e)return;const Q=Array.from(Lt).filter(ge=>!Qt.has(ge)&&!Yt.has(ge));if(Q.length!==0){ft(ge=>{const ke=new Set(ge);for(const Ue of Q)ke.add(Ue);return ke});for(const ge of Q)e.getCommitFiles(n,ge).then(ke=>{rs(Ue=>new Map(Ue).set(ge,ke.files))}).catch(ke=>{console.error("Failed to fetch commit files:",ke),rs(Ue=>new Map(Ue).set(ge,[]))}).finally(()=>{ft(ke=>{const Ue=new Set(ke);return Ue.delete(ge),Ue})})}},[Lt,n,e,Qt,Yt]),a.useEffect(()=>{n&&xd.set(n,{directory:n,commitMessage:_e,generatedHighlights:He})},[_e,n,He]),a.useEffect(()=>{N(),w(),S()},[N,w,S]),a.useEffect(()=>{if(!n||!e?.getRemoteUrl){ts(null);return}e.getRemoteUrl(n).then(ts).catch(()=>ts(null))},[n,e]);const hn=a.useCallback(async()=>{if(!n||!e?.getRemotes){xt([]);return}try{const Q=await e.getRemotes(n);xt(Q)}catch{xt([])}},[n,e]);a.useEffect(()=>{hn()},[hn]),a.useEffect(()=>{if(!me){$t([]);return}let Q=!1;const ge=Yb();return ge&&($t(ge.gitmojis),Qb(ge))?()=>{Q=!0}:((async()=>{try{const Ue=await fetch(qb);if(!Ue.ok)throw new Error(`Failed to load gitmojis: ${Ue.statusText}`);const vt=await Ue.json(),St=Array.isArray(vt.gitmojis)?vt.gitmojis.filter(dm):[];Q||($t(St),Jb(St))}catch(Ue){Q||console.warn("Failed to load gitmoji list:",Ue)}})(),()=>{Q=!0})},[me]),a.useEffect(()=>{n&&(_(n),V(n,e))},[n,_,V,e]),a.useEffect(()=>{if(n)return Ir.onGitRefreshHint(Q=>{_r(Q.directory)===_r(n)&&F(n,e)})},[n,F,e]);const ds=a.useCallback(async(Q=!0)=>{if(n)try{await Promise.all([F(n,e),te(n,e)])}catch(ge){if(Q){const ke=ge instanceof Error?ge.message:t("gitView.toast.refreshRepositoryFailed");ae.error(ke)}}},[n,e,F,te,t]),ws=a.useCallback(async()=>{n&&await Z(n,e,Re)},[n,e,Z,Re]),pn=a.useCallback(async()=>{n&&await U(n,e)},[n,e,U]);a.useEffect(()=>{if(!n||!e?.hasLocalIdentity||v!==!0)return;const Q=typeof h=="string"?h.trim():"";if(!Q||Q==="global"||Le.current.get(n)===Q)return;let ke=!1;return(async()=>{try{const vt=await e.hasLocalIdentity?.(n);if(ke||vt===!0)return;Ye(),await e.setGitIdentity(n,Q),Le.current.set(n,Q),await pn()}catch(vt){console.warn("Failed to auto-apply default git identity:",vt)}finally{ke||rt()}})(),()=>{ke=!0}},[Ye,n,h,rt,e,v,pn]);const Sn=a.useMemo(()=>{if(!j)return[];const Q=j.files??[],ge=new Map;for(const ke of Q)ge.set(ke.path,ke);return Array.from(ge.values()).sort((ke,Ue)=>ke.path.localeCompare(Ue.path))},[j]),Os=a.useMemo(()=>Sn.filter(bd),[Sn]),lr=a.useMemo(()=>Sn.filter(Zb),[Sn]);a.useEffect(()=>{if(!n||Sn.length===0)return;const Q=[],ge=new Set,ke=vt=>{!vt||ge.has(vt)||(ge.add(vt),Q.push(vt))};if(Os.forEach(vt=>ke(vt.path)),Me.forEach(ke),Sn.slice(0,Kb).forEach(vt=>ke(vt.path)),Q.length===0)return;const Ue=window.setTimeout(()=>{ie(n,e,Q,{maxFiles:Gb})},120);return()=>{window.clearTimeout(Ue)}},[Sn,n,e,ie,Os,Me]);const cr=Q=>Q?.pushed[0]?.remote||j?.tracking?.split("/")[0]||us.find(ge=>ge.name==="origin")?.name||us[0]?.name||"origin",qn=async(Q,ge)=>{if(n){D(Q);try{const ke=Ue=>{const vt=`${Ue.name}/`,St=j?.tracking?.startsWith(vt)?j.tracking.slice(vt.length):void 0;return{remote:Ue.name,branch:St,rebase:!0}};if(Q==="fetch"){if(!ge)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:ge.name}),ae.success(t("gitView.toast.fetchedFromRemote",{name:ge.name}))}else if(Q==="pull"){if(!ge)throw new Error("No remote available for pull");const Ue=await e.gitPull(n,ke(ge));ae.success(Ue.files.length===1?t("gitView.toast.pulledFilesSingle",{count:Ue.files.length,name:ge.name}):t("gitView.toast.pulledFilesPlural",{count:Ue.files.length,name:ge.name}))}else if(Q==="push"){const Ue=await e.gitPush(n);ae.success(t("gitView.toast.pushedToUpstream",{name:cr(Ue)}))}else if(Q==="sync"){if(!ge)throw new Error("No remote available for sync");let Ue=0,vt=!1;await e.gitFetch(n,{remote:ge.name});const St=await e.getGitStatus(n);if((St.behind??0)>0){if((St.files?.length??0)>0){ae.error(t("gitView.toast.commitOrStashBeforeSync"));return}Ue=(await e.gitPull(n,ke(ge))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),vt=!0),Ue>0&&vt?ae.success(Ue===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:Ue,name:ge.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:Ue,name:ge.name})):Ue>0?ae.success(Ue===1?t("gitView.toast.pulledFilesSingle",{count:Ue,name:ge.name}):t("gitView.toast.pulledFilesPlural",{count:Ue,name:ge.name})):vt?ae.success(t("gitView.toast.pushedToUpstream",{name:ge.name})):ae.success(t("gitView.toast.alreadyUpToDate"))}await ds(!1),await ws()}catch(ke){const Ue=ke instanceof Error?ke.message:t("gitView.toast.syncActionFailed",{action:Q==="sync"?t("gitView.sync.syncChanges"):Q==="pull"?t("gitView.sync.pull"):Q});ae.error(Ue)}finally{D(null)}}},Er=a.useCallback(async Q=>{if(!n)return;const ge=Q.name.trim();if(!ge){ae.error(t("gitView.toast.remoteNameRequired"));return}if(ge==="origin"){ae.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Ft(ge);try{await e.removeRemote(n,{remote:ge}),ae.success(t("gitView.toast.removedRemote",{name:ge})),await Promise.all([ds(!1),hn()])}catch(ke){const Ue=ke instanceof Error?ke.message:`Failed to remove ${ge}`;ae.error(Ue)}finally{Ft(null)}},[n,e,hn,ds,t]),dr=async(Q={})=>{if(!n)return;if(!_e.trim()){ae.error(t("gitView.toast.enterCommitMessage"));return}const ge=Os.map(Ue=>Ue.path).sort();if(ge.length===0){ae.error(t("gitView.toast.stageFileToCommit"));return}const ke=Q.pushAfter?"commitAndPush":"commit";$e(ke);try{if(await e.createGitCommit(n,_e.trim(),{files:ge,stageFiles:[]}),je(n),ae.success(t("gitView.toast.commitCreated")),J(""),qt(),await ds(),Q.pushAfter){const Ue=await e.gitPush(n);ae.success(t("gitView.toast.pushedToUpstream",{name:cr(Ue)})),mt(),await ds(!1)}else await ds(!1);await ws(),tt(Ue=>Ue+1)}catch(Ue){const vt=Ue instanceof Error?Ue.message:t("gitView.toast.createCommitFailed");ae.error(vt)}finally{$e(null),Q.pushAfter&&D(null)}},yr=a.useCallback(async()=>{if(!n)return;const Q=Os.map(ge=>ge.path).sort();if(Q.length===0){ae.error(t("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Q.length}),gt(!0);try{const{message:ge}=await eh(n,Q),ke=ge.subject?.trim()??"",Ue=Array.isArray(ge.highlights)?ge.highlights:[];if(ke){let vt=ke;if(me&&ks.length>0){const St=Xb(ke,ks);if(St){const{code:xs,emoji:Is}=St;!ke.startsWith(xs)&&!ke.startsWith(Is)&&(vt=`${xs} ${ke}`)}}J(vt)}st(Ue),at()}catch(ge){console.error("[git-generation][browser] GitView generate handler failed",{message:ge instanceof Error?ge.message:String(ge),error:ge});const ke=ge instanceof Error?ge.message:t("gitView.toast.generateCommitMessageFailed");ae.error(ke)}finally{gt(!1)}},[n,Os,me,ks,at,t]),wr=Q=>Q.reason==="attention"?`${Q.attentionReason} in progress`:Q.reason==="missing"?"worktree is missing":"worktree is invalid",ur=async(Q,ge)=>{if(!n||!j)return;const ke=Ta(k);if(ke.length>0){ae.error(t("gitView.toast.cannotCreateBranch",{reason:wr(ke[0])}));return}const Ue=j.current??null,vt=ge?.name??"origin";try{await e.createBranch(n,Q,Ue??"HEAD"),ae.success(t("gitView.toast.createdBranch",{name:Q})),await e.checkoutBranch(n,Q);let St=!1;try{await e.gitPush(n,{remote:vt,branch:Q,options:["--set-upstream"]}),St=!0}catch(xs){const Is=xs instanceof Error?xs.message:`Unable to push new branch to ${vt}.`;ae.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Is]})})}await ds(),await ws(),St&&ae.success(t("gitView.toast.upstreamSet",{branch:Q,remote:vt}))}catch(St){const xs=St instanceof Error?St.message:t("gitView.toast.createBranchFailed");throw ae.error(xs),St}},ee=async(Q,ge)=>{if(!n)return;const ke=Ta(k);if(ke.length>0){ae.error(t("gitView.toast.cannotRenameBranch",{reason:wr(ke[0])}));return}try{await e.renameBranch(n,Q,ge),ae.success(t("gitView.toast.renamedBranch",{oldName:Q,newName:ge})),await ds(),await ws()}catch(Ue){const vt=Ue instanceof Error?Ue.message:t("gitView.toast.renameBranchFailed",{oldName:Q,newName:ge});ae.error(vt)}},it=async Q=>{if(!n)return;const ge=Ta(k);if(ge.length>0){ae.error(t("gitView.toast.cannotCheckout",{reason:wr(ge[0])}));return}const ke=Q.replace(/^remotes\//,"");if(j?.current!==ke)try{await e.checkoutBranch(n,ke),ae.success(t("gitView.toast.checkedOut",{name:ke})),await ds(),await ws()}catch(Ue){const vt=Ue instanceof Error?Ue.message:t("gitView.toast.checkoutFailed",{name:ke});ae.error(vt)}},wt=async Q=>{if(n){Ye();try{await e.setGitIdentity(n,Q.id),ae.success(t("gitView.toast.appliedIdentity",{name:Q.name})),await pn()}catch(ge){const ke=ge instanceof Error?ge.message:t("gitView.toast.applyIdentityFailed");ae.error(ke)}finally{rt()}}},Vt=a.useMemo(()=>P?.all?P.all.filter(Q=>!Q.startsWith("remotes/")).sort():[],[P]),ps=a.useMemo(()=>P?.all?P.all.filter(Q=>Q.startsWith("remotes/")).map(Q=>Q.replace(/^remotes\//,"")).sort():[],[P]),us=a.useMemo(()=>{if(Mt.length>0)return Mt;const Q=new Set,ge=j?.tracking?.trim();ge&&ge.includes("/")&&Q.add(ge.split("/")[0]);for(const ke of ps){const Ue=ke.indexOf("/");Ue>0&&Q.add(ke.slice(0,Ue))}return Q.size===0&&Xt&&Q.add("origin"),Array.from(Q).map(ke=>({name:ke,fetchUrl:Xt??"",pushUrl:Xt??""}))},[Mt,ps,Xt,j?.tracking]),cs=a.useMemo(()=>{const Q=new Set(us.map(vt=>vt.name)),ge=vt=>{if(!vt)return"";let St=vt.trim();if(!St||St==="HEAD")return"";if(Vt.includes(St))return St;St.startsWith("refs/heads/")&&(St=St.slice(11)),St.startsWith("heads/")&&(St=St.slice(6)),St.startsWith("remotes/")&&(St=St.slice(8));const xs=St.indexOf("/");if(xs>0){const Is=St.slice(0,xs);if(Q.has(Is)){const Cr=St.slice(xs+1).trim();Cr&&(St=Cr)}}return St},ke=ge(typeof C?.createdFromBranch=="string"?C.createdFromBranch:"");if(ke)return ke;const Ue=ge(typeof B=="string"?B:"");return Ue||(Vt.includes("main")?"main":Vt.includes("master")?"master":Vt.includes("develop")?"develop":"main")},[us,Vt,B,C?.createdFromBranch]),Us=a.useMemo(()=>us.map(ke=>ke.name).map(ke=>`${ke}/${cs}`).find(ke=>ps.includes(ke))??cs,[cs,us,ps]),js=a.useMemo(()=>{const Q=new Map;b&&Q.set(b.id,b);let ge=null;if(Xt)try{let ke=Xt.trim();ke.startsWith("git@")&&(ke=`https://${ke.slice(4).replace(":","/")}`),ke.endsWith(".git")&&(ke=ke.slice(0,-4));const Ue=new URL(ke);ge=Ue.hostname+Ue.pathname}catch{}for(const ke of y){if(ke.authType!=="token"){Q.set(ke.id,ke);continue}const Ue=ke.host;if(!Ue){Q.set(ke.id,ke);continue}if(!Ue.includes("/")){Q.set(ke.id,ke);continue}ge&&ge===Ue&&Q.set(ke.id,ke)}return Array.from(Q.values())},[y,b,Xt]),Mn=a.useMemo(()=>{if(M?.userName&&M?.userEmail){const Q=y.find(ge=>ge.userName===M.userName&&ge.userEmail===M.userEmail);return Q||(b&&b.userName===M.userName&&b.userEmail===M.userEmail?b:{id:"local-config",name:M.userName,userName:M.userName,userEmail:M.userEmail,sshKey:M.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return b??null},[M,y,b]),mn=Os.length,Rr=H||O!==null||Oe!==null,gn=j?.current??null,Mr=!!(C&&dt&&Ht&&Rt),xn=!!(n&&gn),Vs=!!gn,bn=Mr&&dt&&Ht&&C?{repoRoot:dt,sourceBranch:Ht,worktreeMetadata:C}:null,Ds=a.useMemo(()=>!xn||!n||!gn?null:{directory:n,branch:gn},[xn,gn,n]);a.useEffect(()=>{if(!n||!e||!E?.all?.length||!gn||!cs||gn===cs){ms(null);return}let Q=!1;return(async()=>{try{const ke=await e.getGitLog(n,{from:cs,to:"HEAD",maxCount:Re});if(Q)return;const Ue=new Set((ke?.all??[]).map(St=>St.hash).filter(St=>typeof St=="string"&&St.length>0));if(Ue.size===0){ms(null);return}const vt=E.all.findIndex(St=>!Ue.has(St.hash));if(vt===0){ms(null);return}if(vt===-1){ms({insertBeforeIndex:E.all.length,branchName:gn,direction:"up"});return}ms({insertBeforeIndex:vt,branchName:gn,direction:"up"})}catch{Q||ms(null)}})(),()=>{Q=!0}},[cs,gn,n,e,E,Re]),a.useEffect(()=>{ys(null)},[n]),a.useEffect(()=>{if(Ut!=="graph"||!n){Ut!=="graph"&&ys(null);return}let Q=!1;return Rs(!0),e.getGitLog(n,{maxCount:an,all:!0}).then(ge=>{Q||ys(ge)}).catch(ge=>{console.error("Failed to fetch graph log:",ge)}).finally(()=>{Q||Rs(!1)}),()=>{Q=!0}},[Ut,n,an,e]);const Zs=a.useCallback((Q,ge)=>{if(!n||Q.length===0)return;const ke=Array.from(new Set(Q));It(vt=>{const St=new Set(vt);return ke.forEach(xs=>St.add(xs)),St});const Ue=oe(n,ke,ge);ve.enqueue({directory:n,direction:ge,paths:new Set(ke),rollback:()=>pe(n,Ue)}),Ce()},[n,ve,oe,pe,Ce]),vr=a.useCallback(async Q=>{if(n){ct(ge=>{const ke=new Set(ge);return ke.add(Q),ke});try{await e.revertGitFile(n,Q,{scope:"working"}),ae.success(t("gitView.toast.revertedFile",{path:Q})),await ds(!1)}catch(ge){const ke=ge instanceof Error?ge.message:t("gitView.toast.revertFailed");ae.error(ke)}finally{ct(ge=>{const ke=new Set(ge);return ke.delete(Q),ke})}}},[n,ds,e,t]),jr=a.useCallback(async Q=>{if(!n||Q.length===0||lt)return;const ge=Array.from(new Set(Q)),ke=new Set(Os.map(St=>St.path)),Ue=ge.some(St=>ke.has(St));kt(!0),ct(St=>{const xs=new Set(St);return ge.forEach(Is=>xs.add(Is)),xs});const vt=[];try{if(await Promise.all(ge.map(async St=>{try{await e.revertGitFile(n,St)}catch(xs){vt.push({path:St,message:xs instanceof Error?xs.message:t("gitView.toast.revertFailed")})}})),Ue&&vt.length<ge.length&&je(n),await ds(!1),vt.length===0)ae.success(ge.length===1?t("gitView.toast.revertedFilesSingle",{count:ge.length}):t("gitView.toast.revertedFilesPlural",{count:ge.length}));else if(vt.length===ge.length)ae.error(vt[0]?.message||t("gitView.toast.revertFailed"));else{const St=ge.length-vt.length;ae.warning(St===1?t("gitView.toast.revertedSomeSingle",{success:St,failed:vt.length}):t("gitView.toast.revertedSomePlural",{success:St,failed:vt.length}))}}finally{ct(St=>{const xs=new Set(St);return ge.forEach(Is=>xs.delete(Is)),xs}),kt(!1)}},[je,n,e,lt,ds,Os,t]),Sr=a.useCallback((Q,ge)=>{if(n&&!Se){re(n,Q,ge);return}L(Q,ge),Se&&$(!1)},[n,Se,L,re,$]),Nr=a.useCallback(()=>be(!0),[]),ln=a.useMemo(()=>{const Q=[];return Os.length>0&&Q.push({id:"staged",title:t("gitView.changes.stagedTitle"),entries:Os,actionSymbol:"-",actionAllLabel:t("gitView.changes.unstageAllAria"),getActionLabel:ge=>t("gitView.changes.unstageFileAria",{path:ge}),onActionFile:ge=>{Zs([ge],"unstage")},onActionAll:ge=>{Zs(ge,"unstage")},onViewDiff:ge=>Sr(ge,!0),onRevertFile:vr,showRevertActions:!1,accent:!0}),lr.length>0&&Q.push({id:"unstaged",title:t("gitView.changes.title"),entries:lr,actionSymbol:"+",actionAllLabel:t("gitView.changes.stageAllAria"),getActionLabel:ge=>t("gitView.changes.stageFileAria",{path:ge}),onActionFile:ge=>{Zs([ge],"stage")},onActionAll:ge=>{Zs(ge,"stage")},onViewDiff:ge=>Sr(ge,!1),onRevertFile:vr}),Q},[vr,Sr,Zs,Os,t,lr]),ni=a.useCallback(Q=>{if(Q.length===0)return;const ge=Q.map(ke=>ke.trim()).filter(Boolean);if(ge.length===0){qt();return}J(ke=>{const Ue=ke.trim(),vt=Ue.length>0?`
11
+
12
+ `:"";return`${Ue}${vt}${ge.join(`
13
+ `)}`.trim()}),qt()},[qt]),jo=a.useCallback((Q,ge)=>{const ke=ge||Q;J(Ue=>{const vt=Ue.trimStart();return vt.startsWith(Q)||ge&&vt.startsWith(ge)?Ue:`${ke.endsWith(" ")?ke:`${ke} `}${Ue}`.trimStart()}),$s(""),Be(!1)},[]),ri=a.useCallback(Q=>{const ge=Q instanceof Error?Q.message.toLowerCase():"";return ge.includes("uncommitted changes")||ge.includes("local changes")||ge.includes("your local changes would be overwritten")||ge.includes("please commit your changes or stash them")||ge.includes("cannot rebase: you have unstaged changes")||ge.includes("error: cannot pull with rebase")},[]),Yn=a.useCallback((Q,ge)=>{W(ke=>[...ke,{message:Q,status:ge,timestamp:Date.now()}])},[]),yn=a.useCallback((Q,ge)=>{W(ke=>{if(ke.length===0)return ke;const Ue=[...ke];return Ue[Ue.length-1]={...Ue[Ue.length-1],status:Q,...ge?{message:ge}:{}},Ue})},[]),Vr=a.useCallback(()=>{W([])},[]),$r=a.useCallback(()=>{W([]),es(null)},[]),Fr=a.useCallback(Q=>{const ge=Q.trim(),ke=new Set(us.map(vt=>vt.name)),Ue=ge.indexOf("/");if(Ue>0){const vt=ge.slice(0,Ue),St=ge.slice(Ue+1);if(ke.has(vt)&&St)return{branch:ge,remote:vt,remoteBranch:St}}for(const vt of us){const St=`${vt.name}/${ge}`;if(ps.includes(St))return{branch:St,remote:vt.name,remoteBranch:ge}}return{branch:ge,remote:null,remoteBranch:null}},[us,ps]),ii=a.useCallback(async Q=>{if(!n)return;es("merge"),Vr();const ge=j?.current,ke=Fr(Q);try{ke.remote&&ke.remoteBranch&&(Yn(`Fetching ${ke.remote}/${ke.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:ke.remote,branch:ke.remoteBranch}),yn("done",`Fetched ${ke.remote}/${ke.remoteBranch}`)),Yn(`Merging ${ke.branch} into ${ge}...`,"running");const Ue=await e.merge(n,{branch:ke.branch});Ue.conflict?(yn("error","Merge conflicts detected"),Nt(Ue.conflictFiles??[]),ss("merge"),Xe(!0),Ws(n,Ue.conflictFiles??[],"merge")):(yn("done",`Merged ${ke.branch} into ${ge}`),hs(),Yn("Refreshing repository status...","running"),await ds(),await ws(),yn("done","Repository status updated"))}catch(Ue){if(ri(Ue))yn("error","Uncommitted changes detected"),Kn("merge"),Xs(ke.branch),Rn(!0);else{const vt=Ue instanceof Error?Ue.message:`Failed to merge ${ke.branch}`;yn("error",vt)}}},[n,e,j,Fr,ds,ws,ri,Ws,hs,Yn,yn,Vr]),fn=a.useCallback(async Q=>{if(!n)return;es("rebase"),Vr();const ge=j?.current,ke=Fr(Q);try{ke.remote&&ke.remoteBranch&&(Yn(`Fetching ${ke.remote}/${ke.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:ke.remote,branch:ke.remoteBranch}),yn("done",`Fetched ${ke.remote}/${ke.remoteBranch}`)),Yn(`Rebasing ${ge} onto ${ke.branch}...`,"running");const Ue=await e.rebase(n,{onto:ke.branch});Ue.conflict?(yn("error","Rebase conflicts detected"),Nt(Ue.conflictFiles??[]),ss("rebase"),Xe(!0),Ws(n,Ue.conflictFiles??[],"rebase")):(yn("done",`Rebased ${ge} onto ${ke.branch}`),hs(),Yn("Refreshing repository status...","running"),await ds(),await ws(),yn("done","Repository status updated"))}catch(Ue){if(ri(Ue))yn("error","Uncommitted changes detected"),Kn("rebase"),Xs(ke.branch),Rn(!0);else{const vt=Ue instanceof Error?Ue.message:`Failed to rebase onto ${ke.branch}`;yn("error",vt)}}},[n,e,j,Fr,ds,ws,ri,Ws,hs,Yn,yn,Vr]),kr=a.useCallback(async()=>{if(n)try{ut==="merge"?(await e.abortMerge(n),ae.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),ae.success(t("gitView.toast.rebaseAborted"))),hs(),await ds(),await ws()}catch(Q){const ge=Q instanceof Error?Q.message:`Failed to abort ${ut}`;ae.error(ge)}},[n,e,ut,ds,ws,hs,t]),zr=a.useMemo(()=>j?.files?j.files.some(Q=>Q.index==="U"||Q.working_dir==="U"||Q.index==="A"&&Q.working_dir==="A"||Q.index==="D"&&Q.working_dir==="D"):!1,[j?.files]),Jn=a.useCallback(async()=>{if(n)try{const Q=!!j?.mergeInProgress?.head,ge=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(Q){const ke=await e.continueMerge(n);ke.conflict?(Nt(ke.conflictFiles??[]),ss("merge"),Xe(!0),Ws(n,ke.conflictFiles??[],"merge"),ae.error(t("gitView.toast.mergeConflictsDetected"))):(hs(),ae.success(t("gitView.toast.mergeCompleted")),await ds(),await ws())}else if(ge){const ke=await e.continueRebase(n);ke.conflict?(Nt(ke.conflictFiles??[]),ss("rebase"),Xe(!0),Ws(n,ke.conflictFiles??[],"rebase"),ae.error(t("gitView.toast.rebaseConflictsDetected"))):(hs(),ae.success(t("gitView.toast.rebaseStepCompleted")),await ds(),await ws())}}catch(Q){const ge=Q instanceof Error?Q.message:t("gitView.toast.continueOperationFailed");ae.error(ge)}},[n,e,j,ds,ws,Ws,hs,t]),Ns=a.useCallback(async()=>{if(n)try{!!j?.mergeInProgress?.head?(await e.abortMerge(n),ae.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),ae.success(t("gitView.toast.rebaseAborted"))),hs(),await ds(),await ws()}catch(Q){const ge=Q instanceof Error?Q.message:t("gitView.toast.abortOperationFailed");ae.error(ge)}},[n,e,j,ds,ws,hs,t]),oi=a.useCallback(()=>{if(!n)return;const ge=!!j?.mergeInProgress?.head?"merge":"rebase",ke=j?.files?.filter(Ue=>Ue.index==="U"||Ue.working_dir==="U").map(Ue=>Ue.path)??[];ke.length>0&&Nt(ke),ss(ge),Xe(!0)},[n,j]),ai=a.useCallback(async Q=>{if(!n)return;const ge=j?.current,ke=nr,Ue=As,vt=(j?.files??[]).some(bd);try{await e.stash(n,{message:`Auto-stash before ${ke} with ${Ue}`,includeUntracked:!0}),vt&&je(n)}catch(Is){const Cr=Is instanceof Error?Is.message:"Failed to stash changes";ae.error(Cr);return}let St=!1,xs=!1;try{if(ke==="merge"){const Is=await e.merge(n,{branch:Ue});Is.conflict?(xs=!0,Nt(Is.conflictFiles??[]),ss("merge"),Xe(!0)):(St=!0,ae.success(t("gitView.toast.mergedIntoBranch",{branch:Ue,currentBranch:ge||""})))}else{const Is=await e.rebase(n,{onto:Ue});Is.conflict?(xs=!0,Nt(Is.conflictFiles??[]),ss("rebase"),Xe(!0)):(St=!0,ae.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:ge||"",branch:Ue})))}if(Q&&St)try{await e.stashPop(n),je(n),ae.success(t("gitView.toast.stashedRestored"))}catch(Is){const Cr=Is instanceof Error?Is.message:t("gitView.toast.restoreStashFailed");ae.error(Cr)}else Q&&xs&&ae.info(t("gitView.toast.restoreStashManually"));await ds(),await ws()}catch(Is){if(Q)try{await e.stashPop(n),je(n)}catch{}throw Is}},[je,n,e,j,nr,As,ds,ws,t]),An=a.useCallback(Q=>{ot(Q),n&&(ne(n,Q),Z(n,e,Q))},[n,Z,e,ne]),Lr=a.useCallback(Q=>{Ss(Q)},[]),mr=a.useCallback(()=>{Es(null),n&&(F(n,e),te(n,e),Z(n,e,Re))},[n,F,te,Z,Re,e]),Js=a.useCallback(Q=>{if(Q.conflict){if(Q.operation==="cherry-pick"||Q.operation==="revert"){ae.error(t("gitView.history.actions.conflictToastTitle"),{description:t("gitView.history.actions.conflictToastDescription",{files:Q.conflictFiles?.join(", ")??"unknown files"})}),n&&(F(n,e),te(n,e),Z(n,e,Re));return}Nt(Q.conflictFiles??[]),ss(Q.operation),Xe(!0),n&&Ws(n,Q.conflictFiles??[],Q.operation)}},[t,Nt,ss,Xe,Ws,n,F,te,Z,Re,e]);return n?v===null||v===!0&&!j?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):v===!1?fe?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.notGitRepositoryDescription")}),A.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:Pe("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(Up,{status:j,localBranches:Vt,remoteBranches:ps,branchInfo:P?.branches,syncAction:O,remotes:us,onFetch:Q=>qn("fetch",Q),onSync:Q=>qn("sync",Q),onRemoveRemote:Er,removingRemoteName:Zt,onCheckoutBranch:it,onCreateBranch:ur,onRenameBranch:ee,activeIdentityProfile:Mn,availableIdentities:js,onSelectIdentity:wt,isApplyingIdentity:yt,isWorktreeMode:!!C,onOpenHistory:()=>Es("history"),onOpenGraph:()=>Es("graph"),onOpenStashes:Nr,actionTabItems:Ls,activeActionTab:gs,onSelectActionTab:Q=>Cs(Q)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(Fb,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:Jn,onAbort:Ns,onResolveWithAI:oi,hasUnresolvedConflicts:zr,isLoading:H}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:Pe("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(_n,{as:ba,ref:se,outerClassName:"flex-1 min-h-0",className:Pe("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[gs==="commit"?s.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(Sn?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(Hp,{groups:ln,diffStats:j?.diffStats,revertingPaths:bt,isRevertingAll:lt,onVisiblePathsChange:Ee,onRevertAll:jr})}),s.jsx(Gp,{stagedCount:mn,commitMessage:_e,onCommitMessageChange:J,generatedHighlights:He,onInsertHighlights:ni,onGenerateMessage:yr,isGeneratingMessage:We,onCommit:()=>dr({pushAfter:!1}),onCommitAndPush:()=>dr({pushAfter:!0}),commitAction:Oe,hasPendingIndexMutation:Et,gitmojiEnabled:me,onOpenGitmojiPicker:()=>Be(!0)})]}):s.jsx(_x,{onOpenStashes:()=>be(!0)})}):null,gs==="branch"?s.jsx("div",{className:"space-y-4",children:Vs?s.jsxs(s.Fragment,{children:[s.jsx(Lb,{mode:"inline",currentBranch:j?.current,localBranches:Vt,remoteBranches:ps,defaultTargetBranch:Us,onMerge:ii,onRebase:fn,disabled:Rr,isOperating:is!==null,operationLogs:fs,onOperationComplete:$r}),bn?s.jsx(Lx,{repoRoot:bn.repoRoot,sourceBranch:bn.sourceBranch,worktreeMetadata:bn.worktreeMetadata,localBranches:Vt,defaultTargetBranch:Wt,refreshKey:Ke,onRefresh:()=>{n&&(F(n,e),te(n,e),Z(n,e,Re))}},bn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,gs==="pr"?s.jsx("div",{className:"space-y-4",children:Ds?s.jsx(Cb,{directory:Ds.directory,branch:Ds.branch,baseBranch:cs,trackingBranch:j?.tracking??void 0,remotes:Mt,remoteBranches:ps,onGeneratedDescription:at}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:t("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(Ks,{open:Ut!==null,onOpenChange:Q=>{Q||Es(null)},children:s.jsxs(Gs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Qs,{children:[s.jsx(Ys,{children:t(Ut==="graph"?"gitView.graph.title":"gitView.history.title")}),s.jsx(dn,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(Kx,{mode:Ut==="graph"?"graph":"history",log:Ut==="graph"?bs??E:E,isLogLoading:Ut==="graph"&&Bs||R,logMaxCount:Ut==="graph"?an:Re,onLogMaxCountChange:Ut==="graph"?Lr:An,expandedCommitHashes:Lt,onToggleCommit:un,commitFilesMap:Qt,loadingCommitHashes:Yt,onCopyHash:Cn,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Ut==="graph"?null:Jt,onConflict:Ut==="graph"?Js:void 0,onActionSuccess:Ut==="graph"?mr:void 0})})]})}),s.jsx(Ox,{open:Y,onOpenChange:be,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,hasStagedChanges:Os.length>0,uncommittedFileCount:j?.files?.length??0,onChanged:async Q=>{n&&Q?.affectsIndex&&je(n),await ds(!1),await ws()}}),s.jsx(Ks,{open:Ne,onOpenChange:Be,children:s.jsxs(Gs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Qs,{className:"px-4 pt-4",children:s.jsx(Ys,{children:t("gitView.gitmoji.title")})}),s.jsxs(ma,{className:"h-[420px]",children:[s.jsx(fa,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:as,onValueChange:$s}),s.jsxs(ha,{children:[s.jsx(pa,{children:t("gitView.gitmoji.empty")}),s.jsx(Yr,{children:(ks.length===0?[]:ks.filter(Q=>{const ge=as.trim().toLowerCase();return ge?Q.emoji.includes(ge)||Q.code.toLowerCase().includes(ge)||Q.description.toLowerCase().includes(ge):!0})).map(Q=>s.jsxs(ei,{onSelect:()=>jo(Q.emoji,Q.code),children:[s.jsx("span",{className:"text-lg",children:Q.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Q.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Q.description})]},Q.code))})]})]})]})}),n&&s.jsx(Ab,{open:Ge,onOpenChange:Xe,conflictFiles:ht,directory:n,operation:ut,onAbort:kr,onClearState:hs}),s.jsx(Mb,{open:br,onOpenChange:Rn,operation:nr,targetBranch:As,onConfirm:ai})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:t("gitView.empty.selectSessionOrDirectory")})})},kl=5e3,ey=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},ty=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},sy=async(t,e)=>{if(t.readFile)return(await t.readFile(e,{allowOutsideWorkspace:!0,optional:!0})).content??"";const n=new URLSearchParams({path:e,allowOutsideWorkspace:"true",optional:"true"}),r=await Fs(`/api/fs/read?${n.toString()}`,{cache:"no-store"});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to read file")}return r.text()},nc=async(t,e)=>{try{const n=await sy(t,e);return ey(n,kl)>kl?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:ty(n)}}},rc=t=>t==="too-large"?`File is too large to open (>${kl.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",ny=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Pn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},um=(t,e)=>{const n=Pn(e),r=Pn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},ry=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),iy=new Set(["node_modules"]),oy=t=>iy.has(t),ay=t=>{const e=Pn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},mm=(t,e)=>s.jsx(xr,{filePath:t,extension:e}),ly=t=>{const e=pt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let i;return e[1]!==o?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=i):i=e[2],i},cy=t=>{const e=pt.c(63),{node:n,root:r,isExpanded:o,isActive:i,status:c,badge:l,permissions:u,downloadFile:m,contextMenuPath:d,setContextMenuPath:f,onSelect:g,onToggle:x,onRevealPath:p,onOpenDialog:y}=t,{t:b}=Tt(),h=n.type==="directory",{canRename:N,canCreateFile:w,canCreateFolder:S,canDelete:v,canReveal:j}=u;let k;e[0]!==w||e[1]!==S||e[2]!==v||e[3]!==N||e[4]!==j||e[5]!==n.path||e[6]!==f?(k=ie=>{!N&&!w&&!S&&!v&&!j||(ie?.preventDefault(),f(n.path))},e[0]=w,e[1]=S,e[2]=v,e[3]=N,e[4]=j,e[5]=n.path,e[6]=f,e[7]=k):k=e[7];const A=k;let T;e[8]!==h||e[9]!==n||e[10]!==g||e[11]!==x?(T=()=>{h?x(n.path):g(n)},e[8]=h,e[9]=n,e[10]=g,e[11]=x,e[12]=T):T=e[12];const C=T;let P;e[13]!==n.path||e[14]!==f?(P=ie=>{ie.stopPropagation(),f(n.path)},e[13]=n.path,e[14]=f,e[15]=P):P=e[15];const E=P;let M;e[16]!==n.path||e[17]!==r?(M=ie=>{const oe=um(r,n.path);!oe||oe==="."||(ie.dataTransfer.setData("application/x-openchamber-file-path",oe),ie.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=M):M=e[18];const H=M,R=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let _;e[19]!==R?(_=Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",R,"cursor-grab active:cursor-grabbing"),e[19]=R,e[20]=_):_=e[20];let z;e[21]!==h||e[22]!==o||e[23]!==n.extension||e[24]!==n.path?(z=h?o?s.jsx(I,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):mm(n.path,n.extension),e[21]=h,e[22]=o,e[23]=n.extension,e[24]=n.path,e[25]=z):z=e[25];let V;e[26]!==n.name||e[27]!==n.path?(V=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[26]=n.name,e[27]=n.path,e[28]=V):V=e[28];let F;e[29]!==h||e[30]!==c?(F=!h&&c&&s.jsx(ly,{status:c}),e[29]=h,e[30]=c,e[31]=F):F=e[31];let te;e[32]!==l||e[33]!==h?(te=h&&l&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[l.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",l.modified]}),l.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",l.added]})]}),e[32]=l,e[33]=h,e[34]=te):te=e[34];let Z;e[35]!==A||e[36]!==H||e[37]!==C||e[38]!==te||e[39]!==_||e[40]!==z||e[41]!==V||e[42]!==F?(Z=s.jsxs("button",{type:"button",onClick:C,onContextMenu:A,draggable:!0,onDragStart:H,className:_,children:[z,V,F,te]}),e[35]=A,e[36]=H,e[37]=C,e[38]=te,e[39]=_,e[40]=z,e[41]=V,e[42]=F,e[43]=Z):Z=e[43];let ne;e[44]!==w||e[45]!==S||e[46]!==v||e[47]!==N||e[48]!==j||e[49]!==d||e[50]!==m||e[51]!==E||e[52]!==h||e[53]!==n||e[54]!==y||e[55]!==p||e[56]!==f||e[57]!==b?(ne=(N||w||S||v||j)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(rn,{open:d===n.path,onOpenChange:ie=>f(ie?n.path:null),children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(sn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:E,title:b("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":b("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:b("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsxs(nn,{align:"end",side:"bottom",onCloseAutoFocus:()=>f(null),children:[N&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),y("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.rename")]}),s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),ar(n.path).then(oe=>{if(oe.ok){ae.success(b("sidebarFilesTree.toast.pathCopied"));return}ae.error(b("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.copyPath")]}),!h&&m&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),m(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.save")]}),j&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),p(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",b(Gl())]}),h&&(w||S)&&s.jsxs(s.Fragment,{children:[s.jsx(On,{}),w&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),y("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.newFile")]}),S&&s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),y("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.newFolder")]})]}),v&&s.jsxs(s.Fragment,{children:[s.jsx(On,{}),s.jsxs(zt,{onClick:ie=>{ie.stopPropagation(),y("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=w,e[45]=S,e[46]=v,e[47]=N,e[48]=j,e[49]=d,e[50]=m,e[51]=E,e[52]=h,e[53]=n,e[54]=y,e[55]=p,e[56]=f,e[57]=b,e[58]=ne):ne=e[58];let U;return e[59]!==A||e[60]!==Z||e[61]!==ne?(U=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:A,children:[Z,ne]}),e[59]=A,e[60]=Z,e[61]=ne,e[62]=U):U=e[62],U},dy=()=>{const t=pt.c(251),{t:e}=Tt(),{files:n}=Gn(),r=si()??"";let o;t[0]!==r?(o=Pn(r.trim()),t[0]=r,t[1]=o):o=t[1];const i=o,c=Eu(),l=Ru(),u=Hl(uy),m=Fe(my),d=ya(r),[f,g]=a.useState(""),x=va(f,200),p=a.useRef(null);let y;t[2]===Symbol.for("react.memo_cache_sentinel")?(y=[],t[2]=y):y=t[2];const[b,h]=a.useState(y),[N,w]=a.useState(!1);let S;t[3]===Symbol.for("react.memo_cache_sentinel")?(S={},t[3]=S):S=t[3];const[v,j]=a.useState(S);let k;t[4]===Symbol.for("react.memo_cache_sentinel")?(k={},t[4]=k):k=t[4];const[A,T]=a.useState(k);let C;t[5]===Symbol.for("react.memo_cache_sentinel")?(C=new Set,t[5]=C):C=t[5];const P=a.useRef(C);let E;t[6]===Symbol.for("react.memo_cache_sentinel")?(E=new Set,t[6]=E):E=t[6];const M=a.useRef(E);let H;t[7]===Symbol.for("react.memo_cache_sentinel")?(H=[],t[7]=H):H=t[7];const R=H;let _;t[8]===Symbol.for("react.memo_cache_sentinel")?(_=[],t[8]=_):_=t[8];const z=_;let V;t[9]!==i?(V=Mt=>i?Mt.byRoot[i]?.expandedPaths??R:R,t[9]=i,t[10]=V):V=t[10];const F=Nn(V);let te;t[11]!==i?(te=Mt=>i?Mt.byRoot[i]?.selectedPath??null:null,t[11]=i,t[12]=te):te=t[12];const Z=Nn(te),ne=Nn(fy),U=Nn(hy),ie=Nn(py),oe=Nn(gy);let pe;t[13]!==i?(pe=Mt=>i?Mt.contextPanelByDirectory[i]?.tabs??z:z,t[13]=i,t[14]=pe):pe=t[14];const je=Fe(pe);let Se;t[15]!==je?(Se=new Set(je.map(xy).filter(by).map(yy)),t[15]=je,t[16]=Se):Se=t[16];const re=Se,[L,$]=a.useState(null),[K,he]=a.useState(null),[de,we]=a.useState(null),[xe,De]=a.useState(""),[le,Ce]=a.useState(!1),ue=!!n.writeFile,ve=!!n.createDirectory,G=!!n.rename,Ae=!!n.delete,ce=!!n.revealPath;let fe;t[17]!==ue||t[18]!==ve||t[19]!==Ae||t[20]!==G||t[21]!==ce?(fe={canRename:G,canCreateFile:ue,canCreateFolder:ve,canDelete:Ae,canReveal:ce},t[17]=ue,t[18]=ve,t[19]=Ae,t[20]=G,t[21]=ce,t[22]=fe):fe=t[22];const Te=fe;let me;t[23]!==n||t[24]!==e?(me=Mt=>{n.revealPath&&n.revealPath(Mt).catch(()=>{ae.error(e("sidebarFilesTree.toast.revealFailed"))})},t[23]=n,t[24]=e,t[25]=me):me=t[25];const B=me;let ye;t[26]===Symbol.for("react.memo_cache_sentinel")?(ye=(Mt,xt)=>{he(Mt),we(xt),De(Mt==="rename"&&xt.name||""),Ce(!1)},t[26]=ye):ye=t[26];const _e=ye;let J;t[27]!==l||t[28]!==c?(J=(Mt,xt)=>{const Zt=xt.filter(wy).filter(Ft=>c||!Ft.name.startsWith(".")).filter(Ft=>l||!oy(Ft.name)).map(Ft=>{const is=Ft.name,es=Pn(Ft.path||""),fs=es?ry(es)?es:Pn(`${Mt}/${es}`):Pn(`${Mt}/${is}`),W=Ft.isDirectory?"directory":"file",Ge=W==="file"&&is.includes(".")?is.split(".").pop()?.toLowerCase():void 0;return{name:is,path:fs,type:W,extension:Ge}});return ny(Zt)},t[27]=l,t[28]=c,t[29]=J):J=t[29];const Me=J;let Ee;t[30]!==n||t[31]!==Me?(Ee=async Mt=>{const xt=Pn(Mt.trim());if(!xt||P.current.has(xt)||M.current.has(xt))return;M.current=new Set(M.current),M.current.add(xt),await(n.listDirectory?n.listDirectory(xt).then(jy):Hn.listLocalDirectory(xt).then(Ny)).then(Ft=>{const is=Me(xt,Ft);P.current=new Set(P.current),P.current.add(xt),T(es=>{if(!es[xt])return es;const fs={...es};return delete fs[xt],fs}),j(es=>({...es,[xt]:is}))}).catch(Ft=>{const is=Ft instanceof Error?Ft.message:String(Ft??"");console.error("Failed to load sidebar directory:",Ft),T(es=>({...es,[xt]:is}))}).finally(()=>{M.current=new Set(M.current),M.current.delete(xt)})},t[30]=n,t[31]=Me,t[32]=Ee):Ee=t[32];const Ne=Ee;let Be;t[33]!==Ne||t[34]!==i?(Be=async()=>{i&&(P.current=new Set,M.current=new Set,T({}),j(ky),await Ne(i))},t[33]=Ne,t[34]=i,t[35]=Be):Be=t[35];const se=Be;let O;t[36]!==Ne||t[37]!==se?(O=async Mt=>{if(!Mt){await se();return}const xt=Pn(Mt);P.current=new Set(P.current),P.current.delete(xt),M.current=new Set(M.current),M.current.delete(xt),await Ne(xt)},t[36]=Ne,t[37]=se,t[38]=O):O=t[38];const D=O;let Y;t[39]!==Ne||t[40]!==i?(Y=()=>{i&&(P.current=new Set,M.current=new Set,T({}),j(Cy),Ne(i))},t[39]=Ne,t[40]=i,t[41]=Y):Y=t[41];let be;t[42]!==Ne||t[43]!==i||t[44]!==l||t[45]!==c?(be=[Ne,i,c,l],t[42]=Ne,t[43]=i,t[44]=l,t[45]=c,t[46]=be):be=t[46],a.useEffect(Y,be);let Oe,$e;t[47]!==F||t[48]!==Ne||t[49]!==i?(Oe=()=>{if(!i||F.length===0)return;const Mt=F.map(Ay).filter(Zt=>!!Zt&&Zt!==i&&Zt.startsWith(`${i}/`)&&!P.current.has(Zt)&&!M.current.has(Zt)).sort(Dy);if(Mt.length===0)return;let xt=!1;return(async()=>{for(let Zt=0;Zt<Mt.length&&!xt;Zt=Zt+3,Zt){const Ft=Mt.slice(Zt,Zt+3);await Promise.all(Ft.map(is=>Ne(is)))}})(),()=>{xt=!0}},$e=[F,Ne,i],t[47]=F,t[48]=Ne,t[49]=i,t[50]=Oe,t[51]=$e):(Oe=t[50],$e=t[51]),a.useEffect(Oe,$e);let Re,ot;t[52]!==r||t[53]!==x||t[54]!==u||t[55]!==l||t[56]!==c?(Re=()=>{if(!r){h([]),w(!1);return}const Mt=x.trim();if(!Mt){h([]),w(!1);return}let xt=!1;return w(!0),u(r,Mt,150,{includeHidden:c,respectGitignore:!l,type:"file"}).then(Zt=>{if(xt)return;const is=Zt.filter(es=>l||!ay(es.path)).map(Iy);h(is)}).catch(()=>{xt||h([])}).finally(()=>{xt||w(!1)}),()=>{xt=!0}},ot=[r,x,u,c,l],t[52]=r,t[53]=x,t[54]=u,t[55]=l,t[56]=c,t[57]=Re,t[58]=ot):(Re=t[57],ot=t[58]),a.useEffect(Re,ot);let yt;t[59]!==d||t[60]!==re||t[61]!==i?(yt=Mt=>{if(re.has(Mt))return"open";if(d?.files){const xt=Mt.startsWith(i+"/")?Mt.slice(i.length+1):Mt,Zt=d.files.find(Ft=>Ft.path===xt);if(Zt){if(Zt.index==="A"||Zt.working_dir==="?")return"git-added";if(Zt.index==="D")return"git-deleted";if(Zt.index==="M"||Zt.working_dir==="M")return"git-modified"}}return null},t[59]=d,t[60]=re,t[61]=i,t[62]=yt):yt=t[62];const At=yt;let mt;t[63]!==d||t[64]!==i?(mt=Mt=>{if(!d?.files)return null;const xt=Mt.startsWith(i+"/")?Mt.slice(i.length+1):Mt,Zt=xt?`${xt}/`:"";let Ft=0,is=0;for(const es of d.files)es.path.startsWith(Zt)&&((es.index==="M"||es.working_dir==="M")&&Ft++,(es.index==="A"||es.working_dir==="?")&&is++);return Ft+is>0?{modified:Ft,added:is}:null},t[63]=d,t[64]=i,t[65]=mt):mt=t[65];const Le=mt;let Qe;t[66]!==U||t[67]!==n||t[68]!==m||t[69]!==i||t[70]!==ne?(Qe=async Mt=>{if(!i)return;const xt=await nc(n,Mt.path);if(!xt.ok){ae.error(rc(xt.reason));return}ne(i,Mt.path),U(i,Mt.path),m(i,Mt.path)},t[66]=U,t[67]=n,t[68]=m,t[69]=i,t[70]=ne,t[71]=Qe):Qe=t[71];const Ye=Qe;let rt;t[72]!==Ne||t[73]!==i||t[74]!==oe?(rt=async Mt=>{const xt=Pn(Mt);i&&(oe(i,xt),P.current.has(xt)||await Ne(xt))},t[72]=Ne,t[73]=i,t[74]=oe,t[75]=rt):rt=t[75];const bt=rt;let ct;t[76]!==K||t[77]!==de||t[78]!==xe||t[79]!==n||t[80]!==D||t[81]!==ie||t[82]!==i||t[83]!==Z||t[84]!==ne||t[85]!==e?(ct=async Mt=>{if(Mt?.preventDefault(),!de||!K)return;Ce(!0);const xt=()=>Ce(!1),Zt=()=>he(null);if(K==="createFile"){if(!xe.trim()){ae.error(e("sidebarFilesTree.toast.filenameRequired")),xt();return}if(!n.writeFile){ae.error(e("sidebarFilesTree.toast.writeNotSupported")),xt();return}const Ft=de.path,is=Ft?`${Ft}/`:"",es=Pn(`${is}${xe.trim()}`);await n.writeFile(es,"").then(async fs=>{fs.success&&(ae.success(e("sidebarFilesTree.toast.fileCreated")),await D(Ft)),Zt()}).catch(()=>ae.error(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(K==="createFolder"){if(!xe.trim()){ae.error(e("sidebarFilesTree.toast.folderNameRequired")),xt();return}const Ft=de.path,is=Ft?`${Ft}/`:"",es=Pn(`${is}${xe.trim()}`);await n.createDirectory(es).then(async fs=>{fs.success&&(ae.success(e("sidebarFilesTree.toast.folderCreated")),await D(Ft)),Zt()}).catch(()=>ae.error(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(K==="rename"){if(!xe.trim()){ae.error(e("sidebarFilesTree.toast.nameRequired")),xt();return}if(!n.rename){ae.error(e("sidebarFilesTree.toast.renameNotSupported")),xt();return}const Ft=de.path,is=Ft.split("/").slice(0,-1).join("/"),es=is?`${is}/`:"",fs=Pn(`${es}${xe.trim()}`);await n.rename(Ft,fs).then(async W=>{W.success&&(ae.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await D(is),i&&ie(i,Ft),(Z===Ft||Z&&Z.startsWith(`${Ft}/`))&&ne(i,null)),Zt()}).catch(()=>ae.error(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(K==="delete"){if(!n.delete){ae.error(e("sidebarFilesTree.toast.deleteNotSupported")),xt();return}const Ft=de.path,is=Ft.split("/").slice(0,-1).join("/");await n.delete(Ft).then(async es=>{es.success&&(ae.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await D(is),i&&ie(i,Ft),(Z===Ft||Z&&Z.startsWith(Ft+"/"))&&ne(i,null)),Zt()}).catch(()=>ae.error(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}xt()},t[76]=K,t[77]=de,t[78]=xe,t[79]=n,t[80]=D,t[81]=ie,t[82]=i,t[83]=Z,t[84]=ne,t[85]=e,t[86]=ct):ct=t[86];const nt=ct;let It,lt,kt,Ke,tt,We,gt;if(t[87]!==ue||t[88]!==ve||t[89]!==v||t[90]!==L||t[91]!==r||t[92]!==F||t[93]!==Te||t[94]!==n.downloadFile||t[95]!==At||t[96]!==Le||t[97]!==Ye||t[98]!==B||t[99]!==A||t[100]!==D||t[101]!==se||t[102]!==i||t[103]!==f||t[104]!==b||t[105]!==N||t[106]!==Z||t[107]!==e||t[108]!==bt){let Mt=function(Ss,zs){const Ws=v[Ss]??[];return Ws.map((hs,br)=>{const Rn=hs.type==="directory",nr=Rn&&F.includes(hs.path),Kn=Z===hs.path,As=br===Ws.length-1;return s.jsxs("li",{className:"relative",children:[zs>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),As&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(cy,{node:hs,root:i,isExpanded:nr,isActive:Kn,status:Rn?void 0:At(hs.path),badge:Rn?Le(hs.path):void 0,permissions:Te,downloadFile:n.downloadFile,contextMenuPath:L,setContextMenuPath:$,onSelect:Ye,onToggle:bt,onRevealPath:B,onOpenDialog:_e}),Rn&&nr&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[A[hs.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:A[hs.path],children:A[hs.path]}),s.jsxs(ze,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{D(hs.path)},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),e("sidebarFilesTree.actions.refreshTitle")]})]}):null,Mt(hs.path,zs+1)]})]},hs.path)})};const xt=!!(i&&v[i]),Zt=i?A[i]:null;We="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let Ft;t[116]===Symbol.for("react.memo_cache_sentinel")?(Ft=s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[116]=Ft):Ft=t[116];let is;t[117]===Symbol.for("react.memo_cache_sentinel")?(is=Ss=>g(Ss.target.value),t[117]=is):is=t[117];let es;t[118]!==e?(es=e("sidebarFilesTree.search.placeholder"),t[118]=e,t[119]=es):es=t[119];let fs;t[120]!==f||t[121]!==es?(fs=s.jsx(kn,{ref:p,value:f,onChange:is,placeholder:es,className:"h-8 pl-8 pr-8 typography-meta"}),t[120]=f,t[121]=es,t[122]=fs):fs=t[122];let W;t[123]!==f||t[124]!==e?(W=f.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{g(""),p.current?.focus()},children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,t[123]=f,t[124]=e,t[125]=W):W=t[125];let Ge;t[126]!==fs||t[127]!==W?(Ge=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Ft,fs,W]}),t[126]=fs,t[127]=W,t[128]=Ge):Ge=t[128];let Xe;t[129]!==ue||t[130]!==r||t[131]!==e?(Xe=ue&&s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>_e("createFile",{path:r,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),"aria-label":e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFileTitle")})]}),t[129]=ue,t[130]=r,t[131]=e,t[132]=Xe):Xe=t[132];let ht;t[133]!==ve||t[134]!==r||t[135]!==e?(ht=ve&&s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>_e("createFolder",{path:r,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),"aria-label":e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFolderTitle")})]}),t[133]=ve,t[134]=r,t[135]=e,t[136]=ht):ht=t[136];let Nt;t[137]!==se?(Nt=()=>{se()},t[137]=se,t[138]=Nt):Nt=t[138];let ut;t[139]!==e?(ut=e("sidebarFilesTree.actions.refreshTitle"),t[139]=e,t[140]=ut):ut=t[140];let ss;t[141]!==e?(ss=e("sidebarFilesTree.actions.refreshTitle"),t[141]=e,t[142]=ss):ss=t[142];let bs;t[143]===Symbol.for("react.memo_cache_sentinel")?(bs=s.jsx(I,{name:"refresh",className:"h-4 w-4"}),t[143]=bs):bs=t[143];let ys;t[144]!==Nt||t[145]!==ut||t[146]!==ss?(ys=s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:Nt,className:"h-8 w-8 p-0 flex-shrink-0",title:ut,"aria-label":ss,children:bs})})}),t[144]=Nt,t[145]=ut,t[146]=ss,t[147]=ys):ys=t[147];let Bs;t[148]!==e?(Bs=e("sidebarFilesTree.actions.refreshTitle"),t[148]=e,t[149]=Bs):Bs=t[149];let Rs;t[150]!==Bs?(Rs=s.jsx(Bt,{side:"bottom",sideOffset:6,children:Bs}),t[150]=Bs,t[151]=Rs):Rs=t[151];let an;t[152]!==ys||t[153]!==Rs?(an=s.jsxs(Ot,{children:[ys,Rs]}),t[152]=ys,t[153]=Rs,t[154]=an):an=t[154],t[155]!==Ge||t[156]!==Xe||t[157]!==ht||t[158]!==an?(gt=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[Ge,Xe,ht,an]}),t[155]=Ge,t[156]=Xe,t[157]=ht,t[158]=an,t[159]=gt):gt=t[159],It=_n,Ke="flex-1 min-h-0",tt="p-2",lt="flex flex-col",kt=N?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):b.length>0?b.map(Ss=>{const zs=Z===Ss.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Ye(Ss),draggable:!0,onDragStart:Ws=>{const hs=Ss.relativePath||um(i??"",Ss.path);!hs||hs==="."||(Ws.dataTransfer.setData("application/x-openchamber-file-path",hs),Ws.dataTransfer.effectAllowed="copy")},className:Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",zs?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:Ss.path,children:[mm(Ss.path,Ss.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:Ss.relativePath??Ss.path})]})},Ss.path)}):Zt?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:Zt}),s.jsxs(ze,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{se()},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),e("sidebarFilesTree.actions.refreshTitle")]})]}):xt&&i?Mt(i,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[87]=ue,t[88]=ve,t[89]=v,t[90]=L,t[91]=r,t[92]=F,t[93]=Te,t[94]=n.downloadFile,t[95]=At,t[96]=Le,t[97]=Ye,t[98]=B,t[99]=A,t[100]=D,t[101]=se,t[102]=i,t[103]=f,t[104]=b,t[105]=N,t[106]=Z,t[107]=e,t[108]=bt,t[109]=It,t[110]=lt,t[111]=kt,t[112]=Ke,t[113]=tt,t[114]=We,t[115]=gt}else It=t[109],lt=t[110],kt=t[111],Ke=t[112],tt=t[113],We=t[114],gt=t[115];let He;t[160]!==lt||t[161]!==kt?(He=s.jsx("ul",{className:lt,children:kt}),t[160]=lt,t[161]=kt,t[162]=He):He=t[162];let st;t[163]!==It||t[164]!==Ke||t[165]!==tt||t[166]!==He?(st=s.jsx(It,{outerClassName:Ke,className:tt,children:He}),t[163]=It,t[164]=Ke,t[165]=tt,t[166]=He,t[167]=st):st=t[167];const Et=!!K;let at;t[168]===Symbol.for("react.memo_cache_sentinel")?(at=Mt=>!Mt&&he(null),t[168]=at):at=t[168];let dt;t[169]!==K||t[170]!==e?(dt=K==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[169]=K,t[170]=e,t[171]=dt):dt=t[171];let Ht;t[172]!==K||t[173]!==e?(Ht=K==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[172]=K,t[173]=e,t[174]=Ht):Ht=t[174];let Rt;t[175]!==K||t[176]!==e?(Rt=K==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[175]=K,t[176]=e,t[177]=Rt):Rt=t[177];let Wt;t[178]!==K||t[179]!==e?(Wt=K==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[178]=K,t[179]=e,t[180]=Wt):Wt=t[180];let qt;t[181]!==dt||t[182]!==Ht||t[183]!==Rt||t[184]!==Wt?(qt=s.jsxs(Ys,{children:[dt,Ht,Rt,Wt]}),t[181]=dt,t[182]=Ht,t[183]=Rt,t[184]=Wt,t[185]=qt):qt=t[185];let Lt;t[186]!==K||t[187]!==de?.path||t[188]!==e?(Lt=K==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:de?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[186]=K,t[187]=de?.path,t[188]=e,t[189]=Lt):Lt=t[189];let Gt;t[190]!==K||t[191]!==de?.path||t[192]!==e?(Gt=K==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:de?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[190]=K,t[191]=de?.path,t[192]=e,t[193]=Gt):Gt=t[193];let Qt;t[194]!==K||t[195]!==de?.name||t[196]!==e?(Qt=K==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:de?.name??""}),t[194]=K,t[195]=de?.name,t[196]=e,t[197]=Qt):Qt=t[197];let rs;t[198]!==K||t[199]!==de?.name||t[200]!==e?(rs=K==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:de?.name??""}),t[198]=K,t[199]=de?.name,t[200]=e,t[201]=rs):rs=t[201];let Yt;t[202]!==Lt||t[203]!==Gt||t[204]!==Qt||t[205]!==rs?(Yt=s.jsxs(dn,{children:[Lt,Gt,Qt,rs]}),t[202]=Lt,t[203]=Gt,t[204]=Qt,t[205]=rs,t[206]=Yt):Yt=t[206];let ft;t[207]!==qt||t[208]!==Yt?(ft=s.jsxs(Qs,{children:[qt,Yt]}),t[207]=qt,t[208]=Yt,t[209]=ft):ft=t[209];let Jt;t[210]!==K||t[211]!==xe||t[212]!==nt||t[213]!==e?(Jt=K!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(kn,{value:xe,onChange:Mt=>De(Mt.target.value),placeholder:e(K==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:Mt=>{Mt.key==="Enter"&&nt()},autoFocus:!0})}),t[210]=K,t[211]=xe,t[212]=nt,t[213]=e,t[214]=Jt):Jt=t[214];let ms;t[215]===Symbol.for("react.memo_cache_sentinel")?(ms=()=>he(null),t[215]=ms):ms=t[215];let Xt;t[216]!==e?(Xt=e("sidebarFilesTree.dialog.cancel"),t[216]=e,t[217]=Xt):Xt=t[217];let ts;t[218]!==le||t[219]!==Xt?(ts=s.jsx(ze,{variant:"outline",onClick:ms,disabled:le,children:Xt}),t[218]=le,t[219]=Xt,t[220]=ts):ts=t[220];const ks=K==="delete"?"destructive":"default";let $t;t[221]!==nt?($t=()=>{nt()},t[221]=nt,t[222]=$t):$t=t[222];let as;t[223]!==K||t[224]!==xe||t[225]!==le?(as=le||K!=="delete"&&!xe.trim(),t[223]=K,t[224]=xe,t[225]=le,t[226]=as):as=t[226];let $s;t[227]!==K||t[228]!==le||t[229]!==e?($s=le?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e(K==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[227]=K,t[228]=le,t[229]=e,t[230]=$s):$s=t[230];let Ut;t[231]!==ks||t[232]!==$t||t[233]!==as||t[234]!==$s?(Ut=s.jsx(ze,{variant:ks,onClick:$t,disabled:as,children:$s}),t[231]=ks,t[232]=$t,t[233]=as,t[234]=$s,t[235]=Ut):Ut=t[235];let Es;t[236]!==ts||t[237]!==Ut?(Es=s.jsxs(sr,{children:[ts,Ut]}),t[236]=ts,t[237]=Ut,t[238]=Es):Es=t[238];let Ls;t[239]!==ft||t[240]!==Jt||t[241]!==Es?(Ls=s.jsxs(Gs,{children:[ft,Jt,Es]}),t[239]=ft,t[240]=Jt,t[241]=Es,t[242]=Ls):Ls=t[242];let gs;t[243]!==Et||t[244]!==Ls?(gs=s.jsx(Ks,{open:Et,onOpenChange:at,children:Ls}),t[243]=Et,t[244]=Ls,t[245]=gs):gs=t[245];let Cs;return t[246]!==We||t[247]!==gt||t[248]!==st||t[249]!==gs?(Cs=s.jsxs("section",{className:We,children:[gt,st,gs]}),t[246]=We,t[247]=gt,t[248]=st,t[249]=gs,t[250]=Cs):Cs=t[250],Cs};function uy(t){return t.searchFiles}function my(t){return t.openContextFile}function fy(t){return t.setSelectedPath}function hy(t){return t.addOpenPath}function py(t){return t.removeOpenPathsByPrefix}function gy(t){return t.toggleExpandedPath}function xy(t){return t.mode==="file"?t.targetPath:null}function by(t){return typeof t=="string"&&t.length>0}function yy(t){return Pn(t)}function wy(t){return t&&typeof t.name=="string"&&t.name.length>0}function vy(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function jy(t){return t.entries.map(vy)}function Sy(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function Ny(t){return t.map(Sy)}function ky(t){return Object.keys(t).length===0?t:{}}function Cy(t){return Object.keys(t).length===0?t:{}}function Ay(t){return Pn(t)}function Dy(t,e){return t.split("/").length-e.split("/").length}function Iy(t){return{name:t.name,path:Pn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function Py(t,e){const n=pt.c(6),{git:r}=Gn(),o=_s(Ty);let i,c;n[0]!==t||n[1]!==o||n[2]!==r||n[3]!==e?(i=()=>{if(!t||!r||!e)return;o(t,r);const l=setInterval(()=>{typeof document<"u"&&document.hidden||o(t,r)},1e4);return()=>clearInterval(l)},c=[t,r,e,o],n[0]=t,n[1]=o,n[2]=r,n[3]=e,n[4]=i,n[5]=c):(i=n[4],c=n[5]),a.useEffect(i,c)}function Ty(t){return t.ensureStatus}const fm=()=>{const t=pt.c(17),e=Ms(Ry),n=Ms(My),r=tn(Fy),o=_s(Ly);let i;e:{if(e){let p;t[0]!==e||t[1]!==n?(p=n.find(y=>y.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=p):p=t[2],i=p;break e}i=n[0]??null}const c=i;let l;e:{if(!c){l=null;break e}let p;t[3]!==c.id||t[4]!==c.path?(p={id:c.id,path:c.path},t[3]=c.id,t[4]=c.path,t[5]=p):p=t[5],l=p}const u=l;let m;e:{if(!c){m=null;break e}let p;t[6]!==c.label||t[7]!==c.path||t[8]!==r?(p=c.label?.trim()||Si(c.path,r)||c.path,t[6]=c.label,t[7]=c.path,t[8]=r,t[9]=p):p=t[9],m=p}const d=m;let f;e:{if(!c){f=!1;break e}let p;t[10]!==c.path||t[11]!==o?(p=o.get(c.path)?.isGitRepo,t[10]=c.path,t[11]=o,t[12]=p):p=t[12],f=p===!0}const g=f;let x;return t[13]!==g||t[14]!==d||t[15]!==u?(x=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(hx,{projectRef:u,projectLabel:d,canCreateWorktree:g})}),t[13]=g,t[14]=d,t[15]=u,t[16]=x):x=t[16],x},Ey=()=>{const t=pt.c(38),{t:e}=Tt(),n=Fe(Oy),r=Fe(_y),o=Fe(By),i=si();Py(i,o);let c;t[0]!==e?(c=e("layout.rightSidebar.git"),t[0]=e,t[1]=c):c=t[1];let l;t[2]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=l):l=t[2];let u;t[3]!==c?(u={id:"git",label:c,icon:l},t[3]=c,t[4]=u):u=t[4];let m;t[5]!==e?(m=e("layout.rightSidebar.files"),t[5]=e,t[6]=m):m=t[6];let d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(I,{name:"folder-3",className:"h-3.5 w-3.5"}),t[7]=d):d=t[7];let f;t[8]!==m?(f={id:"files",label:m,icon:d},t[8]=m,t[9]=f):f=t[9];let g;t[10]!==e?(g=e("layout.rightSidebar.context"),t[10]=e,t[11]=g):g=t[11];let x;t[12]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(I,{name:"file-list-2",className:"h-3.5 w-3.5"}),t[12]=x):x=t[12];let p;t[13]!==g?(p={id:"context",label:g,icon:x},t[13]=g,t[14]=p):p=t[14];let y;t[15]!==u||t[16]!==f||t[17]!==p?(y=[u,f,p],t[15]=u,t[16]=f,t[17]=p,t[18]=y):y=t[18];const b=y;let h;t[19]!==r?(h=A=>r(A),t[19]=r,t[20]=h):h=t[20];let N;t[21]!==n||t[22]!==h||t[23]!==b?(N=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(po,{items:b,activeId:n,onSelect:h,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=h,t[23]=b,t[24]=N):N=t[24];let w;t[25]!==n?(w=n==="git"&&s.jsx(Nl,{}),t[25]=n,t[26]=w):w=t[26];let S;t[27]!==n?(S=n==="files"&&s.jsx(dy,{}),t[27]=n,t[28]=S):S=t[28];let v;t[29]!==n?(v=n==="context"&&s.jsx(fm,{}),t[29]=n,t[30]=v):v=t[30];let j;t[31]!==w||t[32]!==S||t[33]!==v?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[w,S,v]}),t[31]=w,t[32]=S,t[33]=v,t[34]=j):j=t[34];let k;return t[35]!==N||t[36]!==j?(k=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[N,j]}),t[35]=N,t[36]=j,t[37]=k):k=t[37],k};function Ry(t){return t.activeProjectId}function My(t){return t.projects}function Fy(t){return t.homeDirectory}function Ly(t){return t.directories}function Oy(t){return t.rightSidebarTab}function _y(t){return t.setRightSidebarTab}function By(t){return t.isRightSidebarOpen}const Vy=1100,Cl=15e3,yd=500,$y=t=>t<=6?t:t<=12?6:t<=25?4:2,hm=a.memo(()=>{const t=pt.c(4),{t:e}=Tt();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),pm={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},zy=pm.M,Vo=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],Wy=t=>{const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"},gm=t=>{const e=Wy(t);return pm[e]??zy},Uy=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},Hy=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Gy=t=>!!t.working_dir?.trim()||t.index==="?",Ky=(t,e)=>sh(t,e),wd=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),vd=(t,e)=>{const n=t.split(`
14
14
  `),r=e.split(`
15
- `),o=Math.min(n.length,r.length);for(let i=0;i<o;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},Hy=t=>{if(!t)return null;const e=t.match(/@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/m);if(!e)return null;const n=Number.parseInt(e[1],10);return!Number.isFinite(n)||n<1?null:n},la=(t,e)=>{const n=t??0,r=e??0;return!n&&!r?null:s.jsxs("span",{className:"typography-meta flex flex-shrink-0 items-center gap-1 text-xs whitespace-nowrap",children:[n?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",n]}):null,r?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",r]}):null]})},Gy=a.memo(t=>{const e=gt.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:o,onSelectFile:i,isMobile:c,showModeSelector:l,mode:u,onModeChange:m}=t,d=l===void 0?!1:l,{t:f}=Tt();let g;e[0]!==c?(g=k=>{if(!c)return k;const D=k.lastIndexOf("/");return D>=0?k.slice(D+1):k},e[0]=c,e[1]=g):g=e[1];const x=g;if(n.length===0)return null;let p;e[2]!==x||e[3]!==o||e[4]!==f?(p=o?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(yr,{filePath:o.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:x(o.path)}),la(o.insertions,o.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:f("diffView.selector.selectFile")}),e[2]=x,e[3]=o,e[4]=f,e[5]=p):p=e[5];let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=y):y=e[6];let b;e[7]!==p?(b=s.jsx(nn,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[p,y]})}),e[7]=p,e[8]=b):b=e[8];let h;e[9]!==u||e[10]!==m||e[11]!==d||e[12]!==f?(h=d&&u&&m?s.jsxs(s.Fragment,{children:[s.jsx(bu,{className:"typography-meta text-muted-foreground",children:f("diffView.selector.viewMode")}),s.jsx(ll,{value:u,onValueChange:k=>m(k),children:Vo.map(k=>s.jsx(cl,{value:k.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:f(k.labelKey)})},k.value))}),s.jsx(Mn,{})]}):null,e[9]=u,e[10]=m,e[11]=d,e[12]=f,e[13]=h):h=e[13];const N=r??"";let w;if(e[14]!==n||e[15]!==x){let k;e[17]!==x?(k=D=>s.jsx(cl,{value:D.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(yr,{filePath:D.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:x(D.path)}),s.jsx("span",{className:"ml-auto",children:la(D.insertions,D.deletions)})]})},D.path),e[17]=x,e[18]=k):k=e[18],w=n.map(k),e[14]=n,e[15]=x,e[16]=w}else w=e[16];let S;e[19]!==i||e[20]!==N||e[21]!==w?(S=s.jsx(ll,{value:N,onValueChange:i,children:w}),e[19]=i,e[20]=N,e[21]=w,e[22]=S):S=e[22];let v;e[23]!==h||e[24]!==S?(v=s.jsxs(rn,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[h,S]}),e[23]=h,e[24]=S,e[25]=v):v=e[25];let j;return e[26]!==v||e[27]!==b?(j=s.jsxs(on,{children:[b,v]}),e[26]=v,e[27]=b,e[28]=j):j=e[28],j}),Ky=a.memo(t=>{const e=gt.c(31),{mode:n,onModeChange:r}=t,{t:o}=Tt();let i,c,l,u,m,d;if(e[0]!==n||e[1]!==o){const w=Vo.find(S=>S.value===n)??Vo[0];c=on,i=nn,d=!0,m="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",l="min-w-0 truncate typography-meta",u=o(w.labelKey),e[0]=n,e[1]=o,e[2]=i,e[3]=c,e[4]=l,e[5]=u,e[6]=m,e[7]=d}else i=e[2],c=e[3],l=e[4],u=e[5],m=e[6],d=e[7];let f;e[8]!==l||e[9]!==u?(f=s.jsx("span",{className:l,children:u}),e[8]=l,e[9]=u,e[10]=f):f=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=g):g=e[11];let x;e[12]!==m||e[13]!==f?(x=s.jsxs("button",{className:m,children:[f,g]}),e[12]=m,e[13]=f,e[14]=x):x=e[14];let p;e[15]!==i||e[16]!==d||e[17]!==x?(p=s.jsx(i,{asChild:d,children:x}),e[15]=i,e[16]=d,e[17]=x,e[18]=p):p=e[18];let y;e[19]!==r?(y=w=>r(w),e[19]=r,e[20]=y):y=e[20];let b;e[21]!==o?(b=Vo.map(w=>s.jsx(cl,{value:w.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:o(w.labelKey)})},w.value)),e[21]=o,e[22]=b):b=e[22];let h;e[23]!==n||e[24]!==b||e[25]!==y?(h=s.jsx(rn,{className:"min-w-[140px]",children:s.jsx(ll,{value:n,onValueChange:y,children:b})}),e[23]=n,e[24]=b,e[25]=y,e[26]=h):h=e[26];let N;return e[27]!==c||e[28]!==h||e[29]!==p?(N=s.jsxs(c,{children:[p,h]}),e[27]=c,e[28]=h,e[29]=p,e[30]=N):N=e[30],N}),qy=a.memo(t=>{const e=gt.c(11),{changedFiles:n,selectedFile:r,onSelectFile:o}=t,{t:i}=Tt();if(n.length===0)return null;let c;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i){let u;e[5]!==o||e[6]!==r||e[7]!==i?(u=m=>{const d=fm(m),f=r===m.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>o(m.path),className:Te("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",f?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(yr,{filePath:m.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:d.color},title:i(d.descriptionKey),"aria-label":i(d.descriptionKey),children:d.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:m.path,children:m.path}),la(m.insertions,m.deletions)]})},m.path)},e[5]=o,e[6]=r,e[7]=i,e[8]=u):u=e[8],c=n.map(u),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=c}else c=e[4];let l;return e[9]!==c?(l=s.jsx(Fn,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:c})}),e[9]=c,e[10]=l):l=e[10],l}),Yy=a.memo(t=>{const e=gt.c(21),{filePath:n,diff:r,isVisible:o,renderSideBySide:i}=t,{t:c}=Tt(),l=r.original.length>0,u=r.modified.length>0;if(!o){let y;return e[0]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=y):y=e[0],y}const m=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",d=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f={contain:"size layout"},e[1]=f):f=e[1];let g;e[2]!==r.original||e[3]!==n||e[4]!==l||e[5]!==d||e[6]!==i||e[7]!==c?(g=l&&s.jsxs("div",{className:d,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:c("diffView.image.original")}),s.jsx("img",{src:r.original,alt:c("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=l,e[5]=d,e[6]=i,e[7]=c,e[8]=g):g=e[8];let x;e[9]!==r.modified||e[10]!==n||e[11]!==u||e[12]!==l||e[13]!==d||e[14]!==i||e[15]!==c?(x=u&&s.jsxs("div",{className:d,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:c(l?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:c("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=u,e[12]=l,e[13]=d,e[14]=i,e[15]=c,e[16]=x):x=e[16];let p;return e[17]!==m||e[18]!==g||e[19]!==x?(p=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:f,children:s.jsxs("div",{className:m,children:[g,x]})}),e[17]=m,e[18]=g,e[19]=x,e[20]=p):p=e[20],p}),Jy=a.memo(t=>{const e=gt.c(20),{filePath:n,diff:r,renderSideBySide:o}=t,{t:i}=Tt(),c=r.original.length>0,l=r.modified.length>0,u=o?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",m=o?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[0]=d):d=e[0];let f;e[1]!==r.original||e[2]!==n||e[3]!==c||e[4]!==m||e[5]!==o||e[6]!==i?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=c,e[4]=m,e[5]=o,e[6]=i,e[7]=f):f=e[7];let g;e[8]!==r.modified||e[9]!==n||e[10]!==l||e[11]!==c||e[12]!==m||e[13]!==o||e[14]!==i?(g=l&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=l,e[11]=c,e[12]=m,e[13]=o,e[14]=i,e[15]=g):g=e[15];let x;return e[16]!==u||e[17]!==f||e[18]!==g?(x=s.jsx("div",{className:"w-full overflow-auto p-4",style:d,children:s.jsxs("div",{className:u,children:[f,g]})}),e[16]=u,e[17]=f,e[18]=g,e[19]=x):x=e[19],x}),Qy=a.memo(t=>{const e=gt.c(15),{filePath:n,diff:r,renderSideBySide:o,wrapLines:i}=t;let c;e[0]!==n?(c=_i(n)||"text",e[0]=n,e[1]=c):c=e[1];const l=c;if(r.isBinary){let d;return e[2]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(um,{}),e[2]=d):d=e[2],d}if(Bi(n)){let d;return e[3]!==r||e[4]!==n||e[5]!==o?(d=s.jsx(Jy,{filePath:n,diff:r,renderSideBySide:o}),e[3]=r,e[4]=n,e[5]=o,e[6]=d):d=e[6],d}let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"layout"},e[7]=u):u=e[7];let m;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==l||e[12]!==o||e[13]!==i?(m=s.jsx("div",{className:"w-full",style:u,children:s.jsx(Xl,{original:r.original,modified:r.modified,language:l,fileName:n,renderSideBySide:o,wrapLines:i,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=l,e[12]=o,e[13]=i,e[14]=m):m=e[14],m}),Xy=a.memo(t=>{const e=gt.c(15),{filePath:n,diff:r,isVisible:o,renderSideBySide:i,wrapLines:c}=t;let l;e[0]!==n?(l=_i(n)||"text",e[0]=n,e[1]=l):l=e[1];const u=l;if(r.isBinary){let d;return e[2]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(um,{}),e[2]=d):d=e[2],d}if(!o)return null;if(Bi(n)){let d;return e[3]!==r||e[4]!==n||e[5]!==o||e[6]!==i?(d=s.jsx(Yy,{filePath:n,diff:r,isVisible:o,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=o,e[6]=i,e[7]=d):d=e[7],d}let m;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==u||e[12]!==i||e[13]!==c?(m=s.jsx(Fn,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Xl,{original:r.original,modified:r.modified,language:u,fileName:n,renderSideBySide:i,wrapLines:c,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=u,e[12]=i,e[13]=c,e[14]=m):m=e[14],m}),Zy=a.memo(t=>{const e=gt.c(129),{directory:n,file:r,layout:o,wrapLines:i,scrollRootRef:c,isSelected:l,onSelect:u,registerSectionRef:m,defaultCollapsed:d,expandRequestPath:f,expandRequestNonce:g,showOpenInEditorAction:x,isOpeningInEditor:p,onOpenInEditor:y,staged:b,stagedRevision:h}=t,N=d===void 0?!1:d,w=f===void 0?null:f,S=g===void 0?0:g,v=x===void 0?!1:x,j=p===void 0?!1:p,k=b===void 0?!1:b,D=h===void 0?0:h,{t:T}=Tt(),{git:C}=Wn();let P;e[0]!==n||e[1]!==r.path?(P=dt=>dt.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=P):P=e[2];const E=_s(P),M=_s(ew),H=Fe(tw),[R,_]=a.useState(!N),[z,V]=a.useState(!1),[F,te]=a.useState(0),[Z,ne]=a.useState(null),[U,ie]=a.useState(!1),[oe,ge]=a.useState(!1),[je,Se]=a.useState(null),re=a.useRef(null),L=a.useRef(null);let $;e[3]!==r?($=fm(r),e[3]=r,e[4]=$):$=e[4];const q=$,he=o==="side-by-side";let de;e:{if(k){de=je;break e}if(!E){de=null;break e}let dt;e[5]!==E.isBinary||e[6]!==E.modified||e[7]!==E.original?(dt={original:E.original,modified:E.modified,isBinary:E.isBinary},e[5]=E.isBinary,e[6]=E.modified,e[7]=E.original,e[8]=dt):dt=e[8],de=dt}const we=de;let be;e[9]!==r.path||e[10]!==m?(be=dt=>{L.current=dt,m(r.path,dt)},e[9]=r.path,e[10]=m,e[11]=be):be=e[11];const De=be;let le;e[12]===Symbol.for("react.memo_cache_sentinel")?(le=dt=>{_(dt),dt&&V(!0)},e[12]=le):le=e[12];const ke=le;let ue;e[13]!==r.path||e[14]!==u?(ue=()=>{u(r.path)},e[13]=r.path,e[14]=u,e[15]=ue):ue=e[15];const ve=ue;let G,Ae;e[16]!==z||e[17]!==R||e[18]!==c?(G=()=>{if(!R||z)return;const dt=L.current;if(!dt)return;if(!c.current||typeof IntersectionObserver>"u"){V(!0);return}const bt=new IntersectionObserver(He=>{He.some(sw)&&(V(!0),bt.disconnect())},{root:c.current,rootMargin:"200px 0px",threshold:.1});return bt.observe(dt),()=>bt.disconnect()},Ae=[z,R,c],e[16]=z,e[17]=R,e[18]=c,e[19]=G,e[20]=Ae):(G=e[19],Ae=e[20]),a.useEffect(G,Ae);let ce,fe;e[21]!==S||e[22]!==w||e[23]!==r.path?(ce=()=>{S<=0||w!==r.path||(_(!0),V(!0))},fe=[S,w,r.path],e[21]=S,e[22]=w,e[23]=r.path,e[24]=ce,e[25]=fe):(ce=e[24],fe=e[25]),a.useEffect(ce,fe);let Ee;e[26]!==k?(Ee=()=>{k&&(Se(null),ne(null),re.current=null)},e[26]=k,e[27]=Ee):Ee=e[27];let me;e[28]!==k||e[29]!==D?(me=[k,D],e[28]=k,e[29]=D,e[30]=me):me=e[30],a.useEffect(Ee,me);let B,ye;e[31]!==we||e[32]!==F||e[33]!==n||e[34]!==r.path||e[35]!==C||e[36]!==z||e[37]!==R||e[38]!==M||e[39]!==k||e[40]!==D?(B=()=>{if(!R||!z)return;if(!n||we){re.current=null,ie(!1);return}const dt=`${n}::${r.path}::${k?`staged:${D}`:"unstaged"}::${F}`;if(re.current===dt)return;re.current=dt,ne(null),ie(!0);let bt=!1;const He=C.getGitFileDiff(n,{path:r.path,staged:k}),Ze=new Promise(nw);return Promise.race([He,Ze]).then(Ue=>{if(bt)return;const jt={original:Ue.original??"",modified:Ue.modified??"",isBinary:Ue.isBinary};k?Se(jt):M(n,r.path,jt),ie(!1)}).catch(Ue=>{if(bt)return;const jt=Ue instanceof Error?Ue.message:String(Ue);ne(jt),ie(!1)}),()=>{bt=!0,re.current===dt&&(re.current=null)}},ye=[n,we,F,r.path,C,z,R,M,k,D],e[31]=we,e[32]=F,e[33]=n,e[34]=r.path,e[35]=C,e[36]=z,e[37]=R,e[38]=M,e[39]=k,e[40]=D,e[41]=B,e[42]=ye):(B=e[41],ye=e[42]),a.useEffect(B,ye);let Oe;e[43]!==ve||e[44]!==R?(Oe=()=>{ke(!R),ve()},e[43]=ve,e[44]=R,e[45]=Oe):Oe=e[45];const Q=Oe,Me=R?"rounded-b-none":"rounded-b-xl",Re=l?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let Ne;e[46]!==Me||e[47]!==Re?(Ne=Te("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Me,"text-muted-foreground hover:text-foreground",Re),e[46]=Me,e[47]=Re,e[48]=Ne):Ne=e[48];let Be;e[49]===Symbol.for("react.memo_cache_sentinel")?(Be=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[49]=Be):Be=e[49];let se;e[50]!==R?(se=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:R?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"})}),e[50]=R,e[51]=se):se=e[51];let O;e[52]!==q.color?(O={color:q.color},e[52]=q.color,e[53]=O):O=e[53];let A;e[54]!==q.descriptionKey||e[55]!==T?(A=T(q.descriptionKey),e[54]=q.descriptionKey,e[55]=T,e[56]=A):A=e[56];let K;e[57]!==q.descriptionKey||e[58]!==T?(K=T(q.descriptionKey),e[57]=q.descriptionKey,e[58]=T,e[59]=K):K=e[59];let pe;e[60]!==q.code||e[61]!==O||e[62]!==A||e[63]!==K?(pe=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:O,title:A,"aria-label":K,children:q.code}),e[60]=q.code,e[61]=O,e[62]=A,e[63]=K,e[64]=pe):pe=e[64];const _e=r.path;let We;e[65]!==r.path?(We=s.jsx(yr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[65]=r.path,e[66]=We):We=e[66];let Le;if(e[67]!==r.path){e:{const dt=r.path.lastIndexOf("/");if(dt===-1){let Et;e[69]===Symbol.for("react.memo_cache_sentinel")?(Et={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[69]=Et):Et=e[69],Le=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:Et,children:r.path});break e}const bt=r.path.slice(0,dt),He=r.path.slice(dt+1);let Ze;e[70]===Symbol.for("react.memo_cache_sentinel")?(Ze={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[70]=Ze):Ze=e[70];let Ue;e[71]!==bt?(Ue=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:Ze,children:bt}),e[71]=bt,e[72]=Ue):Ue=e[72];let jt;e[73]===Symbol.for("react.memo_cache_sentinel")?(jt=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[73]=jt):jt=e[73];let Ge;e[74]!==He?(Ge=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[jt,s.jsx("span",{className:"text-foreground",children:He})]}),e[74]=He,e[75]=Ge):Ge=e[75];let it;e[76]!==Ue||e[77]!==Ge?(it=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[Ue,Ge]}),e[76]=Ue,e[77]=Ge,e[78]=it):it=e[78],Le=it}e[67]=r.path,e[68]=Le}else Le=e[68];let rt;e[79]!==We||e[80]!==Le?(rt=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[We,Le]}),e[79]=We,e[80]=Le,e[81]=rt):rt=e[81];let yt;e[82]!==r.path||e[83]!==rt?(yt=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:_e,children:rt}),e[82]=r.path,e[83]=rt,e[84]=yt):yt=e[84];let Dt;e[85]!==se||e[86]!==pe||e[87]!==yt?(Dt=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[se,pe,yt]}),e[85]=se,e[86]=pe,e[87]=yt,e[88]=Dt):Dt=e[88];let st;e[89]!==r.deletions||e[90]!==r.insertions?(st=la(r.insertions,r.deletions),e[89]=r.deletions,e[90]=r.insertions,e[91]=st):st=e[91];let Pe;e[92]!==we||e[93]!==r.path||e[94]!==j||e[95]!==y||e[96]!==v||e[97]!==T?(Pe=v&&y?s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:T("diffView.actions.openFileInEditorAtChange"),onClick:dt=>{dt.stopPropagation(),y(r.path,we)},disabled:j,children:j?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}):null,e[92]=we,e[93]=r.path,e[94]=j,e[95]=y,e[96]=v,e[97]=T,e[98]=Pe):Pe=e[98];const tt=he?"side-by-side":"unified";let Ye;e[99]!==r.path||e[100]!==H?(Ye=dt=>{const bt=dt==="side-by-side"?"side-by-side":"inline";H(r.path,bt)},e[99]=r.path,e[100]=H,e[101]=Ye):Ye=e[101];let nt;e[102]!==tt||e[103]!==Ye?(nt=s.jsx(Tu,{mode:tt,onModeChange:Ye,className:"opacity-70"}),e[102]=tt,e[103]=Ye,e[104]=nt):nt=e[104];let ft;e[105]!==st||e[106]!==Pe||e[107]!==nt?(ft=s.jsxs("div",{className:"relative flex items-center gap-2",children:[st,Pe,nt]}),e[105]=st,e[106]=Pe,e[107]=nt,e[108]=ft):ft=e[108];let mt;e[109]!==Q||e[110]!==Ne||e[111]!==Dt||e[112]!==ft?(mt=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:Q,className:Ne,children:[Be,Dt,ft]})}),e[109]=Q,e[110]=Ne,e[111]=Dt,e[112]=ft,e[113]=mt):mt=e[113];let ot;e[114]!==we||e[115]!==Z||e[116]!==r.deletions||e[117]!==r.insertions||e[118]!==r.path||e[119]!==oe||e[120]!==R||e[121]!==U||e[122]!==he||e[123]!==i?(ot=R&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[Z?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:Z}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>te(rw),children:"Retry"})]}):null,U&&!we&&!Z?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff…"]}):null,we&&!oe&&r.insertions+r.deletions>gd?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsxs("div",{className:"typography-ui-label font-semibold text-foreground",children:["Large diff (",r.insertions+r.deletions," changed lines)"]}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>ge(!0),children:"Render anyway"})]}):null,we&&(oe||r.insertions+r.deletions<=gd)?s.jsx(Qy,{filePath:r.path,diff:we,renderSideBySide:he,wrapLines:i}):null]}),e[114]=we,e[115]=Z,e[116]=r.deletions,e[117]=r.insertions,e[118]=r.path,e[119]=oe,e[120]=R,e[121]=U,e[122]=he,e[123]=i,e[124]=ot):ot=e[124];let It;return e[125]!==De||e[126]!==mt||e[127]!==ot?(It=s.jsxs("div",{ref:De,className:"scroll-mt-4",children:[mt,ot]}),e[125]=De,e[126]=mt,e[127]=ot,e[128]=It):It=e[128],It}),hm=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:o=!1,diffScope:i="all",targetFilePath:c=null})=>{const{t:l}=Tt(),{git:u,files:m}=Wn(),d=ti(),{screenWidth:f,isMobile:g}=Pr(),x=zl(d??null),p=ya(d??null),y=Wl(d??null),b=_s(Pe=>Pe.setActiveDirectory),h=_s(Pe=>Pe.ensureStatus),N=_s(Pe=>Pe.fetchStatus),w=_s(Pe=>Pe.setDiff),S=_s(a.useCallback(Pe=>d?Pe.directories.get(d)?.indexRevision??0:0,[d])),[v,j]=a.useState(null),[k,D]=a.useState(!1),[T,C]=a.useState(null),[P,E]=a.useState(null),[M,H]=a.useState(0),[R,_]=a.useState(null),[z,V]=a.useState(0),[F,te]=a.useState(null),Z=a.useRef(null),ne=Fe(Pe=>Pe.pendingDiffFile),U=Fe(Pe=>Pe.pendingDiffStaged),ie=Fe(Pe=>Pe.setPendingDiffFile),oe=Fe(Pe=>Pe.diffLayoutPreference),ge=Fe(Pe=>Pe.diffFileLayout),je=Fe(Pe=>Pe.setDiffFileLayout),Se=Fe(Pe=>Pe.diffWrapLines),re=Fe(Pe=>Pe.setDiffWrapLines),L=Fe(Pe=>Pe.diffViewMode),$=Fe(Pe=>Pe.setDiffViewMode),q=Fe(Pe=>Pe.openContextFileAtLine),he=Se,de=i==="staged"?!0:i==="working"?!1:null,we=de??k,be=L==="stacked",De=g||f<=768,le=!t&&!De&&f>=1024,ke=a.useRef(null),ue=a.useRef(new Map),ve=a.useRef(null),G=a.useRef(null),Ae=a.useRef(!1);a.useEffect(()=>{if(!r||!be||!R)return;const Pe=ke.current;if(!Pe)return;let tt=null,Ye=!1,nt=0;const ft=Date.now()+1200;let mt=0;const ot=()=>{Ye||(Ye=!0,_(null))},It=()=>{ot()},dt=()=>{if(mt>0){mt-=1;return}ot()};window.addEventListener("wheel",It,{passive:!0,capture:!0}),window.addEventListener("touchstart",It,{passive:!0,capture:!0}),window.addEventListener("pointerdown",It,{capture:!0}),window.addEventListener("keydown",It,{capture:!0}),Pe.addEventListener("scroll",dt,{passive:!0});const bt=()=>{if(Ye||Date.now()>ft){ot();return}const He=ke.current,Ze=ue.current.get(R);if(!He||!Ze){ot();return}const Ue=He.getBoundingClientRect(),Ge=Ze.getBoundingClientRect().top-Ue.top;if(Math.abs(Ge)<=1){if(nt+=1,nt>=2){ot();return}}else{nt=0;const it=Math.max(0,He.scrollHeight-He.clientHeight),Et=Math.min(it,Math.max(0,He.scrollTop+Ge));if(Math.abs(Et-He.scrollTop)<=.5){ot();return}mt+=1,He.scrollTop=Et}tt=window.requestAnimationFrame(bt)};return tt=window.requestAnimationFrame(bt),()=>{Ye=!0,tt!==null&&window.cancelAnimationFrame(tt),window.removeEventListener("wheel",It,!0),window.removeEventListener("touchstart",It,!0),window.removeEventListener("pointerdown",It,!0),window.removeEventListener("keydown",It,!0),Pe.removeEventListener("scroll",dt)}},[be,r,R]);const ce=a.useMemo(()=>{if(!p?.files)return[];const Pe=p.diffStats??{},tt=i==="staged"?zy:i==="working"?Wy:()=>!0;return p.files.filter(tt).map(Ye=>({...Ye,insertions:Pe[Ye.path]?.insertions??0,deletions:Pe[Ye.path]?.deletions??0,isNew:$y(Ye)})).sort((Ye,nt)=>Ye.path.localeCompare(nt.path))},[i,p]),fe=a.useMemo(()=>v?ce.find(Pe=>Pe.path===v)??null:null,[ce,v]),Ee=a.useCallback(Pe=>{const tt=ge[Pe.path];if(tt)return tt;if(oe==="inline")return"inline";if(oe==="side-by-side")return"side-by-side";const Ye=f<Oy;return Pe.isNew||Ye?"inline":"side-by-side"},[ge,oe,f]),me=a.useMemo(()=>fe?Ee(fe):null,[Ee,fe]);a.useEffect(()=>{d&&(b(d),h(d,u))},[d,b,h,u]),a.useEffect(()=>{if(d)return Ir.onGitRefreshHint(Pe=>{xd(Pe.directory)===xd(d)&&N(d,u)})},[d,N,u]),a.useEffect(()=>{i==="all"&&ne&&(j(ne),D(U),C(null),ie(null),be&&(Ae.current=!0,ve.current=ne,E(ne),H(Pe=>Pe+1)))},[i,be,ne,U,ie]),a.useEffect(()=>{if(i==="all")return;const Pe=c?.trim();Pe&&(j(Pe),D(i==="staged"),C(null),be&&(Ae.current=!0,ve.current=Pe,E(Pe),H(tt=>tt+1)))},[i,be,c]),a.useEffect(()=>{we&&(C(null),te(null),Z.current=null)},[we,S]),a.useEffect(()=>{!v&&!ne&&ce.length>0&&j(ce[0].path)},[ce,v,ne]),a.useEffect(()=>{v&&ce.length>0&&(ce.some(tt=>tt.path===v)||j(ce[0]?.path??null))},[ce,v]);const B=a.useCallback((Pe,tt)=>{const Ye=ue.current;tt?Ye.set(Pe,tt):Ye.delete(Pe)},[]),ye=a.useCallback(Pe=>{const tt=ue.current.get(Pe),Ye=ke.current;if(!tt||!Ye)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const nt=Ye.getBoundingClientRect(),mt=tt.getBoundingClientRect().top-nt.top,ot=Math.max(0,Ye.scrollHeight-Ye.clientHeight),It=Ye.scrollTop+mt,dt=Math.min(ot,Math.max(0,It)),bt=Math.abs(dt-Ye.scrollTop)>.5;Ye.scrollTop=dt;const He=Math.abs(mt)<=1,Ze=dt<=.5||dt>=ot-.5;return{ok:!0,aligned:He,didMove:bt,atScrollLimit:Ze,delta:mt}},[]);a.useEffect(()=>{if(!be){ve.current=null,Ae.current=!1,G.current!==null&&(window.cancelAnimationFrame(G.current),G.current=null);return}if(!ve.current)return;let tt=0;const Ye=120;let nt=!1,ft=0,mt=!1,ot=0;const It=Date.now()+2e3,dt=()=>{mt||(mt=!0,window.removeEventListener("wheel",He,!0),window.removeEventListener("touchstart",He,!0),window.removeEventListener("pointerdown",He,!0),window.removeEventListener("keydown",He,!0),Ue?.removeEventListener("scroll",Ze))},bt=()=>{nt||(nt=!0,dt(),ve.current=null,Ae.current=!1,G.current!==null&&(window.cancelAnimationFrame(G.current),G.current=null))},He=()=>{bt()},Ze=()=>{if(ft>0){ft-=1;return}bt()},Ue=ke.current;window.addEventListener("wheel",He,{passive:!0,capture:!0}),window.addEventListener("touchstart",He,{passive:!0,capture:!0}),window.addEventListener("pointerdown",He,{capture:!0}),window.addEventListener("keydown",He,{capture:!0}),Ue?.addEventListener("scroll",Ze,{passive:!0});const jt=()=>{if(Date.now()>It){bt(),G.current=null;return}if(nt){G.current=null;return}const Ge=ve.current;if(!Ge){bt(),G.current=null;return}ft+=1;const it=ye(Ge);if(!it.ok){ft=Math.max(0,ft-1),tt+=1,tt<Ye?G.current=window.requestAnimationFrame(jt):(bt(),G.current=null);return}if(!it.aligned){if(tt+=1,it.didMove){if(ot=0,tt<Ye){G.current=window.requestAnimationFrame(jt);return}}else if(ot+=1,ot<6&&(it.atScrollLimit||Math.abs(it.delta)>1)){G.current=window.requestAnimationFrame(jt);return}}r&&Ae.current&&_(Ge),bt()};return G.current=window.requestAnimationFrame(jt),()=>{nt=!0,dt(),G.current!==null&&(window.cancelAnimationFrame(G.current),G.current=null)}},[be,r,ye,v,M]);const Oe=a.useCallback(Pe=>{j(Pe),D(!1),C(null)},[]),Q=a.useCallback(Pe=>{if(G.current!==null&&(window.cancelAnimationFrame(G.current),G.current=null),ve.current=null,j(Pe),D(!1),C(null),!be){Ae.current=!1;return}Ae.current=!0,ve.current=Pe,ye(Pe)},[be,ye]),Me=a.useCallback(Pe=>{$(Pe),Pe==="stacked"&&v&&(ye(v).aligned||(ve.current=v))},[ye,v,$]),Re=a.useCallback(Pe=>{const tt=Pe==="side-by-side"?"side-by-side":"inline";if(be){ce.forEach(Ye=>{je(Ye.path,tt)});return}fe&&je(fe.path,tt)},[ce,be,fe,je]),Ne=(me??"side-by-side")==="side-by-side",Be=!n&&(!be||!le),se=_s(a.useCallback(Pe=>!d||!v||we?null:Pe.directories.get(d)?.diffCache.get(v)??null,[we,d,v])),O=a.useMemo(()=>we?T:se?{original:se.original,modified:se.modified,isBinary:se.isBinary}:null,[we,se,T]),[A,K]=a.useState(null),pe=a.useCallback(async(Pe,tt)=>{if(!(!d||!Pe)){K(Pe);try{let Ye=null;if(tt&&!tt.isBinary&&!Bi(Pe)&&(Ye=bd(tt.original,tt.modified)),Ye===null)try{const It=await u.getGitDiff(d,{path:Pe,staged:we,contextLines:3});Ye=Hy(It.diff)}catch{Ye=null}let nt=tt;if(Ye===null||!nt){const It=await u.getGitFileDiff(d,{path:Pe,staged:we});nt={original:It.original??"",modified:It.modified??"",isBinary:It.isBinary},we||w(d,Pe,nt)}const ft=Ye??(nt.isBinary||Bi(Pe)?1:bd(nt.original,nt.modified)),mt=Uy(d,Pe),ot=await sc(m,mt);if(!ot.ok){ae.error(nc(ot.reason));return}q(d,mt,ft,1)}finally{K(Ye=>Ye===Pe?null:Ye)}}},[we,d,m,u,q,w]),_e=a.useCallback(async()=>{v&&await pe(v,O)},[pe,O,v]),We=!!(v&&A===v),Le=we?!!T:!!se,rt=!be&&!!v&&!Le;a.useEffect(()=>{if(be)return;if(te(null),!d||!v){Z.current=null;return}if(we?T:se){Z.current=null;return}const Pe=`${d}::${v}::${we?`staged:${S}`:"unstaged"}::${z}`;if(Z.current===Pe)return;Z.current=Pe;let tt=!1;const Ye=u.getGitFileDiff(d,{path:v,staged:we}),nt=kl,ft=new Promise((mt,ot)=>{setTimeout(()=>ot(new Error(`Timed out after ${nt}ms`)),nt)});return Promise.race([Ye,ft]).then(mt=>{if(tt)return;const ot={original:mt.original??"",modified:mt.modified??"",isBinary:mt.isBinary};we?C(ot):w(d,v,ot)}).catch(mt=>{if(tt)return;const ot=mt instanceof Error?mt.message:String(mt);te(ot)}),()=>{tt=!0,Z.current===Pe&&(Z.current=null)}},[we,d,S,be,v,se,T,u,w,z]);const yt=()=>!d||!v||!O?null:s.jsx(Xy,{filePath:v,diff:O,isVisible:!0,renderSideBySide:Ne,wrapLines:he},v),Dt=()=>{if(!d)return null;const Pe=_y(ce.length),tt=Ye=>de!==null?de:k&&Ye===v;return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[le&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:l("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:ce.length})]}),s.jsx(qy,{changedFiles:ce,selectedFile:v,onSelectFile:Q})]}),s.jsx(Fn,{ref:ke,outerClassName:"flex-1 min-h-0 h-full",className:"pr-2",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx("div",{className:"flex flex-col gap-3",children:ce.map((Ye,nt)=>s.jsx(Zy,{directory:d,file:Ye,layout:Ee(Ye),wrapLines:he,scrollRootRef:ke,isSelected:Ye.path===v,onSelect:Oe,registerSectionRef:B,defaultCollapsed:e?!0:nt>=Pe,expandRequestPath:P,expandRequestNonce:M,showOpenInEditorAction:o,isOpeningInEditor:A===Ye.path,onOpenInEditor:(ft,mt)=>{pe(ft,mt)},staged:tt(Ye.path),stagedRevision:S},`${tt(Ye.path)?"staged":"unstaged"}:${Ye.path}`))})})]})},st=()=>d?y&&!p?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),l("diffView.state.loadingRepositoryStatus")]}):x===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:l("diffView.state.notGitRepository")}):ce.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:l("diffView.state.cleanWorkingTree")}):be?Dt():s.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden px-3 py-3 relative","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[yt(),rt&&!Le&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:F?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:l("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:F}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{te(null),V(Pe=>Pe+1)},children:l("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),l("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:l("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!g&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(I,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:y&&!p?l("diffView.state.loadingChanges"):ce.length===1?l("diffView.summary.changedFilesSingle",{count:ce.length}):l("diffView.summary.changedFilesPlural",{count:ce.length})})]}),!De&&s.jsx(Ky,{mode:L,onModeChange:Me}),Be&&s.jsx(Gy,{changedFiles:ce,selectedFile:v,selectedFileEntry:fe,onSelectFile:Q,isMobile:De,showModeSelector:De,mode:L,onModeChange:Me}),s.jsx("div",{className:"flex-1"}),fe&&s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>re(!Se),className:Te("h-5 w-5 p-0 transition-opacity",he?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:l(he?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})}),o&&fe&&!be&&s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{_e()},disabled:We,title:l("diffView.actions.openFileAtFirstChangedLine"),children:We?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}),fe&&me&&s.jsx(Tu,{mode:me==="side-by-side"?"side-by-side":"unified",onModeChange:Re})]}),st()]})};function ew(t){return t.setDiff}function tw(t){return t.setDiffFileLayout}function sw(t){return t.isIntersecting}function nw(t,e){setTimeout(()=>e(new Error(`Timed out after ${kl}ms`)),kl)}function rw(t){return t+1}const iw=(t,e)=>{if(!e)return null;const n=Number.parseInt(t.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},yd=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},wd=(t,e,n)=>{const r=t.state.doc.line(e),o=Math.max(1,Math.min(n,r.length+1)),i=r.from+o-1;t.dispatch({selection:Jm.cursor(i),effects:Kr.scrollIntoView(i,{y:"center"})})};function ow({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:o}=Tt(),[i,c]=a.useState(""),l=a.useRef(null),u=a.useRef(!1),m=a.useRef(null),d=a.useRef(null),f=a.useMemo(()=>iw(i,n),[i,n]);a.useEffect(()=>{!t||!n||(u.current=!1,l.current=yd(n,n.state.selection),c(""))},[t,n]),a.useEffect(()=>{t&&window.requestAnimationFrame(()=>{d.current?.focus(),d.current?.select()})},[t]),a.useEffect(()=>{if(!(!t||!n||!l.current)){if(f===null){const{selection:b}=l.current;n.dispatch({selection:b,effects:Kr.scrollIntoView(b.main.from,{y:"center"})});return}wd(n,f,l.current.character)}},[f,t,n]);const g=a.useCallback(()=>{if(!n||u.current||!l.current)return;const{selection:b}=l.current;n.dispatch({selection:b,effects:Kr.scrollIntoView(b.main.from,{y:"center"})})},[n]),x=a.useCallback(b=>{b||g(),e(b)},[e,g]),p=a.useCallback(()=>{!n||f===null||!l.current||(u.current=!0,wd(n,f,l.current.character),e(!1),n.focus())},[f,e,n]);a.useEffect(()=>{if(!t)return;const b=N=>{const w=m.current,S=N.target;!w||!(S instanceof Node)||w.contains(S)||x(!1)},h=N=>{N.key==="Escape"&&(N.preventDefault(),x(!1))};return document.addEventListener("pointerdown",b,!0),document.addEventListener("keydown",h,!0),()=>{document.removeEventListener("pointerdown",b,!0),document.removeEventListener("keydown",h,!0)}},[x,t,r]);const y=a.useMemo(()=>{if(!n)return o("goToLineDialog.helper.editorUnavailable");if(f===null){const b=l.current??yd(n,n.state.selection);return o("goToLineDialog.helper.currentLineRange",{current:b.lineNumber,max:n.state.doc.lines})}return o("goToLineDialog.helper.goToLine",{line:f})},[f,o,n]);return r==="inline"?t?s.jsxs("div",{ref:m,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(kn,{ref:d,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:b=>c(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),p())},placeholder:o("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ze,{variant:"outline",size:"xs",onClick:p,disabled:!n||f===null,className:"h-6 px-2",children:o("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:m,className:Te("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(kn,{ref:d,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:b=>c(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),p())},placeholder:o("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:y})]})})}const aw=t=>{const e=tn(t);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const r=e.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},lw=t=>{const e=gt.c(8),{label:n,iconDataUrl:r}=t,[o,i]=a.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const l=c;if(r&&!o){let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=()=>i(!0),e[2]=d):d=e[2];let f;return e[3]!==r?(f=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:d}),e[3]=r,e[4]=f):f=e[4],f}let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=Te("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=u):u=e[5];let m;return e[6]!==l?(m=s.jsx("span",{className:u,children:l}),e[6]=l,e[7]=m):m=e[7],m},cw=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),tn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const o=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!o&&!i&&(r=r.replace(/\/+$/,"")),r},dw=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),vd=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,ca=(t,e)=>{const n=tn(e),r=tn(t);if(!n||!r)return!1;const o=vd(n),i=vd(r);return i===o||i.startsWith(`${o}/`)},jd=(t,e)=>{const n=tn(e),r=tn(t);if(!ca(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),c=[];let l=n;for(let u=0;u<i.length-1;u++)l=l?`${l}/${i[u]}`:i[u],c.push(l);return c},Cl=(t,e)=>{if(!e)return"";const n=tn(e);if(!t||!ca(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},uw=new Set(["node_modules"]),mw=t=>{const e=gt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let i;return e[1]!==o?(i=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=i):i=e[2],i},Sd=t=>{const e=gt.c(11),{name:n}=t,r=a.useRef(null),o=a.useRef(null),[i,c]=a.useState(!1);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{const g=r.current,x=o.current;if(!g||!x)return;const p=()=>{c(x.scrollWidth>g.clientWidth+1)};p();const y=new ResizeObserver(p);return y.observe(g),y.observe(x),()=>{y.disconnect()}},e[0]=l):l=e[0];let u;e[1]!==n?(u=[n],e[1]=n,e[2]=u):u=e[2],a.useLayoutEffect(l,u);let m;e[3]!==n?(m=s.jsx("span",{ref:o,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=m):m=e[4];let d;e[5]!==n||e[6]!==i?(d=i?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:n}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):s.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=i,e[7]=d):d=e[7];let f;return e[8]!==m||e[9]!==d?(f=s.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[m,d]}),e[8]=m,e[9]=d,e[10]=f):f=e[10],f},fw=t=>uw.has(t),hw=t=>{const e=tn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},pw=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Nd=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},Zi=2e5,pm="openchamber:files:auto-save-enabled",gw=t=>{let e=0,n=0;for(let r=0;r<t.length;r+=1)t.charCodeAt(r)===10&&(r>0&&t.charCodeAt(r-1)===13?e+=1:n+=1);return e>n?`\r
15
+ `),o=Math.min(n.length,r.length);for(let i=0;i<o;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},qy=t=>{if(!t)return null;const e=t.match(/@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/m);if(!e)return null;const n=Number.parseInt(e[1],10);return!Number.isFinite(n)||n<1?null:n},la=(t,e)=>{const n=t??0,r=e??0;return!n&&!r?null:s.jsxs("span",{className:"typography-meta flex flex-shrink-0 items-center gap-1 text-xs whitespace-nowrap",children:[n?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",n]}):null,r?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",r]}):null]})},Yy=a.memo(t=>{const e=pt.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:o,onSelectFile:i,isMobile:c,showModeSelector:l,mode:u,onModeChange:m}=t,d=l===void 0?!1:l,{t:f}=Tt();let g;e[0]!==c?(g=k=>{if(!c)return k;const A=k.lastIndexOf("/");return A>=0?k.slice(A+1):k},e[0]=c,e[1]=g):g=e[1];const x=g;if(n.length===0)return null;let p;e[2]!==x||e[3]!==o||e[4]!==f?(p=o?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(xr,{filePath:o.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:x(o.path)}),la(o.insertions,o.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:f("diffView.selector.selectFile")}),e[2]=x,e[3]=o,e[4]=f,e[5]=p):p=e[5];let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=y):y=e[6];let b;e[7]!==p?(b=s.jsx(sn,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[p,y]})}),e[7]=p,e[8]=b):b=e[8];let h;e[9]!==u||e[10]!==m||e[11]!==d||e[12]!==f?(h=d&&u&&m?s.jsxs(s.Fragment,{children:[s.jsx(vu,{className:"typography-meta text-muted-foreground",children:f("diffView.selector.viewMode")}),s.jsx(cl,{value:u,onValueChange:k=>m(k),children:Vo.map(k=>s.jsx(dl,{value:k.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:f(k.labelKey)})},k.value))}),s.jsx(On,{})]}):null,e[9]=u,e[10]=m,e[11]=d,e[12]=f,e[13]=h):h=e[13];const N=r??"";let w;if(e[14]!==n||e[15]!==x){let k;e[17]!==x?(k=A=>s.jsx(dl,{value:A.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(xr,{filePath:A.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:x(A.path)}),s.jsx("span",{className:"ml-auto",children:la(A.insertions,A.deletions)})]})},A.path),e[17]=x,e[18]=k):k=e[18],w=n.map(k),e[14]=n,e[15]=x,e[16]=w}else w=e[16];let S;e[19]!==i||e[20]!==N||e[21]!==w?(S=s.jsx(cl,{value:N,onValueChange:i,children:w}),e[19]=i,e[20]=N,e[21]=w,e[22]=S):S=e[22];let v;e[23]!==h||e[24]!==S?(v=s.jsxs(nn,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[h,S]}),e[23]=h,e[24]=S,e[25]=v):v=e[25];let j;return e[26]!==v||e[27]!==b?(j=s.jsxs(rn,{children:[b,v]}),e[26]=v,e[27]=b,e[28]=j):j=e[28],j}),Jy=a.memo(t=>{const e=pt.c(31),{mode:n,onModeChange:r}=t,{t:o}=Tt();let i,c,l,u,m,d;if(e[0]!==n||e[1]!==o){const w=Vo.find(S=>S.value===n)??Vo[0];c=rn,i=sn,d=!0,m="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",l="min-w-0 truncate typography-meta",u=o(w.labelKey),e[0]=n,e[1]=o,e[2]=i,e[3]=c,e[4]=l,e[5]=u,e[6]=m,e[7]=d}else i=e[2],c=e[3],l=e[4],u=e[5],m=e[6],d=e[7];let f;e[8]!==l||e[9]!==u?(f=s.jsx("span",{className:l,children:u}),e[8]=l,e[9]=u,e[10]=f):f=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=g):g=e[11];let x;e[12]!==m||e[13]!==f?(x=s.jsxs("button",{className:m,children:[f,g]}),e[12]=m,e[13]=f,e[14]=x):x=e[14];let p;e[15]!==i||e[16]!==d||e[17]!==x?(p=s.jsx(i,{asChild:d,children:x}),e[15]=i,e[16]=d,e[17]=x,e[18]=p):p=e[18];let y;e[19]!==r?(y=w=>r(w),e[19]=r,e[20]=y):y=e[20];let b;e[21]!==o?(b=Vo.map(w=>s.jsx(dl,{value:w.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:o(w.labelKey)})},w.value)),e[21]=o,e[22]=b):b=e[22];let h;e[23]!==n||e[24]!==b||e[25]!==y?(h=s.jsx(nn,{className:"min-w-[140px]",children:s.jsx(cl,{value:n,onValueChange:y,children:b})}),e[23]=n,e[24]=b,e[25]=y,e[26]=h):h=e[26];let N;return e[27]!==c||e[28]!==h||e[29]!==p?(N=s.jsxs(c,{children:[p,h]}),e[27]=c,e[28]=h,e[29]=p,e[30]=N):N=e[30],N}),Qy=a.memo(t=>{const e=pt.c(11),{changedFiles:n,selectedFile:r,onSelectFile:o}=t,{t:i}=Tt();if(n.length===0)return null;let c;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i){let u;e[5]!==o||e[6]!==r||e[7]!==i?(u=m=>{const d=gm(m),f=r===m.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>o(m.path),className:Pe("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",f?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(xr,{filePath:m.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:d.color},title:i(d.descriptionKey),"aria-label":i(d.descriptionKey),children:d.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:m.path,children:m.path}),la(m.insertions,m.deletions)]})},m.path)},e[5]=o,e[6]=r,e[7]=i,e[8]=u):u=e[8],c=n.map(u),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=c}else c=e[4];let l;return e[9]!==c?(l=s.jsx(_n,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:c})}),e[9]=c,e[10]=l):l=e[10],l}),Xy=a.memo(t=>{const e=pt.c(21),{filePath:n,diff:r,isVisible:o,renderSideBySide:i}=t,{t:c}=Tt(),l=r.original.length>0,u=r.modified.length>0;if(!o){let y;return e[0]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=y):y=e[0],y}const m=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",d=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f={contain:"size layout"},e[1]=f):f=e[1];let g;e[2]!==r.original||e[3]!==n||e[4]!==l||e[5]!==d||e[6]!==i||e[7]!==c?(g=l&&s.jsxs("div",{className:d,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:c("diffView.image.original")}),s.jsx("img",{src:r.original,alt:c("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=l,e[5]=d,e[6]=i,e[7]=c,e[8]=g):g=e[8];let x;e[9]!==r.modified||e[10]!==n||e[11]!==u||e[12]!==l||e[13]!==d||e[14]!==i||e[15]!==c?(x=u&&s.jsxs("div",{className:d,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:c(l?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:c("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=u,e[12]=l,e[13]=d,e[14]=i,e[15]=c,e[16]=x):x=e[16];let p;return e[17]!==m||e[18]!==g||e[19]!==x?(p=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:f,children:s.jsxs("div",{className:m,children:[g,x]})}),e[17]=m,e[18]=g,e[19]=x,e[20]=p):p=e[20],p}),Zy=a.memo(t=>{const e=pt.c(20),{filePath:n,diff:r,renderSideBySide:o}=t,{t:i}=Tt(),c=r.original.length>0,l=r.modified.length>0,u=o?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",m=o?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[0]=d):d=e[0];let f;e[1]!==r.original||e[2]!==n||e[3]!==c||e[4]!==m||e[5]!==o||e[6]!==i?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=c,e[4]=m,e[5]=o,e[6]=i,e[7]=f):f=e[7];let g;e[8]!==r.modified||e[9]!==n||e[10]!==l||e[11]!==c||e[12]!==m||e[13]!==o||e[14]!==i?(g=l&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=l,e[11]=c,e[12]=m,e[13]=o,e[14]=i,e[15]=g):g=e[15];let x;return e[16]!==u||e[17]!==f||e[18]!==g?(x=s.jsx("div",{className:"w-full overflow-auto p-4",style:d,children:s.jsxs("div",{className:u,children:[f,g]})}),e[16]=u,e[17]=f,e[18]=g,e[19]=x):x=e[19],x}),ew=a.memo(t=>{const e=pt.c(15),{filePath:n,diff:r,renderSideBySide:o,wrapLines:i}=t;let c;e[0]!==n?(c=Oi(n)||"text",e[0]=n,e[1]=c):c=e[1];const l=c;if(r.isBinary){let d;return e[2]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(hm,{}),e[2]=d):d=e[2],d}if(_i(n)){let d;return e[3]!==r||e[4]!==n||e[5]!==o?(d=s.jsx(Zy,{filePath:n,diff:r,renderSideBySide:o}),e[3]=r,e[4]=n,e[5]=o,e[6]=d):d=e[6],d}let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"layout"},e[7]=u):u=e[7];let m;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==l||e[12]!==o||e[13]!==i?(m=s.jsx("div",{className:"w-full",style:u,children:s.jsx(Zl,{original:r.original,modified:r.modified,language:l,fileName:n,renderSideBySide:o,wrapLines:i,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=l,e[12]=o,e[13]=i,e[14]=m):m=e[14],m}),tw=a.memo(t=>{const e=pt.c(15),{filePath:n,diff:r,isVisible:o,renderSideBySide:i,wrapLines:c}=t;let l;e[0]!==n?(l=Oi(n)||"text",e[0]=n,e[1]=l):l=e[1];const u=l;if(r.isBinary){let d;return e[2]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(hm,{}),e[2]=d):d=e[2],d}if(!o)return null;if(_i(n)){let d;return e[3]!==r||e[4]!==n||e[5]!==o||e[6]!==i?(d=s.jsx(Xy,{filePath:n,diff:r,isVisible:o,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=o,e[6]=i,e[7]=d):d=e[7],d}let m;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==u||e[12]!==i||e[13]!==c?(m=s.jsx(_n,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Zl,{original:r.original,modified:r.modified,language:u,fileName:n,renderSideBySide:i,wrapLines:c,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=u,e[12]=i,e[13]=c,e[14]=m):m=e[14],m}),sw=a.memo(t=>{const e=pt.c(129),{directory:n,file:r,layout:o,wrapLines:i,scrollRootRef:c,isSelected:l,onSelect:u,registerSectionRef:m,defaultCollapsed:d,expandRequestPath:f,expandRequestNonce:g,showOpenInEditorAction:x,isOpeningInEditor:p,onOpenInEditor:y,staged:b,stagedRevision:h}=t,N=d===void 0?!1:d,w=f===void 0?null:f,S=g===void 0?0:g,v=x===void 0?!1:x,j=p===void 0?!1:p,k=b===void 0?!1:b,A=h===void 0?0:h,{t:T}=Tt(),{git:C}=Gn();let P;e[0]!==n||e[1]!==r.path?(P=lt=>lt.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=P):P=e[2];const E=_s(P),M=_s(nw),H=Fe(rw),[R,_]=a.useState(!N),[z,V]=a.useState(!1),[F,te]=a.useState(0),[Z,ne]=a.useState(null),[U,ie]=a.useState(!1),[oe,pe]=a.useState(!1),[je,Se]=a.useState(null),re=a.useRef(null),L=a.useRef(null);let $;e[3]!==r?($=gm(r),e[3]=r,e[4]=$):$=e[4];const K=$,he=o==="side-by-side";let de;e:{if(k){de=je;break e}if(!E){de=null;break e}let lt;e[5]!==E.isBinary||e[6]!==E.modified||e[7]!==E.original?(lt={original:E.original,modified:E.modified,isBinary:E.isBinary},e[5]=E.isBinary,e[6]=E.modified,e[7]=E.original,e[8]=lt):lt=e[8],de=lt}const we=de;let xe;e[9]!==r.path||e[10]!==m?(xe=lt=>{L.current=lt,m(r.path,lt)},e[9]=r.path,e[10]=m,e[11]=xe):xe=e[11];const De=xe;let le;e[12]===Symbol.for("react.memo_cache_sentinel")?(le=lt=>{_(lt),lt&&V(!0)},e[12]=le):le=e[12];const Ce=le;let ue;e[13]!==r.path||e[14]!==u?(ue=()=>{u(r.path)},e[13]=r.path,e[14]=u,e[15]=ue):ue=e[15];const ve=ue;let G,Ae;e[16]!==z||e[17]!==R||e[18]!==c?(G=()=>{if(!R||z)return;const lt=L.current;if(!lt)return;if(!c.current||typeof IntersectionObserver>"u"){V(!0);return}const kt=new IntersectionObserver(Ke=>{Ke.some(iw)&&(V(!0),kt.disconnect())},{root:c.current,rootMargin:"200px 0px",threshold:.1});return kt.observe(lt),()=>kt.disconnect()},Ae=[z,R,c],e[16]=z,e[17]=R,e[18]=c,e[19]=G,e[20]=Ae):(G=e[19],Ae=e[20]),a.useEffect(G,Ae);let ce,fe;e[21]!==S||e[22]!==w||e[23]!==r.path?(ce=()=>{S<=0||w!==r.path||(_(!0),V(!0))},fe=[S,w,r.path],e[21]=S,e[22]=w,e[23]=r.path,e[24]=ce,e[25]=fe):(ce=e[24],fe=e[25]),a.useEffect(ce,fe);let Te;e[26]!==k?(Te=()=>{k&&(Se(null),ne(null),re.current=null)},e[26]=k,e[27]=Te):Te=e[27];let me;e[28]!==k||e[29]!==A?(me=[k,A],e[28]=k,e[29]=A,e[30]=me):me=e[30],a.useEffect(Te,me);let B,ye;e[31]!==we||e[32]!==F||e[33]!==n||e[34]!==r.path||e[35]!==C||e[36]!==z||e[37]!==R||e[38]!==M||e[39]!==k||e[40]!==A?(B=()=>{if(!R||!z)return;if(!n||we){re.current=null,ie(!1);return}const lt=`${n}::${r.path}::${k?`staged:${A}`:"unstaged"}::${F}`;if(re.current===lt)return;re.current=lt,ne(null),ie(!0);let kt=!1;const Ke=C.getGitFileDiff(n,{path:r.path,staged:k}),tt=new Promise(ow);return Promise.race([Ke,tt]).then(We=>{if(kt)return;const gt={original:We.original??"",modified:We.modified??"",isBinary:We.isBinary};k?Se(gt):M(n,r.path,gt),ie(!1)}).catch(We=>{if(kt)return;const gt=We instanceof Error?We.message:String(We);ne(gt),ie(!1)}),()=>{kt=!0,re.current===lt&&(re.current=null)}},ye=[n,we,F,r.path,C,z,R,M,k,A],e[31]=we,e[32]=F,e[33]=n,e[34]=r.path,e[35]=C,e[36]=z,e[37]=R,e[38]=M,e[39]=k,e[40]=A,e[41]=B,e[42]=ye):(B=e[41],ye=e[42]),a.useEffect(B,ye);let _e;e[43]!==ve||e[44]!==R?(_e=()=>{Ce(!R),ve()},e[43]=ve,e[44]=R,e[45]=_e):_e=e[45];const J=_e,Me=R?"rounded-b-none":"rounded-b-xl",Ee=l?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let Ne;e[46]!==Me||e[47]!==Ee?(Ne=Pe("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Me,"text-muted-foreground hover:text-foreground",Ee),e[46]=Me,e[47]=Ee,e[48]=Ne):Ne=e[48];let Be;e[49]===Symbol.for("react.memo_cache_sentinel")?(Be=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[49]=Be):Be=e[49];let se;e[50]!==R?(se=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:R?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"})}),e[50]=R,e[51]=se):se=e[51];let O;e[52]!==K.color?(O={color:K.color},e[52]=K.color,e[53]=O):O=e[53];let D;e[54]!==K.descriptionKey||e[55]!==T?(D=T(K.descriptionKey),e[54]=K.descriptionKey,e[55]=T,e[56]=D):D=e[56];let Y;e[57]!==K.descriptionKey||e[58]!==T?(Y=T(K.descriptionKey),e[57]=K.descriptionKey,e[58]=T,e[59]=Y):Y=e[59];let be;e[60]!==K.code||e[61]!==O||e[62]!==D||e[63]!==Y?(be=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:O,title:D,"aria-label":Y,children:K.code}),e[60]=K.code,e[61]=O,e[62]=D,e[63]=Y,e[64]=be):be=e[64];const Oe=r.path;let $e;e[65]!==r.path?($e=s.jsx(xr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[65]=r.path,e[66]=$e):$e=e[66];let Re;if(e[67]!==r.path){e:{const lt=r.path.lastIndexOf("/");if(lt===-1){let Et;e[69]===Symbol.for("react.memo_cache_sentinel")?(Et={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[69]=Et):Et=e[69],Re=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:Et,children:r.path});break e}const kt=r.path.slice(0,lt),Ke=r.path.slice(lt+1);let tt;e[70]===Symbol.for("react.memo_cache_sentinel")?(tt={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[70]=tt):tt=e[70];let We;e[71]!==kt?(We=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:tt,children:kt}),e[71]=kt,e[72]=We):We=e[72];let gt;e[73]===Symbol.for("react.memo_cache_sentinel")?(gt=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[73]=gt):gt=e[73];let He;e[74]!==Ke?(He=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[gt,s.jsx("span",{className:"text-foreground",children:Ke})]}),e[74]=Ke,e[75]=He):He=e[75];let st;e[76]!==We||e[77]!==He?(st=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[We,He]}),e[76]=We,e[77]=He,e[78]=st):st=e[78],Re=st}e[67]=r.path,e[68]=Re}else Re=e[68];let ot;e[79]!==$e||e[80]!==Re?(ot=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[$e,Re]}),e[79]=$e,e[80]=Re,e[81]=ot):ot=e[81];let yt;e[82]!==r.path||e[83]!==ot?(yt=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Oe,children:ot}),e[82]=r.path,e[83]=ot,e[84]=yt):yt=e[84];let At;e[85]!==se||e[86]!==be||e[87]!==yt?(At=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[se,be,yt]}),e[85]=se,e[86]=be,e[87]=yt,e[88]=At):At=e[88];let mt;e[89]!==r.deletions||e[90]!==r.insertions?(mt=la(r.insertions,r.deletions),e[89]=r.deletions,e[90]=r.insertions,e[91]=mt):mt=e[91];let Le;e[92]!==we||e[93]!==r.path||e[94]!==j||e[95]!==y||e[96]!==v||e[97]!==T?(Le=v&&y?s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:T("diffView.actions.openFileInEditorAtChange"),onClick:lt=>{lt.stopPropagation(),y(r.path,we)},disabled:j,children:j?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}):null,e[92]=we,e[93]=r.path,e[94]=j,e[95]=y,e[96]=v,e[97]=T,e[98]=Le):Le=e[98];const Qe=he?"side-by-side":"unified";let Ye;e[99]!==r.path||e[100]!==H?(Ye=lt=>{const kt=lt==="side-by-side"?"side-by-side":"inline";H(r.path,kt)},e[99]=r.path,e[100]=H,e[101]=Ye):Ye=e[101];let rt;e[102]!==Qe||e[103]!==Ye?(rt=s.jsx(Mu,{mode:Qe,onModeChange:Ye,className:"opacity-70"}),e[102]=Qe,e[103]=Ye,e[104]=rt):rt=e[104];let bt;e[105]!==mt||e[106]!==Le||e[107]!==rt?(bt=s.jsxs("div",{className:"relative flex items-center gap-2",children:[mt,Le,rt]}),e[105]=mt,e[106]=Le,e[107]=rt,e[108]=bt):bt=e[108];let ct;e[109]!==J||e[110]!==Ne||e[111]!==At||e[112]!==bt?(ct=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:J,className:Ne,children:[Be,At,bt]})}),e[109]=J,e[110]=Ne,e[111]=At,e[112]=bt,e[113]=ct):ct=e[113];let nt;e[114]!==we||e[115]!==Z||e[116]!==r.deletions||e[117]!==r.insertions||e[118]!==r.path||e[119]!==oe||e[120]!==R||e[121]!==U||e[122]!==he||e[123]!==i?(nt=R&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[Z?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:Z}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>te(aw),children:"Retry"})]}):null,U&&!we&&!Z?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff…"]}):null,we&&!oe&&r.insertions+r.deletions>yd?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsxs("div",{className:"typography-ui-label font-semibold text-foreground",children:["Large diff (",r.insertions+r.deletions," changed lines)"]}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>pe(!0),children:"Render anyway"})]}):null,we&&(oe||r.insertions+r.deletions<=yd)?s.jsx(ew,{filePath:r.path,diff:we,renderSideBySide:he,wrapLines:i}):null]}),e[114]=we,e[115]=Z,e[116]=r.deletions,e[117]=r.insertions,e[118]=r.path,e[119]=oe,e[120]=R,e[121]=U,e[122]=he,e[123]=i,e[124]=nt):nt=e[124];let It;return e[125]!==De||e[126]!==ct||e[127]!==nt?(It=s.jsxs("div",{ref:De,className:"scroll-mt-4",children:[ct,nt]}),e[125]=De,e[126]=ct,e[127]=nt,e[128]=It):It=e[128],It}),xm=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:o=!1,diffScope:i="all",targetFilePath:c=null})=>{const{t:l}=Tt(),{git:u,files:m}=Gn(),d=si(),{screenWidth:f,isMobile:g}=Pr(),x=Wl(d??null),p=ya(d??null),y=Ul(d??null),b=_s(Le=>Le.setActiveDirectory),h=_s(Le=>Le.ensureStatus),N=_s(Le=>Le.fetchStatus),w=_s(Le=>Le.setDiff),S=_s(a.useCallback(Le=>d?Le.directories.get(d)?.indexRevision??0:0,[d])),[v,j]=a.useState(null),[k,A]=a.useState(!1),[T,C]=a.useState(null),[P,E]=a.useState(null),[M,H]=a.useState(0),[R,_]=a.useState(null),[z,V]=a.useState(0),[F,te]=a.useState(null),Z=a.useRef(null),ne=Fe(Le=>Le.pendingDiffFile),U=Fe(Le=>Le.pendingDiffStaged),ie=Fe(Le=>Le.setPendingDiffFile),oe=Fe(Le=>Le.diffLayoutPreference),pe=Fe(Le=>Le.diffFileLayout),je=Fe(Le=>Le.setDiffFileLayout),Se=Fe(Le=>Le.diffWrapLines),re=Fe(Le=>Le.setDiffWrapLines),L=Fe(Le=>Le.diffViewMode),$=Fe(Le=>Le.setDiffViewMode),K=Fe(Le=>Le.openContextFileAtLine),he=Se,de=i==="staged"?!0:i==="working"?!1:null,we=de??k,xe=L==="stacked",De=g||f<=768,le=!t&&!De&&f>=1024,Ce=a.useRef(null),ue=a.useRef(new Map),ve=a.useRef(null),G=a.useRef(null),Ae=a.useRef(!1);a.useEffect(()=>{if(!r||!xe||!R)return;const Le=Ce.current;if(!Le)return;let Qe=null,Ye=!1,rt=0;const bt=Date.now()+1200;let ct=0;const nt=()=>{Ye||(Ye=!0,_(null))},It=()=>{nt()},lt=()=>{if(ct>0){ct-=1;return}nt()};window.addEventListener("wheel",It,{passive:!0,capture:!0}),window.addEventListener("touchstart",It,{passive:!0,capture:!0}),window.addEventListener("pointerdown",It,{capture:!0}),window.addEventListener("keydown",It,{capture:!0}),Le.addEventListener("scroll",lt,{passive:!0});const kt=()=>{if(Ye||Date.now()>bt){nt();return}const Ke=Ce.current,tt=ue.current.get(R);if(!Ke||!tt){nt();return}const We=Ke.getBoundingClientRect(),He=tt.getBoundingClientRect().top-We.top;if(Math.abs(He)<=1){if(rt+=1,rt>=2){nt();return}}else{rt=0;const st=Math.max(0,Ke.scrollHeight-Ke.clientHeight),Et=Math.min(st,Math.max(0,Ke.scrollTop+He));if(Math.abs(Et-Ke.scrollTop)<=.5){nt();return}ct+=1,Ke.scrollTop=Et}Qe=window.requestAnimationFrame(kt)};return Qe=window.requestAnimationFrame(kt),()=>{Ye=!0,Qe!==null&&window.cancelAnimationFrame(Qe),window.removeEventListener("wheel",It,!0),window.removeEventListener("touchstart",It,!0),window.removeEventListener("pointerdown",It,!0),window.removeEventListener("keydown",It,!0),Le.removeEventListener("scroll",lt)}},[xe,r,R]);const ce=a.useMemo(()=>{if(!p?.files)return[];const Le=p.diffStats??{},Qe=i==="staged"?Hy:i==="working"?Gy:()=>!0;return p.files.filter(Qe).map(Ye=>({...Ye,insertions:Le[Ye.path]?.insertions??0,deletions:Le[Ye.path]?.deletions??0,isNew:Uy(Ye)})).sort((Ye,rt)=>Ye.path.localeCompare(rt.path))},[i,p]),fe=a.useMemo(()=>v?ce.find(Le=>Le.path===v)??null:null,[ce,v]),Te=a.useCallback(Le=>{const Qe=pe[Le.path];if(Qe)return Qe;if(oe==="inline")return"inline";if(oe==="side-by-side")return"side-by-side";const Ye=f<Vy;return Le.isNew||Ye?"inline":"side-by-side"},[pe,oe,f]),me=a.useMemo(()=>fe?Te(fe):null,[Te,fe]);a.useEffect(()=>{d&&(b(d),h(d,u))},[d,b,h,u]),a.useEffect(()=>{if(d)return Ir.onGitRefreshHint(Le=>{wd(Le.directory)===wd(d)&&N(d,u)})},[d,N,u]),a.useEffect(()=>{i==="all"&&ne&&(j(ne),A(U),C(null),ie(null),xe&&(Ae.current=!0,ve.current=ne,E(ne),H(Le=>Le+1)))},[i,xe,ne,U,ie]),a.useEffect(()=>{if(i==="all")return;const Le=c?.trim();Le&&(j(Le),A(i==="staged"),C(null),xe&&(Ae.current=!0,ve.current=Le,E(Le),H(Qe=>Qe+1)))},[i,xe,c]),a.useEffect(()=>{we&&(C(null),te(null),Z.current=null)},[we,S]),a.useEffect(()=>{!v&&!ne&&ce.length>0&&j(ce[0].path)},[ce,v,ne]),a.useEffect(()=>{v&&ce.length>0&&(ce.some(Qe=>Qe.path===v)||j(ce[0]?.path??null))},[ce,v]);const B=a.useCallback((Le,Qe)=>{const Ye=ue.current;Qe?Ye.set(Le,Qe):Ye.delete(Le)},[]),ye=a.useCallback(Le=>{const Qe=ue.current.get(Le),Ye=Ce.current;if(!Qe||!Ye)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const rt=Ye.getBoundingClientRect(),ct=Qe.getBoundingClientRect().top-rt.top,nt=Math.max(0,Ye.scrollHeight-Ye.clientHeight),It=Ye.scrollTop+ct,lt=Math.min(nt,Math.max(0,It)),kt=Math.abs(lt-Ye.scrollTop)>.5;Ye.scrollTop=lt;const Ke=Math.abs(ct)<=1,tt=lt<=.5||lt>=nt-.5;return{ok:!0,aligned:Ke,didMove:kt,atScrollLimit:tt,delta:ct}},[]);a.useEffect(()=>{if(!xe){ve.current=null,Ae.current=!1,G.current!==null&&(window.cancelAnimationFrame(G.current),G.current=null);return}if(!ve.current)return;let Qe=0;const Ye=120;let rt=!1,bt=0,ct=!1,nt=0;const It=Date.now()+2e3,lt=()=>{ct||(ct=!0,window.removeEventListener("wheel",Ke,!0),window.removeEventListener("touchstart",Ke,!0),window.removeEventListener("pointerdown",Ke,!0),window.removeEventListener("keydown",Ke,!0),We?.removeEventListener("scroll",tt))},kt=()=>{rt||(rt=!0,lt(),ve.current=null,Ae.current=!1,G.current!==null&&(window.cancelAnimationFrame(G.current),G.current=null))},Ke=()=>{kt()},tt=()=>{if(bt>0){bt-=1;return}kt()},We=Ce.current;window.addEventListener("wheel",Ke,{passive:!0,capture:!0}),window.addEventListener("touchstart",Ke,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Ke,{capture:!0}),window.addEventListener("keydown",Ke,{capture:!0}),We?.addEventListener("scroll",tt,{passive:!0});const gt=()=>{if(Date.now()>It){kt(),G.current=null;return}if(rt){G.current=null;return}const He=ve.current;if(!He){kt(),G.current=null;return}bt+=1;const st=ye(He);if(!st.ok){bt=Math.max(0,bt-1),Qe+=1,Qe<Ye?G.current=window.requestAnimationFrame(gt):(kt(),G.current=null);return}if(!st.aligned){if(Qe+=1,st.didMove){if(nt=0,Qe<Ye){G.current=window.requestAnimationFrame(gt);return}}else if(nt+=1,nt<6&&(st.atScrollLimit||Math.abs(st.delta)>1)){G.current=window.requestAnimationFrame(gt);return}}r&&Ae.current&&_(He),kt()};return G.current=window.requestAnimationFrame(gt),()=>{rt=!0,lt(),G.current!==null&&(window.cancelAnimationFrame(G.current),G.current=null)}},[xe,r,ye,v,M]);const _e=a.useCallback(Le=>{j(Le),A(!1),C(null)},[]),J=a.useCallback(Le=>{if(G.current!==null&&(window.cancelAnimationFrame(G.current),G.current=null),ve.current=null,j(Le),A(!1),C(null),!xe){Ae.current=!1;return}Ae.current=!0,ve.current=Le,ye(Le)},[xe,ye]),Me=a.useCallback(Le=>{$(Le),Le==="stacked"&&v&&(ye(v).aligned||(ve.current=v))},[ye,v,$]),Ee=a.useCallback(Le=>{const Qe=Le==="side-by-side"?"side-by-side":"inline";if(xe){ce.forEach(Ye=>{je(Ye.path,Qe)});return}fe&&je(fe.path,Qe)},[ce,xe,fe,je]),Ne=(me??"side-by-side")==="side-by-side",Be=!n&&(!xe||!le),se=_s(a.useCallback(Le=>!d||!v||we?null:Le.directories.get(d)?.diffCache.get(v)??null,[we,d,v])),O=a.useMemo(()=>we?T:se?{original:se.original,modified:se.modified,isBinary:se.isBinary}:null,[we,se,T]),[D,Y]=a.useState(null),be=a.useCallback(async(Le,Qe)=>{if(!(!d||!Le)){Y(Le);try{let Ye=null;if(Qe&&!Qe.isBinary&&!_i(Le)&&(Ye=vd(Qe.original,Qe.modified)),Ye===null)try{const It=await u.getGitDiff(d,{path:Le,staged:we,contextLines:3});Ye=qy(It.diff)}catch{Ye=null}let rt=Qe;if(Ye===null||!rt){const It=await u.getGitFileDiff(d,{path:Le,staged:we});rt={original:It.original??"",modified:It.modified??"",isBinary:It.isBinary},we||w(d,Le,rt)}const bt=Ye??(rt.isBinary||_i(Le)?1:vd(rt.original,rt.modified)),ct=Ky(d,Le),nt=await nc(m,ct);if(!nt.ok){ae.error(rc(nt.reason));return}K(d,ct,bt,1)}finally{Y(Ye=>Ye===Le?null:Ye)}}},[we,d,m,u,K,w]),Oe=a.useCallback(async()=>{v&&await be(v,O)},[be,O,v]),$e=!!(v&&D===v),Re=we?!!T:!!se,ot=!xe&&!!v&&!Re;a.useEffect(()=>{if(xe)return;if(te(null),!d||!v){Z.current=null;return}if(we?T:se){Z.current=null;return}const Le=`${d}::${v}::${we?`staged:${S}`:"unstaged"}::${z}`;if(Z.current===Le)return;Z.current=Le;let Qe=!1;const Ye=u.getGitFileDiff(d,{path:v,staged:we}),rt=Cl,bt=new Promise((ct,nt)=>{setTimeout(()=>nt(new Error(`Timed out after ${rt}ms`)),rt)});return Promise.race([Ye,bt]).then(ct=>{if(Qe)return;const nt={original:ct.original??"",modified:ct.modified??"",isBinary:ct.isBinary};we?C(nt):w(d,v,nt)}).catch(ct=>{if(Qe)return;const nt=ct instanceof Error?ct.message:String(ct);te(nt)}),()=>{Qe=!0,Z.current===Le&&(Z.current=null)}},[we,d,S,xe,v,se,T,u,w,z]);const yt=()=>!d||!v||!O?null:s.jsx(tw,{filePath:v,diff:O,isVisible:!0,renderSideBySide:Ne,wrapLines:he},v),At=()=>{if(!d)return null;const Le=$y(ce.length),Qe=Ye=>de!==null?de:k&&Ye===v;return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[le&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:l("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:ce.length})]}),s.jsx(Qy,{changedFiles:ce,selectedFile:v,onSelectFile:J})]}),s.jsx(_n,{ref:Ce,outerClassName:"flex-1 min-h-0 h-full",className:"pr-2",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx("div",{className:"flex flex-col gap-3",children:ce.map((Ye,rt)=>s.jsx(sw,{directory:d,file:Ye,layout:Te(Ye),wrapLines:he,scrollRootRef:Ce,isSelected:Ye.path===v,onSelect:_e,registerSectionRef:B,defaultCollapsed:e?!0:rt>=Le,expandRequestPath:P,expandRequestNonce:M,showOpenInEditorAction:o,isOpeningInEditor:D===Ye.path,onOpenInEditor:(bt,ct)=>{be(bt,ct)},staged:Qe(Ye.path),stagedRevision:S},`${Qe(Ye.path)?"staged":"unstaged"}:${Ye.path}`))})})]})},mt=()=>d?y&&!p?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),l("diffView.state.loadingRepositoryStatus")]}):x===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:l("diffView.state.notGitRepository")}):ce.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:l("diffView.state.cleanWorkingTree")}):xe?At():s.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden px-3 py-3 relative","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[yt(),ot&&!Re&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:F?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:l("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:F}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{te(null),V(Le=>Le+1)},children:l("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),l("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:l("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!g&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(I,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:y&&!p?l("diffView.state.loadingChanges"):ce.length===1?l("diffView.summary.changedFilesSingle",{count:ce.length}):l("diffView.summary.changedFilesPlural",{count:ce.length})})]}),!De&&s.jsx(Jy,{mode:L,onModeChange:Me}),Be&&s.jsx(Yy,{changedFiles:ce,selectedFile:v,selectedFileEntry:fe,onSelectFile:J,isMobile:De,showModeSelector:De,mode:L,onModeChange:Me}),s.jsx("div",{className:"flex-1"}),fe&&s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>re(!Se),className:Pe("h-5 w-5 p-0 transition-opacity",he?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:l(he?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})}),o&&fe&&!xe&&s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Oe()},disabled:$e,title:l("diffView.actions.openFileAtFirstChangedLine"),children:$e?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}),fe&&me&&s.jsx(Mu,{mode:me==="side-by-side"?"side-by-side":"unified",onModeChange:Ee})]}),mt()]})};function nw(t){return t.setDiff}function rw(t){return t.setDiffFileLayout}function iw(t){return t.isIntersecting}function ow(t,e){setTimeout(()=>e(new Error(`Timed out after ${Cl}ms`)),Cl)}function aw(t){return t+1}const lw=(t,e)=>{if(!e)return null;const n=Number.parseInt(t.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},jd=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Sd=(t,e,n)=>{const r=t.state.doc.line(e),o=Math.max(1,Math.min(n,r.length+1)),i=r.from+o-1;t.dispatch({selection:Zm.cursor(i),effects:qr.scrollIntoView(i,{y:"center"})})};function cw({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:o}=Tt(),[i,c]=a.useState(""),l=a.useRef(null),u=a.useRef(!1),m=a.useRef(null),d=a.useRef(null),f=a.useMemo(()=>lw(i,n),[i,n]);a.useEffect(()=>{!t||!n||(u.current=!1,l.current=jd(n,n.state.selection),c(""))},[t,n]),a.useEffect(()=>{t&&window.requestAnimationFrame(()=>{d.current?.focus(),d.current?.select()})},[t]),a.useEffect(()=>{if(!(!t||!n||!l.current)){if(f===null){const{selection:b}=l.current;n.dispatch({selection:b,effects:qr.scrollIntoView(b.main.from,{y:"center"})});return}Sd(n,f,l.current.character)}},[f,t,n]);const g=a.useCallback(()=>{if(!n||u.current||!l.current)return;const{selection:b}=l.current;n.dispatch({selection:b,effects:qr.scrollIntoView(b.main.from,{y:"center"})})},[n]),x=a.useCallback(b=>{b||g(),e(b)},[e,g]),p=a.useCallback(()=>{!n||f===null||!l.current||(u.current=!0,Sd(n,f,l.current.character),e(!1),n.focus())},[f,e,n]);a.useEffect(()=>{if(!t)return;const b=N=>{const w=m.current,S=N.target;!w||!(S instanceof Node)||w.contains(S)||x(!1)},h=N=>{N.key==="Escape"&&(N.preventDefault(),x(!1))};return document.addEventListener("pointerdown",b,!0),document.addEventListener("keydown",h,!0),()=>{document.removeEventListener("pointerdown",b,!0),document.removeEventListener("keydown",h,!0)}},[x,t,r]);const y=a.useMemo(()=>{if(!n)return o("goToLineDialog.helper.editorUnavailable");if(f===null){const b=l.current??jd(n,n.state.selection);return o("goToLineDialog.helper.currentLineRange",{current:b.lineNumber,max:n.state.doc.lines})}return o("goToLineDialog.helper.goToLine",{line:f})},[f,o,n]);return r==="inline"?t?s.jsxs("div",{ref:m,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(kn,{ref:d,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:b=>c(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),p())},placeholder:o("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ze,{variant:"outline",size:"xs",onClick:p,disabled:!n||f===null,className:"h-6 px-2",children:o("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:m,className:Pe("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(kn,{ref:d,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:b=>c(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),p())},placeholder:o("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:y})]})})}const dw=t=>{const e=en(t);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const r=e.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},uw=t=>{const e=pt.c(8),{label:n,iconDataUrl:r}=t,[o,i]=a.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const l=c;if(r&&!o){let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=()=>i(!0),e[2]=d):d=e[2];let f;return e[3]!==r?(f=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:d}),e[3]=r,e[4]=f):f=e[4],f}let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=Pe("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=u):u=e[5];let m;return e[6]!==l?(m=s.jsx("span",{className:u,children:l}),e[6]=l,e[7]=m):m=e[7],m},mw=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),en=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const o=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!o&&!i&&(r=r.replace(/\/+$/,"")),r},fw=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Nd=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,ca=(t,e)=>{const n=en(e),r=en(t);if(!n||!r)return!1;const o=Nd(n),i=Nd(r);return i===o||i.startsWith(`${o}/`)},kd=(t,e)=>{const n=en(e),r=en(t);if(!ca(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),c=[];let l=n;for(let u=0;u<i.length-1;u++)l=l?`${l}/${i[u]}`:i[u],c.push(l);return c},Al=(t,e)=>{if(!e)return"";const n=en(e);if(!t||!ca(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},hw=new Set(["node_modules"]),pw=t=>{const e=pt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let i;return e[1]!==o?(i=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=i):i=e[2],i},Cd=t=>{const e=pt.c(11),{name:n}=t,r=a.useRef(null),o=a.useRef(null),[i,c]=a.useState(!1);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{const g=r.current,x=o.current;if(!g||!x)return;const p=()=>{c(x.scrollWidth>g.clientWidth+1)};p();const y=new ResizeObserver(p);return y.observe(g),y.observe(x),()=>{y.disconnect()}},e[0]=l):l=e[0];let u;e[1]!==n?(u=[n],e[1]=n,e[2]=u):u=e[2],a.useLayoutEffect(l,u);let m;e[3]!==n?(m=s.jsx("span",{ref:o,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=m):m=e[4];let d;e[5]!==n||e[6]!==i?(d=i?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:n}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):s.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=i,e[7]=d):d=e[7];let f;return e[8]!==m||e[9]!==d?(f=s.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[m,d]}),e[8]=m,e[9]=d,e[10]=f):f=e[10],f},gw=t=>hw.has(t),xw=t=>{const e=en(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},bw=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Ad=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},Xi=2e5,bm="openchamber:files:auto-save-enabled",yw=t=>{let e=0,n=0;for(let r=0;r<t.length;r+=1)t.charCodeAt(r)===10&&(r>0&&t.charCodeAt(r-1)===13?e+=1:n+=1);return e>n?`\r
16
16
  `:`
17
- `},gm=t=>t.replace(/\r\n/g,`
17
+ `},ym=t=>t.replace(/\r\n/g,`
18
18
  `).replace(/\r/g,`
19
- `),xw=(t,e)=>{const n=gm(t);return e===`\r
19
+ `),ww=(t,e)=>{const n=ym(t);return e===`\r
20
20
  `?n.replace(/\n/g,`\r
21
- `):n},bw=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(pm)!=="false"}catch{return!0}},xm=(t,e)=>s.jsx(yr,{filePath:t,extension:e}),kd=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},yw=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},Po=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},ww=t=>{const e=gt.c(62),{node:n,root:r,isExpanded:o,isActive:i,isMobile:c,alwaysShowActions:l,status:u,badge:m,permissions:d,downloadFile:f,contextMenuPath:g,setContextMenuPath:x,onSelect:p,onToggle:y,onRevealPath:b,onOpenDialog:h}=t,{t:N}=Tt(),w=n.type==="directory",{canRename:S,canCreateFile:v,canCreateFolder:j,canDelete:k,canReveal:D}=d;let T;e[0]!==v||e[1]!==j||e[2]!==k||e[3]!==S||e[4]!==D||e[5]!==n.path||e[6]!==x?(T=ge=>{!S&&!v&&!j&&!k&&!D||(ge?.preventDefault(),x(n.path))},e[0]=v,e[1]=j,e[2]=k,e[3]=S,e[4]=D,e[5]=n.path,e[6]=x,e[7]=T):T=e[7];const C=T;let P;e[8]!==w||e[9]!==n||e[10]!==p||e[11]!==y?(P=()=>{w?y(n.path):p(n)},e[8]=w,e[9]=n,e[10]=p,e[11]=y,e[12]=P):P=e[12];const E=P;let M;e[13]!==n.path||e[14]!==x?(M=ge=>{ge.stopPropagation(),x(n.path)},e[13]=n.path,e[14]=x,e[15]=M):M=e[15];const H=M,R=c?void 0:C,_=c?void 0:C,z=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[16]!==z?(V=Te("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",z),e[16]=z,e[17]=V):V=e[17];let F;e[18]!==w||e[19]!==o||e[20]!==n.extension||e[21]!==n.path?(F=w?o?s.jsx(I,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):xm(n.path,n.extension),e[18]=w,e[19]=o,e[20]=n.extension,e[21]=n.path,e[22]=F):F=e[22];let te;e[23]!==n.name||e[24]!==n.path?(te=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=te):te=e[25];let Z;e[26]!==w||e[27]!==u?(Z=!w&&u&&s.jsx(mw,{status:u}),e[26]=w,e[27]=u,e[28]=Z):Z=e[28];let ne;e[29]!==m||e[30]!==w?(ne=w&&m&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[m.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",m.modified]}),m.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",m.added]})]}),e[29]=m,e[30]=w,e[31]=ne):ne=e[31];let U;e[32]!==E||e[33]!==Z||e[34]!==ne||e[35]!==_||e[36]!==V||e[37]!==F||e[38]!==te?(U=s.jsxs("button",{type:"button",onClick:E,onContextMenu:_,className:V,children:[F,te,Z,ne]}),e[32]=E,e[33]=Z,e[34]=ne,e[35]=_,e[36]=V,e[37]=F,e[38]=te,e[39]=U):U=e[39];let ie;e[40]!==l||e[41]!==v||e[42]!==j||e[43]!==k||e[44]!==S||e[45]!==D||e[46]!==g||e[47]!==f||e[48]!==H||e[49]!==w||e[50]!==c||e[51]!==n||e[52]!==h||e[53]!==b||e[54]!==r||e[55]!==x||e[56]!==N?(ie=(S||v||j||k||D)&&s.jsx("div",{className:Te("absolute right-1 top-1/2 -translate-y-1/2",l?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(on,{open:g===n.path,onOpenChange:ge=>x(ge?n.path:null),children:[s.jsx(nn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"icon",className:"size-6",onClick:H,children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(rn,{align:"end",side:"bottom",onCloseAutoFocus:()=>x(null),children:[S&&s.jsxs(zt,{onClick:ge=>{ge.stopPropagation(),h("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.rename")]}),s.jsxs(zt,{onClick:ge=>{ge.stopPropagation(),cr(n.path).then(je=>{if(je.ok){ae.success(N("sidebarFilesTree.toast.pathCopied"));return}ae.error(N("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.copyPath")]}),s.jsxs(zt,{onClick:ge=>{ge.stopPropagation();const je=Cl(r,n.path)||n.path;cr(je).then(Se=>{if(Se.ok){ae.success(N("filesView.toast.relativePathCopied"));return}ae.error(N("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy-2",className:"mr-2 size-4"})," ",N("filesView.tree.menu.copyRelativePath")]}),!w&&f&&s.jsxs(zt,{onClick:ge=>{ge.stopPropagation(),f(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.save")]}),D&&s.jsxs(zt,{onClick:ge=>{ge.stopPropagation(),b(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 size-4"})," ",N(Hl())]}),w&&(v||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Mn,{}),v&&s.jsxs(zt,{onClick:ge=>{ge.stopPropagation(),h("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs(zt,{onClick:ge=>{ge.stopPropagation(),h("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.newFolder")]})]}),k&&s.jsxs(s.Fragment,{children:[s.jsx(Mn,{}),s.jsxs(zt,{onClick:ge=>{ge.stopPropagation(),h("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=l,e[41]=v,e[42]=j,e[43]=k,e[44]=S,e[45]=D,e[46]=g,e[47]=f,e[48]=H,e[49]=w,e[50]=c,e[51]=n,e[52]=h,e[53]=b,e[54]=r,e[55]=x,e[56]=N,e[57]=ie):ie=e[57];let oe;return e[58]!==U||e[59]!==ie||e[60]!==R?(oe=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:R,children:[U,ie]}),e[58]=U,e[59]=ie,e[60]=R,e[61]=oe):oe=e[61],oe},vw=t=>{const e=gt.c(83),{activeDialog:n,dialogData:r,dialogInputValue:o,onDialogInputChange:i,isDialogSubmitting:c,onDialogSubmit:l,onClose:u,inputRef:m}=t,{t:d}=Tt(),f=!!n;let g;e[0]!==u?(g=F=>!F&&u(),e[0]=u,e[1]=g):g=e[1];let x;e[2]!==n||e[3]!==d?(x=n==="createFile"&&d("filesView.dialog.createFile.title"),e[2]=n,e[3]=d,e[4]=x):x=e[4];let p;e[5]!==n||e[6]!==d?(p=n==="createFolder"&&d("filesView.dialog.createFolder.title"),e[5]=n,e[6]=d,e[7]=p):p=e[7];let y;e[8]!==n||e[9]!==d?(y=n==="rename"&&d("filesView.dialog.rename.title"),e[8]=n,e[9]=d,e[10]=y):y=e[10];let b;e[11]!==n||e[12]!==d?(b=n==="delete"&&d("filesView.dialog.delete.title"),e[11]=n,e[12]=d,e[13]=b):b=e[13];let h;e[14]!==x||e[15]!==p||e[16]!==y||e[17]!==b?(h=s.jsxs(Ys,{children:[x,p,y,b]}),e[14]=x,e[15]=p,e[16]=y,e[17]=b,e[18]=h):h=e[18];let N;e[19]!==n||e[20]!==r?.path||e[21]!==d?(N=n==="createFile"&&d("filesView.dialog.createFile.description",{path:r?.path??d("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=d,e[22]=N):N=e[22];let w;e[23]!==n||e[24]!==r?.path||e[25]!==d?(w=n==="createFolder"&&d("filesView.dialog.createFolder.description",{path:r?.path??d("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=d,e[26]=w):w=e[26];let S;e[27]!==n||e[28]!==r?.name||e[29]!==d?(S=n==="rename"&&d("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=d,e[30]=S):S=e[30];let v;e[31]!==n||e[32]!==r?.name||e[33]!==d?(v=n==="delete"&&d("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=d,e[34]=v):v=e[34];let j;e[35]!==S||e[36]!==v||e[37]!==N||e[38]!==w?(j=s.jsxs(cn,{children:[N,w,S,v]}),e[35]=S,e[36]=v,e[37]=N,e[38]=w,e[39]=j):j=e[39];let k;e[40]!==j||e[41]!==h?(k=s.jsxs(Xs,{children:[h,j]}),e[40]=j,e[41]=h,e[42]=k):k=e[42];let D;e[43]!==n||e[44]!==o||e[45]!==m||e[46]!==i||e[47]!==l||e[48]!==d?(D=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(kn,{value:o,onChange:F=>i(F.target.value),placeholder:d(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:F=>{F.key==="Enter"&&l()},ref:m})}),e[43]=n,e[44]=o,e[45]=m,e[46]=i,e[47]=l,e[48]=d,e[49]=D):D=e[49];let T;e[50]!==d?(T=d("filesView.dialog.cancel"),e[50]=d,e[51]=T):T=e[51];let C;e[52]!==c||e[53]!==u||e[54]!==T?(C=s.jsx(ze,{variant:"outline",onClick:u,disabled:c,children:T}),e[52]=c,e[53]=u,e[54]=T,e[55]=C):C=e[55];const P=n==="delete"?"destructive":"default";let E;e[56]!==l?(E=()=>{l()},e[56]=l,e[57]=E):E=e[57];let M;e[58]!==n||e[59]!==o||e[60]!==c?(M=c||n!=="delete"&&!o.trim(),e[58]=n,e[59]=o,e[60]=c,e[61]=M):M=e[61];let H;e[62]!==n||e[63]!==c||e[64]!==d?(H=c?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):d(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=c,e[64]=d,e[65]=H):H=e[65];let R;e[66]!==P||e[67]!==E||e[68]!==M||e[69]!==H?(R=s.jsx(ze,{variant:P,onClick:E,disabled:M,children:H}),e[66]=P,e[67]=E,e[68]=M,e[69]=H,e[70]=R):R=e[70];let _;e[71]!==C||e[72]!==R?(_=s.jsxs(tr,{children:[C,R]}),e[71]=C,e[72]=R,e[73]=_):_=e[73];let z;e[74]!==m||e[75]!==k||e[76]!==D||e[77]!==_?(z=s.jsxs(Gs,{initialFocus:m,children:[k,D,_]}),e[74]=m,e[75]=k,e[76]=D,e[77]=_,e[78]=z):z=e[78];let V;return e[79]!==f||e[80]!==g||e[81]!==z?(V=s.jsx(Ks,{open:f,onOpenChange:g,children:z}),e[79]=f,e[80]=g,e[81]=z,e[82]=V):V=e[82],V},bm=({mode:t="full"})=>{const{t:e}=Tt(),{files:n,runtime:r}=Wn(),{currentTheme:o,availableThemes:i,lightThemeId:c,darkThemeId:l}=Tr(),{isMobile:u,isTablet:m,screenWidth:d}=Pr(),f=u||m,g=Iu(),x=Pu(),p=ti()??"",y=tn(p.trim()),b=u||t!=="editor-only",h=t==="editor-only"&&!u,N=Ul(Y=>Y.searchFiles),w=ya(p),[S,v]=a.useState(""),j=va(S,200),k=a.useRef(null),[D,T]=a.useState(!1),[C,P]=a.useState(!0),[E,M]=a.useState(!1),[H,R]=a.useState(!1),[_,z]=a.useState(!1),V=a.useRef(null),F=a.useRef(0),te=a.useCallback(Y=>{F.current=Math.max(0,F.current+(Y?1:-1))},[]),Z=a.useCallback(Y=>Y instanceof Element?Y.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);a.useEffect(()=>{if(!_)return;const Y=Ie=>{F.current>0||Z(Ie.target)||V.current&&!V.current.contains(Ie.target)&&z(!1)};return document.addEventListener("mousedown",Y),()=>document.removeEventListener("mousedown",Y)},[Z,_]);const[ne,U]=a.useState("edit"),[ie,oe]=a.useState("edit"),[ge,je]=a.useState("tree"),[Se,re]=a.useState("edit"),L=a.useRef({}),$=a.useRef({}),q=a.useRef({}),he=a.useMemo(()=>i.find(Y=>Y.metadata.id===c)??yc(!1),[i,c]),de=a.useMemo(()=>i.find(Y=>Y.metadata.id===l)??yc(!0),[i,l]);a.useEffect(()=>{wc(he),wc(de)},[he,de]);const we=a.useMemo(()=>[],[]),be=Nn(Y=>y?Y.byRoot[y]?.openPaths??we:we),De=Nn(Y=>y?Y.byRoot[y]?.selectedPath??null:null),le=Nn(Y=>y?Y.byRoot[y]?.expandedPaths??we:we),ke=Nn(Y=>Y.addOpenPath),ue=Nn(Y=>Y.removeOpenPath),ve=Nn(Y=>Y.removeOpenPathsByPrefix),G=Nn(Y=>Y.setSelectedPath),Ae=Nn(Y=>Y.toggleExpandedPath),ce=Nn(Y=>Y.expandPaths),fe=a.useCallback(Y=>{const Ie=tn(Y),Ve=Ie.split("/"),Je=Ve[Ve.length-1]||Ie,kt=Je.includes(".")?Je.split(".").pop()?.toLowerCase():void 0;return{name:Je,path:Ie,type:"file",extension:kt}},[]),Ee=a.useMemo(()=>be.map(fe),[be,fe]),me=a.useMemo(()=>De??be[0]??null,[be,De]),B=a.useMemo(()=>me?fe(me):null,[me,fe]),ye=B?.path??"",Oe=!!(y&&ye&&!ca(ye,y)),Q=a.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Oe}),[t,Oe]),Me=a.useRef(null),[Re,Ne]=a.useState({left:!1,right:!1}),Be=a.useCallback(()=>{const Y=Me.current;Y&&Ne({left:Y.scrollLeft>2,right:Y.scrollLeft+Y.clientWidth<Y.scrollWidth-2})},[]),se=a.useRef(Be);se.current=Be,a.useEffect(()=>{const Y=Me.current;if(!Y)return;const Ie=()=>se.current();Ie(),Y.addEventListener("scroll",Ie,{passive:!0});const Ve=new ResizeObserver(Ie);return Ve.observe(Y),()=>{Y.removeEventListener("scroll",Ie),Ve.disconnect()}},[Ee.length]);const[O,A]=a.useState({}),K=a.useRef(new Set),pe=a.useRef(new Set),_e=a.useRef(new Map),We=a.useRef(0),[Le,rt]=a.useState([]),[yt,Dt]=a.useState(!1),[st,Pe]=a.useState(""),[tt,Ye]=a.useState(!1),[nt,ft]=a.useState(null),[mt,ot]=a.useState(""),[It,dt]=a.useState(""),[bt,He]=a.useState(null),[Ze,Ue]=a.useState(""),[jt,Ge]=a.useState(!1),[it,Et]=a.useState(`
22
- `),lt=a.useRef(null),ct=a.useRef(null),Bt=a.useRef(null),Ft=a.useRef(0),[qt,Ut]=a.useState("idle"),[At,Xt]=a.useState(bw),[ls,es]=a.useState(!1),Gt=a.useRef(null),pt=a.useRef(null),Yt=a.useRef(null),us=a.useRef(!1),Jt=a.useRef(null),ss=a.useRef(null),hs=a.useRef(null),Wt=a.useRef(null),[gs,Ms]=a.useState(0),Vt=a.useRef(null),vs=a.useRef({key:"",attempts:0});a.useEffect(()=>()=>{Vt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Vt.current),Vt.current=null)},[]);const[Ps,Ns]=a.useState(null),[As,Rt]=a.useState(null),[xt,Kt]=a.useState(""),[Ht,ns]=a.useState(!1),[rs,ds]=a.useState(null),[W,qe]=a.useState(!1),[Qe,ht]=a.useState(!1),[Ct,ut]=a.useState(!1),ts=!!n.writeFile,js=!!n.createDirectory,xs=!!n.rename,Bs=!!n.delete,Ts=!!n.revealPath,dn=xr(Y=>Y.availableApps),Ds=xr(Y=>Y.isCacheStale),Vs=xr(Y=>Y.initialize),Us=xr(Y=>Y.loadInstalledApps);a.useEffect(()=>{Vs()},[Vs]);const bs=a.useCallback(Y=>{n.revealPath&&n.revealPath(Y).catch(()=>{ae.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),wr=a.useCallback(async Y=>{if(!B?.path||await eh(B.path,Y.id,Y.appName)||await Xo(B.path,Y.appName))return;const Je=aw(B.path)||y;Je&&await Xo(Je,Y.appName)||ae.error(e("filesView.toast.openInAppFailed",{app:Y.appName}))},[y,B?.path,e]),yn=a.useCallback((Y,Ie)=>{Ns(Y),Rt(Ie),Kt(Y==="rename"&&Ie.name||""),ns(!1)},[]),[ks,ln]=a.useState(null),Tn=a.useRef(!1),un=a.useRef(null),[Un,wn]=a.useState(!1),zs=Fe(Y=>Y.setMainTabGuard),is=Fe(Y=>Y.pendingFileNavigation),Fs=Fe(Y=>Y.setPendingFileNavigation),dr=Fe(Y=>Y.pendingFileFocusPath),Cn=Fe(Y=>Y.setPendingFileFocusPath),$s=Fe(Y=>Y.shortcutOverrides),Hn=cs(Y=>Y.settingsDefaultFileViewerPreview);a.useEffect(()=>{const Y=()=>{Tn.current=!1,un.current=null,wn(!1)};return document.addEventListener("mouseup",Y),()=>document.removeEventListener("mouseup",Y)},[]),a.useEffect(()=>()=>{Jt.current!==null&&window.clearTimeout(Jt.current),ss.current!==null&&window.clearTimeout(ss.current)},[]);const vr=a.useCallback((Y,Ie)=>{const Ve=Y.split(`
23
- `),Je=Math.max(1,Ie.start),kt=Math.min(Ve.length,Ie.end);return Je>kt?"":Ve.slice(Je-1,kt).join(`
24
- `)},[]),Er=Ku({source:"file",fileLabel:B?.path??null,language:B?.path&&_i(B.path)||"text",getCodeForRange:Y=>vr(st,qu(Y)),toStoreRange:Y=>({startLine:Y.start,endLine:Y.end}),fromDraftRange:Y=>({start:Y.startLine,end:Y.endLine})}),{drafts:jr,commentText:sr,editingDraftId:nr,setSelection:Sr,saveComment:Rr,cancel:ee,reset:at,startEdit:St,deleteDraft:$t}=Er;a.useEffect(()=>{ln(null),at(),zs(null),Ue(""),Ge(!1)},[B?.path,at,zs]),a.useEffect(()=>{Sr(ks)},[ks,Sr]),a.useEffect(()=>{if(!ks&&!nr)return;const Y=Ve=>{const Je=Ve.target;Je.closest('[data-comment-input="true"]')||Je.closest('[data-comment-card="true"]')||Je.closest(".cm-gutterElement")||Je.closest("[data-sonner-toast]")||Je.closest("[data-sonner-toaster]")||(ln(null),ee())},Ie=setTimeout(()=>{document.addEventListener("click",Y)},100);return()=>{clearTimeout(Ie),document.removeEventListener("click",Y)}},[ee,nr,ks]);const fs=a.useCallback((Y,Ie)=>{const Ve=Ie??ks??void 0;Ie&&ln(Ie),Rr(Y,Ve),ln(null)},[ks,Rr]),ms=a.useCallback((Y,Ie)=>{const Ve=[];for(const Je of Ie){if(!(Je&&typeof Je.name=="string"&&Je.name.length>0)||!g&&Je.name.startsWith(".")||!x&&fw(Je.name))continue;const kt=Je.name,Mt=tn(Je.path||""),os=Mt?dw(Mt)?Mt:tn(`${Y}/${Mt}`):tn(`${Y}/${kt}`),Cs=Je.isDirectory?"directory":"file",hn=Cs==="file"&&kt.includes(".")?kt.split(".").pop()?.toLowerCase():void 0;Ve.push({name:kt,path:os,type:Cs,extension:hn})}return cw(Ve)},[x,g]),Qt=a.useCallback(async Y=>{const Ie=tn(Y.trim());if(!Ie||K.current.has(Ie)||pe.current.has(Ie))return;pe.current=new Set(pe.current),pe.current.add(Ie);const Ve=We.current+1;We.current=Ve,_e.current=new Map(_e.current),_e.current.set(Ie,Ve);const Je=()=>_e.current.get(Ie)===Ve,kt=!x;await(n.listDirectory?n.listDirectory(Ie,{respectGitignore:kt}).then(os=>os.entries.map(Cs=>({name:Cs.name,path:Cs.path,isDirectory:Cs.isDirectory}))):zn.listLocalDirectory(Ie,{respectGitignore:kt}).then(os=>os.map(Cs=>({name:Cs.name,path:Cs.path,isDirectory:Cs.isDirectory})))).then(os=>{if(!Je())return;const Cs=ms(Ie,os);K.current=new Set(K.current),K.current.add(Ie),A(hn=>({...hn,[Ie]:Cs}))}).catch(()=>{Je()&&A(os=>({...os,[Ie]:os[Ie]??[]}))}).finally(()=>{Je()&&(_e.current=new Map(_e.current),_e.current.delete(Ie),pe.current=new Set(pe.current),pe.current.delete(Ie))})},[n,ms,x]),Ws=a.useCallback(async()=>{y&&(K.current=new Set,pe.current=new Set,_e.current=new Map,A(Y=>Object.keys(Y).length===0?Y:{}),await Qt(y))},[Qt,y]),Is=a.useCallback(async Y=>{if(!Y){await Ws();return}const Ie=tn(Y);K.current=new Set(K.current),K.current.delete(Ie),pe.current=new Set(pe.current),pe.current.delete(Ie),await Qt(Ie)},[Qt,Ws]),Gn=a.useRef(""),ur=a.useRef("");a.useEffect(()=>{if(!y)return;const Y=`${y}|h${g?"1":"0"}|g${x?"1":"0"}`,Ie=Gn.current!==y,Ve=ur.current!==Y;!Ie&&!Ve||(Ie&&(Gn.current=y,Pe(""),ft(null),ot(""),He(null),T(!1)),Ve&&(ur.current=Y,K.current=new Set,pe.current=new Set,_e.current=new Map,A(Je=>Object.keys(Je).length===0?Je:{}),Qt(y)))},[Qt,y,x,g]),a.useEffect(()=>{if(!n.listDirectory)return;const Y=()=>{if(!document.hidden&&le.length>0)for(const Ie of le)Is(Ie)};return document.addEventListener("visibilitychange",Y),()=>document.removeEventListener("visibilitychange",Y)},[le,n.listDirectory,Is]),a.useEffect(()=>{if(!n.listDirectory||le.length===0)return;const Y=setInterval(()=>{if(!document.hidden)for(const Ie of le)Is(Ie)},8e3);return()=>clearInterval(Y)},[le,n.listDirectory,Is]);const _r=a.useCallback(async Y=>{if(Y?.preventDefault(),!As||!Ps)return;ns(!0);const Ie=()=>{Ns(null)},Ve=kt=>{ae.error(kt)},Je=()=>{ns(!1)};if(Ps==="createFile"){if(!xt.trim()){Ve(e("sidebarFilesTree.toast.filenameRequired")),Je();return}if(!n.writeFile){Ve(e("sidebarFilesTree.toast.writeNotSupported")),Je();return}const kt=As.path,Mt=kt?`${kt}/`:"",os=tn(`${Mt}${xt.trim()}`);await n.writeFile(os,"").then(async Cs=>{Cs.success&&(ae.success(e("sidebarFilesTree.toast.fileCreated")),await Is(kt)),Ie()}).catch(()=>Ve(e("sidebarFilesTree.toast.operationFailed"))).finally(Je);return}if(Ps==="createFolder"){if(!xt.trim()){Ve(e("sidebarFilesTree.toast.folderNameRequired")),Je();return}const kt=As.path,Mt=kt?`${kt}/`:"",os=tn(`${Mt}${xt.trim()}`);await n.createDirectory(os).then(async Cs=>{Cs.success&&(ae.success(e("sidebarFilesTree.toast.folderCreated")),await Is(kt)),Ie()}).catch(()=>Ve(e("sidebarFilesTree.toast.operationFailed"))).finally(Je);return}if(Ps==="rename"){if(!xt.trim()){Ve(e("sidebarFilesTree.toast.nameRequired")),Je();return}if(!n.rename){Ve(e("sidebarFilesTree.toast.renameNotSupported")),Je();return}const kt=As.path,Mt=kt.split("/").slice(0,-1).join("/"),os=Mt?`${Mt}/`:"",Cs=tn(`${os}${xt.trim()}`);await n.rename(kt,Cs).then(async hn=>{hn.success&&(ae.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Is(Mt),y&&ve(y,kt),(B?.path===kt||B?.path.startsWith(`${kt}/`))&&(y&&G(y,null),Pe(""),ft(null),ot(""),He(null),u&&T(!1))),Ie()}).catch(()=>Ve(e("sidebarFilesTree.toast.operationFailed"))).finally(Je);return}if(Ps==="delete"){if(!n.delete){Ve(e("sidebarFilesTree.toast.deleteNotSupported")),Je();return}const kt=As.path,Mt=kt.split("/").slice(0,-1).join("/");await n.delete(kt).then(async os=>{os.success&&(ae.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Is(Mt),y&&ve(y,kt),(B?.path===kt||B?.path.startsWith(`${kt}/`))&&(y&&G(y,null),Pe(""),ft(null),ot(""),He(null),u&&T(!1))),Ie()}).catch(()=>Ve(e("sidebarFilesTree.toast.operationFailed"))).finally(Je);return}Je()},[Ps,As,xt,n,Is,u,ve,y,B?.path,G,e]);a.useEffect(()=>{if(!p){rt([]),Dt(!1);return}const Y=j.trim();if(!Y){rt([]),Dt(!1);return}let Ie=!1;return Dt(!0),N(p,Y,150,{includeHidden:g,respectGitignore:!x,type:"file"}).then(Ve=>{if(Ie)return;const kt=Ve.filter(Mt=>x||!hw(Mt.path)).map(Mt=>({name:Mt.name,path:tn(Mt.path),type:"file",extension:Mt.extension,relativePath:Mt.relativePath}));rt(kt)}).catch(()=>{Ie||rt([])}).finally(()=>{Ie||Dt(!1)}),()=>{Ie=!0}},[p,j,N,g,x]);const pn=a.useCallback(async(Y,Ie)=>{if(n.readFile)return(await n.readFile(Y,Ie)).content??"";const Ve=new URLSearchParams({path:Y});Ie?.allowOutsideWorkspace&&Ve.set("allowOutsideWorkspace","true"),Ie?.optional&&Ve.set("optional","true");const Je=await Rs(`/api/fs/read?${Ve.toString()}`,{cache:Ie?.optional?"no-store":"default"});if(!Je.ok){const kt=await Je.json().catch(()=>({error:Je.statusText}));throw new Error(kt.error||e("filesView.error.readFileFailed"))}return Je.text()},[n,e]),Ln=a.useCallback(async(Y,Ie)=>{if(n.statFile){const Ve=await n.statFile(Y,Ie);return{path:Ve.path,size:Ve.size,mtimeMs:Ve.mtimeMs}}return null},[n]);a.useEffect(()=>{if(!y||!n.statFile||be.length===0)return;let Y=!1;const Ie=[...be];return Promise.all(Ie.map(async Ve=>{try{const Je=await n.statFile?.(Ve);!Y&&Je&&!Je.isFile&&ve(y,Ve)}catch(Je){!Y&&Nd(Je)&&ve(y,Ve)}})),()=>{Y=!0}},[n,be,ve,y]);const mn=a.useMemo(()=>st.length>Zi?`${st.slice(0,Zi)}
21
+ `):n},vw=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(bm)!=="false"}catch{return!0}},wm=(t,e)=>s.jsx(xr,{filePath:t,extension:e}),Dd=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},jw=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},Po=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},Sw=t=>{const e=pt.c(62),{node:n,root:r,isExpanded:o,isActive:i,isMobile:c,alwaysShowActions:l,status:u,badge:m,permissions:d,downloadFile:f,contextMenuPath:g,setContextMenuPath:x,onSelect:p,onToggle:y,onRevealPath:b,onOpenDialog:h}=t,{t:N}=Tt(),w=n.type==="directory",{canRename:S,canCreateFile:v,canCreateFolder:j,canDelete:k,canReveal:A}=d;let T;e[0]!==v||e[1]!==j||e[2]!==k||e[3]!==S||e[4]!==A||e[5]!==n.path||e[6]!==x?(T=pe=>{!S&&!v&&!j&&!k&&!A||(pe?.preventDefault(),x(n.path))},e[0]=v,e[1]=j,e[2]=k,e[3]=S,e[4]=A,e[5]=n.path,e[6]=x,e[7]=T):T=e[7];const C=T;let P;e[8]!==w||e[9]!==n||e[10]!==p||e[11]!==y?(P=()=>{w?y(n.path):p(n)},e[8]=w,e[9]=n,e[10]=p,e[11]=y,e[12]=P):P=e[12];const E=P;let M;e[13]!==n.path||e[14]!==x?(M=pe=>{pe.stopPropagation(),x(n.path)},e[13]=n.path,e[14]=x,e[15]=M):M=e[15];const H=M,R=c?void 0:C,_=c?void 0:C,z=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[16]!==z?(V=Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",z),e[16]=z,e[17]=V):V=e[17];let F;e[18]!==w||e[19]!==o||e[20]!==n.extension||e[21]!==n.path?(F=w?o?s.jsx(I,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):wm(n.path,n.extension),e[18]=w,e[19]=o,e[20]=n.extension,e[21]=n.path,e[22]=F):F=e[22];let te;e[23]!==n.name||e[24]!==n.path?(te=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=te):te=e[25];let Z;e[26]!==w||e[27]!==u?(Z=!w&&u&&s.jsx(pw,{status:u}),e[26]=w,e[27]=u,e[28]=Z):Z=e[28];let ne;e[29]!==m||e[30]!==w?(ne=w&&m&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[m.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",m.modified]}),m.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",m.added]})]}),e[29]=m,e[30]=w,e[31]=ne):ne=e[31];let U;e[32]!==E||e[33]!==Z||e[34]!==ne||e[35]!==_||e[36]!==V||e[37]!==F||e[38]!==te?(U=s.jsxs("button",{type:"button",onClick:E,onContextMenu:_,className:V,children:[F,te,Z,ne]}),e[32]=E,e[33]=Z,e[34]=ne,e[35]=_,e[36]=V,e[37]=F,e[38]=te,e[39]=U):U=e[39];let ie;e[40]!==l||e[41]!==v||e[42]!==j||e[43]!==k||e[44]!==S||e[45]!==A||e[46]!==g||e[47]!==f||e[48]!==H||e[49]!==w||e[50]!==c||e[51]!==n||e[52]!==h||e[53]!==b||e[54]!==r||e[55]!==x||e[56]!==N?(ie=(S||v||j||k||A)&&s.jsx("div",{className:Pe("absolute right-1 top-1/2 -translate-y-1/2",l?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(rn,{open:g===n.path,onOpenChange:pe=>x(pe?n.path:null),children:[s.jsx(sn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"icon",className:"size-6",onClick:H,children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(nn,{align:"end",side:"bottom",onCloseAutoFocus:()=>x(null),children:[S&&s.jsxs(zt,{onClick:pe=>{pe.stopPropagation(),h("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.rename")]}),s.jsxs(zt,{onClick:pe=>{pe.stopPropagation(),ar(n.path).then(je=>{if(je.ok){ae.success(N("sidebarFilesTree.toast.pathCopied"));return}ae.error(N("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.copyPath")]}),s.jsxs(zt,{onClick:pe=>{pe.stopPropagation();const je=Al(r,n.path)||n.path;ar(je).then(Se=>{if(Se.ok){ae.success(N("filesView.toast.relativePathCopied"));return}ae.error(N("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy-2",className:"mr-2 size-4"})," ",N("filesView.tree.menu.copyRelativePath")]}),!w&&f&&s.jsxs(zt,{onClick:pe=>{pe.stopPropagation(),f(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.save")]}),A&&s.jsxs(zt,{onClick:pe=>{pe.stopPropagation(),b(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 size-4"})," ",N(Gl())]}),w&&(v||j)&&s.jsxs(s.Fragment,{children:[s.jsx(On,{}),v&&s.jsxs(zt,{onClick:pe=>{pe.stopPropagation(),h("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs(zt,{onClick:pe=>{pe.stopPropagation(),h("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.newFolder")]})]}),k&&s.jsxs(s.Fragment,{children:[s.jsx(On,{}),s.jsxs(zt,{onClick:pe=>{pe.stopPropagation(),h("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 size-4"})," ",N("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=l,e[41]=v,e[42]=j,e[43]=k,e[44]=S,e[45]=A,e[46]=g,e[47]=f,e[48]=H,e[49]=w,e[50]=c,e[51]=n,e[52]=h,e[53]=b,e[54]=r,e[55]=x,e[56]=N,e[57]=ie):ie=e[57];let oe;return e[58]!==U||e[59]!==ie||e[60]!==R?(oe=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:R,children:[U,ie]}),e[58]=U,e[59]=ie,e[60]=R,e[61]=oe):oe=e[61],oe},Nw=t=>{const e=pt.c(83),{activeDialog:n,dialogData:r,dialogInputValue:o,onDialogInputChange:i,isDialogSubmitting:c,onDialogSubmit:l,onClose:u,inputRef:m}=t,{t:d}=Tt(),f=!!n;let g;e[0]!==u?(g=F=>!F&&u(),e[0]=u,e[1]=g):g=e[1];let x;e[2]!==n||e[3]!==d?(x=n==="createFile"&&d("filesView.dialog.createFile.title"),e[2]=n,e[3]=d,e[4]=x):x=e[4];let p;e[5]!==n||e[6]!==d?(p=n==="createFolder"&&d("filesView.dialog.createFolder.title"),e[5]=n,e[6]=d,e[7]=p):p=e[7];let y;e[8]!==n||e[9]!==d?(y=n==="rename"&&d("filesView.dialog.rename.title"),e[8]=n,e[9]=d,e[10]=y):y=e[10];let b;e[11]!==n||e[12]!==d?(b=n==="delete"&&d("filesView.dialog.delete.title"),e[11]=n,e[12]=d,e[13]=b):b=e[13];let h;e[14]!==x||e[15]!==p||e[16]!==y||e[17]!==b?(h=s.jsxs(Ys,{children:[x,p,y,b]}),e[14]=x,e[15]=p,e[16]=y,e[17]=b,e[18]=h):h=e[18];let N;e[19]!==n||e[20]!==r?.path||e[21]!==d?(N=n==="createFile"&&d("filesView.dialog.createFile.description",{path:r?.path??d("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=d,e[22]=N):N=e[22];let w;e[23]!==n||e[24]!==r?.path||e[25]!==d?(w=n==="createFolder"&&d("filesView.dialog.createFolder.description",{path:r?.path??d("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=d,e[26]=w):w=e[26];let S;e[27]!==n||e[28]!==r?.name||e[29]!==d?(S=n==="rename"&&d("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=d,e[30]=S):S=e[30];let v;e[31]!==n||e[32]!==r?.name||e[33]!==d?(v=n==="delete"&&d("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=d,e[34]=v):v=e[34];let j;e[35]!==S||e[36]!==v||e[37]!==N||e[38]!==w?(j=s.jsxs(dn,{children:[N,w,S,v]}),e[35]=S,e[36]=v,e[37]=N,e[38]=w,e[39]=j):j=e[39];let k;e[40]!==j||e[41]!==h?(k=s.jsxs(Qs,{children:[h,j]}),e[40]=j,e[41]=h,e[42]=k):k=e[42];let A;e[43]!==n||e[44]!==o||e[45]!==m||e[46]!==i||e[47]!==l||e[48]!==d?(A=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(kn,{value:o,onChange:F=>i(F.target.value),placeholder:d(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:F=>{F.key==="Enter"&&l()},ref:m})}),e[43]=n,e[44]=o,e[45]=m,e[46]=i,e[47]=l,e[48]=d,e[49]=A):A=e[49];let T;e[50]!==d?(T=d("filesView.dialog.cancel"),e[50]=d,e[51]=T):T=e[51];let C;e[52]!==c||e[53]!==u||e[54]!==T?(C=s.jsx(ze,{variant:"outline",onClick:u,disabled:c,children:T}),e[52]=c,e[53]=u,e[54]=T,e[55]=C):C=e[55];const P=n==="delete"?"destructive":"default";let E;e[56]!==l?(E=()=>{l()},e[56]=l,e[57]=E):E=e[57];let M;e[58]!==n||e[59]!==o||e[60]!==c?(M=c||n!=="delete"&&!o.trim(),e[58]=n,e[59]=o,e[60]=c,e[61]=M):M=e[61];let H;e[62]!==n||e[63]!==c||e[64]!==d?(H=c?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):d(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=c,e[64]=d,e[65]=H):H=e[65];let R;e[66]!==P||e[67]!==E||e[68]!==M||e[69]!==H?(R=s.jsx(ze,{variant:P,onClick:E,disabled:M,children:H}),e[66]=P,e[67]=E,e[68]=M,e[69]=H,e[70]=R):R=e[70];let _;e[71]!==C||e[72]!==R?(_=s.jsxs(sr,{children:[C,R]}),e[71]=C,e[72]=R,e[73]=_):_=e[73];let z;e[74]!==m||e[75]!==k||e[76]!==A||e[77]!==_?(z=s.jsxs(Gs,{initialFocus:m,children:[k,A,_]}),e[74]=m,e[75]=k,e[76]=A,e[77]=_,e[78]=z):z=e[78];let V;return e[79]!==f||e[80]!==g||e[81]!==z?(V=s.jsx(Ks,{open:f,onOpenChange:g,children:z}),e[79]=f,e[80]=g,e[81]=z,e[82]=V):V=e[82],V},vm=({mode:t="full"})=>{const{t:e}=Tt(),{files:n,runtime:r}=Gn(),{currentTheme:o,availableThemes:i,lightThemeId:c,darkThemeId:l}=Tr(),{isMobile:u,isTablet:m,screenWidth:d}=Pr(),f=u||m,g=Eu(),x=Ru(),p=si()??"",y=en(p.trim()),b=u||t!=="editor-only",h=t==="editor-only"&&!u,N=Hl(q=>q.searchFiles),w=ya(p),[S,v]=a.useState(""),j=va(S,200),k=a.useRef(null),[A,T]=a.useState(!1),[C,P]=a.useState(!0),[E,M]=a.useState(!1),[H,R]=a.useState(!1),[_,z]=a.useState(!1),V=a.useRef(null),F=a.useRef(0),te=a.useCallback(q=>{F.current=Math.max(0,F.current+(q?1:-1))},[]),Z=a.useCallback(q=>q instanceof Element?q.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);a.useEffect(()=>{if(!_)return;const q=Ie=>{F.current>0||Z(Ie.target)||V.current&&!V.current.contains(Ie.target)&&z(!1)};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[Z,_]);const[ne,U]=a.useState("edit"),[ie,oe]=a.useState("edit"),[pe,je]=a.useState("tree"),[Se,re]=a.useState("edit"),L=a.useRef({}),$=a.useRef({}),K=a.useRef({}),he=a.useMemo(()=>i.find(q=>q.metadata.id===c)??jc(!1),[i,c]),de=a.useMemo(()=>i.find(q=>q.metadata.id===l)??jc(!0),[i,l]);a.useEffect(()=>{Sc(he),Sc(de)},[he,de]);const we=a.useMemo(()=>[],[]),xe=Nn(q=>y?q.byRoot[y]?.openPaths??we:we),De=Nn(q=>y?q.byRoot[y]?.selectedPath??null:null),le=Nn(q=>y?q.byRoot[y]?.expandedPaths??we:we),Ce=Nn(q=>q.addOpenPath),ue=Nn(q=>q.removeOpenPath),ve=Nn(q=>q.removeOpenPathsByPrefix),G=Nn(q=>q.setSelectedPath),Ae=Nn(q=>q.toggleExpandedPath),ce=Nn(q=>q.expandPaths),fe=a.useCallback(q=>{const Ie=en(q),Ve=Ie.split("/"),Je=Ve[Ve.length-1]||Ie,Ct=Je.includes(".")?Je.split(".").pop()?.toLowerCase():void 0;return{name:Je,path:Ie,type:"file",extension:Ct}},[]),Te=a.useMemo(()=>xe.map(fe),[xe,fe]),me=a.useMemo(()=>De??xe[0]??null,[xe,De]),B=a.useMemo(()=>me?fe(me):null,[me,fe]),ye=B?.path??"",_e=!!(y&&ye&&!ca(ye,y)),J=a.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&_e}),[t,_e]),Me=a.useRef(null),[Ee,Ne]=a.useState({left:!1,right:!1}),Be=a.useCallback(()=>{const q=Me.current;q&&Ne({left:q.scrollLeft>2,right:q.scrollLeft+q.clientWidth<q.scrollWidth-2})},[]),se=a.useRef(Be);se.current=Be,a.useEffect(()=>{const q=Me.current;if(!q)return;const Ie=()=>se.current();Ie(),q.addEventListener("scroll",Ie,{passive:!0});const Ve=new ResizeObserver(Ie);return Ve.observe(q),()=>{q.removeEventListener("scroll",Ie),Ve.disconnect()}},[Te.length]);const[O,D]=a.useState({}),[Y,be]=a.useState({}),Oe=a.useRef(new Set),$e=a.useRef(new Set),Re=a.useRef(new Map),ot=a.useRef(0),[yt,At]=a.useState([]),[mt,Le]=a.useState(!1),[Qe,Ye]=a.useState(""),[rt,bt]=a.useState(!1),[ct,nt]=a.useState(null),[It,lt]=a.useState(""),[kt,Ke]=a.useState(""),[tt,We]=a.useState(null),[gt,He]=a.useState(""),[st,Et]=a.useState(!1),[at,dt]=a.useState(`
22
+ `),Ht=a.useRef(null),Rt=a.useRef(null),Wt=a.useRef(null),qt=a.useRef(0),[Lt,Gt]=a.useState("idle"),[Qt,rs]=a.useState(vw),[Yt,ft]=a.useState(!1),Jt=a.useRef(null),ms=a.useRef(null),Xt=a.useRef(null),ts=a.useRef(!1),ks=a.useRef(null),$t=a.useRef(null),as=a.useRef(null),$s=a.useRef(null),[Ut,Es]=a.useState(0),Ls=a.useRef(null),gs=a.useRef({key:"",attempts:0});a.useEffect(()=>()=>{Ls.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Ls.current),Ls.current=null)},[]);const[Cs,Mt]=a.useState(null),[xt,Zt]=a.useState(null),[Ft,is]=a.useState(""),[es,fs]=a.useState(!1),[W,Ge]=a.useState(null),[Xe,ht]=a.useState(!1),[Nt,ut]=a.useState(!1),[ss,bs]=a.useState(!1),ys=!!n.writeFile,Bs=!!n.createDirectory,Rs=!!n.rename,an=!!n.delete,Ss=!!n.revealPath,zs=pr(q=>q.availableApps),Ws=pr(q=>q.isCacheStale),hs=pr(q=>q.initialize),br=pr(q=>q.loadInstalledApps);a.useEffect(()=>{hs()},[hs]);const Rn=a.useCallback(q=>{n.revealPath&&n.revealPath(q).catch(()=>{ae.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),nr=a.useCallback(async q=>{if(!B?.path||await nh(B.path,q.id,q.appName)||await Xo(B.path,q.appName))return;const Je=dw(B.path)||y;Je&&await Xo(Je,q.appName)||ae.error(e("filesView.toast.openInAppFailed",{app:q.appName}))},[y,B?.path,e]),Kn=a.useCallback((q,Ie)=>{Mt(q),Zt(Ie),is(q==="rename"&&Ie.name||""),fs(!1)},[]),[As,Xs]=a.useState(null),Cn=a.useRef(!1),un=a.useRef(null),[hn,ds]=a.useState(!1),ws=Fe(q=>q.setMainTabGuard),pn=Fe(q=>q.pendingFileNavigation),Sn=Fe(q=>q.setPendingFileNavigation),Os=Fe(q=>q.pendingFileFocusPath),lr=Fe(q=>q.setPendingFileFocusPath),cr=Fe(q=>q.shortcutOverrides),qn=ls(q=>q.settingsDefaultFileViewerPreview);a.useEffect(()=>{const q=()=>{Cn.current=!1,un.current=null,ds(!1)};return document.addEventListener("mouseup",q),()=>document.removeEventListener("mouseup",q)},[]),a.useEffect(()=>()=>{ks.current!==null&&window.clearTimeout(ks.current),$t.current!==null&&window.clearTimeout($t.current)},[]);const Er=a.useCallback((q,Ie)=>{const Ve=q.split(`
23
+ `),Je=Math.max(1,Ie.start),Ct=Math.min(Ve.length,Ie.end);return Je>Ct?"":Ve.slice(Je-1,Ct).join(`
24
+ `)},[]),dr=Ju({source:"file",fileLabel:B?.path??null,language:B?.path&&Oi(B.path)||"text",getCodeForRange:q=>Er(Qe,Qu(q)),toStoreRange:q=>({startLine:q.start,endLine:q.end}),fromDraftRange:q=>({start:q.startLine,end:q.endLine})}),{drafts:yr,commentText:wr,editingDraftId:ur,setSelection:ee,saveComment:it,cancel:wt,reset:Vt,startEdit:ps,deleteDraft:us}=dr;a.useEffect(()=>{Xs(null),Vt(),ws(null),He(""),Et(!1)},[B?.path,Vt,ws]),a.useEffect(()=>{ee(As)},[As,ee]),a.useEffect(()=>{if(!As&&!ur)return;const q=Ve=>{const Je=Ve.target;Je.closest('[data-comment-input="true"]')||Je.closest('[data-comment-card="true"]')||Je.closest(".cm-gutterElement")||Je.closest("[data-sonner-toast]")||Je.closest("[data-sonner-toaster]")||(Xs(null),wt())},Ie=setTimeout(()=>{document.addEventListener("click",q)},100);return()=>{clearTimeout(Ie),document.removeEventListener("click",q)}},[wt,ur,As]);const cs=a.useCallback((q,Ie)=>{const Ve=Ie??As??void 0;Ie&&Xs(Ie),it(q,Ve),Xs(null)},[As,it]),Us=a.useCallback((q,Ie)=>{const Ve=[];for(const Je of Ie){if(!(Je&&typeof Je.name=="string"&&Je.name.length>0)||!g&&Je.name.startsWith(".")||!x&&gw(Je.name))continue;const Ct=Je.name,Dt=en(Je.path||""),ns=Dt?fw(Dt)?Dt:en(`${q}/${Dt}`):en(`${q}/${Ct}`),Ts=Je.isDirectory?"directory":"file",cn=Ts==="file"&&Ct.includes(".")?Ct.split(".").pop()?.toLowerCase():void 0;Ve.push({name:Ct,path:ns,type:Ts,extension:cn})}return mw(Ve)},[x,g]),js=a.useCallback(async q=>{const Ie=en(q.trim());if(!Ie||Oe.current.has(Ie)||$e.current.has(Ie))return;$e.current=new Set($e.current),$e.current.add(Ie);const Ve=ot.current+1;ot.current=Ve,Re.current=new Map(Re.current),Re.current.set(Ie,Ve);const Je=()=>Re.current.get(Ie)===Ve;await(n.listDirectory?n.listDirectory(Ie).then(Dt=>Dt.entries.map(ns=>({name:ns.name,path:ns.path,isDirectory:ns.isDirectory}))):Hn.listLocalDirectory(Ie).then(Dt=>Dt.map(ns=>({name:ns.name,path:ns.path,isDirectory:ns.isDirectory})))).then(Dt=>{if(!Je())return;const ns=Us(Ie,Dt);Oe.current=new Set(Oe.current),Oe.current.add(Ie),be(Ts=>{if(!Ts[Ie])return Ts;const cn={...Ts};return delete cn[Ie],cn}),D(Ts=>({...Ts,[Ie]:ns}))}).catch(Dt=>{if(!Je())return;const ns=Dt instanceof Error?Dt.message:String(Dt??"");console.error("Failed to load files directory:",Dt),be(Ts=>({...Ts,[Ie]:ns}))}).finally(()=>{Je()&&(Re.current=new Map(Re.current),Re.current.delete(Ie),$e.current=new Set($e.current),$e.current.delete(Ie))})},[n,Us]),Mn=a.useCallback(async()=>{y&&(Oe.current=new Set,$e.current=new Set,Re.current=new Map,be({}),D(q=>Object.keys(q).length===0?q:{}),await js(y))},[js,y]),mn=a.useCallback(async q=>{if(!q){await Mn();return}const Ie=en(q);Oe.current=new Set(Oe.current),Oe.current.delete(Ie),$e.current=new Set($e.current),$e.current.delete(Ie),await js(Ie)},[js,Mn]),Rr=a.useRef(""),gn=a.useRef("");a.useEffect(()=>{if(!y)return;const q=`${y}|h${g?"1":"0"}|g${x?"1":"0"}`,Ie=Rr.current!==y,Ve=gn.current!==q;!Ie&&!Ve||(Ie&&(Rr.current=y,Ye(""),nt(null),lt(""),We(null),T(!1)),Ve&&(gn.current=q,Oe.current=new Set,$e.current=new Set,Re.current=new Map,be({}),D(Je=>Object.keys(Je).length===0?Je:{}),js(y)))},[js,y,x,g]),a.useEffect(()=>{if(!n.listDirectory)return;const q=()=>{if(!document.hidden&&le.length>0)for(const Ie of le)mn(Ie)};return document.addEventListener("visibilitychange",q),()=>document.removeEventListener("visibilitychange",q)},[le,n.listDirectory,mn]),a.useEffect(()=>{if(!n.listDirectory||le.length===0)return;const q=setInterval(()=>{if(!document.hidden)for(const Ie of le)mn(Ie)},8e3);return()=>clearInterval(q)},[le,n.listDirectory,mn]);const Mr=a.useCallback(async q=>{if(q?.preventDefault(),!xt||!Cs)return;fs(!0);const Ie=()=>{Mt(null)},Ve=Ct=>{ae.error(Ct)},Je=()=>{fs(!1)};if(Cs==="createFile"){if(!Ft.trim()){Ve(e("sidebarFilesTree.toast.filenameRequired")),Je();return}if(!n.writeFile){Ve(e("sidebarFilesTree.toast.writeNotSupported")),Je();return}const Ct=xt.path,Dt=Ct?`${Ct}/`:"",ns=en(`${Dt}${Ft.trim()}`);await n.writeFile(ns,"").then(async Ts=>{Ts.success&&(ae.success(e("sidebarFilesTree.toast.fileCreated")),await mn(Ct)),Ie()}).catch(()=>Ve(e("sidebarFilesTree.toast.operationFailed"))).finally(Je);return}if(Cs==="createFolder"){if(!Ft.trim()){Ve(e("sidebarFilesTree.toast.folderNameRequired")),Je();return}const Ct=xt.path,Dt=Ct?`${Ct}/`:"",ns=en(`${Dt}${Ft.trim()}`);await n.createDirectory(ns).then(async Ts=>{Ts.success&&(ae.success(e("sidebarFilesTree.toast.folderCreated")),await mn(Ct)),Ie()}).catch(()=>Ve(e("sidebarFilesTree.toast.operationFailed"))).finally(Je);return}if(Cs==="rename"){if(!Ft.trim()){Ve(e("sidebarFilesTree.toast.nameRequired")),Je();return}if(!n.rename){Ve(e("sidebarFilesTree.toast.renameNotSupported")),Je();return}const Ct=xt.path,Dt=Ct.split("/").slice(0,-1).join("/"),ns=Dt?`${Dt}/`:"",Ts=en(`${ns}${Ft.trim()}`);await n.rename(Ct,Ts).then(async cn=>{cn.success&&(ae.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await mn(Dt),y&&ve(y,Ct),(B?.path===Ct||B?.path.startsWith(`${Ct}/`))&&(y&&G(y,null),Ye(""),nt(null),lt(""),We(null),u&&T(!1))),Ie()}).catch(()=>Ve(e("sidebarFilesTree.toast.operationFailed"))).finally(Je);return}if(Cs==="delete"){if(!n.delete){Ve(e("sidebarFilesTree.toast.deleteNotSupported")),Je();return}const Ct=xt.path,Dt=Ct.split("/").slice(0,-1).join("/");await n.delete(Ct).then(async ns=>{ns.success&&(ae.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await mn(Dt),y&&ve(y,Ct),(B?.path===Ct||B?.path.startsWith(`${Ct}/`))&&(y&&G(y,null),Ye(""),nt(null),lt(""),We(null),u&&T(!1))),Ie()}).catch(()=>Ve(e("sidebarFilesTree.toast.operationFailed"))).finally(Je);return}Je()},[Cs,xt,Ft,n,mn,u,ve,y,B?.path,G,e]);a.useEffect(()=>{if(!p){At([]),Le(!1);return}const q=j.trim();if(!q){At([]),Le(!1);return}let Ie=!1;return Le(!0),N(p,q,150,{includeHidden:g,respectGitignore:!x,type:"file"}).then(Ve=>{if(Ie)return;const Ct=Ve.filter(Dt=>x||!xw(Dt.path)).map(Dt=>({name:Dt.name,path:en(Dt.path),type:"file",extension:Dt.extension,relativePath:Dt.relativePath}));At(Ct)}).catch(()=>{Ie||At([])}).finally(()=>{Ie||Le(!1)}),()=>{Ie=!0}},[p,j,N,g,x]);const xn=a.useCallback(async(q,Ie)=>{if(n.readFile)return(await n.readFile(q,Ie)).content??"";const Ve=new URLSearchParams({path:q});Ie?.allowOutsideWorkspace&&Ve.set("allowOutsideWorkspace","true"),Ie?.optional&&Ve.set("optional","true");const Je=await Fs(`/api/fs/read?${Ve.toString()}`,{cache:Ie?.optional?"no-store":"default"});if(!Je.ok){const Ct=await Je.json().catch(()=>({error:Je.statusText}));throw new Error(Ct.error||e("filesView.error.readFileFailed"))}return Je.text()},[n,e]),Vs=a.useCallback(async(q,Ie)=>{if(n.statFile){const Ve=await n.statFile(q,Ie);return{path:Ve.path,size:Ve.size,mtimeMs:Ve.mtimeMs}}return null},[n]);a.useEffect(()=>{if(!y||!n.statFile||xe.length===0)return;let q=!1;const Ie=[...xe];return Promise.all(Ie.map(async Ve=>{try{const Je=await n.statFile?.(Ve);!q&&Je&&!Je.isFile&&ve(y,Ve)}catch(Je){!q&&Ad(Je)&&ve(y,Ve)}})),()=>{q=!0}},[n,xe,ve,y]);const bn=a.useMemo(()=>Qe.length>Xi?`${Qe.slice(0,Xi)}
25
25
 
26
- … truncated …`:st,[st]),ps=Ze!==mn,Zs=a.useCallback(async()=>{if(!B||!n.writeFile)return ae.error(e("filesView.toast.savingNotSupported")),!1;if(!ps)return!0;Ge(!0);try{const Y=xw(Ze,it);return(await n.writeFile(B.path,Y))?.success?(Pe(Ze),Ln(B.path).then(Ve=>{Ve&&(Bt.current=Ve)}).catch(()=>{}),!0):(ae.error(e("filesView.toast.writeFileFailed")),!1)}catch(Y){return ae.error(Y instanceof Error?Y.message:e("filesView.toast.saveFailed")),!1}finally{Ge(!1)}},[Ze,n,ps,it,Ln,B,e]);a.useEffect(()=>{if(!ps){zs(null);return}const Y=Ie=>us.current?(us.current=!1,!0):(es(!0),pt.current=Ie,!1);return zs(Y),()=>{Fe.getState().mainTabGuard===Y&&zs(null)}},[ps,zs]),a.useEffect(()=>{try{window.localStorage.setItem(pm,At?"true":"false")}catch{}},[At]),a.useEffect(()=>{At||(Ut("idle"),ct.current&&(clearTimeout(ct.current),ct.current=null))},[At]);const vn=1500;a.useEffect(()=>{const Y=!!(B&&n.writeFile);if(!(!At||!ps||!Y||jt))return ct.current=setTimeout(()=>{Zs().then(Ie=>{Ie&&(Ut("saved"),setTimeout(()=>Ut("idle"),2e3))})},vn),()=>{ct.current&&(clearTimeout(ct.current),ct.current=null)}},[At,Ze,ps,B,n.writeFile,jt,Zs]),a.useEffect(()=>{Ut("idle")},[B?.path]),a.useEffect(()=>{const Y=Ie=>{Vl(Ie)&&(Ie.key.toLowerCase()==="s"?(Ie.preventDefault(),ct.current&&(clearTimeout(ct.current),ct.current=null),jt||Zs().then(Ve=>{Ve&&(Ut("saved"),setTimeout(()=>Ut("idle"),2e3))})):Ie.key.toLowerCase()==="f"&&(Ie.preventDefault(),R(!0)))};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[jt,Zs]);const jn=a.useCallback(async Y=>{const Ie=Ft.current+1;Ft.current=Ie;const Ve=()=>{if(!y)return!1;const os=Nn.getState().byRoot[y],Cs=os?.selectedPath??os?.openPaths[0]??null;return Ft.current===Ie&&Cs===Y.path};ft(null),ot(""),He(null);const Je=Bi(Y.path),kt=Y.path.toLowerCase().endsWith(".svg");if(u&&T(!0),r.isDesktop&&Je&&!kt){Pe(""),Ue(""),Ye(!0);return}if(!r.isDesktop&&Je&&!kt){Pe(""),Ue(""),He(Y.path),Ye(!1);return}Ye(!0);const Mt={allowOutsideWorkspace:t==="editor-only"&&!!y&&!ca(Y.path,y)};await pn(Y.path,Mt).then(os=>{if(!Ve())return;const Cs=gm(os);Et(gw(os)),Pe(Cs),Ue(Cs.length>Zi?`${Cs.slice(0,Zi)}
26
+ … truncated …`:Qe,[Qe]),Ds=gt!==bn,Zs=a.useCallback(async()=>{if(!B||!n.writeFile)return ae.error(e("filesView.toast.savingNotSupported")),!1;if(!Ds)return!0;Et(!0);try{const q=ww(gt,at);return(await n.writeFile(B.path,q))?.success?(Ye(gt),Vs(B.path).then(Ve=>{Ve&&(Wt.current=Ve)}).catch(()=>{}),!0):(ae.error(e("filesView.toast.writeFileFailed")),!1)}catch(q){return ae.error(q instanceof Error?q.message:e("filesView.toast.saveFailed")),!1}finally{Et(!1)}},[gt,n,Ds,at,Vs,B,e]);a.useEffect(()=>{if(!Ds){ws(null);return}const q=Ie=>ts.current?(ts.current=!1,!0):(ft(!0),ms.current=Ie,!1);return ws(q),()=>{Fe.getState().mainTabGuard===q&&ws(null)}},[Ds,ws]),a.useEffect(()=>{try{window.localStorage.setItem(bm,Qt?"true":"false")}catch{}},[Qt]),a.useEffect(()=>{Qt||(Gt("idle"),Rt.current&&(clearTimeout(Rt.current),Rt.current=null))},[Qt]);const vr=1500;a.useEffect(()=>{const q=!!(B&&n.writeFile);if(!(!Qt||!Ds||!q||st))return Rt.current=setTimeout(()=>{Zs().then(Ie=>{Ie&&(Gt("saved"),setTimeout(()=>Gt("idle"),2e3))})},vr),()=>{Rt.current&&(clearTimeout(Rt.current),Rt.current=null)}},[Qt,gt,Ds,B,n.writeFile,st,Zs]),a.useEffect(()=>{Gt("idle")},[B?.path]),a.useEffect(()=>{const q=Ie=>{$l(Ie)&&(Ie.key.toLowerCase()==="s"?(Ie.preventDefault(),Rt.current&&(clearTimeout(Rt.current),Rt.current=null),st||Zs().then(Ve=>{Ve&&(Gt("saved"),setTimeout(()=>Gt("idle"),2e3))})):Ie.key.toLowerCase()==="f"&&(Ie.preventDefault(),R(!0)))};return window.addEventListener("keydown",q),()=>window.removeEventListener("keydown",q)},[st,Zs]);const jr=a.useCallback(async q=>{const Ie=qt.current+1;qt.current=Ie;const Ve=()=>{if(!y)return!1;const ns=Nn.getState().byRoot[y],Ts=ns?.selectedPath??ns?.openPaths[0]??null;return qt.current===Ie&&Ts===q.path};nt(null),lt(""),We(null);const Je=_i(q.path),Ct=q.path.toLowerCase().endsWith(".svg");if(u&&T(!0),r.isDesktop&&Je&&!Ct){Ye(""),He(""),bt(!0);return}if(!r.isDesktop&&Je&&!Ct){Ye(""),He(""),We(q.path),bt(!1);return}bt(!0);const Dt={allowOutsideWorkspace:t==="editor-only"&&!!y&&!ca(q.path,y)};await xn(q.path,Dt).then(ns=>{if(!Ve())return;const Ts=ym(ns);dt(yw(ns)),Ye(Ts),He(Ts.length>Xi?`${Ts.slice(0,Xi)}
27
27
 
28
- … truncated …`:Cs),He(Y.path),Ln(Y.path,Mt).then(hn=>{hn&&Ve()&&(Bt.current=hn)}).catch(()=>{})}).catch(os=>{if(Ve()){if(pw(os)){if(Ye(!1),y&&G(y,null),ft(null),Pe(""),Ue(""),He(null),Bt.current=null,S.trim().length>0&&v(""),u&&T(!1),y){const hn=[...jd(Y.path,y),Y.path];hn.length>0&&ce(y,hn);for(const So of hn)K.current.has(So)||Qt(So)}return}if(Nd(os)){y&&ve(y,Y.path),Pe(""),Ue(""),ft(null),Bt.current=null,u&&T(!1);return}Pe(""),Ue(""),ft(os instanceof Error?os.message:e("filesView.error.readFileFailed")),Bt.current=null}}).finally(()=>{Ve()&&Ye(!1)})},[ce,u,Qt,t,pn,Ln,ve,y,r.isDesktop,S,G,e]),Kn=a.useCallback(async(Y,Ie)=>{if(!y)return;const Ve=jd(Y,y),Je=Ie?[...Ve,Y]:Ve;Je.length>0&&ce(y,Je);const kt=Je.map(Mt=>{if(!K.current.has(Mt))return Qt(Mt)}).filter(Boolean);await Promise.all(kt)},[ce,Qt,y]),Nr=a.useCallback((Y,Ie)=>{const Ve=Ie.findIndex(Je=>Je.path===Y);return Ve===-1||Ie.length<=1?null:Ie[Ve+1]??Ie[Ve-1]??null},[]),en=a.useCallback(async Y=>{if(us.current)us.current=!1;else if(ps){es(!0),Gt.current=Y;return}y&&(G(y,Y.path),ke(y,Y.path),Kn(Y.path,!1)),ft(null),ot(""),Pe(""),Ue(""),He(null),u&&T(!0)},[ke,Kn,ps,u,y,G]);a.useEffect(()=>{B?.path&&Kn(B.path,!1)},[Kn,B?.path]),a.useEffect(()=>{if(!B){Ft.current+=1,Ye(!1);return}bt!==B.path&&jn(B)},[jn,bt,B]);const kr=a.useRef(ps);kr.current=ps,a.useEffect(()=>{if(!B?.path||bt!==B.path)return;let Y=!1;const Ie=window.setInterval(()=>{document.hidden||Ln(B.path,Q).then(Ve=>{if(Y||!Ve)return;const Je=Bt.current;if(!Je||Je.path!==B.path){Bt.current=Ve;return}const kt=Ve.mtimeMs!==void 0&&Je.mtimeMs!==void 0&&Ve.mtimeMs!==Je.mtimeMs,Mt=Ve.size!==Je.size;!kt&&!Mt||kr.current||(Bt.current=Ve,He(null))}).catch(()=>{})},2e3);return()=>{Y=!0,window.clearInterval(Ie)}},[bt,Ln,B?.path,Q]);const qi=a.useCallback(()=>{const Y=Gt.current,Ie=pt.current,Ve=Yt.current;if(Gt.current=null,pt.current=null,Yt.current=null,us.current=!0,es(!1),Ue(mn),Ve){y&&ue(y,Ve),B?.path===Ve&&(Y?en(Y):(y&&G(y,null),Pe(""),ft(null),ot(""),He(null),u&&T(!1)));return}if(Y){en(Y);return}Ie&&(zs(null),Fe.getState().setActiveMainTab(Ie))},[mn,en,u,ue,y,B?.path,zs,G]),ji=a.useCallback(async()=>{const Y=Gt.current,Ie=pt.current,Ve=Yt.current;if(!await Zs()){us.current=!1;return}if(Gt.current=null,pt.current=null,Yt.current=null,us.current=!0,es(!1),Ve){y&&ue(y,Ve),B?.path===Ve&&(Y?await en(Y):(y&&G(y,null),Pe(""),ft(null),ot(""),He(null),u&&T(!1)));return}if(Y){await en(Y);return}Ie&&(zs(null),Fe.getState().setActiveMainTab(Ie))},[en,u,ue,y,Zs,B?.path,zs,G]),Yi=a.useCallback(Y=>{const Ie=B?.path===Y,Ve=Nr(Y,Ee);if(Ie&&ps){es(!0),Gt.current=Ve,Yt.current=Y;return}if(y&&ue(y,Y),!!Ie){if(Ve){en(Ve);return}y&&G(y,null),Pe(""),ft(null),ot(""),He(null),u&&T(!1)}},[Nr,en,ps,u,Ee,ue,y,B?.path,G]),si=a.useCallback(Y=>{if(be.includes(Y))return"open";if(w?.files){const Ie=Y.startsWith(y+"/")?Y.slice(y.length+1):Y,Ve=w.files.find(Je=>Je.path===Ie);if(Ve){if(Ve.index==="A"||Ve.working_dir==="?")return"git-added";if(Ve.index==="D")return"git-deleted";if(Ve.index==="M"||Ve.working_dir==="M")return"git-modified"}}return null},[be,w,y]),rr=a.useCallback(Y=>{if(!w?.files)return null;const Ie=Y.startsWith(y+"/")?Y.slice(y.length+1):Y,Ve=Ie?`${Ie}/`:"";let Je=0,kt=0;for(const Mt of w.files)Mt.path.startsWith(Ve)&&((Mt.index==="M"||Mt.working_dir==="M")&&Je++,(Mt.index==="A"||Mt.working_dir==="?")&&kt++);return Je+kt>0?{modified:Je,added:kt}:null},[w,y]),gn=a.useCallback(async Y=>{const Ie=tn(Y);y&&(Ae(y,Ie),K.current.has(Ie)||await Qt(Ie))},[Qt,y,Ae]),Br=a.useMemo(()=>({canRename:xs,canCreateFile:ts,canCreateFolder:js,canDelete:Bs,canReveal:Ts}),[xs,ts,js,Bs,Ts]);function Mr(Y,Ie){const Ve=O[Y]??[];return Ve.map((Je,kt)=>{const Mt=Je.type==="directory",os=Mt&&le.includes(Je.path),Cs=B?.path===Je.path,hn=kt===Ve.length-1;return s.jsxs("li",{className:"relative",children:[Ie>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),hn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(ww,{node:Je,root:y,isExpanded:os,isActive:Cs,isMobile:u,alwaysShowActions:f,status:Mt?void 0:si(Je.path),badge:Mt?rr(Je.path):void 0,permissions:Br,downloadFile:n.downloadFile,contextMenuPath:rs,setContextMenuPath:ds,onSelect:en,onToggle:gn,onRevealPath:bs,onOpenDialog:yn}),Mt&&os&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Mr(Je.path,Ie+1)})]},Je.path)})}const Js=!!(B?.path&&Bi(B.path)),mr=!!(B?.path&&B.path.toLowerCase().endsWith(".svg")),Si=a.useMemo(()=>tn(is?.path??""),[is?.path]),Cr=!!(is&&Si&&ye&&ye===Si&&!tt&&!nt&&!Js),fr=a.useMemo(()=>Cl(y,ye),[ye,y]),Vr=!!(B&&(!Js||mr)&&st.length>0),Ls=!!(B&&fr.length>0),xn=!!(B&&!Oe&&!Js&&n.writeFile&&st.length<=Zi),hr=!!(B?.path&&kd(B.path)),ni=!!(B?.path&&yw(B.path)),ri=!!(B?.path&&Po(B.path)),Qs=!!(B&&!Js)&&!hr&&!(ri&&Se==="preview"),J=a.useMemo(()=>ye?Eu(ye):null,[ye]),[xe,Ce]=a.useState(null);a.useEffect(()=>{let Y=!1;const Ie=B?.path;if(!Ie||J){Ce(null);return}return Ce(null),th(Ie).then(Ve=>{Y||Ce(Ve)}),()=>{Y=!0}},[B?.path,J]),a.useEffect(()=>{!xn&&ne==="edit"&&U("view")},[xn,ne]);const $e="openchamber:files:md-viewer-mode",wt="openchamber:files:html-viewer-mode",Nt="openchamber:files:json-viewer-mode";a.useEffect(()=>{const Y=B?.path;if(!Y)return;const Ie=Hn?"view":"edit";U(L.current[Y]??Ie);let Ve=Hn?"preview":"edit";try{const Mt=localStorage.getItem($e);(Mt==="preview"||Mt==="edit")&&(Ve=Mt)}catch{}oe($.current[Y]??Ve);let Je=Hn?"preview":"edit";try{const Mt=localStorage.getItem(wt);(Mt==="preview"||Mt==="edit")&&(Je=Mt)}catch{}re(q.current[Y]??Je);let kt=Hn?"tree":"text";try{const Mt=localStorage.getItem(Nt);(Mt==="tree"||Mt==="text")&&(kt=Mt)}catch{}je(kt)},[B?.path,Hn]);const Ss=a.useCallback(Y=>{const Ie=B?.path;Ie&&(L.current[Ie]=Y),U(Y)},[B?.path]),Os=a.useCallback(Y=>{const Ie=B?.path;Ie&&($.current[Ie]=Y),oe(Y);try{localStorage.setItem($e,Y)}catch{}},[B?.path]),qn=a.useCallback(()=>ie,[ie]),Da=a.useCallback(Y=>{je(Y);try{localStorage.setItem(Nt,Y)}catch{}},[]),X=a.useCallback(Y=>{const Ie=B?.path;Ie&&(q.current[Ie]=Y),re(Y);try{localStorage.setItem(wt,Y)}catch{}},[B?.path]),Xe=a.useCallback(()=>Se,[Se]);a.useEffect(()=>{const Y=Ve=>{const Je=Ve?"view":"edit",kt=Ve?"preview":"edit",Mt=Ve?"tree":"text";for(const os of be)L.current[os]=Je,kd(os)&&($.current[os]=kt),Po(os)&&(q.current[os]=kt);U(Je),oe(kt),re(kt),je(Mt);try{localStorage.setItem($e,kt),localStorage.setItem(wt,kt),localStorage.setItem(Nt,Mt)}catch{}},Ie=Ve=>{const Je=!!Ve.detail?.enabled;Y(Je)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",Ie),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",Ie)}},[be]),a.useEffect(()=>{if(!is||!y)return;const Y=()=>{typeof window>"u"||Vt.current===null&&(Vt.current=window.requestAnimationFrame(()=>{Vt.current=null,Ms(Fr=>Fr+1)}))},Ie=(Fr,ii)=>{if(Fr.state.doc.length!==ii.length)return!1;if(ii.length===0)return!0;const Ia=Math.min(128,ii.length);if(Fr.state.sliceDoc(0,Ia)!==ii.slice(0,Ia))return!1;const dc=Math.max(0,ii.length-Ia);return Fr.state.sliceDoc(dc,ii.length)===ii.slice(dc)},Ve=tn(is.path);if(!Ve){Fs(null),vs.current={key:"",attempts:0};return}const Je=`${Ve}:${is.line}:${is.column??1}`;if(vs.current.key!==Je&&(vs.current={key:Je,attempts:0}),B?.path!==Ve){if(ls)return;en(fe(Ve));return}if(tt||bt!==Ve)return;if(nt||Js){Fs(null),vs.current={key:"",attempts:0};return}if(!xn)return;if(ne!=="edit"){U("edit");return}const kt=hs.current;if(!kt){Y();return}if(!Ie(kt,Ze)){Y();return}const Mt=Math.max(1,Math.min(is.line,kt.state.doc.lines)),os=kt.state.doc.line(Mt),Cs=Math.max(1,is.column||1),hn=Math.max(0,os.to-os.from),So=Math.min(hn,Cs-1),Ji=os.from+So;if(!(kt.state.selection.main.head===Ji)||vs.current.attempts===0){vs.current.attempts+=1,kt.dispatch({selection:{anchor:Ji},effects:Kr.scrollIntoView(Ji,{y:"center"})}),kt.focus(),Y();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Fr=hs.current;Fr&&(Fr.dispatch({selection:{anchor:Ji},effects:Kr.scrollIntoView(Ji,{y:"center"})}),Fr.focus())}),Fs(null),vs.current={key:"",attempts:0}},[xn,ls,Ze,gs,nt,tt,Js,bt,en,is,y,B?.path,Fs,ne,fe]),a.useEffect(()=>{if(!dr||!y)return;const Y=tn(dr);if(!Y){Cn(null);return}if(B?.path!==Y){if(ls)return;en(fe(Y));return}if(!(tt||bt!==Y||nt||Js)){if(xn&&ne==="edit"){const Ie=hs.current;if(!Ie)return;Ie.focus()}Cn(null)}},[xn,ls,nt,tt,en,Js,bt,dr,y,B?.path,Cn,ne,fe]);const Ke=a.useCallback(Y=>{if(!u||!Y||!Y.hasFocus||typeof window>"u")return;const Ie=window.visualViewport;if(!Ie)return;const Ve=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,Ve-(Ie.offsetTop+Ie.height))<=0)return;const kt=Y.state.selection.main.head,Mt=Y.coordsAtPos(kt);if(!Mt)return;const os=Math.round(Ie.offsetTop+Ie.height),hn=Mt.bottom+20-os;hn<=0||(Y.scrollDOM.scrollTop+=hn)},[u]);a.useEffect(()=>{if(!u||typeof window>"u")return;const Y=()=>{window.requestAnimationFrame(()=>{Ke(hs.current)})},Ie=window.visualViewport;return Ie?.addEventListener("resize",Y),Ie?.addEventListener("scroll",Y,{passive:!0}),document.addEventListener("selectionchange",Y),()=>{Ie?.removeEventListener("resize",Y),Ie?.removeEventListener("scroll",Y),document.removeEventListener("selectionchange",Y)}},[u,Ke]),a.useEffect(()=>{if(!xn||ne!=="edit"||u)return;const Y=mi("open_go_to_line",$s),Ie=Ve=>{const Je=Ve.target;if(Je?.closest('[role="dialog"]'))return;const kt=!!Je?.closest(".cm-editor");Je?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!kt||!document.activeElement?.closest(".cm-editor")||Lo(Ve,Y)&&(Ve.preventDefault(),ut(!0))};return window.addEventListener("keydown",Ie),()=>window.removeEventListener("keydown",Ie)},[xn,u,$s,ne]);const Pt=a.useMemo(()=>{if(!B?.path)return[ml(o)];const Y=[ml(o)],Ie=J??xe;return Ie&&Y.push(Ie),C&&Y.push(Kr.lineWrapping),u&&Y.push(Kr.updateListener.of(Ve=>{Ve.view.hasFocus&&(Ve.selectionSet||Ve.focusChanged||Ve.viewportChanged||Ve.geometryChanged)&&window.requestAnimationFrame(()=>{Ke(Ve.view)})})),Y},[o,B?.path,J,xe,C,u,Ke]),Zt=a.useMemo(()=>({light:he.metadata.id,dark:de.metadata.id}),[he.metadata.id,de.metadata.id]),ys=B?.path&&Js&&!r.isDesktop&&!mr?`${B.path}|${Q.allowOutsideWorkspace?"outside":"workspace"}`:"";a.useEffect(()=>{if(!ys){dt("");return}let Y=!1;return dt(""),Fl(Qr()).then(Ie=>{!Y&&Ie&&dt(ys)}).catch(()=>{}),()=>{Y=!0}},[ys]);const bn=!!(ys&&It!==ys),ir=B?.path&&Js?r.isDesktop?mr?`data:${vc(B.path)};utf8,${encodeURIComponent(st)}`:mt:mr?`data:${vc(B.path)};utf8,${encodeURIComponent(st)}`:It===ys?Oi().authenticatedAsset("/api/fs/raw",{path:B.path,allowOutsideWorkspace:Q.allowOutsideWorkspace?"true":void 0}):"":"";a.useEffect(()=>{let Y=!1;return(async()=>{if(!r.isDesktop||!B?.path||!Js||mr){ot("");return}ft(null),await(n.readFileBinary?n.readFileBinary(B.path,Q).then(Je=>Je.dataUrl):Promise.resolve(Oi().authenticatedAsset("/api/fs/raw",{path:B.path,allowOutsideWorkspace:Q.allowOutsideWorkspace?"true":void 0}))).then(Je=>{Y||(ot(Je),He(B.path))}).catch(Je=>{Y||(ot(""),ft(Je instanceof Error?Je.message:e("filesView.error.readFileFailed")),He(null))}).finally(()=>{Y||Ye(!1)})})(),()=>{Y=!0}},[n,Js,mr,r.isDesktop,B?.path,Q,e]);const Yn=a.useCallback(()=>Ns(null),[]),Sn=a.useMemo(()=>Yu({drafts:jr,editingDraftId:nr,commentText:sr,selection:ks,isDragging:Un,fileLabel:B?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Y=>({start:Y.startLine,end:Y.endLine}),onSave:fs,onCancel:()=>{ln(null),ee()},onEdit:Y=>{St(Y),ln({start:Y.startLine,end:Y.endLine})},onDelete:$t}),[ee,sr,$t,nr,jr,fs,Un,ks,B?.path,St]),fn=a.useCallback((Y,Ie)=>s.jsx("div",{className:"h-full",children:s.jsx(Qm,{file:{name:Y.name,contents:Ie,lang:_i(Y.path)||void 0},options:{disableFileHeader:!0,overflow:C?"wrap":"scroll",theme:Zt,themeType:o.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[o.metadata.variant,Zt,C]),Ni=({exitFullscreenOnly:Y=!1}={})=>{if(!B)return null;const Ie=(Ve,Je)=>s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:Je})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:Ve})]});return s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[xn&&ne==="edit"&&s.jsxs(s.Fragment,{children:[jt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):At&&qt==="saved"&&!ps?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(I,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):ps?Ie(e(At?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${Ta()}+S`}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{Zs()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(At?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${Ta()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${Ta()}+S`}),children:s.jsx(I,{name:"save-3",className:"size-4"})})):null,Ie(e(At?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Xt(Ve=>!Ve),className:Te("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",At?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(At?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(At?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:At?s.jsx(I,{name:"file-check-fill",className:"size-4"}):s.jsx(I,{name:"file-check",className:"size-4"})}))]}),s.jsxs(on,{onOpenChange:te,children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(nn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(I,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(rn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[dn.map(Ve=>s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{wr(Ve)},children:[s.jsx(lw,{label:Ve.label,iconDataUrl:Ve.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Ve.label})]},Ve.id)),Ds?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{Us(!0)},children:[s.jsx(I,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Js&&s.jsxs(s.Fragment,{children:[Ie(e(C?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>P(!C),className:Te("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",C?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(C?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})})),ne==="edit"&&s.jsxs(s.Fragment,{children:[Ie(e("filesView.editor.findInFile"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:Ve=>{R(!H),Ve.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(I,{name:"search",className:"size-4"})})),Ie(e("filesView.editor.goToLine"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:Ve=>{ut(Je=>!Je),Ve.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(I,{name:"menu-fold-2",className:"size-4"})})),s.jsx(ow,{open:Ct,onOpenChange:ut,view:hs.current,variant:"inline"})]})]}),Qs&&xn&&!ni&&!ri&&s.jsx(hl,{currentMode:ne==="view"?"preview":"edit",onToggle:()=>{Ss(ne==="view"?"edit":"view")}}),(hr||Po(B?.path??""))&&s.jsx(hl,{currentMode:hr?qn():Xe(),onToggle:()=>{Po(B?.path??"")?X(Xe()==="preview"?"edit":"preview"):Os(qn()==="preview"?"edit":"preview")}}),ni&&Ie(e(ge==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Da(ge==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ge==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ge==="tree"?s.jsx(I,{name:"code-sslash",className:"size-4"}):s.jsx(I,{name:"node-tree",className:"size-4"})})),Vr&&Ie(e("filesView.editor.copyFileContents"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await cr(st)).ok?(qe(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{qe(!1)},1200)):ae.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:W?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"size-4"})})),Ls&&Ie(e("filesView.editor.copyFilePathTitle",{path:fr}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await cr(fr)).ok?(ht(!0),ss.current!==null&&window.clearTimeout(ss.current),ss.current=window.setTimeout(()=>{ht(!1)},1200)):ae.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:fr}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:fr}),children:Qe?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&Ie(e("filesView.editor.saveFile"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{const Ve=n.downloadFile;Ve&&Ve(B.path)},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(I,{name:"download",className:"size-4"})})),Y?Ie(e("filesView.editor.exitFullscreen"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>M(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(I,{name:"fullscreen-exit",className:"size-4"})})):!u&&t==="full"&&Ie(e(E?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>M(!E),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(E?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(E?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:E?s.jsx(I,{name:"fullscreen-exit",className:"size-4"}):s.jsx(I,{name:"fullscreen",className:"size-4"})}))]})},ki=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Ks,{open:ls,onOpenChange:Y=>{Y||es(!0)},children:s.jsxs(Gs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Xs,{children:[s.jsx(Ys,{children:e("filesView.unsaved.title")}),s.jsx(cn,{children:e("filesView.unsaved.description")})]}),s.jsxs(tr,{children:[s.jsx(ze,{variant:"outline",onClick:()=>{ji()},disabled:jt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(ze,{variant:"destructive",onClick:qi,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:Te("flex flex-col flex-shrink-0",b&&"border-b border-border/40"),children:b?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[u&&D&&s.jsx("button",{type:"button",onClick:()=>T(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"arrow-left-s",className:"size-5"})}),u?B?s.jsxs(on,{children:[s.jsx(nn,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(yr,{filePath:B.path,extension:B.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Sd,{name:B.name}),s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(rn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Ee.map(Y=>{const Ie=B?.path===Y.path;return s.jsxs(zt,{onSelect:Ve=>{if(Ve.target.closest("[data-close-open-file]")){Ve.preventDefault();return}Ie||en(Y)},className:Te("flex min-w-0 items-center justify-between gap-2 overflow-hidden",Ie&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(yr,{filePath:Y.path,extension:Y.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Sd,{name:Y.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:Ve=>{Ve.preventDefault(),Ve.stopPropagation()},onClick:Ve=>{Ve.preventDefault(),Ve.stopPropagation(),Yi(Y.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:Y.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},Y.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Ee.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Re.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),Re.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Me,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Ee.map(Y=>{const Ie=B?.path===Y.path;return s.jsxs("div",{title:Cl(y,Y.path),className:Te("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",Ie?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(yr,{filePath:Y.path,extension:Y.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Ie||en(Y)},className:"max-w-[12rem] truncate text-left",children:Y.name}),s.jsx("button",{type:"button",onClick:Ve=>{Ve.stopPropagation(),Yi(Y.path)},className:Te("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!Ie&&!f&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Y.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},Y.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[B&&!H&&s.jsx("div",{ref:V,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>z(!0),onMouseLeave:()=>{F.current>0||z(!1)},children:_?Ni():s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>z(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})}),s.jsx(Fn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:B?tt||bn?h?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):nt?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:nt}):Js?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:ir,alt:B?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):B&&ni&&ge==="tree"?s.jsx(an,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(sh,{jsonString:st,maxHeight:"100%",initiallyExpandedDepth:2})})}):B&&hr&&qn()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[st.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(st.length/1024)})}),s.jsx(an,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(ho,{content:st,className:"typography-markdown-body",stripFrontmatter:!0})})]}):B&&ri&&Se==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Y=B.path.substring(0,B.path.lastIndexOf("/")+1);if(!Y)return st;const Ie=`<base href="${r.isDesktop,Y}">`;return st.replace(/<head([^>]*)>/i,`<head$1>${Ie}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):B&&Qs&&ne==="view"?fn(B,Ze):s.jsxs("div",{className:Te("relative h-full",Cr&&"overflow-hidden"),ref:Wt,children:[s.jsx("div",{className:Te("h-full",Cr&&"invisible"),children:s.jsx(fl,{value:Ze,onChange:Ue,readOnly:!xn,extensions:Pt,className:"h-full",blockWidgets:Sn,onViewReady:Y=>{hs.current=Y,Ms(Ie=>Ie+1),window.requestAnimationFrame(()=>{Ke(Y)})},onViewDestroy:()=>{hs.current&&(hs.current=null),Ms(Y=>Y+1)},enableSearch:!0,searchOpen:H,onSearchOpenChange:R,highlightLines:ks?{start:Math.min(ks.start,ks.end),end:Math.max(ks.start,ks.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Y,Ie,Ve)=>{if(!(Ve instanceof MouseEvent)||Ve.button!==0)return!1;Ve.preventDefault();const Je=Y.state.doc.lineAt(Ie.from).number;if(u&&ks&&!Ve.shiftKey){const kt=Math.min(ks.start,ks.end,Je),Mt=Math.max(ks.start,ks.end,Je);return ln({start:kt,end:Mt}),Tn.current=!1,un.current=null,wn(!1),!0}if(Tn.current=!0,un.current=Je,wn(!0),ks&&Ve.shiftKey){const kt=Math.min(ks.start,Je),Mt=Math.max(ks.end,Je);ln({start:kt,end:Mt})}else ln({start:Je,end:Je});return!0},mouseover:(Y,Ie,Ve)=>{if(!(Ve instanceof MouseEvent)||Ve.buttons!==1||!Tn.current||un.current===null)return!1;const Je=Y.state.doc.lineAt(Ie.from).number,kt=Math.min(un.current,Je),Mt=Math.max(un.current,Je);return ln({start:kt,end:Mt}),wn(!0),!1},mouseup:()=>(Tn.current=!1,un.current=null,wn(!1),!1)}}})}),Cr&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),qm=!!(y&&O[y]),cc=s.jsxs("section",{className:Te("flex min-h-0 flex-col overflow-hidden",u?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:Te("flex flex-col gap-2 py-2",u?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(kn,{ref:k,value:S,onChange:Y=>v(Y.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),S.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{v(""),k.current?.focus()},children:s.jsx(I,{name:"close",className:"size-4"})})]}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>yn("createFile",{path:p,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"size-4"})})})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>yn("createFolder",{path:p,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"size-4"})})})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{Ws()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(I,{name:"refresh",className:"size-4"})})})}),s.jsx(_t,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(Fn,{outerClassName:"flex-1 min-h-0",className:Te("py-2",u?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:yt?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):Le.length>0?Le.map(Y=>{const Ie=B?.path===Y.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{en(Y)},className:Te("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Ie?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[xm(Y.path,Y.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Y.path,children:Y.relativePath??Y.path})]})},Y.path)}):qm?Mr(y,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Ym=t==="full"&&E&&B&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:Ni({exitFullscreenOnly:!0})}),s.jsx(Fn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:tt||bn?h?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):nt?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:nt}):Js?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:ir,alt:B.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):hr&&qn()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[st.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(st.length/1024)})}),s.jsx(an,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(ho,{content:st,className:"typography-markdown-body",stripFrontmatter:!0})})]}):Qs&&ne==="view"?fn(B,Ze):s.jsxs("div",{className:Te("relative h-full",Cr&&"overflow-hidden"),children:[s.jsx("div",{className:Te("h-full",Cr&&"invisible"),children:s.jsx(fl,{value:Ze,onChange:Ue,readOnly:!xn,extensions:Pt,className:"h-full",onViewReady:Y=>{hs.current=Y,window.requestAnimationFrame(()=>{Ke(Y)})},onViewDestroy:()=>{hs.current&&(hs.current=null)}})}),Cr&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(vw,{activeDialog:Ps,dialogData:As,dialogInputValue:xt,onDialogInputChange:Kt,isDialogSubmitting:Ht,onDialogSubmit:_r,onClose:Yn,inputRef:lt}),Ym,u?D?ki:cc:t==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:ki})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[d>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:cc}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:ki})]})]})},br=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Ha=(t,e)=>{const n=br(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},jw=(t,e,n)=>Ha(Ha(Ha(t,".opencode"),"plans"),`${e}-${n}.md`),Sw=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,Nw=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},kw=(t,e)=>{const n=br(e.currentDirectory),r=br(e.homeDirectory),o=br(t);return n&&o.startsWith(n+"/")?o.slice(n.length+1):r&&o===r?"~":r&&o.startsWith(r+"/")?`~${o.slice(r.length)}`:o},Cw=(t,e,n)=>{const r=br(t.trim());if(!r)return null;const o=n?e.find(c=>c.id===n)??null:null;if(o?.path){const c=br(o.path);if(r===c||r.startsWith(`${c}/`))return{id:o.id,path:o.path}}const i=e.filter(c=>{const l=br(c.path);return r===l||r.startsWith(`${l}/`)}).sort((c,l)=>br(l.path).length-br(c.path).length)[0];return i?{id:i.id,path:i.path}:null},ym=({targetPath:t=null})=>{const{t:e}=Tt(),n=vt(se=>se.currentSessionId),r=vt(se=>se.createSession),o=vt(se=>se.initializeNewOpenChamberSession),i=vt(se=>se.sendMessage),c=vt(se=>se.setCurrentSession),l=Gl(),u=sn(se=>se.homeDirectory),m=_l(se=>se.planModeEnabled),d=Es(se=>se.projects),f=Es(se=>se.activeProjectId),g=_s(se=>se.directories),x=ti()??"",p=Fe(se=>se.setActiveMainTab),y=Fe(se=>se.setSessionSwitcherOpen),b=Wn(),{isMobile:h}=Pr(),{currentTheme:N}=Tr();a.useMemo(()=>Ru(N),[N]);const w=a.useMemo(()=>n?l.find(se=>se.id===n)??null:null,[n,l]),S=a.useMemo(()=>{const se=typeof w?.directory=="string"?w.directory:"";return br(se||"")},[w?.directory]),v=a.useMemo(()=>br(x||S),[x,S]),j=a.useMemo(()=>Cw(v,d,f),[f,v,d]),k=a.useMemo(()=>j?g.get(j.path)?.isGitRepo===!0:!1,[j,g]),[D,T]=a.useState(null),[C,P]=a.useState(!1),[E,M]=a.useState(null),H=a.useMemo(()=>!E||!S||!u?E:kw(E,{currentDirectory:S,homeDirectory:u}),[E,S,u]),[R,_]=a.useState(""),[z,V]=a.useState(null),F=a.useMemo(()=>H&&H.split("/").pop()||e("planView.file.defaultName"),[H,e]),te=a.useMemo(()=>R.trim()&&nh(R).title||e("planView.title.default"),[R,e]),Z=a.useMemo(()=>te.trim()||e("planView.title.default"),[te,e]),[ne,U]=a.useState(!1),[ie,oe]=a.useState(!1),[ge,je]=a.useState("edit"),Se=a.useRef(null),[re,L]=a.useState(null),$=a.useRef(null),q=a.useRef(null),he="openchamber:plan:md-viewer-mode";a.useEffect(()=>{try{const se=localStorage.getItem(he);if(!se)return;const O=JSON.parse(se);(O==="preview"||O==="edit")&&je(O)}catch{}},[]);const de=a.useCallback(se=>{je(se);try{localStorage.setItem(he,JSON.stringify(se))}catch{}},[]),we=a.useRef(!1),be=a.useRef(null),[De,le]=a.useState(!1);a.useEffect(()=>{const se=()=>{we.current=!1,be.current=null,le(!1)};return document.addEventListener("mouseup",se),()=>document.removeEventListener("mouseup",se)},[]);const ke=a.useCallback((se,O)=>{const A=se.split(`
29
- `),K=Math.max(1,O.start),pe=Math.min(A.length,O.end);return K>pe?"":A.slice(K-1,pe).join(`
30
- `)},[]),ue=Ku({source:"plan",fileLabel:F,language:E&&_i(E)||"markdown",getCodeForRange:se=>ke(R,qu(se)),toStoreRange:se=>({startLine:se.start,endLine:se.end}),fromDraftRange:se=>({start:se.startLine,end:se.endLine})}),{drafts:ve,commentText:G,editingDraftId:Ae,setSelection:ce,saveComment:fe,cancel:Ee,reset:me,startEdit:B,deleteDraft:ye}=ue;a.useEffect(()=>{L(null),me()},[R,me]),a.useEffect(()=>{ce(re)},[re,ce]);const Oe=a.useCallback(()=>{L(null),Ee()},[Ee]),Q=a.useCallback((se,O)=>{O&&L(O),fe(se,O??re??void 0),L(null)},[re,fe]);a.useEffect(()=>{if(!re)return;const se=A=>{const K=A.target;K.closest('[data-comment-card="true"]')||K.closest('[data-comment-input="true"]')||K.closest(".oc-block-widget")||K.closest(".cm-gutterElement")||K.closest("[data-sonner-toast]")||K.closest("[data-sonner-toaster]")||(L(null),Ee())},O=window.setTimeout(()=>{document.addEventListener("click",se)},100);return()=>{window.clearTimeout(O),document.removeEventListener("click",se)}},[Ee,Ae,h,re]);const Me=a.useMemo(()=>{const se=[ml(N)],O=Eu(E||"plan.md");return O&&se.push(O),se.push(Kr.lineWrapping),se},[N,E]);a.useEffect(()=>{if(!m&&!t){M(null),_(""),U(!1);return}let se=!1;const O=async K=>{if(b.files?.readFile)return(await b.files.readFile(K))?.content??"";const pe=yo()?.files;if(pe?.readFile)return(await pe.readFile(K,{optional:!0}))?.content??"";const _e=await Rs(`/api/fs/read?path=${encodeURIComponent(K)}&optional=true`,{cache:"no-store"});if(!_e.ok)throw new Error(`Failed to read plan file (${_e.status})`);return _e.text()};return(async()=>{if(M(null),_(""),V(null),t){U(!0);try{const K=await O(t);if(se)return;M(t),_(K)}catch{if(se)return;M(null),_("")}finally{se||U(!1)}return}if(!w?.slug||!w?.time?.created||!S){M(null),_("");return}U(!0);try{const K=jw(S,w.time.created,w.slug),pe=Nw(Sw(w.time.created,w.slug),u||null);let _e=null,We=null;try{We=await O(K),_e=K}catch{}if(!_e)try{We=await O(pe),_e=pe}catch{}if(se)return;if(!_e||We===null){M(null),_("");return}M(_e),_(We)}catch{if(se)return;M(null),_("")}finally{se||U(!1)}})(),()=>{se=!0}},[u,m,b.files,S,w?.slug,w?.time?.created,t]),a.useEffect(()=>{if(!E){V(null);return}const se=window.setTimeout(async()=>{V(null);try{if(b.files?.writeFile){if(!(await b.files.writeFile(E,R))?.success)throw new Error(e("planView.error.writeFailed"))}else{const O=await Rs("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:E,content:R})});if(!O.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:O.status}))}}catch(O){V(O instanceof Error?O.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(se)}},[R,E,b.files,e]),a.useEffect(()=>()=>{Se.current!==null&&window.clearTimeout(Se.current)},[]);const Re=a.useCallback(()=>{p("chat"),y(!1)},[p,y]),Ne=a.useCallback(async se=>{if(!j||!D)return;const O=await In(D.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:Z}),K=[{synthetic:!0,text:await In(D.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:Z,plan_path:E??""})}];P(!0);try{Re();let pe=null,_e=j.path;if(D.target==="worktree"){if(!k)return;const Le=await Cu(j.path,Au());if(!Le?.id)return;pe=Le.id,_e=Le.path}else{const Le=await r(void 0,j.path,null);if(!Le?.id)return;pe=Le.id,_e=Le.directory??j.path,o(Le.id,cs.getState().agents??[])}if(!pe)return;const We=$l.getState();We.saveSessionModelSelection(pe,se.providerID,se.modelID),se.agent.trim()&&(We.saveSessionAgentSelection(pe,se.agent),We.saveAgentModelForSession(pe,se.agent,se.providerID,se.modelID),We.saveAgentModelVariantForSession(pe,se.agent,se.providerID,se.modelID,se.variant||void 0)),c(pe,_e),await i(O,se.providerID,se.modelID,se.agent.trim()||void 0,void 0,void 0,K,se.variant||void 0),T(null)}finally{P(!1)}},[k,r,j,o,D,E,Re,i,Z,c]),Be=a.useMemo(()=>Yu({drafts:ve,editingDraftId:Ae,commentText:G,selection:re,isDragging:De,fileLabel:F,newWidgetId:"plan-new-comment-input",mapDraftToRange:se=>({start:se.startLine,end:se.endLine}),onSave:Q,onCancel:Oe,onEdit:se=>{B(se),L({start:se.startLine,end:se.endLine})},onDelete:ye}),[G,ye,Ae,Oe,Q,De,re,ve,F,B]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:te}),z?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:z,children:e("planView.error.saveFailed")}):null]}),E?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(on,{children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(nn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!R.trim(),children:s.jsx(I,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(_t,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(rn,{align:"end",children:[s.jsx(zt,{onClick:()=>T({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(zt,{onClick:()=>T({action:"improve",target:"worktree"}),disabled:!k,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(on,{children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(nn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!R.trim(),children:s.jsx(I,{name:"code-ai",className:"size-4"})})})}),s.jsx(_t,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(rn,{align:"end",children:[s.jsx(zt,{onClick:()=>T({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(zt,{onClick:()=>T({action:"implement",target:"worktree"}),disabled:!k,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(hl,{currentMode:ge,onToggle:()=>de(ge==="preview"?"edit":"preview")}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await cr(R)).ok&&(oe(!0),Se.current!==null&&window.clearTimeout(Se.current),Se.current=window.setTimeout(()=>{oe(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:ie?s.jsx(I,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(Xu,{open:D!==null,onOpenChange:se=>{!se&&!C&&T(null)},target:D?.target??"session",projectDirectory:j?.path??null,submitting:C,onConfirm:Ne}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Fn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:ne?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("planView.state.loading")}):s.jsx("div",{className:"relative h-full",children:s.jsx("div",{className:"h-full",children:ge==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(an,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("planView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("planView.error.switchToEditMode")})]}),children:s.jsx(ho,{content:R,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:q,children:s.jsx(fl,{value:R,onChange:_,readOnly:!1,className:"h-full",extensions:Me,onViewReady:se=>{$.current=se},onViewDestroy:()=>{$.current=null},blockWidgets:Be,highlightLines:re?{start:Math.min(re.start,re.end),end:Math.max(re.start,re.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(se,O,A)=>{if(!(A instanceof MouseEvent)||A.button!==0)return!1;A.preventDefault();const K=se.state.doc.lineAt(O.from).number;if(h&&re&&!A.shiftKey){const pe=Math.min(re.start,re.end,K),_e=Math.max(re.start,re.end,K);return L({start:pe,end:_e}),we.current=!1,be.current=null,le(!1),!0}if(we.current=!0,be.current=K,le(!0),re&&A.shiftKey){const pe=Math.min(re.start,K),_e=Math.max(re.end,K);L({start:pe,end:_e})}else L({start:K,end:K});return!0},mouseover:(se,O,A)=>{if(!(A instanceof MouseEvent)||A.buttons!==1||!we.current||be.current===null)return!1;const K=se.state.doc.lineAt(O.from).number,pe=Math.min(be.current,K),_e=Math.max(be.current,K);return L({start:pe,end:_e}),le(!0),!1},mouseup:()=>(we.current=!1,be.current=null,le(!1),!1)}}})})})})})})]})},Al={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},$o={user:0,assistant:0,tool:0,other:0},li=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Cd=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(m=>m.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Al,total:li(n)};if(!n||typeof n!="object")return Al;const r=n,o=li(r.input),i=li(r.output),c=li(r.reasoning),l=li(r.cache?.read),u=li(r.cache?.write);return{input:o,output:i,reasoning:c,cacheRead:l,cacheWrite:u,total:o+i+c+l+u}},Aw=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},Qn=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+Qn(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+Qn(n),0):0,Dw=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...$o,assistant:Qn(n.text)+Qn(n.content)};const o=Aw(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:Qn(n.input)+Qn(n.output)+Qn(n.error)+Qn(n.call?.input)+Qn(n.call?.output)+Qn(n.call?.error)+Qn(n.raw)+Math.round(Qn(n.metadata)*.25)+Math.round(Qn(n.state)*.1),other:0}:e==="user"?{user:o.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},Ad=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),Iw=t=>{const e=wo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},Pw=(t,e)=>{if(t.length===0)return{...$o};const n=t.reduce((r,o)=>{const i=Iw(o);let c={...$o};for(const l of o.parts)c=Ad(c,Dw(l,i));return Ad(r,c)},{...$o});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Ii=t=>t.toLocaleString(),Tw=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,Ew=(t,e)=>!t||!Number.isFinite(t)?"-":ga(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),Rw=(t,e)=>!t||!Number.isFinite(t)?"-":ga(t,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),Mw=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,Fw=(t,e,n)=>{const r=t.find(i=>i.id===e),o=r?.models?.find(i=>i.id===n);return{providerName:r?.name||e||"-",modelName:o?.name||n||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},Lw=()=>{const t=gt.c(202),{t:e}=Tt(),{currentTheme:n}=Tr(),r=Fe(Ow);let o;t[0]!==n?(o=Ru(n),t[0]=n,t[1]=o):o=t[1];const i=o;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c={},t[2]=c):c=t[2];const[l,u]=a.useState(c),[m,d]=a.useState(null),f=a.useRef(null),g=vt(_w),x=Gl(),p=rh(g??""),y=cs(Bw);let b;t[3]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null),u(Vw),d(null)},t[3]=b):b=t[3];let h;t[4]!==g?(h=[g],t[4]=g,t[5]=h):h=t[5],a.useEffect(b,h);let N,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=()=>()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=[],t[6]=N,t[7]=w):(N=t[6],w=t[7]),a.useEffect(N,w);let S;t[8]===Symbol.for("react.memo_cache_sentinel")?(S=async(lt,ct)=>{(await cr(ct)).ok?(d(lt),f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{d(Ft=>Ft===lt?null:Ft),f.current=null},2e3)):d(null)},t[8]=S):S=t[8];const v=S;let j;t[9]!==g||t[10]!==x?(j=g?x.find(lt=>lt.id===g)??null:null,t[9]=g,t[10]=x,t[11]=j):j=t[11];const k=j;let D,T,C,P,E;if(t[12]!==y||t[13]!==p){D=p.filter($w);let lt;t[19]!==p?(lt=p.filter(zw),t[19]=p,t[20]=lt):lt=t[20],E=lt;let ct=null;for(let Ft=D.length-1;Ft>=0;Ft=Ft-1,Ft){const qt=D[Ft];if(Cd(qt).total>0){ct=qt;break}}C=ct?Cd(ct):Al,P=D.reduce(Ww,0);const Bt=ct?.info??null;T=Fw(y,Bt?.providerID||"",Bt?.modelID||""),t[12]=y,t[13]=p,t[14]=D,t[15]=T,t[16]=C,t[17]=P,t[18]=E}else D=t[14],T=t[15],C=t[16],P=t[17],E=t[18];const M=T,H=M.contextLimit,R=H&&H>0?Math.min(999,C.total/H*100):0;let _;if(t[21]!==p){const lt=[...p].reverse().find(Uw)?.info?.system||"";_=Pw(p,lt),t[21]=p,t[22]=_}else _=t[22];const z=_,V=z.user,F=z.assistant,te=z.tool,Z=Math.max(0,C.input-V-F-te),ne=V+F+te+Z,U=p[0]?.info?.time?.created,ie=p.length>0?p[p.length-1]?.info?.time?.created:null;let oe;t[23]!==k?.title||t[24]!==e?(oe=k?.title||e("contextSidebar.session.untitled"),t[23]=k?.title,t[24]=e,t[25]=oe):oe=t[25];const ge=k?.time?.created??U??null,je=ie??k?.time?.created??null;let Se;t[26]!==F||t[27]!==Z||t[28]!==te||t[29]!==V?(Se={user:V,assistant:F,tool:te,other:Z},t[26]=F,t[27]=Z,t[28]=te,t[29]=V,t[30]=Se):Se=t[30];let re;t[31]!==D.length||t[32]!==ne||t[33]!==H||t[34]!==M||t[35]!==p.length||t[36]!==oe||t[37]!==ge||t[38]!==je||t[39]!==Se||t[40]!==C||t[41]!==P||t[42]!==R||t[43]!==E.length?(re={sessionTitle:oe,messagesCount:p.length,userMessagesCount:E.length,assistantMessagesCount:D.length,createdAt:ge,lastActivityAt:je,providerModel:M,tokenBreakdown:C,usagePercent:R,totalAssistantCost:P,contextLimit:H,breakdown:Se,breakdownTotal:ne},t[31]=D.length,t[32]=ne,t[33]=H,t[34]=M,t[35]=p.length,t[36]=oe,t[37]=ge,t[38]=je,t[39]=Se,t[40]=C,t[41]=P,t[42]=R,t[43]=E.length,t[44]=re):re=t[44];const L=re;if(!g){let lt;t[45]!==e?(lt=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=lt):lt=t[46];let ct;return t[47]!==lt?(ct=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:lt}),t[47]=lt,t[48]=ct):ct=t[48],ct}let $;t[49]!==e?($=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=$):$=t[50];let q;t[51]!==$||t[52]!==L.breakdown.user?(q={key:"user",label:$,value:L.breakdown.user,color:"var(--status-success)"},t[51]=$,t[52]=L.breakdown.user,t[53]=q):q=t[53];let he;t[54]!==e?(he=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=he):he=t[55];let de;t[56]!==he||t[57]!==L.breakdown.assistant?(de={key:"assistant",label:he,value:L.breakdown.assistant,color:"var(--primary-base)"},t[56]=he,t[57]=L.breakdown.assistant,t[58]=de):de=t[58];let we;t[59]!==e?(we=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=we):we=t[60];let be;t[61]!==we||t[62]!==L.breakdown.tool?(be={key:"tool",label:we,value:L.breakdown.tool,color:"var(--status-warning)"},t[61]=we,t[62]=L.breakdown.tool,t[63]=be):be=t[63];let De;t[64]!==e?(De=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=De):De=t[65];let le;t[66]!==De||t[67]!==L.breakdown.other?(le={key:"other",label:De,value:L.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=De,t[67]=L.breakdown.other,t[68]=le):le=t[68];let ke;t[69]!==q||t[70]!==de||t[71]!==be||t[72]!==le?(ke=[q,de,be,le],t[69]=q,t[70]=de,t[71]=be,t[72]=le,t[73]=ke):ke=t[73];const ue=ke;let ve;t[74]!==L.sessionTitle?(ve=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:L.sessionTitle}),t[74]=L.sessionTitle,t[75]=ve):ve=t[75];let G;t[76]!==L.providerModel.modelName||t[77]!==L.providerModel.providerName?(G=s.jsxs("span",{children:[L.providerModel.providerName," / ",L.providerModel.modelName]}),t[76]=L.providerModel.modelName,t[77]=L.providerModel.providerName,t[78]=G):G=t[78];let Ae;t[79]!==r||t[80]!==L.createdAt?(Ae=L.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:Ew(L.createdAt,r)})]}),t[79]=r,t[80]=L.createdAt,t[81]=Ae):Ae=t[81];let ce;t[82]!==G||t[83]!==Ae?(ce=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[G,Ae]}),t[82]=G,t[83]=Ae,t[84]=ce):ce=t[84];let fe;t[85]!==ve||t[86]!==ce?(fe=s.jsxs("div",{className:"mb-6",children:[ve,ce]}),t[85]=ve,t[86]=ce,t[87]=fe):fe=t[87];let Ee;t[88]!==e?(Ee=e("contextSidebar.section.context"),t[88]=e,t[89]=Ee):Ee=t[89];let me;t[90]!==Ee?(me=s.jsx("span",{className:"typography-micro text-muted-foreground",children:Ee}),t[90]=Ee,t[91]=me):me=t[91];let B;t[92]!==L.tokenBreakdown.total?(B=Ii(L.tokenBreakdown.total),t[92]=L.tokenBreakdown.total,t[93]=B):B=t[93];let ye;t[94]!==L.contextLimit?(ye=L.contextLimit?` / ${Ii(L.contextLimit)}`:"",t[94]=L.contextLimit,t[95]=ye):ye=t[95];let Oe;t[96]!==B||t[97]!==ye?(Oe=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[B,ye]}),t[96]=B,t[97]=ye,t[98]=Oe):Oe=t[98];let Q;t[99]!==me||t[100]!==Oe?(Q=s.jsxs("div",{className:"flex items-baseline justify-between",children:[me,Oe]}),t[99]=me,t[100]=Oe,t[101]=Q):Q=t[101];let Me;t[102]!==L.usagePercent?(Me=L.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,L.usagePercent)}%`,backgroundColor:L.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[102]=L.usagePercent,t[103]=Me):Me=t[103];let Re;t[104]!==Me?(Re=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Me}),t[104]=Me,t[105]=Re):Re=t[105];let Ne;t[106]!==e||t[107]!==L.usagePercent?(Ne=e("contextSidebar.context.percentUsed",{percent:L.usagePercent.toFixed(1)}),t[106]=e,t[107]=L.usagePercent,t[108]=Ne):Ne=t[108];let Be;t[109]!==Ne?(Be=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Ne}),t[109]=Ne,t[110]=Be):Be=t[110];let se;t[111]!==Q||t[112]!==Re||t[113]!==Be?(se=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Q,Re,Be]}),t[111]=Q,t[112]=Re,t[113]=Be,t[114]=se):se=t[114];let O;t[115]!==e?(O=e("contextSidebar.stats.messages"),t[115]=e,t[116]=O):O=t[116];let A;t[117]!==L.messagesCount?(A=Ii(L.messagesCount),t[117]=L.messagesCount,t[118]=A):A=t[118];let K;t[119]!==O||t[120]!==A?(K={label:O,value:A},t[119]=O,t[120]=A,t[121]=K):K=t[121];let pe;t[122]!==e?(pe=e("contextSidebar.stats.user"),t[122]=e,t[123]=pe):pe=t[123];let _e;t[124]!==L.userMessagesCount?(_e=Ii(L.userMessagesCount),t[124]=L.userMessagesCount,t[125]=_e):_e=t[125];let We;t[126]!==pe||t[127]!==_e?(We={label:pe,value:_e},t[126]=pe,t[127]=_e,t[128]=We):We=t[128];let Le;t[129]!==e?(Le=e("contextSidebar.stats.assistant"),t[129]=e,t[130]=Le):Le=t[130];let rt;t[131]!==L.assistantMessagesCount?(rt=Ii(L.assistantMessagesCount),t[131]=L.assistantMessagesCount,t[132]=rt):rt=t[132];let yt;t[133]!==Le||t[134]!==rt?(yt={label:Le,value:rt},t[133]=Le,t[134]=rt,t[135]=yt):yt=t[135];let Dt;t[136]!==e?(Dt=e("contextSidebar.stats.cost"),t[136]=e,t[137]=Dt):Dt=t[137];let st;t[138]!==L.totalAssistantCost?(st=Tw(L.totalAssistantCost),t[138]=L.totalAssistantCost,t[139]=st):st=t[139];let Pe;t[140]!==Dt||t[141]!==st?(Pe={label:Dt,value:st},t[140]=Dt,t[141]=st,t[142]=Pe):Pe=t[142];let tt;t[143]!==K||t[144]!==We||t[145]!==yt||t[146]!==Pe?(tt=[K,We,yt,Pe],t[143]=K,t[144]=We,t[145]=yt,t[146]=Pe,t[147]=tt):tt=t[147];const Ye=tt;let nt;t[148]!==Ye?(nt=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:Ye.map(Hw)}),t[148]=Ye,t[149]=nt):nt=t[149];let ft;t[150]!==e?(ft=e("contextSidebar.section.lastAssistantMessage"),t[150]=e,t[151]=ft):ft=t[151];let mt;t[152]!==ft?(mt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:ft}),t[152]=ft,t[153]=mt):mt=t[153];let ot;t[154]!==e||t[155]!==L.tokenBreakdown.cacheRead||t[156]!==L.tokenBreakdown.cacheWrite||t[157]!==L.tokenBreakdown.input||t[158]!==L.tokenBreakdown.output||t[159]!==L.tokenBreakdown.reasoning?(ot=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:L.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:L.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:L.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:L.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:L.tokenBreakdown.cacheWrite}].map(Gw)}),t[154]=e,t[155]=L.tokenBreakdown.cacheRead,t[156]=L.tokenBreakdown.cacheWrite,t[157]=L.tokenBreakdown.input,t[158]=L.tokenBreakdown.output,t[159]=L.tokenBreakdown.reasoning,t[160]=ot):ot=t[160];let It;t[161]!==mt||t[162]!==ot?(It=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[mt,ot]}),t[161]=mt,t[162]=ot,t[163]=It):It=t[163];let dt;t[164]!==ue||t[165]!==L.breakdownTotal?(dt=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ue.map(lt=>lt.value<=0||L.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${lt.value/L.breakdownTotal*100}%`,backgroundColor:lt.color}},lt.key))}),t[164]=ue,t[165]=L.breakdownTotal,t[166]=dt):dt=t[166];let bt;t[167]!==ue||t[168]!==L.breakdownTotal?(bt=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ue.map(lt=>{const ct=L.breakdownTotal>0?lt.value/L.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:lt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[lt.label," ",s.jsxs("span",{className:"tabular-nums",children:[ct.toFixed(0),"%"]})]})]},lt.key)})}),t[167]=ue,t[168]=L.breakdownTotal,t[169]=bt):bt=t[169];let He;t[170]!==dt||t[171]!==bt?(He=s.jsxs("div",{className:"mb-6",children:[dt,bt]}),t[170]=dt,t[171]=bt,t[172]=He):He=t[172];let Ze;t[173]!==e?(Ze=e("contextSidebar.section.rawMessages"),t[173]=e,t[174]=Ze):Ze=t[174];let Ue;t[175]!==Ze?(Ue=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ze}),t[175]=Ze,t[176]=Ue):Ue=t[176];let jt;if(t[177]!==m||t[178]!==l||t[179]!==p||t[180]!==i||t[181]!==e||t[182]!==r){let lt;t[184]!==m||t[185]!==l||t[186]!==i||t[187]!==e||t[188]!==r?(lt=ct=>{const Bt=wo(ct.info).role,Ft=l[ct.info.id]===!0,qt=m===ct.info.id,Ut=ct.info.time?.created??null,At=Ft?JSON.stringify({info:ct.info,parts:ct.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":Ft,onClick:()=>{u(Xt=>({...Xt,[ct.info.id]:Xt[ct.info.id]!==!0}))},children:s.jsxs("div",{className:"flex items-center justify-between gap-2 whitespace-nowrap overflow-hidden",children:[s.jsxs("span",{className:"min-w-0 inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:Mw(Bt)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:ct.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:Rw(Ut,r)})]})}),Ft&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:Xt=>{Xt.stopPropagation(),v(ct.info.id,At)},"aria-label":e(qt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(qt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:qt?s.jsx(I,{name:"check",className:"size-3.5"}):s.jsx(I,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Xm,{language:"json",style:i,PreTag:"div",customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},codeTagProps:{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"break-word"}},wrapLongLines:!0,children:At})]})})]},ct.info.id)},t[184]=m,t[185]=l,t[186]=i,t[187]=e,t[188]=r,t[189]=lt):lt=t[189],jt=[...p].reverse().map(lt),t[177]=m,t[178]=l,t[179]=p,t[180]=i,t[181]=e,t[182]=r,t[183]=jt}else jt=t[183];let Ge;t[190]!==jt?(Ge=s.jsx("div",{className:"mt-2.5 space-y-1",children:jt}),t[190]=jt,t[191]=Ge):Ge=t[191];let it;t[192]!==Ue||t[193]!==Ge?(it=s.jsxs("div",{children:[Ue,Ge]}),t[192]=Ue,t[193]=Ge,t[194]=it):it=t[194];let Et;return t[195]!==fe||t[196]!==se||t[197]!==nt||t[198]!==It||t[199]!==He||t[200]!==it?(Et=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[fe,se,nt,It,He,it]})}),t[195]=fe,t[196]=se,t[197]=nt,t[198]=It,t[199]=He,t[200]=it,t[201]=Et):Et=t[201],Et};function Ow(t){return t.timeFormatPreference}function _w(t){return t.currentSessionId}function Bw(t){return t.providers}function Vw(t){return Object.keys(t).length>0?{}:t}function $w(t){return wo(t.info).role==="assistant"}function zw(t){return wo(t.info).isUser}function Ww(t,e){const n=li(e.info.cost);return t+n}function Uw(t){return wo(t.info).isUser&&typeof t.info.system=="string"}function Hw(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function Gw(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:Ii(t.value)})]},t.label)}const Kw=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.x=="number"&&typeof e.y=="number"},Dd=t=>!t||typeof t!="object"?!1:Object.values(t).every(e=>typeof e=="string"),Ri=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.text=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"&&Kw(e.center)&&Dd(e.attributes)&&Dd(e.computedStyle)&&Array.isArray(e.ancestry)},rc=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:o,intro:i})=>{const c=r.text.trim(),l=Object.entries(r.attributes).map(([x,p])=>`${x}="${p}"`).join(" "),u=r.computedStyle,m=r.bounds,d=r.center,f=i.replace(/[.:]+$/g,""),g=r.ancestry.map(x=>x.selectorPart).join(" > ");return[`${f}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${r.tag}`,c?`Text: ${c}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,g?`- Ancestry: ${g}`:null,l?`- Attributes: ${l}`:null,`- Bounds: x=${Math.round(m.x)}, y=${Math.round(m.y)}, width=${Math.round(m.width)}, height=${Math.round(m.height)}`,`- Center: x=${Math.round(d.x)}, y=${Math.round(d.y)}`,`Styles: display=${u.display}; position=${u.position}; font=${u.fontWeight} ${u.fontSize} / ${u.lineHeight} ${u.fontFamily}; color=${u.color}; background=${u.backgroundColor}; z-index=${u.zIndex}`].filter(x=>typeof x=="string").join(`
31
- `)},wm=async(t,e)=>{if(typeof window<"u")try{const n=t.getBoundingClientRect(),r=await ui("desktop_capture_page_rect",{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw new Error("Desktop screenshot capture is not available");const o=new Image;await new Promise((p,y)=>{o.onload=()=>p(),o.onerror=()=>y(new Error("Failed to load desktop preview screenshot")),o.src=`data:${r.mime};base64,${r.base64}`});const i=Math.max(1,o.naturalWidth||r.width||Math.floor(n.width)),c=Math.max(1,o.naturalHeight||r.height||Math.floor(n.height)),u=Math.min(1,1200/i),m=document.createElement("canvas");m.width=Math.floor(i*u),m.height=Math.floor(c*u);const d=m.getContext("2d");if(!d)return null;d.scale(u,u),d.drawImage(o,0,0,i,c);const f=i/Math.max(1,n.width),g=c/Math.max(1,n.height);d.fillStyle="rgba(37, 99, 235, 0.28)",d.strokeStyle="rgb(37, 99, 235)",d.lineWidth=Math.max(2,2*f),d.fillRect(e.bounds.x*f,e.bounds.y*g,e.bounds.width*f,e.bounds.height*g),d.strokeRect(e.bounds.x*f,e.bounds.y*g,e.bounds.width*f,e.bounds.height*g);const x=await new Promise(p=>m.toBlob(p,"image/jpeg",.82));return x?new File([x],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(n){return console.warn("[preview] failed to capture annotation screenshot:",n),null}return await l1(t,e)},ic=async(t,e,n,r,o,i)=>{if(!t)return null;try{const c=new Image;await new Promise((b,h)=>{c.onload=()=>b(),c.onerror=()=>h(new Error("Failed to load desktop browser screenshot")),c.src=`data:image/jpeg;base64,${t}`});const l=Math.max(1,c.naturalWidth||e),u=Math.max(1,c.naturalHeight||n),d=Math.min(1,1200/l),f=document.createElement("canvas");f.width=Math.floor(l*d),f.height=Math.floor(u*d);const g=f.getContext("2d");if(!g)return null;g.scale(d,d),g.drawImage(c,0,0,l,u);const x=l/Math.max(1,r||l),p=u/Math.max(1,o||u);g.fillStyle="rgba(37, 99, 235, 0.14)",g.strokeStyle="rgb(37, 99, 235)",g.lineWidth=Math.max(2,2*x),g.fillRect(i.bounds.x*x,i.bounds.y*p,i.bounds.width*x,i.bounds.height*p),g.strokeRect(i.bounds.x*x,i.bounds.y*p,i.bounds.width*x,i.bounds.height*p);const y=await new Promise(b=>f.toBlob(b,"image/jpeg",.82));return y?new File([y],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Mi="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",_n=new Map,Ga=new Map,qw=3e4,oc=t=>{const e=_n.get(t);return e?e.expiresAt-Date.now()<=qw?(_n.delete(t),null):e:null},Yw=t=>{try{return new URL(t).origin}catch{return t}};function vm(t){const e="#ffffff",n=t.defaultView??window;try{const r=t.body?n.getComputedStyle(t.body).backgroundColor:"";if(r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent")return r;const o=n.getComputedStyle(t.documentElement).backgroundColor;if(o&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent")return o}catch{}return e}const jm=t=>new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(typeof r.result=="string"?r.result:Mi),r.onerror=()=>n(r.error??new Error("Failed to read image blob")),r.readAsDataURL(t)}),Jw=async(t,e=.82)=>{const n=await new Promise(r=>t.toBlob(r,"image/jpeg",e));return n&&(await jm(n)).split(",",2)[1]||""},Qw=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},zo=(...t)=>{Qw()&&console.info("[preview-capture]",...t)},Sm=(t,e=8)=>{const n=[];try{const r=t.querySelectorAll("*");for(const o of r){const i=o.scrollTop||0,c=o.scrollLeft||0;if(i<=0&&c<=0)continue;const l=o.tagName.toLowerCase(),u=o.id?`#${o.id}`:"",m=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(n.push({selector:`${l}${u}${m}`,scrollTop:i,scrollLeft:c,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),n.length>=e)break}}catch{}return n},lo="data-oc-fixed-pin",Xw=(t,e,n)=>{if(e<=0&&n<=0)return()=>{};const r=t.defaultView;if(!r)return()=>{};const o=[],i=[];try{for(const c of t.querySelectorAll("*")){if(r.getComputedStyle(c).position!=="fixed")continue;const l=c.getBoundingClientRect();if(!(l.width>0&&l.height>0))continue;c.setAttribute(lo,JSON.stringify({top:l.top+n,left:l.left+e,width:l.width,height:l.height})),o.push(c);const u=c.tagName.toLowerCase(),m=typeof c.className=="string"&&c.className?`.${c.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";i.push({selector:`${u}${m}`,top:Math.round(l.top),left:Math.round(l.left),width:Math.round(l.width),height:Math.round(l.height)})}}catch{}return zo("tagged fixed elements",i),()=>{for(const c of o)try{c.removeAttribute(lo)}catch{}}},Zw={name:"oc-fixed-pin",afterClone(t){const e=t?.clone;if(!(!e||typeof e.querySelectorAll!="function"))for(const n of e.querySelectorAll(`[${lo}]`)){let r;try{r=JSON.parse(n.getAttribute(lo)||"")}catch{continue}n.style.setProperty("position","absolute","important"),n.style.setProperty("top",`${r.top}px`,"important"),n.style.setProperty("left",`${r.left}px`,"important"),n.style.setProperty("right","auto","important"),n.style.setProperty("bottom","auto","important"),n.style.setProperty("width",`${r.width}px`,"important"),n.style.setProperty("height",`${r.height}px`,"important"),n.removeAttribute(lo)}}},Pi="data-oc-scroll-pin",e1=t=>{const e=[],n=Sm(t,64);try{const i=t.documentElement,c=t.body;for(const l of t.querySelectorAll("*")){const u=l.scrollTop||0,m=l.scrollLeft||0;if(u<=0&&m<=0)continue;const d=l!==i&&l!==c;d&&l.setAttribute(Pi,JSON.stringify({top:u,left:m})),e.push({el:l,top:u,left:m,tagged:d})}}catch{}return{reapply:()=>{for(const i of e)try{i.el.scrollHeight,i.el.scrollTop!==i.top&&(i.el.scrollTop=i.top),i.el.scrollLeft!==i.left&&(i.el.scrollLeft=i.left)}catch{}},cleanup:()=>{for(const i of e)if(i.tagged)try{i.el.removeAttribute(Pi)}catch{}},snapshot:n}},t1={name:"oc-nested-scroll",afterClone(t){const e=t?.clone;if(!e||typeof e.querySelectorAll!="function")return;const n=e.ownerDocument;if(n)for(const r of e.querySelectorAll(`[${Pi}]`)){let o;try{o=JSON.parse(r.getAttribute(Pi)||"")}catch{r.removeAttribute(Pi);continue}const i=`translate(${-o.left}px, ${-o.top}px)`,c=r.children.length===1&&r.firstElementChild instanceof HTMLElement&&r.firstElementChild.style.willChange==="transform"?r.firstElementChild:null;if(c)c.style.transform=i;else{r.style.overflow="hidden";const l=n.createElement("div");for(l.style.transform=i,l.style.willChange="transform",l.style.display="inline-block",l.style.width="100%";r.firstChild;)l.appendChild(r.firstChild);r.appendChild(l)}r.removeAttribute(Pi)}}},Ka=async(t,e)=>{try{const n=await fetch(t,{credentials:e});return n.ok?await jm(await n.blob()):null}catch{return null}},s1=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const e=t.origin,n=oc(e);if(n)return`${n.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const r=Ga.get(e),o=r??(async()=>{try{const c=await Rs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!c.ok)return _n.delete(e),null;const l=await c.json(),u=typeof l.proxyBasePath=="string"?l.proxyBasePath:"",m=typeof l.expiresAt=="number"?l.expiresAt:0;if(!u)return _n.delete(e),null;const d={proxyBasePath:u,expiresAt:m};return _n.set(e,d),d}catch{return _n.delete(e),null}finally{Ga.delete(e)}})();r||Ga.set(e,o);const i=await o;return i?`${i.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},Nm=async(t,e)=>{if(!t||t.startsWith("data:"))return t;try{const n=new URL(t,e.baseURI);if(n.origin===window.location.origin||n.protocol!=="http:"&&n.protocol!=="https:")return await Ka(n.toString(),"include")??Mi;const r=await s1(n),o=r?await Ka(r,"include"):null;return o||(await Ka(n.toString(),"omit")??Mi)}catch{return Mi}},n1=async(t,e)=>{if(!t||t==="none"||!t.includes("url("))return t;const n=Array.from(t.matchAll(/url\((['"]?)(.*?)\1\)/g));let r=t;for(const o of n){const i=o[2]||"";if(!i||i.startsWith("data:"))continue;const c=await Nm(i,e);r=r.replace(o[0],`url("${c}")`)}return r},Id=t=>t.complete?Promise.resolve():new Promise(e=>{t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0})}),km=t=>{const e=t.style.cssText;return()=>{t.style.cssText=e}},r1=t=>{const e=Number.parseFloat(t.lineHeight);if(Number.isFinite(e)&&e>0)return e;const n=Number.parseFloat(t.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},i1=(t,e,n)=>{const r=[],o=t.defaultView??window,c=Array.from(t.querySelectorAll('button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *'));for(const l of c){const u=l.textContent?.replace(/\s+/g," ").trim()??"";if(!u||!u.includes(" "))continue;const m=l.getBoundingClientRect();if(m.width<=0||m.height<=0||m.right<0||m.bottom<0||m.left>e||m.top>n)continue;const d=o.getComputedStyle(l);if(d.display==="none"||d.visibility==="hidden"||Number(d.opacity)===0)continue;const f=d.getPropertyValue("text-wrap"),g=d.getPropertyValue("text-wrap-mode"),x=d.whiteSpace.includes("nowrap")||f==="nowrap"||g==="nowrap",p=m.height<=r1(d)*1.7;!x&&(!p||m.width>e*.72)||(r.push(km(l)),l.style.whiteSpace="nowrap",l.style.overflowWrap="normal",l.style.wordBreak="normal",l.style.setProperty("text-wrap","nowrap"),l.style.setProperty("text-wrap-mode","nowrap"))}return()=>{for(let l=r.length-1;l>=0;l-=1)r[l]?.()}},o1=(t,e,n,r)=>{const o=[],i=t.defaultView??window,c=i.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,l=i.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,u=Array.from(t.querySelectorAll("*")).filter(m=>{const d=i.getComputedStyle(m);if(d.position!=="fixed"||d.display==="none"||d.visibility==="hidden"||Number(d.opacity)===0)return!1;const f=m.getBoundingClientRect();return f.width>0&&f.height>0&&f.right>=0&&f.bottom>=0&&f.left<=e&&f.top<=n}).filter((m,d,f)=>!f.some((g,x)=>x<d&&g.contains(m)));for(const m of u){const d=m.getBoundingClientRect(),f=i.getComputedStyle(m),g=Math.ceil(d.width)+8,x=Math.ceil(d.height)+2;r?.add(m),o.push(km(m)),m.style.position="absolute",m.style.top=`${d.top+l}px`,m.style.left=`${d.left+c}px`,m.style.right="auto",m.style.bottom="auto",m.style.width=`${g}px`,m.style.minWidth=`${g}px`,m.style.height=`${x}px`,m.style.minHeight=`${x}px`,m.style.margin="0",m.style.boxSizing="border-box",m.style.transform="none",f.zIndex!=="auto"&&(m.style.zIndex=f.zIndex)}return()=>{for(let m=o.length-1;m>=0;m-=1)o[m]?.()}},Cm=async(t,e,n,r={})=>{const o=[],i=t.defaultView??window,c=f=>{if(f===t.documentElement||f===t.body)return!0;try{const g=f.getBoundingClientRect();return g.width>0&&g.height>0&&g.right>=0&&g.bottom>=0&&g.left<=e&&g.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){const f=new WeakSet;o.push(o1(t,e,n,f)),o.push(i1(t,e,n))}const l=new Map;for(const f of Array.from(t.images))l.set(f,f.currentSrc||f.src||f.getAttribute("src")||"");const u=Array.from(t.querySelectorAll("picture"));for(const f of u){const g=Array.from(f.querySelectorAll("source"));if(g.length===0)continue;const x=g.map(p=>({source:p,srcset:p.getAttribute("srcset"),sizes:p.getAttribute("sizes")}));o.push(()=>{for(const p of x)p.srcset===null?p.source.removeAttribute("srcset"):p.source.setAttribute("srcset",p.srcset),p.sizes===null?p.source.removeAttribute("sizes"):p.source.setAttribute("sizes",p.sizes)});for(const p of g)p.removeAttribute("srcset"),p.removeAttribute("sizes")}const m=Array.from(t.images).filter(f=>c(f));await Promise.all(m.map(async f=>{const g=l.get(f)||f.currentSrc||f.src||f.getAttribute("src")||"";if(!g)return;await Id(f);const x=await Nm(g,t),p={src:f.getAttribute("src"),srcset:f.getAttribute("srcset"),sizes:f.getAttribute("sizes")};o.push(()=>{p.src===null?f.removeAttribute("src"):f.setAttribute("src",p.src),p.srcset===null?f.removeAttribute("srcset"):f.setAttribute("srcset",p.srcset),p.sizes===null?f.removeAttribute("sizes"):f.setAttribute("sizes",p.sizes)}),f.removeAttribute("srcset"),f.removeAttribute("sizes"),f.setAttribute("src",x||Mi),await Id(f)}));const d=Array.from(t.querySelectorAll("*")).filter(c);return await Promise.all(d.map(async f=>{const g=i.getComputedStyle(f).backgroundImage;if(!g||g==="none"||!g.includes("url("))return;const x=await n1(g,t);if(x===g)return;const p=f.style.backgroundImage;o.push(()=>{f.style.backgroundImage=p}),f.style.backgroundImage=x})),()=>{for(let f=o.length-1;f>=0;f-=1)try{o[f]?.()}catch{}}};async function a1(t,e){try{const n=t.contentWindow,r=t.contentDocument??n?.document,o=r?.documentElement;if(!n||!r||!o)return null;const i=t.getBoundingClientRect(),c=Math.max(1,Math.ceil(n.innerWidth||t.clientWidth||i.width)),l=Math.max(1,Math.ceil(n.innerHeight||t.clientHeight||i.height)),u=r.body,m=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,d=n.scrollX||0,f=n.scrollY||0,g=n.pageXOffset||0,x=n.pageYOffset||0,p=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,y=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,b=o.scrollLeft||0,h=o.scrollTop||0,N=u?.scrollLeft||0,w=u?.scrollTop||0,S=m?.scrollLeft||0,v=m?.scrollTop||0,j=Math.max(d,g,p,b,N,S),k=Math.max(f,x,y,h,w,v);zo("scroll sources",{windowScrollX:d,windowScrollY:f,pageScrollX:g,pageScrollY:x,visualViewportScrollX:p,visualViewportScrollY:y,rootScrollX:b,rootScrollY:h,bodyScrollX:N,bodyScrollY:w,scrollingElementScrollX:S,scrollingElementScrollY:v,scrollingElementTag:m?.tagName?.toLowerCase()??null,resolvedScrollX:j,resolvedScrollY:k,nestedScrolledElements:Sm(r)});const D=Math.max(c,o.scrollWidth||0,u?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),T=Math.max(l,o.scrollHeight||0,u?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),C=Math.min(2,Math.max(1,window.devicePixelRatio||1)),P=o.style.scrollBehavior,E=u?.style.scrollBehavior??"";o.style.scrollBehavior="auto",u&&(u.style.scrollBehavior="auto");const M=e1(r);zo("nested scroll snapshot",M.snapshot);let H=()=>{},R=()=>{};try{await r.fonts?.ready.catch(()=>{}),H=await Cm(r,c,l,{applyLayoutWorkarounds:!1}),n.scrollTo(j,k),R=Xw(r,j,k),M.reapply();const _={backgroundColor:vm(r),cache:"disabled",dpr:C,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[Zw,t1],quality:.82,width:D},V=await(await tf(o,_)).toCanvas();if(!V.width||!V.height)return null;const F=V.width/Math.max(1,D),te=V.height/Math.max(1,T),Z=Math.min(V.width,Math.max(1,Math.round(c*F))),ne=Math.min(V.height,Math.max(1,Math.round(l*te))),U=Math.max(0,V.width-Z),ie=Math.max(0,V.height-ne),oe=Math.min(U,Math.max(0,Math.round(j*F))),ge=Math.min(ie,Math.max(0,Math.round(k*te)));zo("capture geometry",{viewportWidth:c,viewportHeight:l,captureWidth:D,captureHeight:T,canvasWidth:V.width,canvasHeight:V.height,xScale:F,yScale:te,sourceX:oe,sourceY:ge,sourceWidth:Z,sourceHeight:ne});const je=r.createElement("canvas");je.width=Z,je.height=ne;const Se=je.getContext("2d");if(!Se)return null;Se.drawImage(V,oe,ge,Z,ne,0,0,Z,ne);const re=await Jw(je,.82);return re?await ic(re,c,l,c,l,e):null}finally{R(),M.cleanup(),H(),n.scrollTo(j,k),M.reapply(),o.style.scrollBehavior=P,u&&(u.style.scrollBehavior=E)}}catch(n){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",n),null}}async function l1(t,e){const n=await a1(t,e);if(n)return n;try{const r=t.contentWindow,o=t.contentDocument??r?.document,i=o?.documentElement;if(!r||!o||!i)return null;const c=t.getBoundingClientRect(),l=Math.max(1,Math.ceil(r.innerWidth||t.clientWidth||c.width)),u=Math.max(1,Math.ceil(r.innerHeight||t.clientHeight||c.height)),m=r.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,d=r.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,f=o.body,g=Math.max(u,i.scrollHeight||0,f?.scrollHeight||0),x=Math.min(2,Math.max(1,window.devicePixelRatio||1)),p=i.style.scrollBehavior,y=f?.style.scrollBehavior??"";i.style.scrollBehavior="auto",f&&(f.style.scrollBehavior="auto");let b="",h=()=>{};try{await o.fonts?.ready.catch(()=>{}),h=await Cm(o,l,u,{applyLayoutWorkarounds:!0}),r.scrollTo(m,d);const w=await Zm(i).catch(()=>"");b=await ef(i,{quality:.82,pixelRatio:x,width:l,height:u,backgroundColor:vm(o),imagePlaceholder:Mi,fontEmbedCSS:w||void 0,style:{transform:`translate(${-m}px, ${-d}px)`,transformOrigin:"top left",minWidth:`${l}px`,minHeight:`${g}px`},cacheBust:!0})}finally{h(),r.scrollTo(m,d),i.style.scrollBehavior=p,f&&(f.style.scrollBehavior=y)}const N=b.split(",",2)[1]||"";return N?await ic(N,l,u,l,u,e):null}catch(r){return console.warn("[preview] failed to capture iframe DOM screenshot:",r),null}}const Am=380,c1=1400,Dm=600,d1=24,Pd=200,u1=(t,e)=>e==="all"?!0:e==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":e==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",m1=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Im=t=>Number.isFinite(t)?Math.min(c1,Math.max(Am,Math.round(t))):Dm,f1=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},qa=(t,e)=>{const n=Im(t),r=f1(e);return r===null?n:Math.min(n,Math.max(1,r))},h1=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},p1=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":"contextPanel.mode.context"),g1=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},x1=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return g1(t.targetPath)||e("contextPanel.mode.files");if(t.mode==="preview"){const n=t.targetPath;if(n)try{const r=new URL(n);return r.host||r.hostname||e("contextPanel.mode.preview")}catch{}return e("contextPanel.mode.preview")}return t.mode==="diff"?t.stagedDiff?e("contextPanel.mode.stagedDiff"):e("contextPanel.mode.workingDiff"):p1(t.mode,e)},b1=t=>{if(t.mode==="file")return t.targetPath?s.jsx(yr,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(I,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(I,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(I,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(I,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5"})},y1=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,Pm=`new Promise((resolve) => {
28
+ … truncated …`:Ts),We(q.path),Vs(q.path,Dt).then(cn=>{cn&&Ve()&&(Wt.current=cn)}).catch(()=>{})}).catch(ns=>{if(Ve()){if(bw(ns)){if(bt(!1),y&&G(y,null),nt(null),Ye(""),He(""),We(null),Wt.current=null,S.trim().length>0&&v(""),u&&T(!1),y){const cn=[...kd(q.path,y),q.path];cn.length>0&&ce(y,cn);for(const So of cn)Oe.current.has(So)||js(So)}return}if(Ad(ns)){y&&ve(y,q.path),Ye(""),He(""),nt(null),Wt.current=null,u&&T(!1);return}Ye(""),He(""),nt(ns instanceof Error?ns.message:e("filesView.error.readFileFailed")),Wt.current=null}}).finally(()=>{Ve()&&bt(!1)})},[ce,u,js,t,xn,Vs,ve,y,r.isDesktop,S,G,e]),Sr=a.useCallback(async(q,Ie)=>{if(!y)return;const Ve=kd(q,y),Je=Ie?[...Ve,q]:Ve;Je.length>0&&ce(y,Je);const Ct=Je.map(Dt=>{if(!Oe.current.has(Dt))return js(Dt)}).filter(Boolean);await Promise.all(Ct)},[ce,js,y]),Nr=a.useCallback((q,Ie)=>{const Ve=Ie.findIndex(Je=>Je.path===q);return Ve===-1||Ie.length<=1?null:Ie[Ve+1]??Ie[Ve-1]??null},[]),ln=a.useCallback(async q=>{if(ts.current)ts.current=!1;else if(Ds){ft(!0),Jt.current=q;return}y&&(G(y,q.path),Ce(y,q.path),Sr(q.path,!1)),nt(null),lt(""),Ye(""),He(""),We(null),u&&T(!0)},[Ce,Sr,Ds,u,y,G]);a.useEffect(()=>{B?.path&&Sr(B.path,!1)},[Sr,B?.path]),a.useEffect(()=>{if(!B){qt.current+=1,bt(!1);return}tt!==B.path&&jr(B)},[jr,tt,B]);const ni=a.useRef(Ds);ni.current=Ds,a.useEffect(()=>{if(!B?.path||tt!==B.path)return;let q=!1;const Ie=window.setInterval(()=>{document.hidden||Vs(B.path,J).then(Ve=>{if(q||!Ve)return;const Je=Wt.current;if(!Je||Je.path!==B.path){Wt.current=Ve;return}const Ct=Ve.mtimeMs!==void 0&&Je.mtimeMs!==void 0&&Ve.mtimeMs!==Je.mtimeMs,Dt=Ve.size!==Je.size;!Ct&&!Dt||ni.current||(Wt.current=Ve,We(null))}).catch(()=>{})},2e3);return()=>{q=!0,window.clearInterval(Ie)}},[tt,Vs,B?.path,J]);const jo=a.useCallback(()=>{const q=Jt.current,Ie=ms.current,Ve=Xt.current;if(Jt.current=null,ms.current=null,Xt.current=null,ts.current=!0,ft(!1),He(bn),Ve){y&&ue(y,Ve),B?.path===Ve&&(q?ln(q):(y&&G(y,null),Ye(""),nt(null),lt(""),We(null),u&&T(!1)));return}if(q){ln(q);return}Ie&&(ws(null),Fe.getState().setActiveMainTab(Ie))},[bn,ln,u,ue,y,B?.path,ws,G]),ri=a.useCallback(async()=>{const q=Jt.current,Ie=ms.current,Ve=Xt.current;if(!await Zs()){ts.current=!1;return}if(Jt.current=null,ms.current=null,Xt.current=null,ts.current=!0,ft(!1),Ve){y&&ue(y,Ve),B?.path===Ve&&(q?await ln(q):(y&&G(y,null),Ye(""),nt(null),lt(""),We(null),u&&T(!1)));return}if(q){await ln(q);return}Ie&&(ws(null),Fe.getState().setActiveMainTab(Ie))},[ln,u,ue,y,Zs,B?.path,ws,G]),Yn=a.useCallback(q=>{const Ie=B?.path===q,Ve=Nr(q,Te);if(Ie&&Ds){ft(!0),Jt.current=Ve,Xt.current=q;return}if(y&&ue(y,q),!!Ie){if(Ve){ln(Ve);return}y&&G(y,null),Ye(""),nt(null),lt(""),We(null),u&&T(!1)}},[Nr,ln,Ds,u,Te,ue,y,B?.path,G]),yn=a.useCallback(q=>{if(xe.includes(q))return"open";if(w?.files){const Ie=q.startsWith(y+"/")?q.slice(y.length+1):q,Ve=w.files.find(Je=>Je.path===Ie);if(Ve){if(Ve.index==="A"||Ve.working_dir==="?")return"git-added";if(Ve.index==="D")return"git-deleted";if(Ve.index==="M"||Ve.working_dir==="M")return"git-modified"}}return null},[xe,w,y]),Vr=a.useCallback(q=>{if(!w?.files)return null;const Ie=q.startsWith(y+"/")?q.slice(y.length+1):q,Ve=Ie?`${Ie}/`:"";let Je=0,Ct=0;for(const Dt of w.files)Dt.path.startsWith(Ve)&&((Dt.index==="M"||Dt.working_dir==="M")&&Je++,(Dt.index==="A"||Dt.working_dir==="?")&&Ct++);return Je+Ct>0?{modified:Je,added:Ct}:null},[w,y]),$r=a.useCallback(async q=>{const Ie=en(q);y&&(Ae(y,Ie),Oe.current.has(Ie)||await js(Ie))},[js,y,Ae]),Fr=a.useMemo(()=>({canRename:Rs,canCreateFile:ys,canCreateFolder:Bs,canDelete:an,canReveal:Ss}),[Rs,ys,Bs,an,Ss]);function ii(q,Ie){const Ve=O[q]??[];return Ve.map((Je,Ct)=>{const Dt=Je.type==="directory",ns=Dt&&le.includes(Je.path),Ts=B?.path===Je.path,cn=Ct===Ve.length-1;return s.jsxs("li",{className:"relative",children:[Ie>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),cn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(Sw,{node:Je,root:y,isExpanded:ns,isActive:Ts,isMobile:u,alwaysShowActions:f,status:Dt?void 0:yn(Je.path),badge:Dt?Vr(Je.path):void 0,permissions:Fr,downloadFile:n.downloadFile,contextMenuPath:W,setContextMenuPath:Ge,onSelect:ln,onToggle:$r,onRevealPath:Rn,onOpenDialog:Kn}),Dt&&ns&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[Y[Je.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:Y[Je.path],children:Y[Je.path]}),s.jsxs(ze,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{mn(Je.path)},children:[s.jsx(I,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,ii(Je.path,Ie+1)]})]},Je.path)})}const fn=!!(B?.path&&_i(B.path)),kr=!!(B?.path&&B.path.toLowerCase().endsWith(".svg")),zr=a.useMemo(()=>en(pn?.path??""),[pn?.path]),Jn=!!(pn&&zr&&ye&&ye===zr&&!rt&&!ct&&!fn),Ns=a.useMemo(()=>Al(y,ye),[ye,y]),oi=!!(B&&(!fn||kr)&&Qe.length>0),ai=!!(B&&Ns.length>0),An=!!(B&&!_e&&!fn&&n.writeFile&&Qe.length<=Xi),Lr=!!(B?.path&&Dd(B.path)),mr=!!(B?.path&&jw(B.path)),Js=!!(B?.path&&Po(B.path)),ge=!!(B&&!fn)&&!Lr&&!(Js&&Se==="preview"),ke=a.useMemo(()=>ye?Fu(ye):null,[ye]),[Ue,vt]=a.useState(null);a.useEffect(()=>{let q=!1;const Ie=B?.path;if(!Ie||ke){vt(null);return}return vt(null),rh(Ie).then(Ve=>{q||vt(Ve)}),()=>{q=!0}},[B?.path,ke]),a.useEffect(()=>{!An&&ne==="edit"&&U("view")},[An,ne]);const St="openchamber:files:md-viewer-mode",xs="openchamber:files:html-viewer-mode",Is="openchamber:files:json-viewer-mode";a.useEffect(()=>{const q=B?.path;if(!q)return;const Ie=qn?"view":"edit";U(L.current[q]??Ie);let Ve=qn?"preview":"edit";try{const Dt=localStorage.getItem(St);(Dt==="preview"||Dt==="edit")&&(Ve=Dt)}catch{}oe($.current[q]??Ve);let Je=qn?"preview":"edit";try{const Dt=localStorage.getItem(xs);(Dt==="preview"||Dt==="edit")&&(Je=Dt)}catch{}re(K.current[q]??Je);let Ct=qn?"tree":"text";try{const Dt=localStorage.getItem(Is);(Dt==="tree"||Dt==="text")&&(Ct=Dt)}catch{}je(Ct)},[B?.path,qn]);const Cr=a.useCallback(q=>{const Ie=B?.path;Ie&&(L.current[Ie]=q),U(q)},[B?.path]),Da=a.useCallback(q=>{const Ie=B?.path;Ie&&($.current[Ie]=q),oe(q);try{localStorage.setItem(St,q)}catch{}},[B?.path]),X=a.useCallback(()=>ie,[ie]),Ze=a.useCallback(q=>{je(q);try{localStorage.setItem(Is,q)}catch{}},[]),qe=a.useCallback(q=>{const Ie=B?.path;Ie&&(K.current[Ie]=q),re(q);try{localStorage.setItem(xs,q)}catch{}},[B?.path]),Pt=a.useCallback(()=>Se,[Se]);a.useEffect(()=>{const q=Ve=>{const Je=Ve?"view":"edit",Ct=Ve?"preview":"edit",Dt=Ve?"tree":"text";for(const ns of xe)L.current[ns]=Je,Dd(ns)&&($.current[ns]=Ct),Po(ns)&&(K.current[ns]=Ct);U(Je),oe(Ct),re(Ct),je(Dt);try{localStorage.setItem(St,Ct),localStorage.setItem(xs,Ct),localStorage.setItem(Is,Dt)}catch{}},Ie=Ve=>{const Je=!!Ve.detail?.enabled;q(Je)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",Ie),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",Ie)}},[xe]),a.useEffect(()=>{if(!pn||!y)return;const q=()=>{typeof window>"u"||Ls.current===null&&(Ls.current=window.requestAnimationFrame(()=>{Ls.current=null,Es(Or=>Or+1)}))},Ie=(Or,li)=>{if(Or.state.doc.length!==li.length)return!1;if(li.length===0)return!0;const Pa=Math.min(128,li.length);if(Or.state.sliceDoc(0,Pa)!==li.slice(0,Pa))return!1;const fc=Math.max(0,li.length-Pa);return Or.state.sliceDoc(fc,li.length)===li.slice(fc)},Ve=en(pn.path);if(!Ve){Sn(null),gs.current={key:"",attempts:0};return}const Je=`${Ve}:${pn.line}:${pn.column??1}`;if(gs.current.key!==Je&&(gs.current={key:Je,attempts:0}),B?.path!==Ve){if(Yt)return;ln(fe(Ve));return}if(rt||tt!==Ve)return;if(ct||fn){Sn(null),gs.current={key:"",attempts:0};return}if(!An)return;if(ne!=="edit"){U("edit");return}const Ct=as.current;if(!Ct){q();return}if(!Ie(Ct,gt)){q();return}const Dt=Math.max(1,Math.min(pn.line,Ct.state.doc.lines)),ns=Ct.state.doc.line(Dt),Ts=Math.max(1,pn.column||1),cn=Math.max(0,ns.to-ns.from),So=Math.min(cn,Ts-1),Yi=ns.from+So;if(!(Ct.state.selection.main.head===Yi)||gs.current.attempts===0){gs.current.attempts+=1,Ct.dispatch({selection:{anchor:Yi},effects:qr.scrollIntoView(Yi,{y:"center"})}),Ct.focus(),q();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Or=as.current;Or&&(Or.dispatch({selection:{anchor:Yi},effects:qr.scrollIntoView(Yi,{y:"center"})}),Or.focus())}),Sn(null),gs.current={key:"",attempts:0}},[An,Yt,gt,Ut,ct,rt,fn,tt,ln,pn,y,B?.path,Sn,ne,fe]),a.useEffect(()=>{if(!Os||!y)return;const q=en(Os);if(!q){lr(null);return}if(B?.path!==q){if(Yt)return;ln(fe(q));return}if(!(rt||tt!==q||ct||fn)){if(An&&ne==="edit"){const Ie=as.current;if(!Ie)return;Ie.focus()}lr(null)}},[An,Yt,ct,rt,ln,fn,tt,Os,y,B?.path,lr,ne,fe]);const Kt=a.useCallback(q=>{if(!u||!q||!q.hasFocus||typeof window>"u")return;const Ie=window.visualViewport;if(!Ie)return;const Ve=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,Ve-(Ie.offsetTop+Ie.height))<=0)return;const Ct=q.state.selection.main.head,Dt=q.coordsAtPos(Ct);if(!Dt)return;const ns=Math.round(Ie.offsetTop+Ie.height),cn=Dt.bottom+20-ns;cn<=0||(q.scrollDOM.scrollTop+=cn)},[u]);a.useEffect(()=>{if(!u||typeof window>"u")return;const q=()=>{window.requestAnimationFrame(()=>{Kt(as.current)})},Ie=window.visualViewport;return Ie?.addEventListener("resize",q),Ie?.addEventListener("scroll",q,{passive:!0}),document.addEventListener("selectionchange",q),()=>{Ie?.removeEventListener("resize",q),Ie?.removeEventListener("scroll",q),document.removeEventListener("selectionchange",q)}},[u,Kt]),a.useEffect(()=>{if(!An||ne!=="edit"||u)return;const q=pi("open_go_to_line",cr),Ie=Ve=>{const Je=Ve.target;if(Je?.closest('[role="dialog"]'))return;const Ct=!!Je?.closest(".cm-editor");Je?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Ct||!document.activeElement?.closest(".cm-editor")||Lo(Ve,q)&&(Ve.preventDefault(),bs(!0))};return window.addEventListener("keydown",Ie),()=>window.removeEventListener("keydown",Ie)},[An,u,cr,ne]);const Ps=a.useMemo(()=>{if(!B?.path)return[fl(o)];const q=[fl(o)],Ie=ke??Ue;return Ie&&q.push(Ie),C&&q.push(qr.lineWrapping),u&&q.push(qr.updateListener.of(Ve=>{Ve.view.hasFocus&&(Ve.selectionSet||Ve.focusChanged||Ve.viewportChanged||Ve.geometryChanged)&&window.requestAnimationFrame(()=>{Kt(Ve.view)})})),q},[o,B?.path,ke,Ue,C,u,Kt]),wn=a.useMemo(()=>({light:he.metadata.id,dark:de.metadata.id}),[he.metadata.id,de.metadata.id]),Dn=B?.path&&fn&&!r.isDesktop&&!kr?`${B.path}|${J.allowOutsideWorkspace?"outside":"workspace"}`:"";a.useEffect(()=>{if(!Dn){Ke("");return}let q=!1;return Ke(""),Ll(Xr()).then(Ie=>{!q&&Ie&&Ke(Dn)}).catch(()=>{}),()=>{q=!0}},[Dn]);const Bn=!!(Dn&&kt!==Dn),vn=B?.path&&fn?r.isDesktop?kr?`data:${Nc(B.path)};utf8,${encodeURIComponent(Qe)}`:It:kr?`data:${Nc(B.path)};utf8,${encodeURIComponent(Qe)}`:kt===Dn?Li().authenticatedAsset("/api/fs/raw",{path:B.path,allowOutsideWorkspace:J.allowOutsideWorkspace?"true":void 0}):"":"";a.useEffect(()=>{let q=!1;return(async()=>{if(!r.isDesktop||!B?.path||!fn||kr){lt("");return}nt(null),await(n.readFileBinary?n.readFileBinary(B.path,J).then(Je=>Je.dataUrl):Promise.resolve(Li().authenticatedAsset("/api/fs/raw",{path:B.path,allowOutsideWorkspace:J.allowOutsideWorkspace?"true":void 0}))).then(Je=>{q||(lt(Je),We(B.path))}).catch(Je=>{q||(lt(""),nt(Je instanceof Error?Je.message:e("filesView.error.readFileFailed")),We(null))}).finally(()=>{q||bt(!1)})})(),()=>{q=!0}},[n,fn,kr,r.isDesktop,B?.path,J,e]);const jn=a.useCallback(()=>Mt(null),[]),Ki=a.useMemo(()=>Xu({drafts:yr,editingDraftId:ur,commentText:wr,selection:As,isDragging:hn,fileLabel:B?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:q=>({start:q.startLine,end:q.endLine}),onSave:cs,onCancel:()=>{Xs(null),wt()},onEdit:q=>{ps(q),Xs({start:q.startLine,end:q.endLine})},onDelete:us}),[wt,wr,us,ur,yr,cs,hn,As,B?.path,ps]),qi=a.useCallback((q,Ie)=>s.jsx("div",{className:"h-full",children:s.jsx(ef,{file:{name:q.name,contents:Ie,lang:Oi(q.path)||void 0},options:{disableFileHeader:!0,overflow:C?"wrap":"scroll",theme:wn,themeType:o.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[o.metadata.variant,wn,C]),dc=({exitFullscreenOnly:q=!1}={})=>{if(!B)return null;const Ie=(Ve,Je)=>s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:Je})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:Ve})]});return s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[An&&ne==="edit"&&s.jsxs(s.Fragment,{children:[st?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):Qt&&Lt==="saved"&&!Ds?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(I,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Ds?Ie(e(Qt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${Ea()}+S`}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{Zs()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Qt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${Ea()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${Ea()}+S`}),children:s.jsx(I,{name:"save-3",className:"size-4"})})):null,Ie(e(Qt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>rs(Ve=>!Ve),className:Pe("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Qt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(Qt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(Qt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:Qt?s.jsx(I,{name:"file-check-fill",className:"size-4"}):s.jsx(I,{name:"file-check",className:"size-4"})}))]}),s.jsxs(rn,{onOpenChange:te,children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(sn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(I,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(nn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[zs.map(Ve=>s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{nr(Ve)},children:[s.jsx(uw,{label:Ve.label,iconDataUrl:Ve.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Ve.label})]},Ve.id)),Ws?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{br(!0)},children:[s.jsx(I,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!fn&&s.jsxs(s.Fragment,{children:[Ie(e(C?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>P(!C),className:Pe("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",C?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(C?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})})),ne==="edit"&&s.jsxs(s.Fragment,{children:[Ie(e("filesView.editor.findInFile"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:Ve=>{R(!H),Ve.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(I,{name:"search",className:"size-4"})})),Ie(e("filesView.editor.goToLine"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:Ve=>{bs(Je=>!Je),Ve.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(I,{name:"menu-fold-2",className:"size-4"})})),s.jsx(cw,{open:ss,onOpenChange:bs,view:as.current,variant:"inline"})]})]}),ge&&An&&!mr&&!Js&&s.jsx(pl,{currentMode:ne==="view"?"preview":"edit",onToggle:()=>{Cr(ne==="view"?"edit":"view")}}),(Lr||Po(B?.path??""))&&s.jsx(pl,{currentMode:Lr?X():Pt(),onToggle:()=>{Po(B?.path??"")?qe(Pt()==="preview"?"edit":"preview"):Da(X()==="preview"?"edit":"preview")}}),mr&&Ie(e(pe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Ze(pe==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(pe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:pe==="tree"?s.jsx(I,{name:"code-sslash",className:"size-4"}):s.jsx(I,{name:"node-tree",className:"size-4"})})),oi&&Ie(e("filesView.editor.copyFileContents"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await ar(Qe)).ok?(ht(!0),ks.current!==null&&window.clearTimeout(ks.current),ks.current=window.setTimeout(()=>{ht(!1)},1200)):ae.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Xe?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"size-4"})})),ai&&Ie(e("filesView.editor.copyFilePathTitle",{path:Ns}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await ar(Ns)).ok?(ut(!0),$t.current!==null&&window.clearTimeout($t.current),$t.current=window.setTimeout(()=>{ut(!1)},1200)):ae.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:Ns}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:Ns}),children:Nt?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&Ie(e("filesView.editor.saveFile"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{const Ve=n.downloadFile;Ve&&Ve(B.path)},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(I,{name:"download",className:"size-4"})})),q?Ie(e("filesView.editor.exitFullscreen"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>M(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(I,{name:"fullscreen-exit",className:"size-4"})})):!u&&t==="full"&&Ie(e(E?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>M(!E),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(E?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(E?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:E?s.jsx(I,{name:"fullscreen-exit",className:"size-4"}):s.jsx(I,{name:"fullscreen",className:"size-4"})}))]})},Ia=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Ks,{open:Yt,onOpenChange:q=>{q||ft(!0)},children:s.jsxs(Gs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Qs,{children:[s.jsx(Ys,{children:e("filesView.unsaved.title")}),s.jsx(dn,{children:e("filesView.unsaved.description")})]}),s.jsxs(sr,{children:[s.jsx(ze,{variant:"outline",onClick:()=>{ri()},disabled:st,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(ze,{variant:"destructive",onClick:jo,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:Pe("flex flex-col flex-shrink-0",b&&"border-b border-border/40"),children:b?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[u&&A&&s.jsx("button",{type:"button",onClick:()=>T(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"arrow-left-s",className:"size-5"})}),u?B?s.jsxs(rn,{children:[s.jsx(sn,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(xr,{filePath:B.path,extension:B.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Cd,{name:B.name}),s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(nn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Te.map(q=>{const Ie=B?.path===q.path;return s.jsxs(zt,{onSelect:Ve=>{if(Ve.target.closest("[data-close-open-file]")){Ve.preventDefault();return}Ie||ln(q)},className:Pe("flex min-w-0 items-center justify-between gap-2 overflow-hidden",Ie&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(xr,{filePath:q.path,extension:q.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Cd,{name:q.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:Ve=>{Ve.preventDefault(),Ve.stopPropagation()},onClick:Ve=>{Ve.preventDefault(),Ve.stopPropagation(),Yn(q.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:q.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},q.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Te.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Ee.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),Ee.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Me,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Te.map(q=>{const Ie=B?.path===q.path;return s.jsxs("div",{title:Al(y,q.path),className:Pe("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",Ie?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(xr,{filePath:q.path,extension:q.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Ie||ln(q)},className:"max-w-[12rem] truncate text-left",children:q.name}),s.jsx("button",{type:"button",onClick:Ve=>{Ve.stopPropagation(),Yn(q.path)},className:Pe("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!Ie&&!f&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:q.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},q.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[B&&!H&&s.jsx("div",{ref:V,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>z(!0),onMouseLeave:()=>{F.current>0||z(!1)},children:_?dc():s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>z(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})}),s.jsx(_n,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:B?rt||Bn?h?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):ct?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:ct}):fn?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:vn,alt:B?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):B&&mr&&pe==="tree"?s.jsx(on,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(ih,{jsonString:Qe,maxHeight:"100%",initiallyExpandedDepth:2})})}):B&&Lr&&X()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Qe.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Qe.length/1024)})}),s.jsx(on,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(fo,{content:Qe,className:"typography-markdown-body",stripFrontmatter:!0})})]}):B&&Js&&Se==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const q=B.path.substring(0,B.path.lastIndexOf("/")+1);if(!q)return Qe;const Ie=`<base href="${r.isDesktop,q}">`;return Qe.replace(/<head([^>]*)>/i,`<head$1>${Ie}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):B&&ge&&ne==="view"?qi(B,gt):s.jsxs("div",{className:Pe("relative h-full",Jn&&"overflow-hidden"),ref:$s,children:[s.jsx("div",{className:Pe("h-full",Jn&&"invisible"),children:s.jsx(hl,{value:gt,onChange:He,readOnly:!An,extensions:Ps,className:"h-full",blockWidgets:Ki,onViewReady:q=>{as.current=q,Es(Ie=>Ie+1),window.requestAnimationFrame(()=>{Kt(q)})},onViewDestroy:()=>{as.current&&(as.current=null),Es(q=>q+1)},enableSearch:!0,searchOpen:H,onSearchOpenChange:R,highlightLines:As?{start:Math.min(As.start,As.end),end:Math.max(As.start,As.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(q,Ie,Ve)=>{if(!(Ve instanceof MouseEvent)||Ve.button!==0)return!1;Ve.preventDefault();const Je=q.state.doc.lineAt(Ie.from).number;if(u&&As&&!Ve.shiftKey){const Ct=Math.min(As.start,As.end,Je),Dt=Math.max(As.start,As.end,Je);return Xs({start:Ct,end:Dt}),Cn.current=!1,un.current=null,ds(!1),!0}if(Cn.current=!0,un.current=Je,ds(!0),As&&Ve.shiftKey){const Ct=Math.min(As.start,Je),Dt=Math.max(As.end,Je);Xs({start:Ct,end:Dt})}else Xs({start:Je,end:Je});return!0},mouseover:(q,Ie,Ve)=>{if(!(Ve instanceof MouseEvent)||Ve.buttons!==1||!Cn.current||un.current===null)return!1;const Je=q.state.doc.lineAt(Ie.from).number,Ct=Math.min(un.current,Je),Dt=Math.max(un.current,Je);return Xs({start:Ct,end:Dt}),ds(!0),!1},mouseup:()=>(Cn.current=!1,un.current=null,ds(!1),!1)}}})}),Jn&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),Qm=!!(y&&O[y]),uc=y?Y[y]:null,mc=s.jsxs("section",{className:Pe("flex min-h-0 flex-col overflow-hidden",u?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:Pe("flex flex-col gap-2 py-2",u?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(kn,{ref:k,value:S,onChange:q=>v(q.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),S.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{v(""),k.current?.focus()},children:s.jsx(I,{name:"close",className:"size-4"})})]}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Kn("createFile",{path:p,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"size-4"})})})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Kn("createFolder",{path:p,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"size-4"})})})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{Mn()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(I,{name:"refresh",className:"size-4"})})})}),s.jsx(Bt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(_n,{outerClassName:"flex-1 min-h-0",className:Pe("py-2",u?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:mt?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):yt.length>0?yt.map(q=>{const Ie=B?.path===q.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{ln(q)},className:Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Ie?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[wm(q.path,q.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:q.path,children:q.relativePath??q.path})]})},q.path)}):uc?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:uc}),s.jsxs(ze,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{Mn()},children:[s.jsx(I,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):Qm?ii(y,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Xm=t==="full"&&E&&B&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:dc({exitFullscreenOnly:!0})}),s.jsx(_n,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:rt||Bn?h?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):ct?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:ct}):fn?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:vn,alt:B.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):Lr&&X()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Qe.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Qe.length/1024)})}),s.jsx(on,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(fo,{content:Qe,className:"typography-markdown-body",stripFrontmatter:!0})})]}):ge&&ne==="view"?qi(B,gt):s.jsxs("div",{className:Pe("relative h-full",Jn&&"overflow-hidden"),children:[s.jsx("div",{className:Pe("h-full",Jn&&"invisible"),children:s.jsx(hl,{value:gt,onChange:He,readOnly:!An,extensions:Ps,className:"h-full",onViewReady:q=>{as.current=q,window.requestAnimationFrame(()=>{Kt(q)})},onViewDestroy:()=>{as.current&&(as.current=null)}})}),Jn&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(Nw,{activeDialog:Cs,dialogData:xt,dialogInputValue:Ft,onDialogInputChange:is,isDialogSubmitting:es,onDialogSubmit:Mr,onClose:jn,inputRef:Ht}),Xm,u?A?Ia:mc:t==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:Ia})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[d>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:mc}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Ia})]})]})},gr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Ga=(t,e)=>{const n=gr(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},kw=(t,e,n)=>Ga(Ga(Ga(t,".opencode"),"plans"),`${e}-${n}.md`),Cw=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,Aw=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},Dw=(t,e)=>{const n=gr(e.currentDirectory),r=gr(e.homeDirectory),o=gr(t);return n&&o.startsWith(n+"/")?o.slice(n.length+1):r&&o===r?"~":r&&o.startsWith(r+"/")?`~${o.slice(r.length)}`:o},Iw=(t,e,n)=>{const r=gr(t.trim());if(!r)return null;const o=n?e.find(c=>c.id===n)??null:null;if(o?.path){const c=gr(o.path);if(r===c||r.startsWith(`${c}/`))return{id:o.id,path:o.path}}const i=e.filter(c=>{const l=gr(c.path);return r===l||r.startsWith(`${l}/`)}).sort((c,l)=>gr(l.path).length-gr(c.path).length)[0];return i?{id:i.id,path:i.path}:null},jm=({targetPath:t=null})=>{const{t:e}=Tt(),n=jt(se=>se.currentSessionId),r=jt(se=>se.createSession),o=jt(se=>se.initializeNewOpenChamberSession),i=jt(se=>se.sendMessage),c=jt(se=>se.setCurrentSession),l=Kl(),u=tn(se=>se.homeDirectory),m=Bl(se=>se.planModeEnabled),d=Ms(se=>se.projects),f=Ms(se=>se.activeProjectId),g=_s(se=>se.directories),x=si()??"",p=Fe(se=>se.setActiveMainTab),y=Fe(se=>se.setSessionSwitcherOpen),b=Gn(),{isMobile:h}=Pr(),{currentTheme:N}=Tr();a.useMemo(()=>Lu(N),[N]);const w=a.useMemo(()=>n?l.find(se=>se.id===n)??null:null,[n,l]),S=a.useMemo(()=>{const se=typeof w?.directory=="string"?w.directory:"";return gr(se||"")},[w?.directory]),v=a.useMemo(()=>gr(x||S),[x,S]),j=a.useMemo(()=>Iw(v,d,f),[f,v,d]),k=a.useMemo(()=>j?g.get(j.path)?.isGitRepo===!0:!1,[j,g]),[A,T]=a.useState(null),[C,P]=a.useState(!1),[E,M]=a.useState(null),H=a.useMemo(()=>!E||!S||!u?E:Dw(E,{currentDirectory:S,homeDirectory:u}),[E,S,u]),[R,_]=a.useState(""),[z,V]=a.useState(null),F=a.useMemo(()=>H&&H.split("/").pop()||e("planView.file.defaultName"),[H,e]),te=a.useMemo(()=>R.trim()&&oh(R).title||e("planView.title.default"),[R,e]),Z=a.useMemo(()=>te.trim()||e("planView.title.default"),[te,e]),[ne,U]=a.useState(!1),[ie,oe]=a.useState(!1),[pe,je]=a.useState("edit"),Se=a.useRef(null),[re,L]=a.useState(null),$=a.useRef(null),K=a.useRef(null),he="openchamber:plan:md-viewer-mode";a.useEffect(()=>{try{const se=localStorage.getItem(he);if(!se)return;const O=JSON.parse(se);(O==="preview"||O==="edit")&&je(O)}catch{}},[]);const de=a.useCallback(se=>{je(se);try{localStorage.setItem(he,JSON.stringify(se))}catch{}},[]),we=a.useRef(!1),xe=a.useRef(null),[De,le]=a.useState(!1);a.useEffect(()=>{const se=()=>{we.current=!1,xe.current=null,le(!1)};return document.addEventListener("mouseup",se),()=>document.removeEventListener("mouseup",se)},[]);const Ce=a.useCallback((se,O)=>{const D=se.split(`
29
+ `),Y=Math.max(1,O.start),be=Math.min(D.length,O.end);return Y>be?"":D.slice(Y-1,be).join(`
30
+ `)},[]),ue=Ju({source:"plan",fileLabel:F,language:E&&Oi(E)||"markdown",getCodeForRange:se=>Ce(R,Qu(se)),toStoreRange:se=>({startLine:se.start,endLine:se.end}),fromDraftRange:se=>({start:se.startLine,end:se.endLine})}),{drafts:ve,commentText:G,editingDraftId:Ae,setSelection:ce,saveComment:fe,cancel:Te,reset:me,startEdit:B,deleteDraft:ye}=ue;a.useEffect(()=>{L(null),me()},[R,me]),a.useEffect(()=>{ce(re)},[re,ce]);const _e=a.useCallback(()=>{L(null),Te()},[Te]),J=a.useCallback((se,O)=>{O&&L(O),fe(se,O??re??void 0),L(null)},[re,fe]);a.useEffect(()=>{if(!re)return;const se=D=>{const Y=D.target;Y.closest('[data-comment-card="true"]')||Y.closest('[data-comment-input="true"]')||Y.closest(".oc-block-widget")||Y.closest(".cm-gutterElement")||Y.closest("[data-sonner-toast]")||Y.closest("[data-sonner-toaster]")||(L(null),Te())},O=window.setTimeout(()=>{document.addEventListener("click",se)},100);return()=>{window.clearTimeout(O),document.removeEventListener("click",se)}},[Te,Ae,h,re]);const Me=a.useMemo(()=>{const se=[fl(N)],O=Fu(E||"plan.md");return O&&se.push(O),se.push(qr.lineWrapping),se},[N,E]);a.useEffect(()=>{if(!m&&!t){M(null),_(""),U(!1);return}let se=!1;const O=async Y=>{if(b.files?.readFile)return(await b.files.readFile(Y))?.content??"";const be=bo()?.files;if(be?.readFile)return(await be.readFile(Y,{optional:!0}))?.content??"";const Oe=await Fs(`/api/fs/read?path=${encodeURIComponent(Y)}&optional=true`,{cache:"no-store"});if(!Oe.ok)throw new Error(`Failed to read plan file (${Oe.status})`);return Oe.text()};return(async()=>{if(M(null),_(""),V(null),t){U(!0);try{const Y=await O(t);if(se)return;M(t),_(Y)}catch{if(se)return;M(null),_("")}finally{se||U(!1)}return}if(!w?.slug||!w?.time?.created||!S){M(null),_("");return}U(!0);try{const Y=kw(S,w.time.created,w.slug),be=Aw(Cw(w.time.created,w.slug),u||null);let Oe=null,$e=null;try{$e=await O(Y),Oe=Y}catch{}if(!Oe)try{$e=await O(be),Oe=be}catch{}if(se)return;if(!Oe||$e===null){M(null),_("");return}M(Oe),_($e)}catch{if(se)return;M(null),_("")}finally{se||U(!1)}})(),()=>{se=!0}},[u,m,b.files,S,w?.slug,w?.time?.created,t]),a.useEffect(()=>{if(!E){V(null);return}const se=window.setTimeout(async()=>{V(null);try{if(b.files?.writeFile){if(!(await b.files.writeFile(E,R))?.success)throw new Error(e("planView.error.writeFailed"))}else{const O=await Fs("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:E,content:R})});if(!O.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:O.status}))}}catch(O){V(O instanceof Error?O.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(se)}},[R,E,b.files,e]),a.useEffect(()=>()=>{Se.current!==null&&window.clearTimeout(Se.current)},[]);const Ee=a.useCallback(()=>{p("chat"),y(!1)},[p,y]),Ne=a.useCallback(async se=>{if(!j||!A)return;const O=await Tn(A.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:Z}),Y=[{synthetic:!0,text:await Tn(A.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:Z,plan_path:E??""})}];P(!0);try{Ee();let be=null,Oe=j.path;if(A.target==="worktree"){if(!k)return;const Re=await Iu(j.path,Pu());if(!Re?.id)return;be=Re.id,Oe=Re.path}else{const Re=await r(void 0,j.path,null);if(!Re?.id)return;be=Re.id,Oe=Re.directory??j.path,o(Re.id,ls.getState().agents??[])}if(!be)return;const $e=zl.getState();$e.saveSessionModelSelection(be,se.providerID,se.modelID),se.agent.trim()&&($e.saveSessionAgentSelection(be,se.agent),$e.saveAgentModelForSession(be,se.agent,se.providerID,se.modelID),$e.saveAgentModelVariantForSession(be,se.agent,se.providerID,se.modelID,se.variant||void 0)),c(be,Oe),await i(O,se.providerID,se.modelID,se.agent.trim()||void 0,void 0,void 0,Y,se.variant||void 0),T(null)}finally{P(!1)}},[k,r,j,o,A,E,Ee,i,Z,c]),Be=a.useMemo(()=>Xu({drafts:ve,editingDraftId:Ae,commentText:G,selection:re,isDragging:De,fileLabel:F,newWidgetId:"plan-new-comment-input",mapDraftToRange:se=>({start:se.startLine,end:se.endLine}),onSave:J,onCancel:_e,onEdit:se=>{B(se),L({start:se.startLine,end:se.endLine})},onDelete:ye}),[G,ye,Ae,_e,J,De,re,ve,F,B]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:te}),z?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:z,children:e("planView.error.saveFailed")}):null]}),E?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(rn,{children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(sn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!R.trim(),children:s.jsx(I,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(Bt,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(nn,{align:"end",children:[s.jsx(zt,{onClick:()=>T({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(zt,{onClick:()=>T({action:"improve",target:"worktree"}),disabled:!k,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(rn,{children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(sn,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!R.trim(),children:s.jsx(I,{name:"code-ai",className:"size-4"})})})}),s.jsx(Bt,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(nn,{align:"end",children:[s.jsx(zt,{onClick:()=>T({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(zt,{onClick:()=>T({action:"implement",target:"worktree"}),disabled:!k,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(pl,{currentMode:pe,onToggle:()=>de(pe==="preview"?"edit":"preview")}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await ar(R)).ok&&(oe(!0),Se.current!==null&&window.clearTimeout(Se.current),Se.current=window.setTimeout(()=>{oe(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:ie?s.jsx(I,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(tm,{open:A!==null,onOpenChange:se=>{!se&&!C&&T(null)},target:A?.target??"session",projectDirectory:j?.path??null,submitting:C,onConfirm:Ne}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(_n,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:ne?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("planView.state.loading")}):s.jsx("div",{className:"relative h-full",children:s.jsx("div",{className:"h-full",children:pe==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(on,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("planView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("planView.error.switchToEditMode")})]}),children:s.jsx(fo,{content:R,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:K,children:s.jsx(hl,{value:R,onChange:_,readOnly:!1,className:"h-full",extensions:Me,onViewReady:se=>{$.current=se},onViewDestroy:()=>{$.current=null},blockWidgets:Be,highlightLines:re?{start:Math.min(re.start,re.end),end:Math.max(re.start,re.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(se,O,D)=>{if(!(D instanceof MouseEvent)||D.button!==0)return!1;D.preventDefault();const Y=se.state.doc.lineAt(O.from).number;if(h&&re&&!D.shiftKey){const be=Math.min(re.start,re.end,Y),Oe=Math.max(re.start,re.end,Y);return L({start:be,end:Oe}),we.current=!1,xe.current=null,le(!1),!0}if(we.current=!0,xe.current=Y,le(!0),re&&D.shiftKey){const be=Math.min(re.start,Y),Oe=Math.max(re.end,Y);L({start:be,end:Oe})}else L({start:Y,end:Y});return!0},mouseover:(se,O,D)=>{if(!(D instanceof MouseEvent)||D.buttons!==1||!we.current||xe.current===null)return!1;const Y=se.state.doc.lineAt(O.from).number,be=Math.min(xe.current,Y),Oe=Math.max(xe.current,Y);return L({start:be,end:Oe}),le(!0),!1},mouseup:()=>(we.current=!1,xe.current=null,le(!1),!1)}}})})})})})})]})},Dl={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},$o={user:0,assistant:0,tool:0,other:0},ui=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Id=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(m=>m.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Dl,total:ui(n)};if(!n||typeof n!="object")return Dl;const r=n,o=ui(r.input),i=ui(r.output),c=ui(r.reasoning),l=ui(r.cache?.read),u=ui(r.cache?.write);return{input:o,output:i,reasoning:c,cacheRead:l,cacheWrite:u,total:o+i+c+l+u}},Pw=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},Xn=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+Xn(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+Xn(n),0):0,Tw=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...$o,assistant:Xn(n.text)+Xn(n.content)};const o=Pw(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:Xn(n.input)+Xn(n.output)+Xn(n.error)+Xn(n.call?.input)+Xn(n.call?.output)+Xn(n.call?.error)+Xn(n.raw)+Math.round(Xn(n.metadata)*.25)+Math.round(Xn(n.state)*.1),other:0}:e==="user"?{user:o.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},Pd=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),Ew=t=>{const e=yo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},Rw=(t,e)=>{if(t.length===0)return{...$o};const n=t.reduce((r,o)=>{const i=Ew(o);let c={...$o};for(const l of o.parts)c=Pd(c,Tw(l,i));return Pd(r,c)},{...$o});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Di=t=>t.toLocaleString(),Mw=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,Fw=(t,e)=>!t||!Number.isFinite(t)?"-":ga(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),Lw=(t,e)=>!t||!Number.isFinite(t)?"-":ga(t,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),Ow=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,_w=(t,e,n)=>{const r=t.find(i=>i.id===e),o=r?.models?.find(i=>i.id===n);return{providerName:r?.name||e||"-",modelName:o?.name||n||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},Bw=()=>{const t=pt.c(202),{t:e}=Tt(),{currentTheme:n}=Tr(),r=Fe(Vw);let o;t[0]!==n?(o=Lu(n),t[0]=n,t[1]=o):o=t[1];const i=o;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c={},t[2]=c):c=t[2];const[l,u]=a.useState(c),[m,d]=a.useState(null),f=a.useRef(null),g=jt($w),x=Kl(),p=ah(g??""),y=ls(zw);let b;t[3]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null),u(Ww),d(null)},t[3]=b):b=t[3];let h;t[4]!==g?(h=[g],t[4]=g,t[5]=h):h=t[5],a.useEffect(b,h);let N,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=()=>()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=[],t[6]=N,t[7]=w):(N=t[6],w=t[7]),a.useEffect(N,w);let S;t[8]===Symbol.for("react.memo_cache_sentinel")?(S=async(at,dt)=>{(await ar(dt)).ok?(d(at),f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{d(Rt=>Rt===at?null:Rt),f.current=null},2e3)):d(null)},t[8]=S):S=t[8];const v=S;let j;t[9]!==g||t[10]!==x?(j=g?x.find(at=>at.id===g)??null:null,t[9]=g,t[10]=x,t[11]=j):j=t[11];const k=j;let A,T,C,P,E;if(t[12]!==y||t[13]!==p){A=p.filter(Uw);let at;t[19]!==p?(at=p.filter(Hw),t[19]=p,t[20]=at):at=t[20],E=at;let dt=null;for(let Rt=A.length-1;Rt>=0;Rt=Rt-1,Rt){const Wt=A[Rt];if(Id(Wt).total>0){dt=Wt;break}}C=dt?Id(dt):Dl,P=A.reduce(Gw,0);const Ht=dt?.info??null;T=_w(y,Ht?.providerID||"",Ht?.modelID||""),t[12]=y,t[13]=p,t[14]=A,t[15]=T,t[16]=C,t[17]=P,t[18]=E}else A=t[14],T=t[15],C=t[16],P=t[17],E=t[18];const M=T,H=M.contextLimit,R=H&&H>0?Math.min(999,C.total/H*100):0;let _;if(t[21]!==p){const at=[...p].reverse().find(Kw)?.info?.system||"";_=Rw(p,at),t[21]=p,t[22]=_}else _=t[22];const z=_,V=z.user,F=z.assistant,te=z.tool,Z=Math.max(0,C.input-V-F-te),ne=V+F+te+Z,U=p[0]?.info?.time?.created,ie=p.length>0?p[p.length-1]?.info?.time?.created:null;let oe;t[23]!==k?.title||t[24]!==e?(oe=k?.title||e("contextSidebar.session.untitled"),t[23]=k?.title,t[24]=e,t[25]=oe):oe=t[25];const pe=k?.time?.created??U??null,je=ie??k?.time?.created??null;let Se;t[26]!==F||t[27]!==Z||t[28]!==te||t[29]!==V?(Se={user:V,assistant:F,tool:te,other:Z},t[26]=F,t[27]=Z,t[28]=te,t[29]=V,t[30]=Se):Se=t[30];let re;t[31]!==A.length||t[32]!==ne||t[33]!==H||t[34]!==M||t[35]!==p.length||t[36]!==oe||t[37]!==pe||t[38]!==je||t[39]!==Se||t[40]!==C||t[41]!==P||t[42]!==R||t[43]!==E.length?(re={sessionTitle:oe,messagesCount:p.length,userMessagesCount:E.length,assistantMessagesCount:A.length,createdAt:pe,lastActivityAt:je,providerModel:M,tokenBreakdown:C,usagePercent:R,totalAssistantCost:P,contextLimit:H,breakdown:Se,breakdownTotal:ne},t[31]=A.length,t[32]=ne,t[33]=H,t[34]=M,t[35]=p.length,t[36]=oe,t[37]=pe,t[38]=je,t[39]=Se,t[40]=C,t[41]=P,t[42]=R,t[43]=E.length,t[44]=re):re=t[44];const L=re;if(!g){let at;t[45]!==e?(at=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=at):at=t[46];let dt;return t[47]!==at?(dt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:at}),t[47]=at,t[48]=dt):dt=t[48],dt}let $;t[49]!==e?($=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=$):$=t[50];let K;t[51]!==$||t[52]!==L.breakdown.user?(K={key:"user",label:$,value:L.breakdown.user,color:"var(--status-success)"},t[51]=$,t[52]=L.breakdown.user,t[53]=K):K=t[53];let he;t[54]!==e?(he=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=he):he=t[55];let de;t[56]!==he||t[57]!==L.breakdown.assistant?(de={key:"assistant",label:he,value:L.breakdown.assistant,color:"var(--primary-base)"},t[56]=he,t[57]=L.breakdown.assistant,t[58]=de):de=t[58];let we;t[59]!==e?(we=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=we):we=t[60];let xe;t[61]!==we||t[62]!==L.breakdown.tool?(xe={key:"tool",label:we,value:L.breakdown.tool,color:"var(--status-warning)"},t[61]=we,t[62]=L.breakdown.tool,t[63]=xe):xe=t[63];let De;t[64]!==e?(De=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=De):De=t[65];let le;t[66]!==De||t[67]!==L.breakdown.other?(le={key:"other",label:De,value:L.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=De,t[67]=L.breakdown.other,t[68]=le):le=t[68];let Ce;t[69]!==K||t[70]!==de||t[71]!==xe||t[72]!==le?(Ce=[K,de,xe,le],t[69]=K,t[70]=de,t[71]=xe,t[72]=le,t[73]=Ce):Ce=t[73];const ue=Ce;let ve;t[74]!==L.sessionTitle?(ve=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:L.sessionTitle}),t[74]=L.sessionTitle,t[75]=ve):ve=t[75];let G;t[76]!==L.providerModel.modelName||t[77]!==L.providerModel.providerName?(G=s.jsxs("span",{children:[L.providerModel.providerName," / ",L.providerModel.modelName]}),t[76]=L.providerModel.modelName,t[77]=L.providerModel.providerName,t[78]=G):G=t[78];let Ae;t[79]!==r||t[80]!==L.createdAt?(Ae=L.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:Fw(L.createdAt,r)})]}),t[79]=r,t[80]=L.createdAt,t[81]=Ae):Ae=t[81];let ce;t[82]!==G||t[83]!==Ae?(ce=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[G,Ae]}),t[82]=G,t[83]=Ae,t[84]=ce):ce=t[84];let fe;t[85]!==ve||t[86]!==ce?(fe=s.jsxs("div",{className:"mb-6",children:[ve,ce]}),t[85]=ve,t[86]=ce,t[87]=fe):fe=t[87];let Te;t[88]!==e?(Te=e("contextSidebar.section.context"),t[88]=e,t[89]=Te):Te=t[89];let me;t[90]!==Te?(me=s.jsx("span",{className:"typography-micro text-muted-foreground",children:Te}),t[90]=Te,t[91]=me):me=t[91];let B;t[92]!==L.tokenBreakdown.total?(B=Di(L.tokenBreakdown.total),t[92]=L.tokenBreakdown.total,t[93]=B):B=t[93];let ye;t[94]!==L.contextLimit?(ye=L.contextLimit?` / ${Di(L.contextLimit)}`:"",t[94]=L.contextLimit,t[95]=ye):ye=t[95];let _e;t[96]!==B||t[97]!==ye?(_e=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[B,ye]}),t[96]=B,t[97]=ye,t[98]=_e):_e=t[98];let J;t[99]!==me||t[100]!==_e?(J=s.jsxs("div",{className:"flex items-baseline justify-between",children:[me,_e]}),t[99]=me,t[100]=_e,t[101]=J):J=t[101];let Me;t[102]!==L.usagePercent?(Me=L.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,L.usagePercent)}%`,backgroundColor:L.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[102]=L.usagePercent,t[103]=Me):Me=t[103];let Ee;t[104]!==Me?(Ee=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Me}),t[104]=Me,t[105]=Ee):Ee=t[105];let Ne;t[106]!==e||t[107]!==L.usagePercent?(Ne=e("contextSidebar.context.percentUsed",{percent:L.usagePercent.toFixed(1)}),t[106]=e,t[107]=L.usagePercent,t[108]=Ne):Ne=t[108];let Be;t[109]!==Ne?(Be=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Ne}),t[109]=Ne,t[110]=Be):Be=t[110];let se;t[111]!==J||t[112]!==Ee||t[113]!==Be?(se=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[J,Ee,Be]}),t[111]=J,t[112]=Ee,t[113]=Be,t[114]=se):se=t[114];let O;t[115]!==e?(O=e("contextSidebar.stats.messages"),t[115]=e,t[116]=O):O=t[116];let D;t[117]!==L.messagesCount?(D=Di(L.messagesCount),t[117]=L.messagesCount,t[118]=D):D=t[118];let Y;t[119]!==O||t[120]!==D?(Y={label:O,value:D},t[119]=O,t[120]=D,t[121]=Y):Y=t[121];let be;t[122]!==e?(be=e("contextSidebar.stats.user"),t[122]=e,t[123]=be):be=t[123];let Oe;t[124]!==L.userMessagesCount?(Oe=Di(L.userMessagesCount),t[124]=L.userMessagesCount,t[125]=Oe):Oe=t[125];let $e;t[126]!==be||t[127]!==Oe?($e={label:be,value:Oe},t[126]=be,t[127]=Oe,t[128]=$e):$e=t[128];let Re;t[129]!==e?(Re=e("contextSidebar.stats.assistant"),t[129]=e,t[130]=Re):Re=t[130];let ot;t[131]!==L.assistantMessagesCount?(ot=Di(L.assistantMessagesCount),t[131]=L.assistantMessagesCount,t[132]=ot):ot=t[132];let yt;t[133]!==Re||t[134]!==ot?(yt={label:Re,value:ot},t[133]=Re,t[134]=ot,t[135]=yt):yt=t[135];let At;t[136]!==e?(At=e("contextSidebar.stats.cost"),t[136]=e,t[137]=At):At=t[137];let mt;t[138]!==L.totalAssistantCost?(mt=Mw(L.totalAssistantCost),t[138]=L.totalAssistantCost,t[139]=mt):mt=t[139];let Le;t[140]!==At||t[141]!==mt?(Le={label:At,value:mt},t[140]=At,t[141]=mt,t[142]=Le):Le=t[142];let Qe;t[143]!==Y||t[144]!==$e||t[145]!==yt||t[146]!==Le?(Qe=[Y,$e,yt,Le],t[143]=Y,t[144]=$e,t[145]=yt,t[146]=Le,t[147]=Qe):Qe=t[147];const Ye=Qe;let rt;t[148]!==Ye?(rt=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:Ye.map(qw)}),t[148]=Ye,t[149]=rt):rt=t[149];let bt;t[150]!==e?(bt=e("contextSidebar.section.lastAssistantMessage"),t[150]=e,t[151]=bt):bt=t[151];let ct;t[152]!==bt?(ct=s.jsx("div",{className:"typography-micro text-muted-foreground",children:bt}),t[152]=bt,t[153]=ct):ct=t[153];let nt;t[154]!==e||t[155]!==L.tokenBreakdown.cacheRead||t[156]!==L.tokenBreakdown.cacheWrite||t[157]!==L.tokenBreakdown.input||t[158]!==L.tokenBreakdown.output||t[159]!==L.tokenBreakdown.reasoning?(nt=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:L.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:L.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:L.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:L.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:L.tokenBreakdown.cacheWrite}].map(Yw)}),t[154]=e,t[155]=L.tokenBreakdown.cacheRead,t[156]=L.tokenBreakdown.cacheWrite,t[157]=L.tokenBreakdown.input,t[158]=L.tokenBreakdown.output,t[159]=L.tokenBreakdown.reasoning,t[160]=nt):nt=t[160];let It;t[161]!==ct||t[162]!==nt?(It=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[ct,nt]}),t[161]=ct,t[162]=nt,t[163]=It):It=t[163];let lt;t[164]!==ue||t[165]!==L.breakdownTotal?(lt=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ue.map(at=>at.value<=0||L.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${at.value/L.breakdownTotal*100}%`,backgroundColor:at.color}},at.key))}),t[164]=ue,t[165]=L.breakdownTotal,t[166]=lt):lt=t[166];let kt;t[167]!==ue||t[168]!==L.breakdownTotal?(kt=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ue.map(at=>{const dt=L.breakdownTotal>0?at.value/L.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:at.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[at.label," ",s.jsxs("span",{className:"tabular-nums",children:[dt.toFixed(0),"%"]})]})]},at.key)})}),t[167]=ue,t[168]=L.breakdownTotal,t[169]=kt):kt=t[169];let Ke;t[170]!==lt||t[171]!==kt?(Ke=s.jsxs("div",{className:"mb-6",children:[lt,kt]}),t[170]=lt,t[171]=kt,t[172]=Ke):Ke=t[172];let tt;t[173]!==e?(tt=e("contextSidebar.section.rawMessages"),t[173]=e,t[174]=tt):tt=t[174];let We;t[175]!==tt?(We=s.jsx("div",{className:"typography-micro text-muted-foreground",children:tt}),t[175]=tt,t[176]=We):We=t[176];let gt;if(t[177]!==m||t[178]!==l||t[179]!==p||t[180]!==i||t[181]!==e||t[182]!==r){let at;t[184]!==m||t[185]!==l||t[186]!==i||t[187]!==e||t[188]!==r?(at=dt=>{const Ht=yo(dt.info).role,Rt=l[dt.info.id]===!0,Wt=m===dt.info.id,qt=dt.info.time?.created??null,Lt=Rt?JSON.stringify({info:dt.info,parts:dt.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":Rt,onClick:()=>{u(Gt=>({...Gt,[dt.info.id]:Gt[dt.info.id]!==!0}))},children:s.jsxs("div",{className:"flex items-center justify-between gap-2 whitespace-nowrap overflow-hidden",children:[s.jsxs("span",{className:"min-w-0 inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:Ow(Ht)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:dt.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:Lw(qt,r)})]})}),Rt&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:Gt=>{Gt.stopPropagation(),v(dt.info.id,Lt)},"aria-label":e(Wt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Wt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Wt?s.jsx(I,{name:"check",className:"size-3.5"}):s.jsx(I,{name:"file-copy",className:"size-3.5"})})}),s.jsx(tf,{language:"json",style:i,PreTag:"div",customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},codeTagProps:{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"break-word"}},wrapLongLines:!0,children:Lt})]})})]},dt.info.id)},t[184]=m,t[185]=l,t[186]=i,t[187]=e,t[188]=r,t[189]=at):at=t[189],gt=[...p].reverse().map(at),t[177]=m,t[178]=l,t[179]=p,t[180]=i,t[181]=e,t[182]=r,t[183]=gt}else gt=t[183];let He;t[190]!==gt?(He=s.jsx("div",{className:"mt-2.5 space-y-1",children:gt}),t[190]=gt,t[191]=He):He=t[191];let st;t[192]!==We||t[193]!==He?(st=s.jsxs("div",{children:[We,He]}),t[192]=We,t[193]=He,t[194]=st):st=t[194];let Et;return t[195]!==fe||t[196]!==se||t[197]!==rt||t[198]!==It||t[199]!==Ke||t[200]!==st?(Et=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[fe,se,rt,It,Ke,st]})}),t[195]=fe,t[196]=se,t[197]=rt,t[198]=It,t[199]=Ke,t[200]=st,t[201]=Et):Et=t[201],Et};function Vw(t){return t.timeFormatPreference}function $w(t){return t.currentSessionId}function zw(t){return t.providers}function Ww(t){return Object.keys(t).length>0?{}:t}function Uw(t){return yo(t.info).role==="assistant"}function Hw(t){return yo(t.info).isUser}function Gw(t,e){const n=ui(e.info.cost);return t+n}function Kw(t){return yo(t.info).isUser&&typeof t.info.system=="string"}function qw(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function Yw(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:Di(t.value)})]},t.label)}const Jw=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.x=="number"&&typeof e.y=="number"},Td=t=>!t||typeof t!="object"?!1:Object.values(t).every(e=>typeof e=="string"),Ei=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.text=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"&&Jw(e.center)&&Td(e.attributes)&&Td(e.computedStyle)&&Array.isArray(e.ancestry)},ic=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:o,intro:i})=>{const c=r.text.trim(),l=Object.entries(r.attributes).map(([x,p])=>`${x}="${p}"`).join(" "),u=r.computedStyle,m=r.bounds,d=r.center,f=i.replace(/[.:]+$/g,""),g=r.ancestry.map(x=>x.selectorPart).join(" > ");return[`${f}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${r.tag}`,c?`Text: ${c}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,g?`- Ancestry: ${g}`:null,l?`- Attributes: ${l}`:null,`- Bounds: x=${Math.round(m.x)}, y=${Math.round(m.y)}, width=${Math.round(m.width)}, height=${Math.round(m.height)}`,`- Center: x=${Math.round(d.x)}, y=${Math.round(d.y)}`,`Styles: display=${u.display}; position=${u.position}; font=${u.fontWeight} ${u.fontSize} / ${u.lineHeight} ${u.fontFamily}; color=${u.color}; background=${u.backgroundColor}; z-index=${u.zIndex}`].filter(x=>typeof x=="string").join(`
31
+ `)},Sm=async(t,e)=>{if(typeof window<"u")try{const n=t.getBoundingClientRect(),r=await hi("desktop_capture_page_rect",{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw new Error("Desktop screenshot capture is not available");const o=new Image;await new Promise((p,y)=>{o.onload=()=>p(),o.onerror=()=>y(new Error("Failed to load desktop preview screenshot")),o.src=`data:${r.mime};base64,${r.base64}`});const i=Math.max(1,o.naturalWidth||r.width||Math.floor(n.width)),c=Math.max(1,o.naturalHeight||r.height||Math.floor(n.height)),u=Math.min(1,1200/i),m=document.createElement("canvas");m.width=Math.floor(i*u),m.height=Math.floor(c*u);const d=m.getContext("2d");if(!d)return null;d.scale(u,u),d.drawImage(o,0,0,i,c);const f=i/Math.max(1,n.width),g=c/Math.max(1,n.height);d.fillStyle="rgba(37, 99, 235, 0.28)",d.strokeStyle="rgb(37, 99, 235)",d.lineWidth=Math.max(2,2*f),d.fillRect(e.bounds.x*f,e.bounds.y*g,e.bounds.width*f,e.bounds.height*g),d.strokeRect(e.bounds.x*f,e.bounds.y*g,e.bounds.width*f,e.bounds.height*g);const x=await new Promise(p=>m.toBlob(p,"image/jpeg",.82));return x?new File([x],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(n){return console.warn("[preview] failed to capture annotation screenshot:",n),null}return await u1(t,e)},oc=async(t,e,n,r,o,i)=>{if(!t)return null;try{const c=new Image;await new Promise((b,h)=>{c.onload=()=>b(),c.onerror=()=>h(new Error("Failed to load desktop browser screenshot")),c.src=`data:image/jpeg;base64,${t}`});const l=Math.max(1,c.naturalWidth||e),u=Math.max(1,c.naturalHeight||n),d=Math.min(1,1200/l),f=document.createElement("canvas");f.width=Math.floor(l*d),f.height=Math.floor(u*d);const g=f.getContext("2d");if(!g)return null;g.scale(d,d),g.drawImage(c,0,0,l,u);const x=l/Math.max(1,r||l),p=u/Math.max(1,o||u);g.fillStyle="rgba(37, 99, 235, 0.14)",g.strokeStyle="rgb(37, 99, 235)",g.lineWidth=Math.max(2,2*x),g.fillRect(i.bounds.x*x,i.bounds.y*p,i.bounds.width*x,i.bounds.height*p),g.strokeRect(i.bounds.x*x,i.bounds.y*p,i.bounds.width*x,i.bounds.height*p);const y=await new Promise(b=>f.toBlob(b,"image/jpeg",.82));return y?new File([y],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Ri="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",$n=new Map,Ka=new Map,Qw=3e4,ac=t=>{const e=$n.get(t);return e?e.expiresAt-Date.now()<=Qw?($n.delete(t),null):e:null},Xw=t=>{try{return new URL(t).origin}catch{return t}};function Nm(t){const e="#ffffff",n=t.defaultView??window;try{const r=t.body?n.getComputedStyle(t.body).backgroundColor:"";if(r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent")return r;const o=n.getComputedStyle(t.documentElement).backgroundColor;if(o&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent")return o}catch{}return e}const km=t=>new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(typeof r.result=="string"?r.result:Ri),r.onerror=()=>n(r.error??new Error("Failed to read image blob")),r.readAsDataURL(t)}),Zw=async(t,e=.82)=>{const n=await new Promise(r=>t.toBlob(r,"image/jpeg",e));return n&&(await km(n)).split(",",2)[1]||""},e1=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},zo=(...t)=>{e1()&&console.info("[preview-capture]",...t)},Cm=(t,e=8)=>{const n=[];try{const r=t.querySelectorAll("*");for(const o of r){const i=o.scrollTop||0,c=o.scrollLeft||0;if(i<=0&&c<=0)continue;const l=o.tagName.toLowerCase(),u=o.id?`#${o.id}`:"",m=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(n.push({selector:`${l}${u}${m}`,scrollTop:i,scrollLeft:c,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),n.length>=e)break}}catch{}return n},ao="data-oc-fixed-pin",t1=(t,e,n)=>{if(e<=0&&n<=0)return()=>{};const r=t.defaultView;if(!r)return()=>{};const o=[],i=[];try{for(const c of t.querySelectorAll("*")){if(r.getComputedStyle(c).position!=="fixed")continue;const l=c.getBoundingClientRect();if(!(l.width>0&&l.height>0))continue;c.setAttribute(ao,JSON.stringify({top:l.top+n,left:l.left+e,width:l.width,height:l.height})),o.push(c);const u=c.tagName.toLowerCase(),m=typeof c.className=="string"&&c.className?`.${c.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";i.push({selector:`${u}${m}`,top:Math.round(l.top),left:Math.round(l.left),width:Math.round(l.width),height:Math.round(l.height)})}}catch{}return zo("tagged fixed elements",i),()=>{for(const c of o)try{c.removeAttribute(ao)}catch{}}},s1={name:"oc-fixed-pin",afterClone(t){const e=t?.clone;if(!(!e||typeof e.querySelectorAll!="function"))for(const n of e.querySelectorAll(`[${ao}]`)){let r;try{r=JSON.parse(n.getAttribute(ao)||"")}catch{continue}n.style.setProperty("position","absolute","important"),n.style.setProperty("top",`${r.top}px`,"important"),n.style.setProperty("left",`${r.left}px`,"important"),n.style.setProperty("right","auto","important"),n.style.setProperty("bottom","auto","important"),n.style.setProperty("width",`${r.width}px`,"important"),n.style.setProperty("height",`${r.height}px`,"important"),n.removeAttribute(ao)}}},Ii="data-oc-scroll-pin",n1=t=>{const e=[],n=Cm(t,64);try{const i=t.documentElement,c=t.body;for(const l of t.querySelectorAll("*")){const u=l.scrollTop||0,m=l.scrollLeft||0;if(u<=0&&m<=0)continue;const d=l!==i&&l!==c;d&&l.setAttribute(Ii,JSON.stringify({top:u,left:m})),e.push({el:l,top:u,left:m,tagged:d})}}catch{}return{reapply:()=>{for(const i of e)try{i.el.scrollHeight,i.el.scrollTop!==i.top&&(i.el.scrollTop=i.top),i.el.scrollLeft!==i.left&&(i.el.scrollLeft=i.left)}catch{}},cleanup:()=>{for(const i of e)if(i.tagged)try{i.el.removeAttribute(Ii)}catch{}},snapshot:n}},r1={name:"oc-nested-scroll",afterClone(t){const e=t?.clone;if(!e||typeof e.querySelectorAll!="function")return;const n=e.ownerDocument;if(n)for(const r of e.querySelectorAll(`[${Ii}]`)){let o;try{o=JSON.parse(r.getAttribute(Ii)||"")}catch{r.removeAttribute(Ii);continue}const i=`translate(${-o.left}px, ${-o.top}px)`,c=r.children.length===1&&r.firstElementChild instanceof HTMLElement&&r.firstElementChild.style.willChange==="transform"?r.firstElementChild:null;if(c)c.style.transform=i;else{r.style.overflow="hidden";const l=n.createElement("div");for(l.style.transform=i,l.style.willChange="transform",l.style.display="inline-block",l.style.width="100%";r.firstChild;)l.appendChild(r.firstChild);r.appendChild(l)}r.removeAttribute(Ii)}}},qa=async(t,e)=>{try{const n=await fetch(t,{credentials:e});return n.ok?await km(await n.blob()):null}catch{return null}},i1=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const e=t.origin,n=ac(e);if(n)return`${n.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const r=Ka.get(e),o=r??(async()=>{try{const c=await Fs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!c.ok)return $n.delete(e),null;const l=await c.json(),u=typeof l.proxyBasePath=="string"?l.proxyBasePath:"",m=typeof l.expiresAt=="number"?l.expiresAt:0;if(!u)return $n.delete(e),null;const d={proxyBasePath:u,expiresAt:m};return $n.set(e,d),d}catch{return $n.delete(e),null}finally{Ka.delete(e)}})();r||Ka.set(e,o);const i=await o;return i?`${i.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},Am=async(t,e)=>{if(!t||t.startsWith("data:"))return t;try{const n=new URL(t,e.baseURI);if(n.origin===window.location.origin||n.protocol!=="http:"&&n.protocol!=="https:")return await qa(n.toString(),"include")??Ri;const r=await i1(n),o=r?await qa(r,"include"):null;return o||(await qa(n.toString(),"omit")??Ri)}catch{return Ri}},o1=async(t,e)=>{if(!t||t==="none"||!t.includes("url("))return t;const n=Array.from(t.matchAll(/url\((['"]?)(.*?)\1\)/g));let r=t;for(const o of n){const i=o[2]||"";if(!i||i.startsWith("data:"))continue;const c=await Am(i,e);r=r.replace(o[0],`url("${c}")`)}return r},Ed=t=>t.complete?Promise.resolve():new Promise(e=>{t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0})}),Dm=t=>{const e=t.style.cssText;return()=>{t.style.cssText=e}},a1=t=>{const e=Number.parseFloat(t.lineHeight);if(Number.isFinite(e)&&e>0)return e;const n=Number.parseFloat(t.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},l1=(t,e,n)=>{const r=[],o=t.defaultView??window,c=Array.from(t.querySelectorAll('button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *'));for(const l of c){const u=l.textContent?.replace(/\s+/g," ").trim()??"";if(!u||!u.includes(" "))continue;const m=l.getBoundingClientRect();if(m.width<=0||m.height<=0||m.right<0||m.bottom<0||m.left>e||m.top>n)continue;const d=o.getComputedStyle(l);if(d.display==="none"||d.visibility==="hidden"||Number(d.opacity)===0)continue;const f=d.getPropertyValue("text-wrap"),g=d.getPropertyValue("text-wrap-mode"),x=d.whiteSpace.includes("nowrap")||f==="nowrap"||g==="nowrap",p=m.height<=a1(d)*1.7;!x&&(!p||m.width>e*.72)||(r.push(Dm(l)),l.style.whiteSpace="nowrap",l.style.overflowWrap="normal",l.style.wordBreak="normal",l.style.setProperty("text-wrap","nowrap"),l.style.setProperty("text-wrap-mode","nowrap"))}return()=>{for(let l=r.length-1;l>=0;l-=1)r[l]?.()}},c1=(t,e,n,r)=>{const o=[],i=t.defaultView??window,c=i.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,l=i.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,u=Array.from(t.querySelectorAll("*")).filter(m=>{const d=i.getComputedStyle(m);if(d.position!=="fixed"||d.display==="none"||d.visibility==="hidden"||Number(d.opacity)===0)return!1;const f=m.getBoundingClientRect();return f.width>0&&f.height>0&&f.right>=0&&f.bottom>=0&&f.left<=e&&f.top<=n}).filter((m,d,f)=>!f.some((g,x)=>x<d&&g.contains(m)));for(const m of u){const d=m.getBoundingClientRect(),f=i.getComputedStyle(m),g=Math.ceil(d.width)+8,x=Math.ceil(d.height)+2;r?.add(m),o.push(Dm(m)),m.style.position="absolute",m.style.top=`${d.top+l}px`,m.style.left=`${d.left+c}px`,m.style.right="auto",m.style.bottom="auto",m.style.width=`${g}px`,m.style.minWidth=`${g}px`,m.style.height=`${x}px`,m.style.minHeight=`${x}px`,m.style.margin="0",m.style.boxSizing="border-box",m.style.transform="none",f.zIndex!=="auto"&&(m.style.zIndex=f.zIndex)}return()=>{for(let m=o.length-1;m>=0;m-=1)o[m]?.()}},Im=async(t,e,n,r={})=>{const o=[],i=t.defaultView??window,c=f=>{if(f===t.documentElement||f===t.body)return!0;try{const g=f.getBoundingClientRect();return g.width>0&&g.height>0&&g.right>=0&&g.bottom>=0&&g.left<=e&&g.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){const f=new WeakSet;o.push(c1(t,e,n,f)),o.push(l1(t,e,n))}const l=new Map;for(const f of Array.from(t.images))l.set(f,f.currentSrc||f.src||f.getAttribute("src")||"");const u=Array.from(t.querySelectorAll("picture"));for(const f of u){const g=Array.from(f.querySelectorAll("source"));if(g.length===0)continue;const x=g.map(p=>({source:p,srcset:p.getAttribute("srcset"),sizes:p.getAttribute("sizes")}));o.push(()=>{for(const p of x)p.srcset===null?p.source.removeAttribute("srcset"):p.source.setAttribute("srcset",p.srcset),p.sizes===null?p.source.removeAttribute("sizes"):p.source.setAttribute("sizes",p.sizes)});for(const p of g)p.removeAttribute("srcset"),p.removeAttribute("sizes")}const m=Array.from(t.images).filter(f=>c(f));await Promise.all(m.map(async f=>{const g=l.get(f)||f.currentSrc||f.src||f.getAttribute("src")||"";if(!g)return;await Ed(f);const x=await Am(g,t),p={src:f.getAttribute("src"),srcset:f.getAttribute("srcset"),sizes:f.getAttribute("sizes")};o.push(()=>{p.src===null?f.removeAttribute("src"):f.setAttribute("src",p.src),p.srcset===null?f.removeAttribute("srcset"):f.setAttribute("srcset",p.srcset),p.sizes===null?f.removeAttribute("sizes"):f.setAttribute("sizes",p.sizes)}),f.removeAttribute("srcset"),f.removeAttribute("sizes"),f.setAttribute("src",x||Ri),await Ed(f)}));const d=Array.from(t.querySelectorAll("*")).filter(c);return await Promise.all(d.map(async f=>{const g=i.getComputedStyle(f).backgroundImage;if(!g||g==="none"||!g.includes("url("))return;const x=await o1(g,t);if(x===g)return;const p=f.style.backgroundImage;o.push(()=>{f.style.backgroundImage=p}),f.style.backgroundImage=x})),()=>{for(let f=o.length-1;f>=0;f-=1)try{o[f]?.()}catch{}}};async function d1(t,e){try{const n=t.contentWindow,r=t.contentDocument??n?.document,o=r?.documentElement;if(!n||!r||!o)return null;const i=t.getBoundingClientRect(),c=Math.max(1,Math.ceil(n.innerWidth||t.clientWidth||i.width)),l=Math.max(1,Math.ceil(n.innerHeight||t.clientHeight||i.height)),u=r.body,m=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,d=n.scrollX||0,f=n.scrollY||0,g=n.pageXOffset||0,x=n.pageYOffset||0,p=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,y=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,b=o.scrollLeft||0,h=o.scrollTop||0,N=u?.scrollLeft||0,w=u?.scrollTop||0,S=m?.scrollLeft||0,v=m?.scrollTop||0,j=Math.max(d,g,p,b,N,S),k=Math.max(f,x,y,h,w,v);zo("scroll sources",{windowScrollX:d,windowScrollY:f,pageScrollX:g,pageScrollY:x,visualViewportScrollX:p,visualViewportScrollY:y,rootScrollX:b,rootScrollY:h,bodyScrollX:N,bodyScrollY:w,scrollingElementScrollX:S,scrollingElementScrollY:v,scrollingElementTag:m?.tagName?.toLowerCase()??null,resolvedScrollX:j,resolvedScrollY:k,nestedScrolledElements:Cm(r)});const A=Math.max(c,o.scrollWidth||0,u?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),T=Math.max(l,o.scrollHeight||0,u?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),C=Math.min(2,Math.max(1,window.devicePixelRatio||1)),P=o.style.scrollBehavior,E=u?.style.scrollBehavior??"";o.style.scrollBehavior="auto",u&&(u.style.scrollBehavior="auto");const M=n1(r);zo("nested scroll snapshot",M.snapshot);let H=()=>{},R=()=>{};try{await r.fonts?.ready.catch(()=>{}),H=await Im(r,c,l,{applyLayoutWorkarounds:!1}),n.scrollTo(j,k),R=t1(r,j,k),M.reapply();const _={backgroundColor:Nm(r),cache:"disabled",dpr:C,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[s1,r1],quality:.82,width:A},V=await(await rf(o,_)).toCanvas();if(!V.width||!V.height)return null;const F=V.width/Math.max(1,A),te=V.height/Math.max(1,T),Z=Math.min(V.width,Math.max(1,Math.round(c*F))),ne=Math.min(V.height,Math.max(1,Math.round(l*te))),U=Math.max(0,V.width-Z),ie=Math.max(0,V.height-ne),oe=Math.min(U,Math.max(0,Math.round(j*F))),pe=Math.min(ie,Math.max(0,Math.round(k*te)));zo("capture geometry",{viewportWidth:c,viewportHeight:l,captureWidth:A,captureHeight:T,canvasWidth:V.width,canvasHeight:V.height,xScale:F,yScale:te,sourceX:oe,sourceY:pe,sourceWidth:Z,sourceHeight:ne});const je=r.createElement("canvas");je.width=Z,je.height=ne;const Se=je.getContext("2d");if(!Se)return null;Se.drawImage(V,oe,pe,Z,ne,0,0,Z,ne);const re=await Zw(je,.82);return re?await oc(re,c,l,c,l,e):null}finally{R(),M.cleanup(),H(),n.scrollTo(j,k),M.reapply(),o.style.scrollBehavior=P,u&&(u.style.scrollBehavior=E)}}catch(n){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",n),null}}async function u1(t,e){const n=await d1(t,e);if(n)return n;try{const r=t.contentWindow,o=t.contentDocument??r?.document,i=o?.documentElement;if(!r||!o||!i)return null;const c=t.getBoundingClientRect(),l=Math.max(1,Math.ceil(r.innerWidth||t.clientWidth||c.width)),u=Math.max(1,Math.ceil(r.innerHeight||t.clientHeight||c.height)),m=r.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,d=r.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,f=o.body,g=Math.max(u,i.scrollHeight||0,f?.scrollHeight||0),x=Math.min(2,Math.max(1,window.devicePixelRatio||1)),p=i.style.scrollBehavior,y=f?.style.scrollBehavior??"";i.style.scrollBehavior="auto",f&&(f.style.scrollBehavior="auto");let b="",h=()=>{};try{await o.fonts?.ready.catch(()=>{}),h=await Im(o,l,u,{applyLayoutWorkarounds:!0}),r.scrollTo(m,d);const w=await sf(i).catch(()=>"");b=await nf(i,{quality:.82,pixelRatio:x,width:l,height:u,backgroundColor:Nm(o),imagePlaceholder:Ri,fontEmbedCSS:w||void 0,style:{transform:`translate(${-m}px, ${-d}px)`,transformOrigin:"top left",minWidth:`${l}px`,minHeight:`${g}px`},cacheBust:!0})}finally{h(),r.scrollTo(m,d),i.style.scrollBehavior=p,f&&(f.style.scrollBehavior=y)}const N=b.split(",",2)[1]||"";return N?await oc(N,l,u,l,u,e):null}catch(r){return console.warn("[preview] failed to capture iframe DOM screenshot:",r),null}}const Pm=380,m1=1400,Tm=600,f1=24,Rd=200,h1=(t,e)=>e==="all"?!0:e==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":e==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",p1=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Em=t=>Number.isFinite(t)?Math.min(m1,Math.max(Pm,Math.round(t))):Tm,g1=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},Ya=(t,e)=>{const n=Em(t),r=g1(e);return r===null?n:Math.min(n,Math.max(1,r))},x1=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},b1=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":"contextPanel.mode.context"),y1=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},w1=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return y1(t.targetPath)||e("contextPanel.mode.files");if(t.mode==="preview"){const n=t.targetPath;if(n)try{const r=new URL(n);return r.host||r.hostname||e("contextPanel.mode.preview")}catch{}return e("contextPanel.mode.preview")}return t.mode==="diff"?t.stagedDiff?e("contextPanel.mode.stagedDiff"):e("contextPanel.mode.workingDiff"):b1(t.mode,e)},v1=t=>{if(t.mode==="file")return t.targetPath?s.jsx(xr,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(I,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(I,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(I,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(I,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5"})},j1=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,Rm=`new Promise((resolve) => {
32
32
  const existing = document.getElementById('__openchamber_desktop_browser_overlay');
33
33
  if (existing) existing.remove();
34
34
  if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
@@ -119,7 +119,7 @@ ${JSON.stringify({directory:i,operation:w.operation,headInfo:w.headInfo,statusPo
119
119
  }
120
120
  const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
121
121
  if (overlay) overlay.remove();
122
- })()`,w1=`(() => {
122
+ })()`,S1=`(() => {
123
123
  if (window.__openchamberSameWebviewNavigationInstalled) return;
124
124
  window.__openchamberSameWebviewNavigationInstalled = true;
125
125
 
@@ -151,43 +151,43 @@ ${JSON.stringify({directory:i,operation:w.operation,headInfo:w.headInfo,statusPo
151
151
  event.preventDefault();
152
152
  event.stopPropagation();
153
153
  }, true);
154
- })()`,co=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},Td=async(t,e)=>{const n=t.contentWindow;if(!n)throw new Error("Iframe window is not available");const o=n.eval.call(n,e);return await Promise.resolve(o)},v1=(t,e,n)=>{if(typeof window>"u")return"";const r=new URL(window.location.pathname,window.location.origin);return r.searchParams.set("ocPanel","session-chat"),r.searchParams.set("sessionId",t),n?r.searchParams.set("readOnly","1"):r.searchParams.delete("readOnly"),e&&e.trim().length>0?r.searchParams.set("directory",e):r.searchParams.delete("directory"),r.hash="",r.toString()},j1=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Tm=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},Ed=(t,e,n)=>{const r=Tm(e);t.postMessage(n,r)},S1=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},N1=({rawUrl:t,onNavigate:e})=>{const{t:n}=Tt(),{currentTheme:r}=Tr(),[o,i]=a.useReducer(ue=>ue+1,0),[c,l]=a.useReducer(ue=>ue+1,0),[u,m]=a.useState({status:"idle"}),[d,f]=a.useState(""),g=a.useRef(null),x=a.useRef(1),[p,y]=a.useState(!1),[b,h]=a.useState(!1),[N,w]=a.useState("all"),[S,v]=a.useState([]),[j,k]=a.useState(!1),[D,T]=a.useState(null),C=vt(ue=>ue.currentSessionId),P=vt(ue=>ue.newSessionDraft?.open),E=Kl(ue=>ue.addDraft),M=ei(ue=>ue.addAttachedFile);let H=null;try{H=t?new URL(t):null}catch{H=null}const R=H?H.hostname==="localhost"||H.hostname==="127.0.0.1"||H.hostname==="::1"||H.hostname==="[::1]"||H.hostname==="0.0.0.0":!1,_=H?H.hostname==="0.0.0.0"?new URL(H.toString().replace("0.0.0.0","127.0.0.1")):H:null,z=_?_.toString():"",V=z?`${Qr()||"same-origin"}|${z}`:"",F=r.metadata.variant;a.useEffect(()=>{if(!z||!R){m({status:"idle"});return}const ue=oc(V);if(ue?.previewToken){m({status:"ready",proxyBasePath:ue.proxyBasePath,previewToken:ue.previewToken,expiresAt:ue.expiresAt});return}ue&&_n.delete(V);let ve=!1;return m({status:"loading"}),(async()=>{try{const G=await Rs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:z})});if(!G.ok){_n.delete(V);const me=await G.json().catch(()=>({})),B=typeof me?.error=="string"?me.error:`HTTP ${G.status}`;ve||m({status:"error",message:B});return}const Ae=await G.json(),ce=typeof Ae.proxyBasePath=="string"?Ae.proxyBasePath:"",fe=typeof Ae.previewToken=="string"?Ae.previewToken:"",Ee=typeof Ae.expiresAt=="number"?Ae.expiresAt:0;if(!ce||!fe){_n.delete(V),ve||m({status:"error",message:n("contextPanel.preview.proxyError")});return}_n.set(V,{proxyBasePath:ce,previewToken:fe,expiresAt:Ee}),ve||m({status:"ready",proxyBasePath:ce,previewToken:fe,expiresAt:Ee})}catch(G){if(_n.delete(V),!ve){const Ae=G instanceof Error?G.message:String(G);m({status:"error",message:Ae})}}})(),()=>{ve=!0}},[R,V,c,n,z]);const te=_&&(_.protocol==="http:"||_.protocol==="https:")?_.toString():"",Z=R&&u.status==="ready"?`${u.proxyBasePath}|${u.previewToken||""}|${o}`:"";a.useEffect(()=>{if(!Z){f("");return}let ue=!1;return f(""),Fl(Qr()).then(ve=>{!ue&&ve&&f(Z)}).catch(()=>{}),()=>{ue=!0}},[Z]);const ne=R&&u.status==="ready"&&_&&d===Z?(()=>{const ue=_.pathname||"/",ve=new URLSearchParams(_.search);ve.set("ocPreview",String(o)),ve.set("oc_preview_token",u.previewToken||"");const G=ve.toString(),Ae=_.hash||"";return Oi().authenticatedAsset(`${u.proxyBasePath}${ue}${G?`?${G}`:""}${Ae}`)})():"",U=R?ne:te,ie=R?S1(ne):te,oe=R&&(u.status==="loading"||u.status==="idle"||d!==Z),ge=R&&u.status==="error",je=a.useCallback(ue=>{const ve=C??(P?"draft":null);if(!ve){ae.error(n("contextPanel.preview.inspect.attachNoSession"));return}const G=t||U||"",Ae=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},ce=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let fe=!1;try{const Ee=g.current,me=Ee?await wm(Ee,ue):null;me&&(await M(me),fe=!0)}catch{fe=!1}E({sessionKey:ve,source:"preview-annotation",fileLabel:G||"preview",startLine:1,endLine:1,code:rc({pageUrl:G,viewport:Ae,devicePixelRatio:ce,target:ue,screenshotAttached:fe,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),ae.success(n("contextPanel.preview.inspect.attached"))})()},[M,E,C,U,P,t,n]);a.useEffect(()=>{y(!1),v([]),h(!1),w("all"),k(!1),T(null),x.current=1},[U]),a.useEffect(()=>{const ue=g.current?.contentWindow;!p||!ue||Ed(ue,ne,{source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:j})},[p,j,ne]),a.useEffect(()=>{const ue=g.current?.contentWindow;!p||!ue||Ed(ue,ne,{source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:F})},[p,F,ne]),a.useEffect(()=>{if(!j||typeof window>"u")return;const ue=ve=>{ve.key==="Escape"&&(ve.preventDefault(),ve.stopImmediatePropagation(),k(!1))};return window.addEventListener("keydown",ue,!0),()=>window.removeEventListener("keydown",ue,!0)},[j]),a.useEffect(()=>{if(!R||typeof window>"u")return;const ue=Ae=>{if(typeof Ae=="string")return Ae;if(Ae==null)return"";try{return JSON.stringify(Ae)}catch{return String(Ae)}},ve=Ae=>{const ce=x.current;x.current+=1,v(fe=>{const Ee=[...fe,{...Ae,id:ce}];return Ee.length>Pd?Ee.slice(Ee.length-Pd):Ee})},G=Ae=>{if(Ae.source!==g.current?.contentWindow)return;const ce=Ae.data;if(!(!ce||ce.source!=="openchamber-preview-bridge"||ce.version!==1)){if(ce.type==="ready"){y(!0);return}if(ce.type==="console"){const fe=ce.level==="error"||ce.level==="warn"||ce.level==="info"||ce.level==="debug"?ce.level:"log",Ee=Array.isArray(ce.args)?ce.args.map(ue).filter(Boolean):[];ve({level:fe,message:Ee.join(" "),ts:typeof ce.ts=="number"?ce.ts:Date.now()});return}if(ce.type==="runtime-error"){const fe=ue(ce.filename),Ee=typeof ce.line=="number"?ce.line:null,me=typeof ce.column=="number"?ce.column:null,B=fe?`${fe}${Ee!==null?`:${Ee}${me!==null?`:${me}`:""}`:""}`:"",ye=ue(ce.stack);ve({level:"runtime",message:ue(ce.message)||n("contextPanel.preview.console.runtimeError"),details:[B,ye].filter(Boolean).join(`
155
- `),ts:typeof ce.ts=="number"?ce.ts:Date.now()});return}if(ce.type==="resource-error"){const fe=ue(ce.tag)||"resource",Ee=ue(ce.url);ve({level:"resource",message:Ee?`${fe}: ${Ee}`:fe,details:ue(ce.outerHTML),ts:typeof ce.ts=="number"?ce.ts:Date.now()});return}if(ce.type==="hover"){T(Ri(ce.target)?ce.target:null);return}if(ce.type==="select"&&Ri(ce.target)){T(ce.target),k(!1),je(ce.target);return}if(ce.type==="navigate-preview"){const fe=typeof ce.url=="string"?ce.url:"",Ee=ce.navigation==="external"?"external":"proxy";if(fe&&Ee==="external"){xi(fe);return}fe&&e(fe)}}};return window.addEventListener("message",G),()=>{window.removeEventListener("message",G)}},[je,R,e,n]);const Se=S.filter(ue=>ue.level==="error"||ue.level==="runtime"||ue.level==="resource").length,re=S.filter(ue=>u1(ue,N)),L=a.useCallback(()=>{const ue=[`Preview URL: ${t||U||""}`,`Events: ${S.length}`,""].join(`
154
+ })()`,lo=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},Md=async(t,e)=>{const n=t.contentWindow;if(!n)throw new Error("Iframe window is not available");const o=n.eval.call(n,e);return await Promise.resolve(o)},N1=(t,e,n)=>{if(typeof window>"u")return"";const r=new URL(window.location.pathname,window.location.origin);return r.searchParams.set("ocPanel","session-chat"),r.searchParams.set("sessionId",t),n?r.searchParams.set("readOnly","1"):r.searchParams.delete("readOnly"),e&&e.trim().length>0?r.searchParams.set("directory",e):r.searchParams.delete("directory"),r.hash="",r.toString()},k1=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Mm=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},Fd=(t,e,n)=>{const r=Mm(e);t.postMessage(n,r)},C1=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},A1=({rawUrl:t,onNavigate:e})=>{const{t:n}=Tt(),{currentTheme:r}=Tr(),[o,i]=a.useReducer(ue=>ue+1,0),[c,l]=a.useReducer(ue=>ue+1,0),[u,m]=a.useState({status:"idle"}),[d,f]=a.useState(""),g=a.useRef(null),x=a.useRef(1),[p,y]=a.useState(!1),[b,h]=a.useState(!1),[N,w]=a.useState("all"),[S,v]=a.useState([]),[j,k]=a.useState(!1),[A,T]=a.useState(null),C=jt(ue=>ue.currentSessionId),P=jt(ue=>ue.newSessionDraft?.open),E=ql(ue=>ue.addDraft),M=ti(ue=>ue.addAttachedFile);let H=null;try{H=t?new URL(t):null}catch{H=null}const R=H?H.hostname==="localhost"||H.hostname==="127.0.0.1"||H.hostname==="::1"||H.hostname==="[::1]"||H.hostname==="0.0.0.0":!1,_=H?H.hostname==="0.0.0.0"?new URL(H.toString().replace("0.0.0.0","127.0.0.1")):H:null,z=_?_.toString():"",V=z?`${Xr()||"same-origin"}|${z}`:"",F=r.metadata.variant;a.useEffect(()=>{if(!z||!R){m({status:"idle"});return}const ue=ac(V);if(ue?.previewToken){m({status:"ready",proxyBasePath:ue.proxyBasePath,previewToken:ue.previewToken,expiresAt:ue.expiresAt});return}ue&&$n.delete(V);let ve=!1;return m({status:"loading"}),(async()=>{try{const G=await Fs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:z})});if(!G.ok){$n.delete(V);const me=await G.json().catch(()=>({})),B=typeof me?.error=="string"?me.error:`HTTP ${G.status}`;ve||m({status:"error",message:B});return}const Ae=await G.json(),ce=typeof Ae.proxyBasePath=="string"?Ae.proxyBasePath:"",fe=typeof Ae.previewToken=="string"?Ae.previewToken:"",Te=typeof Ae.expiresAt=="number"?Ae.expiresAt:0;if(!ce||!fe){$n.delete(V),ve||m({status:"error",message:n("contextPanel.preview.proxyError")});return}$n.set(V,{proxyBasePath:ce,previewToken:fe,expiresAt:Te}),ve||m({status:"ready",proxyBasePath:ce,previewToken:fe,expiresAt:Te})}catch(G){if($n.delete(V),!ve){const Ae=G instanceof Error?G.message:String(G);m({status:"error",message:Ae})}}})(),()=>{ve=!0}},[R,V,c,n,z]);const te=_&&(_.protocol==="http:"||_.protocol==="https:")?_.toString():"",Z=R&&u.status==="ready"?`${u.proxyBasePath}|${u.previewToken||""}|${o}`:"";a.useEffect(()=>{if(!Z){f("");return}let ue=!1;return f(""),Ll(Xr()).then(ve=>{!ue&&ve&&f(Z)}).catch(()=>{}),()=>{ue=!0}},[Z]);const ne=R&&u.status==="ready"&&_&&d===Z?(()=>{const ue=_.pathname||"/",ve=new URLSearchParams(_.search);ve.set("ocPreview",String(o)),ve.set("oc_preview_token",u.previewToken||"");const G=ve.toString(),Ae=_.hash||"";return Li().authenticatedAsset(`${u.proxyBasePath}${ue}${G?`?${G}`:""}${Ae}`)})():"",U=R?ne:te,ie=R?C1(ne):te,oe=R&&(u.status==="loading"||u.status==="idle"||d!==Z),pe=R&&u.status==="error",je=a.useCallback(ue=>{const ve=C??(P?"draft":null);if(!ve){ae.error(n("contextPanel.preview.inspect.attachNoSession"));return}const G=t||U||"",Ae=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},ce=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let fe=!1;try{const Te=g.current,me=Te?await Sm(Te,ue):null;me&&(await M(me),fe=!0)}catch{fe=!1}E({sessionKey:ve,source:"preview-annotation",fileLabel:G||"preview",startLine:1,endLine:1,code:ic({pageUrl:G,viewport:Ae,devicePixelRatio:ce,target:ue,screenshotAttached:fe,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),ae.success(n("contextPanel.preview.inspect.attached"))})()},[M,E,C,U,P,t,n]);a.useEffect(()=>{y(!1),v([]),h(!1),w("all"),k(!1),T(null),x.current=1},[U]),a.useEffect(()=>{const ue=g.current?.contentWindow;!p||!ue||Fd(ue,ne,{source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:j})},[p,j,ne]),a.useEffect(()=>{const ue=g.current?.contentWindow;!p||!ue||Fd(ue,ne,{source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:F})},[p,F,ne]),a.useEffect(()=>{if(!j||typeof window>"u")return;const ue=ve=>{ve.key==="Escape"&&(ve.preventDefault(),ve.stopImmediatePropagation(),k(!1))};return window.addEventListener("keydown",ue,!0),()=>window.removeEventListener("keydown",ue,!0)},[j]),a.useEffect(()=>{if(!R||typeof window>"u")return;const ue=Ae=>{if(typeof Ae=="string")return Ae;if(Ae==null)return"";try{return JSON.stringify(Ae)}catch{return String(Ae)}},ve=Ae=>{const ce=x.current;x.current+=1,v(fe=>{const Te=[...fe,{...Ae,id:ce}];return Te.length>Rd?Te.slice(Te.length-Rd):Te})},G=Ae=>{if(Ae.source!==g.current?.contentWindow)return;const ce=Ae.data;if(!(!ce||ce.source!=="openchamber-preview-bridge"||ce.version!==1)){if(ce.type==="ready"){y(!0);return}if(ce.type==="console"){const fe=ce.level==="error"||ce.level==="warn"||ce.level==="info"||ce.level==="debug"?ce.level:"log",Te=Array.isArray(ce.args)?ce.args.map(ue).filter(Boolean):[];ve({level:fe,message:Te.join(" "),ts:typeof ce.ts=="number"?ce.ts:Date.now()});return}if(ce.type==="runtime-error"){const fe=ue(ce.filename),Te=typeof ce.line=="number"?ce.line:null,me=typeof ce.column=="number"?ce.column:null,B=fe?`${fe}${Te!==null?`:${Te}${me!==null?`:${me}`:""}`:""}`:"",ye=ue(ce.stack);ve({level:"runtime",message:ue(ce.message)||n("contextPanel.preview.console.runtimeError"),details:[B,ye].filter(Boolean).join(`
155
+ `),ts:typeof ce.ts=="number"?ce.ts:Date.now()});return}if(ce.type==="resource-error"){const fe=ue(ce.tag)||"resource",Te=ue(ce.url);ve({level:"resource",message:Te?`${fe}: ${Te}`:fe,details:ue(ce.outerHTML),ts:typeof ce.ts=="number"?ce.ts:Date.now()});return}if(ce.type==="hover"){T(Ei(ce.target)?ce.target:null);return}if(ce.type==="select"&&Ei(ce.target)){T(ce.target),k(!1),je(ce.target);return}if(ce.type==="navigate-preview"){const fe=typeof ce.url=="string"?ce.url:"",Te=ce.navigation==="external"?"external":"proxy";if(fe&&Te==="external"){wi(fe);return}fe&&e(fe)}}};return window.addEventListener("message",G),()=>{window.removeEventListener("message",G)}},[je,R,e,n]);const Se=S.filter(ue=>ue.level==="error"||ue.level==="runtime"||ue.level==="resource").length,re=S.filter(ue=>h1(ue,N)),L=a.useCallback(()=>{const ue=[`Preview URL: ${t||U||""}`,`Events: ${S.length}`,""].join(`
156
156
  `),ve=S.map(G=>{const Ae=new Date(G.ts).toISOString(),ce=G.details?`
157
157
  ${G.details}`:"";return`[${Ae}] [${G.level}] ${G.message}${ce}`}).join(`
158
- `);cr(`${ue}${ve}`).then(G=>{G.ok?ae.success(n("contextPanel.preview.console.copied")):ae.error(n("contextPanel.preview.console.copyFailed"))})},[S,U,t,n]),$=a.useCallback(()=>{const ue=C??(P?"draft":null);if(!ue){ae.error(n("contextPanel.preview.console.attachNoSession"));return}const ve=[`Preview URL: ${t||U||""}`,`Events: ${S.length}`,""].join(`
158
+ `);ar(`${ue}${ve}`).then(G=>{G.ok?ae.success(n("contextPanel.preview.console.copied")):ae.error(n("contextPanel.preview.console.copyFailed"))})},[S,U,t,n]),$=a.useCallback(()=>{const ue=C??(P?"draft":null);if(!ue){ae.error(n("contextPanel.preview.console.attachNoSession"));return}const ve=[`Preview URL: ${t||U||""}`,`Events: ${S.length}`,""].join(`
159
159
  `),G=S.map(Ae=>{const ce=new Date(Ae.ts).toISOString(),fe=Ae.details?`
160
160
  ${Ae.details}`:"";return`[${ce}] [${Ae.level}] ${Ae.message}${fe}`}).join(`
161
- `);E({sessionKey:ue,source:"preview-console",fileLabel:t||U||"preview",startLine:1,endLine:Math.max(1,S.length),code:`${ve}${G}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),ae.success(n("contextPanel.preview.console.attached"))},[E,S,C,U,P,t,n]),[q,he]=a.useState("unknown"),de=a.useRef(0),we=a.useRef(0),be=15e3;a.useEffect(()=>{if(!ne){he("unknown"),de.current=0,we.current=0;return}let ue=!1;return de.current||(de.current=Date.now(),we.current=0),he("unknown"),(async()=>{const G=await(async()=>{try{return await Rs(ne,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(ue)return;if(!G){he("unreachable");return}if(G.status===403||G.status===404){_n.delete(V),m({status:"loading"}),l();return}if(G.status!==502){he("reachable");return}const Ae=de.current||Date.now();if(Date.now()-Ae<be){he("starting"),we.current+=1;const fe=we.current,Ee=Math.min(2e3,250*Math.pow(2,Math.min(4,fe)));setTimeout(()=>{ue||i()},Ee).unref?.();return}he("unreachable")})(),()=>{ue=!0}},[V,ne,o]);const De=R&&u.status==="ready"&&(q==="unknown"||q==="starting"),le=R&&u.status==="ready"&&q==="unreachable",ke=a.useCallback(ue=>{if(!R||u.status!=="ready"||typeof window>"u")return;const ve=ue.currentTarget.contentWindow;if(ve)try{const G=ve.location,Ae=Tm(ne);if(G.origin!==Ae||G.pathname.startsWith(u.proxyBasePath))return;const ce=`${u.proxyBasePath}${G.pathname}${G.search}${G.hash}`;ve.location.replace(ce)}catch{}},[R,ne,u]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:ie||t,children:ie||t||n("contextPanel.preview.empty")}),s.jsx(ze,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!U,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{te&&xi(te)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!te,children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})}),R?s.jsx(ze,{type:"button",size:"sm",variant:j?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>k(ue=>!ue),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!p,children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}):null,R?s.jsxs(ze,{type:"button",size:"sm",variant:b?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>h(ue=>!ue),title:n(p?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(p?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!p&&S.length===0,children:[s.jsx(I,{name:"terminal-box",className:"h-3.5 w-3.5"}),Se>0?s.jsx("span",{className:"typography-micro text-status-error",children:Se}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[De?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):le?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(ze,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):U&&(!R||q==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:g,src:U,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:F},onLoad:ke,sandbox:R?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${U}:${o}`),j&&D?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:D.bounds.x,top:D.bounds.y,width:D.bounds.width,height:D.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[D.tag,D.text?` · ${D.text}`:""]})}):null]}):oe?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):ge?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),u.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:u.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),b?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:$,disabled:S.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:L,disabled:S.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:()=>v([]),disabled:S.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(ue=>s.jsx(ze,{type:"button",size:"xs",variant:N===ue?"secondary":"ghost",onClick:()=>w(ue),children:n(ue==="all"?"contextPanel.preview.console.filter.all":ue==="errors"?"contextPanel.preview.console.filter.errors":ue==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},ue))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:S.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):re.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):re.map(ue=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:Te("shrink-0 uppercase",ue.level==="error"||ue.level==="runtime"||ue.level==="resource"?"text-status-error":ue.level==="warn"?"text-status-warning":"text-muted-foreground"),children:ue.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:ue.message})]})},ue.id))})]}):null]})]})},k1=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,C1=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=Tt(),o=a.useRef(null),i=Fe(L=>L.setContextPanelTabTargetPath),c=co(t),l=c!=="about:blank"?c:"",[u,m]=a.useState(l),[d,f]=a.useState(l),[g,x]=a.useState(()=>l?[l]:[]),[p,y]=a.useState(()=>l?0:-1),[b,h]=a.useReducer(L=>L+1,0),[N,w]=a.useState(!!l),[S,v]=a.useState(!1),[j,k]=a.useState(null),[D,T]=a.useState({status:"idle"}),[C,P]=a.useState(""),E=vt(L=>L.currentSessionId),M=vt(L=>L.newSessionDraft?.open),H=Kl(L=>L.addDraft),R=ei(L=>L.addAttachedFile),_=a.useCallback(L=>{!L||L==="about:blank"||!e||!n||i(e,n,L)},[e,n,i]),z=a.useCallback((L,$)=>{const q=co(L),he=q!=="about:blank"?q:"";f(he),m(he),w(!!he),_(he),x(de=>{if(!he)return y(-1),[];if($?.replaceHistory)return de;const we=p>=0?de.slice(0,p+1):[];if(we[we.length-1]===he)return y(we.length-1),we;const De=[...we,he];return y(De.length-1),De})},[p,_]),V=a.useCallback(L=>{const $=g[L];$&&(y(L),f($),m($),w(!0),_($))},[g,_]),F=a.useCallback(()=>{if(d){w(!0);try{o.current?.contentWindow?.location.reload()}catch{h()}}},[d]);a.useEffect(()=>{if(!d){T({status:"idle"});return}const L=Yw(d),$=oc(L);if($?.previewToken){T({status:"ready",proxyBasePath:$.proxyBasePath,previewToken:$.previewToken,expiresAt:$.expiresAt});return}$&&_n.delete(L);let q=!1;return T({status:"loading"}),w(!0),(async()=>{try{const he=await Rs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:d,allowExternal:!0})});if(!he.ok){const le=await he.json().catch(()=>({})),ke=typeof le?.error=="string"?le.error:`HTTP ${he.status}`;q||T({status:"error",message:ke});return}const de=await he.json(),we=typeof de.proxyBasePath=="string"?de.proxyBasePath:"",be=typeof de.previewToken=="string"?de.previewToken:"",De=typeof de.expiresAt=="number"?de.expiresAt:0;if(!we||!be){q||T({status:"error",message:r("contextPanel.preview.proxyError")});return}_n.set(L,{proxyBasePath:we,previewToken:be,expiresAt:De}),q||T({status:"ready",proxyBasePath:we,previewToken:be,expiresAt:De})}catch(he){if(!q){const de=he instanceof Error?he.message:String(he);T({status:"error",message:de})}}})(),()=>{q=!0}},[d,r]);const te=d&&D.status==="ready"?`${D.proxyBasePath}|${D.previewToken||""}|${b}`:"";a.useEffect(()=>{if(!te){P("");return}let L=!1;return P(""),Fl(Qr()).then($=>{!L&&$&&P(te)}).catch(()=>{}),()=>{L=!0}},[te]);const Z=a.useMemo(()=>{if(C!==te||!d||D.status!=="ready")return"";try{const L=new URL(d),$=L.pathname||"/",q=new URLSearchParams(L.search);q.set("ocPreview",String(b)),q.set("oc_preview_token",D.previewToken||"");const he=q.toString();return Oi().authenticatedAsset(`${D.proxyBasePath}${$}${he?`?${he}`:""}${L.hash}`)}catch{return""}},[d,D,te,b,C]),ne=Z||(D.status==="error"?d:""),U=a.useCallback(L=>{if(!L||!d||D.status!=="ready")return"";try{const $=new URL(L,window.location.origin),q=D.proxyBasePath.endsWith("/")?D.proxyBasePath.slice(0,-1):D.proxyBasePath;if($.origin!==window.location.origin||!$.pathname.startsWith(q))return"";const he=$.pathname.slice(q.length)||"/",de=new URL(d).origin;return new URL(`${he}${$.search}${$.hash}`,de).toString()}catch{return""}},[d,D]),ie=a.useCallback(L=>{if(!L||!d||D.status!=="ready")return"";try{const $=new URL(L,window.location.origin),q=new URL(d).origin;if($.origin!==window.location.origin||q===window.location.origin)return"";const he=D.proxyBasePath.endsWith("/")?D.proxyBasePath.slice(0,-1):D.proxyBasePath;return $.pathname.startsWith(he)?"":new URL(`${$.pathname}${$.search}${$.hash}`,q).toString()}catch{return""}},[d,D]),oe=a.useCallback(L=>{const $=o.current?.contentWindow;$&&$.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:L},window.location.origin)},[]),ge=a.useCallback(async L=>{const $=E??(M?"draft":null);if(!$){ae.error(r("contextPanel.preview.inspect.attachNoSession"));return}const q=o.current,he=q?.contentWindow,de=q?.getBoundingClientRect(),we={width:Number.isFinite(he?.innerWidth)?he?.innerWidth??de?.width??0:de?.width??0,height:Number.isFinite(he?.innerHeight)?he?.innerHeight??de?.height??0:de?.height??0},be=q?await wm(q,L):null,De=!!be;be&&await R(be),H({sessionKey:$,source:"preview-annotation",fileLabel:d||"browser",startLine:1,endLine:1,code:rc({pageUrl:d,viewport:we,devicePixelRatio:window.devicePixelRatio||1,target:L,screenshotAttached:De,intro:r(De?"contextPanel.preview.inspect.attachAnnotationWithScreenshot":"contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),ae.success(r("contextPanel.preview.inspect.attached"))},[R,H,E,d,M,r]),je=a.useCallback(()=>{const L=o.current;k(null),oe(!1),L&&Td(L,Wo).catch(()=>{})},[oe]);a.useEffect(()=>{if(!S)return;const L=$=>{$.key==="Escape"&&($.preventDefault(),$.stopImmediatePropagation(),v(!1),je())};return window.addEventListener("keydown",L,!0),()=>window.removeEventListener("keydown",L,!0)},[je,S]),a.useEffect(()=>()=>je(),[je]),a.useEffect(()=>{const L=$=>{if($.source!==o.current?.contentWindow)return;const q=$.data;if(!(!q||q.source!=="openchamber-preview-bridge"||q.version!==1)){if(q.type==="ready"){const he=typeof q.url=="string"?q.url:"",de=U(he);de&&de!==d&&z(de);return}if(q.type==="hover"){k(Ri(q.target)?q.target:null);return}if(q.type==="select"&&Ri(q.target)){k(null),v(!1),oe(!1),ge(q.target);return}if(q.type==="navigate-preview"){const he=typeof q.url=="string"?q.url:"",de=ie(he);if(de){z(de);return}he&&z(he)}}};return window.addEventListener("message",L),()=>window.removeEventListener("message",L)},[z,ge,d,U,ie,oe]);const Se=a.useCallback(()=>{const L=o.current;if(!(!L||!d)){if(S){v(!1),je();return}if(Z){k(null),v(!0),oe(!0);return}v(!0),(async()=>{try{const $=await Td(L,Pm);if(v(!1),!$||!Ri($))return;await ge($)}catch{v(!1),ae.error(r("contextPanel.browser.inspectUnavailable"))}})()}},[ge,je,d,S,oe,Z,r]),re=a.useCallback(()=>{try{const L=o.current?.contentWindow?.location.href||"",$=ie(L);if($){w(!0),z($);return}}catch{}w(!1),S&&Z&&oe(!0)},[z,ie,S,oe,Z]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:p<=0,onClick:()=>V(p-1),children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:p<0||p>=g.length-1,onClick:()=>V(p+1),children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!d,onClick:F,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:L=>{L.preventDefault(),z(u)},children:s.jsx("input",{value:u,onChange:L=>m(L.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(ze,{type:"button",variant:S?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!d,onClick:Se,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!d,onClick:()=>{xi(d)},children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[ne?s.jsxs("div",{className:"absolute inset-0",children:[s.jsx("iframe",{ref:o,src:ne,title:r("contextPanel.browser.empty"),className:"absolute inset-0 h-full w-full border-0 bg-background",allow:"clipboard-read; clipboard-write; fullscreen",allowFullScreen:!0,onLoad:re},`${ne}:${b}`),S&&j?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:j.bounds.x,top:j.bounds.y,width:j.bounds.width,height:j.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[j.tag,j.text?` · ${j.text}`:""]})}):null]}):s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(ja,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")}),s.jsx("span",{className:"max-w-sm typography-micro text-muted-foreground",children:r("contextPanel.browser.emptyHint")}),s.jsx("span",{className:"max-w-md typography-micro leading-relaxed text-status-warning/70",children:r("contextPanel.browser.trustNotice")})]}),N?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},A1=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=Tt(),o=a.useRef(null),i=Fe(T=>T.setContextPanelTabTargetPath),c=co(t),l=c!=="about:blank"?c:"",[u,m]=a.useState(l),[d,f]=a.useState(l),[g,x]=a.useState(!1),[p,y]=a.useState(!0),b=a.useRef(null),h=p,N=a.useCallback(T=>{!T||T==="about:blank"||!e||!n||i(e,n,T)},[e,n,i]),w=vt(T=>T.currentSessionId),S=vt(T=>T.newSessionDraft?.open),v=Kl(T=>T.addDraft),j=ei(T=>T.addAttachedFile);a.useEffect(()=>{const T=o.current;if(!T)return;const C=()=>{try{const _=T.getURL();_&&_!=="about:blank"&&(f(_),m(_),N(_))}catch{}},P=_=>{const z=_.detail;typeof z?.url=="string"&&z.url&&(f(z.url),m(z.url),N(z.url))},E=()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>y(!0),200)},M=()=>{b.current&&clearTimeout(b.current),y(!1),C()},H=_=>{const z=_.detail;if(z?.disposition==="new-window"||z?.disposition==="foreground-tab"||z?.disposition==="background-tab"){_.preventDefault();const V=o.current;typeof V?.loadURL=="function"&&z.url&&V.loadURL(z.url)}},R=()=>{try{T.executeJavaScript?.(w1,!0).catch(()=>{})}catch{}};T.addEventListener("did-navigate",P),T.addEventListener("did-navigate-in-page",P),T.addEventListener("did-start-loading",E),T.addEventListener("did-stop-loading",M),T.addEventListener("new-window",H),T.addEventListener("dom-ready",R);try{T.isLoading()||(y(!1),C())}catch{}return R(),()=>{b.current&&clearTimeout(b.current),T.removeEventListener("did-navigate",P),T.removeEventListener("did-navigate-in-page",P),T.removeEventListener("did-start-loading",E),T.removeEventListener("did-stop-loading",M),T.removeEventListener("new-window",H),T.removeEventListener("dom-ready",R)}},[N]),a.useEffect(()=>{const T=setTimeout(()=>y(!1),3e4);return()=>clearTimeout(T)},[]),a.useEffect(()=>{if(!g)return;const T=C=>{if(C.key!=="Escape")return;C.preventDefault(),C.stopImmediatePropagation(),x(!1);const P=o.current;try{P?.executeJavaScript?.(Wo).catch(()=>{})}catch{}};return window.addEventListener("keydown",T,!0),()=>window.removeEventListener("keydown",T,!0)},[g]),a.useEffect(()=>{const T=o.current;return()=>{try{const C=T?.getURL?.();C&&C!=="about:blank"&&i(e,n,C)}catch{}try{T?.executeJavaScript?.(Wo).catch(()=>{})}catch{}}},[e,n,i]);const k=a.useCallback(T=>{const C=o.current;if(typeof C?.loadURL!="function")return;const P=co(T);try{C.loadURL(P)}catch{}},[]),D=a.useCallback(()=>{const T=o.current;if(T){if(g){x(!1);try{T.executeJavaScript?.(Wo).catch(()=>{})}catch{}return}x(!0),T.executeJavaScript?.(Pm,!0).then(async C=>{if(x(!1),!C||!Ri(C))return;const P=w??(S?"draft":null);if(!P){ae.error(r("contextPanel.preview.inspect.attachNoSession"));return}const E=typeof T.getWebContentsId=="function"?T.getWebContentsId():null;if(E==null)return;const M=await ih("desktop_browser_capture_page",{webContentsId:E}),H=await T.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(H?.width)?H.width:M.width,_=Number.isFinite(H?.height)?H.height:M.height,z=await ic(M.base64,M.width,M.height,R,_,C),V=!!z;z&&await j(z),v({sessionKey:P,source:"preview-annotation",fileLabel:d||"browser",startLine:1,endLine:1,code:rc({pageUrl:d,viewport:{width:R,height:_},devicePixelRatio:window.devicePixelRatio||1,target:C,screenshotAttached:V,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),ae.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>x(!1))}},[j,v,w,d,g,S,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goBack?.()}catch{}},children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goForward?.()}catch{}},children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.reload?.()}catch{}},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:T=>{T.preventDefault(),k(u)},children:s.jsx("input",{value:u,onChange:T=>m(T.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(ze,{type:"button",variant:g?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:D,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{xi(d)},children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:o,src:co(t),partition:"persist:openchamber-browser",allowpopups:!0,style:{width:"100%",height:"100%",border:"none"}}),(!d||d==="about:blank")&&!p?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(ja,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,h?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},D1=()=>{const{t}=Tt(),e=ti()??"",n=a.useMemo(()=>m1(e),[e]),r=Fe(le=>n?le.contextPanelByDirectory[n]:void 0),o=Fe(le=>le.closeContextPanel),i=Fe(le=>le.closeContextPanelTab),c=Fe(le=>le.toggleContextPanelExpanded),l=Fe(le=>le.setContextPanelWidth),u=Fe(le=>le.setActiveContextPanelTab),m=Fe(le=>le.reorderContextPanelTabs),d=Nn(le=>le.setSelectedPath),f=Fe(le=>le.openContextPreview),{themeMode:g,lightThemeId:x,darkThemeId:p,currentTheme:y}=Tr(),b=a.useMemo(()=>r?.tabs??[],[r?.tabs]),h=b.find(le=>le.id===r?.activeTabId)??b[b.length-1]??null,N=!!(r?.isOpen&&h),w=!!(N&&r?.expanded),S=Im(r?.width??Dm),[v,j]=a.useState(!1),[k,D]=a.useState(!1),T=a.useRef(0),C=a.useRef(S),P=a.useRef(null),E=a.useRef(null),M=a.useRef(null),H=a.useRef(new Map),R=a.useRef(!1),_=a.useRef(N),z=a.useRef(null),V=a.useCallback(()=>{D(!0),z.current!==null&&window.cancelAnimationFrame(z.current),z.current=window.requestAnimationFrame(()=>{z.current=null,D(!1)})},[]);a.useEffect(()=>()=>{z.current!==null&&window.cancelAnimationFrame(z.current)},[]),a.useLayoutEffect(()=>{const le=_.current;if(_.current=N,!N){D(!1);return}le||V()},[N,V]),a.useEffect(()=>{if(!N||R.current){R.current=N;return}const le=window.requestAnimationFrame(()=>{M.current?.focus({preventScroll:!0})});return R.current=!0,()=>window.cancelAnimationFrame(le)},[N]);const F=a.useCallback(le=>{const ke=M.current;ke&&ke.style.setProperty("--oc-context-panel-width",`${qa(le,ke)}px`)},[]),te=a.useCallback(le=>{if(!(!N||w||!n)){try{le.currentTarget.setPointerCapture(le.pointerId)}catch{}E.current=le.pointerId,j(!0),T.current=le.clientX,C.current=S,P.current=S,F(S),le.preventDefault()}},[F,n,w,N,S]),Z=a.useCallback(le=>{if(!v||E.current!==le.pointerId)return;const ke=T.current-le.clientX,ue=qa(C.current+ke,M.current);P.current!==ue&&(P.current=ue,F(ue))},[F,v]),ne=a.useCallback(le=>{if(E.current!==le.pointerId||!n)return;try{le.currentTarget.releasePointerCapture(le.pointerId)}catch{}const ke=qa(P.current??S,M.current);V(),F(ke),P.current=ke,l(n,ke),j(!1),E.current=null},[F,n,l,V,S]);a.useEffect(()=>{v||(P.current=null)},[v]);const U=a.useCallback(()=>{n&&o(n)},[o,n]),ie=a.useCallback(()=>{n&&c(n)},[n,c]),oe=a.useCallback(le=>{le.key==="Escape"&&(le.preventDefault(),le.stopPropagation(),U())},[U]);a.useEffect(()=>{if(!(!n||!h)&&h.mode==="file"&&h.targetPath){d(n,h.targetPath);return}},[h,n,d]);const ge=h?.mode==="chat"?h.id:null,je=a.useCallback(()=>{if(typeof window>"u")return;const le={themeMode:g,lightThemeId:x,darkThemeId:p,currentTheme:y};for(const ke of H.current.values()){const ue=ke.contentWindow;if(!ue)continue;const ve=ue.__openchamberApplyThemeSync;if(typeof ve=="function")try{ve(le);continue}catch{}ue.postMessage({type:"openchamber:theme-sync",payload:le},window.location.origin)}},[y,p,x,g]),Se=a.useCallback(()=>{if(!(typeof window>"u"))for(const[le,ke]of H.current.entries()){const ue=ke.contentWindow;if(!ue)continue;const ve={visible:ge===le},G=ue.__openchamberSetEmbeddedVisibility;if(typeof G=="function")try{G(ve);continue}catch{}ue.postMessage({type:"openchamber:embedded-visibility",payload:ve},window.location.origin)}},[ge]);a.useLayoutEffect(()=>{b.some(ke=>ke.mode==="chat")&&(je(),Se())},[p,x,Se,je,b,g]);const re=a.useMemo(()=>b.map(le=>{const ke=x1(le,t),ue=j1(ke,d1),ve=h1(le.targetPath,e);return{id:le.id,label:ue,icon:b1(le),title:ve?`${ke}: ${ve}`:ke,closeLabel:t("contextPanel.tab.closeTabAria",{label:ue})}}),[e,t,b]),L=h?.mode==="diff"?s.jsx(hm,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:h.stagedDiff?"staged":"working",targetFilePath:h.targetPath},h.id):h?.mode==="context"?s.jsx(Lw,{}):h?.mode==="plan"?s.jsx(ym,{targetPath:h.targetPath}):h?.mode==="preview"?s.jsx(N1,{rawUrl:h.targetPath??"",onNavigate:le=>f(e,le)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(I,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),$=a.useMemo(()=>b.filter(le=>le.mode==="chat"),[b]),q=a.useMemo(()=>b.filter(le=>le.mode==="browser"),[b]),he=k1()?A1:C1,de=a.useMemo(()=>b.some(le=>le.mode==="file"),[b]),we=h?.mode==="file",be=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-transparent",children:[s.jsx(go,{items:re,activeId:h?.id??null,onSelect:le=>{n&&u(n,le)},onClose:le=>{n&&i(n,le)},onReorder:(le,ke)=>{n&&m(n,le,ke)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:ie,className:"h-7 w-7 p-0",title:t(w?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(w?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:w?s.jsx(I,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:U,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),De=N?w?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",minWidth:`min(${Am}px, 100%)`,maxWidth:"100%","--oc-context-panel-width":`${v?P.current??S:S}px`}:{"--oc-context-panel-width":`${v?P.current??S:S}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:"hidden",visibility:"hidden"};return s.jsxs("aside",{ref:M,"data-context-panel":"true",tabIndex:-1,inert:!N||void 0,className:Te("flex min-h-0 flex-col overflow-hidden bg-background",!w&&"border-l border-border/40",w?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",!N&&"pointer-events-none",v||!N||k?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:oe,style:De,children:[!w&&s.jsx("div",{className:Te("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",v&&"bg-[var(--interactive-border)]"),onPointerDown:te,onPointerMove:Z,onPointerUp:ne,onPointerCancel:ne,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),be,s.jsxs("div",{className:Te("relative min-h-0 flex-1 overflow-hidden",v&&"pointer-events-none"),children:[de?s.jsx("div",{className:Te("absolute inset-0",we?"block":"hidden"),children:s.jsx(bm,{mode:"editor-only"})}):null,$.map(le=>{const ke=y1(le.dedupeKey);if(!ke)return null;const ue=v1(ke,n||null,le.readOnly);return ue?s.jsx("iframe",{ref:ve=>{if(!ve){H.current.delete(le.id);return}H.current.set(le.id,ve)},src:ue,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ke}),className:Te("absolute inset-0 h-full w-full border-0 bg-background",ge===le.id?"block":"hidden"),onLoad:()=>{je(),Se()}},le.id):null}),q.map(le=>s.jsx("div",{className:Te("absolute inset-0",h?.id!==le.id&&"hidden"),children:s.jsx(he,{initialUrl:le.targetPath??"",directory:n,tabID:le.id})},le.id)),h?.mode!=="chat"&&!we&&h?.mode!=="browser"?L:null]})]})},Dl=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const o=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!o&&!i&&(r=r.replace(/\/+$/,"")),r},I1=()=>{const t=gt.c(162),{t:e}=Tt(),n=Fe(P1),r=Fe(T1),o=Fe(E1),i=Fe(R1),c=Fe(M1),l=Fe(F1),u=Fe(L1),m=Fe(O1),d=Fe(_1),f=Fe(B1),g=Fe(V1),x=Fe($1),p=vt(z1),y=vt(W1),b=Xr(U1),h=sn(H1),N=Es(G1),w=ti(),S=Ul(K1),{files:v,git:j}=Wn(),k=_s(q1),{isMobile:D}=Pr();let T;t[0]!==w?(T=w?Dl(w):null,t[0]=w,t[1]=T):T=t[1];const C=T,[P,E]=a.useState(""),M=va(P,200);let H;t[2]!==M?(H=M.trim(),t[2]=M,t[3]=H):H=t[3];const R=H;let _;t[4]!==P?(_=P.trim(),t[4]=P,t[5]=_):_=t[5];const z=_;let V,F;t[6]!==n?(V=()=>{n&&E("")},F=[n],t[6]=n,t[7]=V,t[8]=F):(V=t[7],F=t[8]),a.useEffect(V,F);let te,Z;t[9]!==b||t[10]!==k||t[11]!==j||t[12]!==n?(te=()=>{if(!n||!j)return;const He=setTimeout(()=>{const Ze=new Set;for(const Ue of b){const jt=hi(Ue);!jt||Ze.has(jt)||(Ze.add(jt),k(jt,j))}},0);return()=>clearTimeout(He)},Z=[n,b,j,k],t[9]=b,t[10]=k,t[11]=j,t[12]=n,t[13]=te,t[14]=Z):(te=t[13],Z=t[14]),a.useEffect(te,Z);let ne;t[15]!==r?(ne=()=>r(!1),t[15]=r,t[16]=ne):ne=t[16];const U=ne;let ie;t[17]!==U?(ie=He=>()=>{U(),He()},t[17]=U,t[18]=ie):ie=t[18];const oe=ie;let ge;t[19]!==N?.id||t[20]!==N?.path||t[21]!==h||t[22]!==D||t[23]!==f||t[24]!==p||t[25]!==oe||t[26]!==o||t[27]!==l||t[28]!==i||t[29]!==e||t[30]!==d||t[31]!==m||t[32]!==u?(ge=()=>{const He=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(I,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:oe(()=>{o("chat"),l(!1),p()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(I,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:oe(Y1)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:oe(J1)},{id:"toggle-sidebar",title:e(D?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(I,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(D?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:oe(()=>{if(D){const{isSessionSwitcherOpen:Ze}=Fe.getState();l(!Ze)}else u()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(I,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:oe(()=>m())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(I,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:oe(()=>d())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(I,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:oe(()=>{h&&f(h)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(I,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:oe(()=>i(!0))}];return Ol()&&He.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(I,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:oe(()=>{ui("desktop_open_draft_mini_chat_window",{directory:Dl(h||N?.path||""),projectId:N?.id??null}).catch(Q1)})}),He},t[19]=N?.id,t[20]=N?.path,t[21]=h,t[22]=D,t[23]=f,t[24]=p,t[25]=oe,t[26]=o,t[27]=l,t[28]=i,t[29]=e,t[30]=d,t[31]=m,t[32]=u,t[33]=ge):ge=t[33],N?.id,N?.path;let je;t[34]!==ge?(je=ge(),t[34]=ge,t[35]=je):je=t[35];const Se=je;let re;t[36]===Symbol.for("react.memo_cache_sentinel")?(re=lr(),t[36]=re):re=t[36];const L=re;let $;t[37]===Symbol.for("react.memo_cache_sentinel")?($={isVSCode:Gi(),isWeb:!L&&ql(),isDesktop:L},t[37]=$):$=t[37];const q=$;let he;if(t[38]!==oe||t[39]!==i||t[40]!==c){let He;t[42]===Symbol.for("react.memo_cache_sentinel")?(He=Ze=>Ze.isAvailable?Ze.isAvailable(q):!0,t[42]=He):He=t[42],he=Up.filter(X1).filter(He).map(Ze=>{const Ue=Hp(Ze.slug)??"settings-3",jt=(Ze.keywords??[]).join(" ");return{id:`settings:${Ze.slug}`,title:Ze.title,icon:s.jsx(I,{name:Ue,className:"mr-2 h-4 w-4"}),searchText:`${Ze.title} ${Ze.group} ${jt}`,onSelect:oe(()=>{c(Ze.slug),i(!0)})}}),t[38]=oe,t[39]=i,t[40]=c,t[41]=he}else he=t[41];const de=he,we=Z1;let be;if(t[43]!==b){let He;t[45]===Symbol.for("react.memo_cache_sentinel")?(He=(Ze,Ue)=>we(Ue)-we(Ze),t[45]=He):He=t[45],be=[...b].sort(He),t[43]=b,t[44]=be}else be=t[44];const De=be,le=Mu(),ke=vt(ev);let ue;t[46]!==le||t[47]!==ke?(ue=(He,Ze)=>{const Ue=ke.get(He);return Ue?.branch?Ue.branch.trim()||null:Ze&&le.get(Ze)?.trim()||null},t[46]=le,t[47]=ke,t[48]=ue):ue=t[48];const ve=ue;let G;t[49]===Symbol.for("react.memo_cache_sentinel")?(G=[],t[49]=G):G=t[49];const[Ae,ce]=a.useState(G),[fe,Ee]=a.useState(!1);let me,B;t[50]!==C||t[51]!==n||t[52]!==S||t[53]!==R?(me=()=>{if(!n){ce([]),Ee(!1);return}if(!C||R.length===0){ce([]),Ee(!1);return}let He=!1;return Ee(!0),S(C,R,10,{type:"file"}).then(Ze=>{He||ce(Ze.map(tv))}).catch(()=>{He||ce([])}).finally(()=>{He||Ee(!1)}),()=>{He=!0}},B=[n,C,R,S],t[50]=C,t[51]=n,t[52]=S,t[53]=R,t[54]=me,t[55]=B):(me=t[54],B=t[55]),a.useEffect(me,B);const ye=z.length>0;let Oe;e:{if(!ye){let Ze;t[56]!==Se?(Ze=Se.map(sv),t[56]=Se,t[57]=Ze):Ze=t[57],Oe=Ze;break e}let He;t[58]!==Se||t[59]!==z?(He=ko(Se,z,nv,{limit:7,noFuzzy:!0}),t[58]=Se,t[59]=z,t[60]=He):He=t[60],Oe=He}const Q=Oe;let Me;e:{if(!ye){let Ze;t[61]===Symbol.for("react.memo_cache_sentinel")?(Ze=[],t[61]=Ze):Ze=t[61],Me=Ze;break e}let He;t[62]!==z||t[63]!==de?(He=ko(de,z,rv,{limit:7,noFuzzy:!0}),t[62]=z,t[63]=de,t[64]=He):He=t[64],Me=He}const Re=Me;let Ne;e:{if(!ye){let Ze;t[65]!==De?(Ze=De.slice(0,5).map(iv),t[65]=De,t[66]=Ze):Ze=t[66],Ne=Ze;break e}let He;t[67]!==z||t[68]!==De?(He=ko(De,z,ov,{limit:7,threshold:.2}),t[67]=z,t[68]=De,t[69]=He):He=t[69],Ne=He}const Be=Ne;let se;e:{if(!ye||Ae.length===0){let Ze;t[70]===Symbol.for("react.memo_cache_sentinel")?(Ze=[],t[70]=Ze):Ze=t[70],se=Ze;break e}let He;t[71]!==Ae||t[72]!==z?(He=ko(Ae,z,av,{limit:10,threshold:.4}),t[71]=Ae,t[72]=z,t[73]=He):He=t[73],se=He}const O=se;let A,K,pe,_e,We,Le,rt,yt,Dt,st,Pe,tt,Ye,nt,ft;if(t[74]!==ve||t[75]!==U||t[76]!==C||t[77]!==v||t[78]!==ye||t[79]!==n||t[80]!==g||t[81]!==P||t[82]!==Q||t[83]!==O||t[84]!==Be||t[85]!==Re||t[86]!==r||t[87]!==y||t[88]!==x||t[89]!==e){const He=Q.map(lv),Ze=Re.map(cv),Ue=Be.map(dv);ft=ye?O.map(uv):[];let jt;e:{if(!ye){jt=["commands","sessions"];break e}const Gt=mv,pt=[{key:"commands",score:Gt(Q)},{key:"settings",score:Gt(Re)},{key:"sessions",score:Gt(Be)},{key:"files",score:Gt(O)}];pt.sort(fv),jt=pt.map(hv)}const Ge=jt;let it;t[105]!==U||t[106]!==y?(it=Gt=>{U(),y(Gt.id,hi(Gt))},t[105]=U,t[106]=y,t[107]=it):it=t[107];const Et=it;let lt;t[108]!==U||t[109]!==C||t[110]!==v||t[111]!==g?(lt=async Gt=>{if(!C)return;const pt=await sc(v,Gt);if(!pt.ok){ae.error(nc(pt.reason));return}g(C,Gt),U()},t[108]=U,t[109]=C,t[110]=v,t[111]=g,t[112]=lt):lt=t[112];const ct=lt;let Bt;t[113]!==x?(Bt=Gt=>Bl(mi(Gt,x)),t[113]=x,t[114]=Bt):Bt=t[114];const Ft=Bt;_e=Ks,tt=n,Ye=r;let qt;t[115]!==e?(qt=e("commandPalette.title"),t[115]=e,t[116]=qt):qt=t[116];let Ut;t[117]!==qt?(Ut=s.jsx(Ys,{children:qt}),t[117]=qt,t[118]=Ut):Ut=t[118];let At;t[119]!==e?(At=e("commandPalette.description"),t[119]=e,t[120]=At):At=t[120];let Xt;t[121]!==At?(Xt=s.jsx(cn,{children:At}),t[121]=At,t[122]=Xt):Xt=t[122],t[123]!==Ut||t[124]!==Xt?(nt=s.jsxs(Xs,{className:"sr-only",children:[Ut,Xt]}),t[123]=Ut,t[124]=Xt,t[125]=nt):nt=t[125],pe=Gs,st="overflow-hidden p-0",Pe=!0,K=ma,rt=!1,yt="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let ls;t[126]!==e?(ls=e("commandPalette.input.placeholder"),t[126]=e,t[127]=ls):ls=t[127],t[128]!==P||t[129]!==ls?(Dt=s.jsx(fa,{value:P,onValueChange:E,placeholder:ls}),t[128]=P,t[129]=ls,t[130]=Dt):Dt=t[130],A=ha;let es;t[131]!==e?(es=e("commandPalette.empty.noResults"),t[131]=e,t[132]=es):es=t[132],t[133]!==es?(We=s.jsx(pa,{children:es}),t[133]=es,t[134]=We):We=t[134],Le=Ge.map(Gt=>Gt==="commands"&&He.length>0?s.jsx(qr,{children:He.map(pt=>s.jsxs(Zr,{value:pt.id,onSelect:pt.onSelect,children:[pt.icon,s.jsx("span",{children:pt.title}),pt.shortcutId?s.jsx(oh,{children:Ft(pt.shortcutId)}):null]},pt.id))},"commands"):Gt==="settings"&&Ze.length>0?s.jsx(qr,{children:Ze.map(pv)},"settings"):Gt==="sessions"&&Ue.length>0?s.jsx(qr,{children:Ue.map(pt=>{const Yt=pt.title||e("commandPalette.session.untitled"),us=hi(pt),Jt=ve(pt.id,us);return s.jsxs(Zr,{value:`session:${pt.id}`,onSelect:()=>Et(pt),children:[s.jsx(I,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Yt}),Jt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Jt})]}):null]},pt.id)})},"sessions"):Gt==="files"&&ft.length>0?s.jsx(qr,{children:ft.map(pt=>{const Yt=ah(pt.relativePath||pt.name,{maxLength:80});return s.jsxs(Zr,{value:`file:${pt.path}`,onSelect:()=>{ct(pt.path)},children:[s.jsx(yr,{filePath:pt.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":pt.relativePath,children:Yt})]},`file:${pt.path}`)})},"files"):null),t[74]=ve,t[75]=U,t[76]=C,t[77]=v,t[78]=ye,t[79]=n,t[80]=g,t[81]=P,t[82]=Q,t[83]=O,t[84]=Be,t[85]=Re,t[86]=r,t[87]=y,t[88]=x,t[89]=e,t[90]=A,t[91]=K,t[92]=pe,t[93]=_e,t[94]=We,t[95]=Le,t[96]=rt,t[97]=yt,t[98]=Dt,t[99]=st,t[100]=Pe,t[101]=tt,t[102]=Ye,t[103]=nt,t[104]=ft}else A=t[90],K=t[91],pe=t[92],_e=t[93],We=t[94],Le=t[95],rt=t[96],yt=t[97],Dt=t[98],st=t[99],Pe=t[100],tt=t[101],Ye=t[102],nt=t[103],ft=t[104];let mt;t[135]!==ye||t[136]!==fe||t[137]!==e||t[138]!==ft?(mt=ye&&fe&&ft.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=ye,t[136]=fe,t[137]=e,t[138]=ft,t[139]=mt):mt=t[139];let ot;t[140]!==A||t[141]!==We||t[142]!==Le||t[143]!==mt?(ot=s.jsxs(A,{children:[We,Le,mt]}),t[140]=A,t[141]=We,t[142]=Le,t[143]=mt,t[144]=ot):ot=t[144];let It;t[145]!==K||t[146]!==rt||t[147]!==yt||t[148]!==Dt||t[149]!==ot?(It=s.jsxs(K,{shouldFilter:rt,className:yt,children:[Dt,ot]}),t[145]=K,t[146]=rt,t[147]=yt,t[148]=Dt,t[149]=ot,t[150]=It):It=t[150];let dt;t[151]!==pe||t[152]!==st||t[153]!==Pe||t[154]!==It?(dt=s.jsx(pe,{className:st,showCloseButton:Pe,children:It}),t[151]=pe,t[152]=st,t[153]=Pe,t[154]=It,t[155]=dt):dt=t[155];let bt;return t[156]!==_e||t[157]!==tt||t[158]!==Ye||t[159]!==nt||t[160]!==dt?(bt=s.jsxs(_e,{open:tt,onOpenChange:Ye,children:[nt,dt]}),t[156]=_e,t[157]=tt,t[158]=Ye,t[159]=nt,t[160]=dt,t[161]=bt):bt=t[161],bt};function P1(t){return t.isCommandPaletteOpen}function T1(t){return t.setCommandPaletteOpen}function E1(t){return t.setActiveMainTab}function R1(t){return t.setSettingsDialogOpen}function M1(t){return t.setSettingsPage}function F1(t){return t.setSessionSwitcherOpen}function L1(t){return t.toggleSidebar}function O1(t){return t.toggleRightSidebar}function _1(t){return t.toggleBottomTerminal}function B1(t){return t.openContextOverview}function V1(t){return t.openContextFile}function $1(t){return t.shortcutOverrides}function z1(t){return t.openNewSessionDraft}function W1(t){return t.setCurrentSession}function U1(t){return t.activeSessions}function H1(t){return t.currentDirectory}function G1(t){return t.getActiveProject()}function K1(t){return t.searchFiles}function q1(t){return t.ensureStatus}function Y1(){Fu()}function J1(){Ir.requestDirectoryDialog()}function Q1(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function X1(t){return t.slug!=="home"}function Z1(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function ev(t){return t.worktreeMetadata}function tv(t){return{path:Dl(t.path),name:t.name,relativePath:t.relativePath}}function sv(t){return{item:t,score:0}}function nv(t){return t.searchText}function rv(t){return t.searchText}function iv(t){return{item:t,score:0}}function ov(t){return t.title||""}function av(t){return t.name}function lv(t){return t.item}function cv(t){return t.item}function dv(t){return t.item}function uv(t){return t.item}function mv(t){return t.length?t[0].score:1/0}function fv(t,e){return t.score-e.score}function hv(t){return t.key}function pv(t){return s.jsxs(Zr,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Rd=(t,e,n)=>ch(t)?Bl(mi(t,n)):e,gv=()=>{const t=gt.c(68),{t:e}=Tt(),n=Fe(xv),r=Fe(bv),o=Fe(yv);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=lh(),t[0]=i):i=t[0];const c=i;let l,u,m,d,f,g,x,p,y;if(t[1]!==n||t[2]!==r||t[3]!==o||t[4]!==e){const R=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${c} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${c} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];u=Ks,p=n,y=r,l=Gs,g="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let _;t[14]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(I,{name:"settings-3",className:"h-5 w-5"}),t[14]=_):_=t[14];let z;t[15]!==e?(z=e("helpDialog.title"),t[15]=e,t[16]=z):z=t[16];let V;t[17]!==z?(V=s.jsxs(Ys,{className:"flex items-center gap-2",children:[_,z]}),t[17]=z,t[18]=V):V=t[18];let F;t[19]!==e?(F=e("helpDialog.description"),t[19]=e,t[20]=F):F=t[20];let te;t[21]!==F?(te=s.jsx(cn,{children:F}),t[21]=F,t[22]=te):te=t[22],t[23]!==V||t[24]!==te?(x=s.jsxs(Xs,{children:[V,te]}),t[23]=V,t[24]=te,t[25]=x):x=t[25],f="flex-1 overflow-y-auto mt-3 pr-1",m="space-y-4",d=R.map(Z=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(Z.categoryKey)}),s.jsx("div",{className:"space-y-1",children:Z.items.map(ne=>{const U=ne.id?Rd(ne.id,Array.isArray(ne.keys)?ne.keys[0]:ne.keys,o):Array.isArray(ne.keys)?ne.keys:ne.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ne.icon&&s.jsx(I,{name:ne.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(ne.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(U)?U:[U]).map((ie,oe)=>s.jsxs(a.Fragment,{children:[oe>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:ie})]},`${ie}-${oe}`))})]},ne.id||ne.descriptionKey)})})]},Z.categoryKey)),t[1]=n,t[2]=r,t[3]=o,t[4]=e,t[5]=l,t[6]=u,t[7]=m,t[8]=d,t[9]=f,t[10]=g,t[11]=x,t[12]=p,t[13]=y}else l=t[5],u=t[6],m=t[7],d=t[8],f=t[9],g=t[10],x=t[11],p=t[12],y=t[13];let b;t[26]!==m||t[27]!==d?(b=s.jsx("div",{className:m,children:d}),t[26]=m,t[27]=d,t[28]=b):b=t[28];let h;t[29]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(I,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=h):h=t[29];let N;t[30]!==e?(N=e("helpDialog.proTips.title"),t[30]=e,t[31]=N):N=t[31];let w;t[32]!==N?(w=s.jsx("p",{className:"font-medium mb-1",children:N}),t[32]=N,t[33]=w):w=t[33];let S;t[34]!==o||t[35]!==e?(S=e("helpDialog.proTips.commandPalette",{shortcut:Rd("open_command_palette",`${c} P`,o)}),t[34]=o,t[35]=e,t[36]=S):S=t[36];let v;t[37]!==S?(v=s.jsxs("li",{children:["• ",S]}),t[37]=S,t[38]=v):v=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let k;t[41]!==j?(k=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=k):k=t[42];let D;t[43]!==e?(D=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=D):D=t[44];let T;t[45]!==D?(T=s.jsxs("li",{children:["• ",D]}),t[45]=D,t[46]=T):T=t[46];let C;t[47]!==v||t[48]!==k||t[49]!==T?(C=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[v,k,T]}),t[47]=v,t[48]=k,t[49]=T,t[50]=C):C=t[50];let P;t[51]!==w||t[52]!==C?(P=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[h,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[w,C]})]})}),t[51]=w,t[52]=C,t[53]=P):P=t[53];let E;t[54]!==P||t[55]!==f||t[56]!==b?(E=s.jsxs("div",{className:f,children:[b,P]}),t[54]=P,t[55]=f,t[56]=b,t[57]=E):E=t[57];let M;t[58]!==l||t[59]!==E||t[60]!==g||t[61]!==x?(M=s.jsxs(l,{className:g,children:[x,E]}),t[58]=l,t[59]=E,t[60]=g,t[61]=x,t[62]=M):M=t[62];let H;return t[63]!==u||t[64]!==M||t[65]!==p||t[66]!==y?(H=s.jsx(u,{open:p,onOpenChange:y,children:M}),t[63]=u,t[64]=M,t[65]=p,t[66]=y,t[67]=H):H=t[67],H};function xv(t){return t.isHelpDialogOpen}function bv(t){return t.setHelpDialogOpen}function yv(t){return t.shortcutOverrides}const wv=()=>{const t=gt.c(32),{t:e}=Tt(),n=Fe(vv),r=Fe(jv),o=Fe(Sv);let i;t[0]!==o||t[1]!==e?(i=async()=>{if(!o)return;if((await cr(o)).ok){ae.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}ae.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=o,t[1]=e,t[2]=i):i=t[2];const c=i;let l;t[3]!==e?(l=e("openCodeStatusDialog.title"),t[3]=e,t[4]=l):l=t[4];let u;t[5]!==l?(u=s.jsx(Ys,{children:l}),t[5]=l,t[6]=u):u=t[6];let m;t[7]!==e?(m=e("openCodeStatusDialog.description"),t[7]=e,t[8]=m):m=t[8];let d;t[9]!==m?(d=s.jsx(cn,{children:m}),t[9]=m,t[10]=d):d=t[10];let f;t[11]!==u||t[12]!==d?(f=s.jsxs(Xs,{children:[u,d]}),t[11]=u,t[12]=d,t[13]=f):f=t[13];let g;t[14]!==e?(g=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=g):g=t[15];let x;t[16]!==c||t[17]!==g?(x=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:c,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:g})}),t[16]=c,t[17]=g,t[18]=x):x=t[18];let p;t[19]!==o||t[20]!==e?(p=o||e("openCodeStatusDialog.empty.noData"),t[19]=o,t[20]=e,t[21]=p):p=t[21];let y;t[22]!==p?(y=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:p}),t[22]=p,t[23]=y):y=t[23];let b;t[24]!==f||t[25]!==x||t[26]!==y?(b=s.jsxs(Gs,{className:"max-w-2xl",children:[f,x,y]}),t[24]=f,t[25]=x,t[26]=y,t[27]=b):b=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==b?(h=s.jsx(Ks,{open:n,onOpenChange:r,children:b}),t[28]=n,t[29]=r,t[30]=b,t[31]=h):h=t[31],h};function vv(t){return t.isOpenCodeStatusDialogOpen}function jv(t){return t.setOpenCodeStatusDialogOpen}function Sv(t){return t.openCodeStatusText}const Nv=180,Md=600,kv=1,Cv=6,Av=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const o=a.useRef(new Map),i=a.useRef([]),c=a.useRef(new Set),l=a.useMemo(()=>Gi(),[]),u=a.useCallback(()=>{if(!(l||typeof window>"u"))for(;c.current.size<kv&&i.current.length>0;){const d=i.current.shift();if(!d)break;vt.getState().currentSessionId!==d&&(jc(d).renderable||(c.current.add(d),r(d).catch(()=>{}).finally(()=>{c.current.delete(d),u()})))}},[r,l]),m=a.useCallback(d=>{if(l||!d||d===t||typeof window>"u"||jc(d).renderable||c.current.has(d)||i.current.includes(d))return;i.current.length>=Cv&&i.current.shift();const f=o.current.get(d);f!==void 0&&window.clearTimeout(f);const g=window.setTimeout(()=>{o.current.delete(d),i.current.push(d),u()},Nv);o.current.set(d,g)},[t,l,u]);a.useEffect(()=>{if(l||!t||e.length===0)return;const d=window.setTimeout(()=>{const f=e.findIndex(g=>g.id===t);f<0||(m(e[f-1]?.id),m(e[f+1]?.id))},Md);return()=>window.clearTimeout(d)},[t,l,m,e]),a.useEffect(()=>{if(l||!t||n.length===0)return;const d=window.setTimeout(()=>{const f=n.indexOf(t);f<0||(m(n[f-1]),m(n[f+1]))},Md);return()=>window.clearTimeout(d)},[t,l,n,m]),a.useEffect(()=>{const d=o.current;return()=>{d.forEach(f=>{clearTimeout(f)}),d.clear(),i.current=[]}},[])};let Fi=null,Li=null,Uo=null,xo=0,da=null;const gi=new Set,Dv=3e4,Iv=45e3,Em=()=>{Uo&&(clearTimeout(Uo),Uo=null)},Rm=()=>{if(Li||gi.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(xo,5)),Dv);Li=setTimeout(()=>{Li=null,xo+=1,ac()},t)},bo=()=>{Em(),Fi&&Fi.close(),Fi=null},Fd=()=>{Em(),gi.size!==0&&(Uo=setTimeout(()=>{bo(),Rm()},Iv))},Pv=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},Tv=t=>{if(t.type==="openchamber:event-stream-ready"){xo=0;return}if(t.type==="openchamber:heartbeat"||t.type!=="openchamber:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",o=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,c=i==="running"||i==="error"?i:"success";if(!n||!r)return;const l={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:o,status:c,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const u of gi)u(l)},ac=()=>{if(typeof window>"u"||gi.size===0||typeof EventSource!="function"||Fi&&Fi.readyState!==EventSource.CLOSED)return;bo();const t=new EventSource(Oi().sse("/api/openchamber/events"));t.onopen=()=>{Fd()},t.onmessage=e=>{Fd();const n=Pv(e.data);n&&Tv(n)},t.onerror=()=>{bo(),Rm()},Fi=t},Ev=()=>{da||typeof window>"u"||(da=pu(()=>{bo(),xo=0,ac()}))},Rv=()=>{da?.(),da=null},Mm=t=>(gi.add(t),Ev(),ac(),()=>{gi.delete(t),gi.size===0&&(Li&&(clearTimeout(Li),Li=null),xo=0,bo(),Rv())}),Aa=async(t,e)=>{try{const n=await t.json();if(n&&typeof n.error=="string"&&n.error.trim().length>0)return n.error}catch{return e}return e},Ui=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},Mv=async t=>{const e=Ui(t),n=await Rs(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Aa(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Ld=async(t,e)=>{const n=Ui(t),r=await Rs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:e})});if(!r.ok)throw new Error(await Aa(r,"Failed to save scheduled task"));const o=await r.json().catch(()=>null);return!o||!Array.isArray(o.tasks)?[]:o.tasks},Fv=async(t,e)=>{const n=Ui(t),r=Ui(e),o=await Rs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Aa(o,"Failed to delete scheduled task"));const i=await o.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},Lv=async(t,e)=>{const n=Ui(t),r=Ui(e),o=await Rs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Aa(o,"Failed to run scheduled task"));const i=await o.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0}},Fm=[0,1,2,3,4,5,6],Od=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?Intl.supportedValuesOf("timeZone"):["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],_d=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Ho=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),o=Number(e[3]),i=new Date(n,r-1,o);return Number.isNaN(i.getTime())||i.getFullYear()!==n||i.getMonth()!==r-1||i.getDate()!==o?null:i},Bd=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Ov=(t,e,n)=>{const r=Ho(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Vd=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),_v=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),c=(new Date(n,r,1).getDay()-e+7)%7,l=new Date(n,r+1,0).getDate(),u=new Date(n,r,0).getDate(),m=[];for(let d=0;d<42;d+=1){const f=d-c+1;if(f<=0){const g=u+f;m.push({date:new Date(n,r-1,g),inCurrentMonth:!1});continue}if(f>l){m.push({date:new Date(n,r+1,f-l),inCurrentMonth:!1});continue}m.push({date:new Date(n,r,f),inCurrentMonth:!0})}return m},Bv=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],o=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:o}},oi=(t,e,n)=>{const r=Number(t),o=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,c=Number.isFinite(o)?Math.min(59,Math.max(0,o)):0;let l=i%12;return n==="PM"&&(l+=12),`${String(l).padStart(2,"0")}:${String(c).padStart(2,"0")}`},Ki=(t,e)=>{const{max:n,min:r=0,loop:o=!1}=e;let i=Number.parseInt(t,10);return Number.isFinite(i)?(o?(i>n&&(i=r),i<r&&(i=n)):(i>n&&(i=n),i<r&&(i=r)),String(i).padStart(2,"0")):"00"},$d=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:Ki(t,{min:1,max:12}),To=t=>/^[0-5][0-9]$/.test(t)?t:Ki(t,{max:59}),Vv=(t,e)=>Ki(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),zd=(t,e)=>Ki(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),$v=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},zv=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},Wv=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Fm.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},Uv=(t,e)=>[...t.slice(e),...t.slice(0,e)],ar=t=>{const e=gt.c(6),{htmlFor:n,required:r,children:o}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let c;return e[2]!==o||e[3]!==n||e[4]!==i?(c=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,i]})}),e[2]=o,e[3]=n,e[4]=i,e[5]=c):c=e[5],c},Wd=t=>{const e=gt.c(84),{value:n,onChange:r,use24Hour:o,hourAriaLabel:i,minuteAriaLabel:c,periodAriaLabel:l,amLabel:u,pmLabel:m}=t;let d;e[0]!==n?(d=Bv(n),e[0]=n,e[1]=d):d=e[1];const f=d,g=et.useRef(null),x=et.useRef(null),[p,y]=et.useState(null),[b,h]=et.useState(null),N=et.useRef(null),w=et.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=G=>{N.current=G,y(G)},e[2]=S):S=e[2];const v=S;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=G=>{w.current=G,h(G)},e[3]=j):j=e[3];const k=j,D=Jv,T=Qv,C=Xv;let P;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==o?(P=G=>{const Ae=G.replace(/\D/g,"").slice(0,2);v(Ae),Ae.length===2&&(r(o?C(D(Ae),f.minute):oi($d(Ae),f.minute,f.meridiem)),v(null),x.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=o,e[8]=P):P=e[8];const E=P;let M;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==o?(M=()=>{const G=N.current;if(G!==null&&(v(null),G.length!==0)){if(o){r(C(D(G.padStart(2,"0")),f.minute));return}r(oi($d(G.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=o,e[13]=M):M=e[13];const H=M;let R;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==o?(R=G=>{const Ae=G.replace(/\D/g,"").slice(0,2);k(Ae),Ae.length===2&&(r(o?C(f.hour24,To(Ae)):oi(f.hour12,To(Ae),f.meridiem)),k(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=o,e[19]=R):R=e[19];const _=R;let z;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==o?(z=()=>{const G=w.current;G!==null&&(k(null),G.length!==0&&r(o?C(f.hour24,To(G.padStart(2,"0"))):oi(f.hour12,To(G.padStart(2,"0")),f.meridiem)))},e[20]=r,e[21]=f.hour12,e[22]=f.hour24,e[23]=f.meridiem,e[24]=o,e[25]=z):z=e[25];const V=z;let F;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==o?(F=G=>r(o?C(T(f.hour24,G),f.minute):oi(Vv(f.hour12,G),f.minute,f.meridiem)),e[26]=r,e[27]=f.hour12,e[28]=f.hour24,e[29]=f.meridiem,e[30]=f.minute,e[31]=o,e[32]=F):F=e[32];const te=F;let Z;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==o?(Z=G=>r(o?C(f.hour24,zd(f.minute,G)):oi(f.hour12,zd(f.minute,G),f.meridiem)),e[33]=r,e[34]=f.hour12,e[35]=f.hour24,e[36]=f.meridiem,e[37]=f.minute,e[38]=o,e[39]=Z):Z=e[39];const ne=Z;let U;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(U=G=>{G!==f.meridiem&&r(oi(f.hour12,f.minute,G))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=U):U=e[44];const ie=U;let oe;e[45]!==H||e[46]!==te?(oe=G=>{if(G.key==="ArrowRight"){G.preventDefault(),H(),x.current?.focus();return}(G.key==="ArrowUp"||G.key==="ArrowDown")&&(G.preventDefault(),v(null),te(G.key==="ArrowUp"?1:-1))},e[45]=H,e[46]=te,e[47]=oe):oe=e[47];const ge=oe;let je;e[48]!==V||e[49]!==ne?(je=G=>{if(G.key==="ArrowLeft"&&(G.currentTarget.selectionStart??0)===0){G.preventDefault(),V(),g.current?.focus();return}(G.key==="ArrowUp"||G.key==="ArrowDown")&&(G.preventDefault(),k(null),ne(G.key==="ArrowUp"?1:-1))},e[48]=V,e[49]=ne,e[50]=je):je=e[50];const Se=je,re=o?"px-2":"pl-2 pr-1";let L;e[51]!==re?(L=Te("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",re),e[51]=re,e[52]=L):L=e[52];const $=p??(o?f.hour24:f.hour12);let q;e[53]!==E?(q=G=>E(G.target.value),e[53]=E,e[54]=q):q=e[54];let he;e[55]===Symbol.for("react.memo_cache_sentinel")?(he=()=>v(""),e[55]=he):he=e[55];let de;e[56]!==H||e[57]!==i||e[58]!==ge||e[59]!==$||e[60]!==q?(de=s.jsx("input",{ref:g,inputMode:"numeric",value:$,onChange:q,onKeyDown:ge,onFocus:he,onBlur:H,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=H,e[57]=i,e[58]=ge,e[59]=$,e[60]=q,e[61]=de):de=e[61];let we;e[62]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=we):we=e[62];const be=b??f.minute;let De;e[63]!==_?(De=G=>_(G.target.value),e[63]=_,e[64]=De):De=e[64];let le;e[65]===Symbol.for("react.memo_cache_sentinel")?(le=()=>k(""),e[65]=le):le=e[65];let ke;e[66]!==V||e[67]!==c||e[68]!==Se||e[69]!==be||e[70]!==De?(ke=s.jsx("input",{ref:x,inputMode:"numeric",value:be,onChange:De,onKeyDown:Se,onFocus:le,onBlur:V,maxLength:2,"aria-label":c,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=V,e[67]=c,e[68]=Se,e[69]=be,e[70]=De,e[71]=ke):ke=e[71];let ue;e[72]!==u||e[73]!==f.meridiem||e[74]!==l||e[75]!==m||e[76]!==ie||e[77]!==o?(ue=o?null:s.jsxs(Bn,{value:f.meridiem,onValueChange:G=>ie(G),children:[s.jsx(Vn,{"aria-label":l,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(Pn,{})}),s.jsxs($n,{children:[s.jsx(qs,{value:"AM",children:u}),s.jsx(qs,{value:"PM",children:m})]})]}),e[72]=u,e[73]=f.meridiem,e[74]=l,e[75]=m,e[76]=ie,e[77]=o,e[78]=ue):ue=e[78];let ve;return e[79]!==L||e[80]!==de||e[81]!==ke||e[82]!==ue?(ve=s.jsxs("div",{className:L,children:[de,we,ke,ue]}),e[79]=L,e[80]=de,e[81]=ke,e[82]=ue,e[83]=ve):ve=e[83],ve},Ud=t=>new Date(t.getFullYear(),t.getMonth(),1),Hv=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Hd=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),Gv=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(o=>typeof o=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(o)).map(o=>o.trim()),r=Array.from(new Set(n)).sort((o,i)=>o.localeCompare(i));return r.length>0?r:["09:00"]},Gd=(t,e)=>{const n=Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC";return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:Gv(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:_d(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:t.schedule.timezone||n},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||""},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:_d(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},Kv=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},qv=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))};function Yv(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:i,locale:c}=Tt(),l=cs(A=>A.loadProviders),u=cs(A=>A.loadAgents),m=cs(A=>A.providers),d=cs(A=>A.currentProviderId),f=cs(A=>A.currentModelId),g=cs(A=>A.currentVariant||""),x=cs(A=>A.currentAgentName||""),p=Fe(A=>A.timeFormatPreference),y=Fe(A=>A.weekStartPreference),b=Fe(A=>A.isMobile),[h,N]=et.useState(()=>Gd(n,{providerID:d,modelID:f,variant:g,agent:x})),[w,S]=et.useState(!1),[v,j]=et.useState(!1),[k,D]=et.useState(!1),[T,C]=et.useState(""),[P,E]=et.useState(!1),[M,H]=et.useState(""),[R,_]=et.useState(!1),[z,V]=et.useState(""),[F,te]=et.useState(()=>{const A=Ho(n?.schedule?.date||"")||new Date;return new Date(A.getFullYear(),A.getMonth(),1)}),Z=et.useRef(null),ne=et.useRef(null),U=et.useRef(null),ie=et.useRef(null),oe=et.useRef(null),ge=et.useMemo(()=>zv(c),[c]),je=et.useMemo(()=>$v(c),[c]),Se=et.useMemo(()=>p==="24h"?!0:p==="12h"?!1:ge,[p,ge]),re=et.useMemo(()=>y==="sunday"?0:y==="monday"?1:je,[y,je]),L=et.useMemo(()=>{const A=Wv(c);return Uv(Fm.map(K=>({value:K,label:A[K]||""})),re)},[c,re]);et.useEffect(()=>{e&&(l({source:"scheduledTaskEditor"}),u({source:"scheduledTaskEditor"}))},[e,l,u]),et.useEffect(()=>{if(!e)return;N(Gd(n,{providerID:d,modelID:f,variant:g,agent:x}));const A=Ho(n?.schedule?.date||"")||new Date;te(new Date(A.getFullYear(),A.getMonth(),1)),j(!1),E(!1),D(!1),H(""),C("")},[e,n,d,f,g,x]),et.useEffect(()=>{if(!v)return;const A=K=>{Z.current&&!Z.current.contains(K.target)&&j(!1)};return document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[v]);const $=et.useMemo(()=>{const K=m.find(pe=>pe.id===h.execution.providerID)?.models?.find(pe=>pe.id===h.execution.modelID);return K?.variants?Object.keys(K.variants):[]},[m,h.execution.providerID,h.execution.modelID]),q=$.length>0,he=et.useMemo(()=>!q||!h.execution.variant?"__default":$.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,q,$]);et.useEffect(()=>{q||!h.execution.variant||N(A=>({...A,execution:{...A.execution,variant:""}}))},[q,h.execution.variant]);const de=et.useCallback((A,K)=>{N(pe=>{const _e=new Set(pe.schedule.weekdays);return K?_e.add(A):_e.delete(A),{...pe,schedule:{...pe.schedule,weekdays:Array.from(_e).sort((We,Le)=>We-Le)}}})},[]),we=et.useCallback((A,K)=>{N(pe=>{const _e=pe.schedule.times.slice();return _e[A]=K,{...pe,schedule:{...pe.schedule,times:_e}}})},[]),be=et.useCallback(A=>{N(K=>{const pe=K.schedule.times.filter((_e,We)=>We!==A);return{...K,schedule:{...K.schedule,times:pe.length>0?pe:["09:00"]}}})},[]),De=et.useCallback(()=>{N(A=>({...A,schedule:{...A.schedule,times:[...A.schedule.times,"12:00"]}}))},[]),le=et.useMemo(()=>Hv(),[]),ke=et.useMemo(()=>Ud(le),[le]),ue=et.useMemo(()=>{const A=Ho(h.schedule.onceDate);return A?Hd(A,le)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format(A):null},[h.schedule.onceDate,c,i,le]),ve=et.useMemo(()=>Ud(F).getTime()<=ke.getTime(),[F,ke]),G=et.useMemo(()=>L.map(A=>A.label),[L]),Ae=et.useCallback(A=>{N(K=>({...K,schedule:{...K.schedule,onceDate:A}}))},[]),ce=et.useCallback((A,K)=>{if(A.startsWith("/")){const Le=A.indexOf(" "),rt=A.indexOf(`
162
- `),yt=Math.min(Le===-1?A.length:Le,rt===-1?A.length:rt);if(K<=yt&&Le===-1){H(A.substring(1,yt)),E(!0),D(!1),_(!1);return}}E(!1);const pe=A.substring(0,K),_e=pe.lastIndexOf("#");if(_e!==-1){const Le=_e>0?pe[_e-1]:null,rt=pe.substring(_e+1);if((!Le||/\s/.test(Le))&&!rt.includes(" ")&&!rt.includes(`
163
- `)){V(rt),_(!0),D(!1);return}}_(!1);const We=pe.lastIndexOf("@");if(We!==-1){const Le=We>0?pe[We-1]:null,rt=pe.substring(We+1);(!Le||/\s/.test(Le))&&!rt.includes(" ")&&!rt.includes(`
164
- `)?(C(rt),D(!0)):D(!1);return}D(!1)},[]),fe=et.useCallback(A=>{N(K=>({...K,execution:{...K.execution,prompt:A}}))},[]),Ee=et.useCallback(A=>{const K=h.execution.prompt,_e=ne.current?.selectionStart??K.length,Le=K.substring(0,_e).lastIndexOf("@"),rt=A.relativePath&&A.relativePath.trim().length>0?A.relativePath.trim():A.path||A.name,yt=Le!==-1?Le:_e,Dt=`${K.substring(0,yt)}@${rt} ${K.substring(_e)}`,st=yt+rt.length+2;fe(Dt),D(!1),C(""),requestAnimationFrame(()=>{const Pe=ne.current;Pe&&(Pe.selectionStart=st,Pe.selectionEnd=st,Pe.focus()),ce(Dt,st)})},[h.execution.prompt,fe,ce]),me=et.useCallback(A=>{const K=h.execution.prompt,_e=ne.current?.selectionStart??K.length,Le=K.substring(0,_e).lastIndexOf("@"),rt=Le!==-1?Le:_e,yt=`${K.substring(0,rt)}@${A} ${K.substring(_e)}`,Dt=rt+A.length+2;fe(yt),D(!1),C(""),requestAnimationFrame(()=>{const st=ne.current;st&&(st.selectionStart=Dt,st.selectionEnd=Dt,st.focus()),ce(yt,Dt)})},[h.execution.prompt,fe,ce]),B=et.useCallback(A=>{const K=`/${A.name} `;fe(K),E(!1),H(""),_(!1),requestAnimationFrame(()=>{const pe=ne.current;pe&&(pe.focus(),pe.selectionStart=pe.value.length,pe.selectionEnd=pe.value.length),ce(K,K.length)})},[fe,ce]),ye=et.useCallback((A,K)=>{const pe=h.execution.prompt,We=ne.current?.selectionStart??pe.length,rt=pe.substring(0,We).lastIndexOf("#"),yt=rt!==-1?rt:We,Dt=`${pe.substring(0,yt)}#${K} ${pe.substring(We)}`,st=yt+K.length+2;fe(Dt),_(!1),V(""),requestAnimationFrame(()=>{const Pe=ne.current;Pe&&(Pe.selectionStart=st,Pe.selectionEnd=st,Pe.focus()),ce(Dt,st)})},[h.execution.prompt,fe,ce]),Oe=et.useCallback(A=>{if(P&&ie.current&&(A.key==="Enter"||A.key==="ArrowUp"||A.key==="ArrowDown"||A.key==="Escape"||A.key==="Tab")){A.preventDefault(),ie.current.handleKeyDown(A.key);return}k&&U.current&&(A.key==="Enter"||A.key==="ArrowUp"||A.key==="ArrowDown"||A.key==="Escape"||A.key==="Tab")&&(A.preventDefault(),U.current.handleKeyDown(A.key)),R&&oe.current&&(A.key==="Enter"||A.key==="ArrowUp"||A.key==="ArrowDown"||A.key==="Escape"||A.key==="Tab")&&(A.preventDefault(),oe.current.handleKeyDown(A.key))},[P,k,R]),Q=et.useCallback(async()=>{const A=Kv(h,i);if(A){ae.error(A);return}const K=qv(h.schedule.times),pe={...h.id?{id:h.id}:{},name:h.name.trim(),enabled:h.enabled,schedule:{kind:h.schedule.kind,timezone:h.schedule.timezone.trim(),...h.schedule.kind==="once"?{date:h.schedule.onceDate,time:h.schedule.onceTime}:{times:K,...h.schedule.kind==="weekly"?{weekdays:h.schedule.weekdays}:{}}},execution:{prompt:h.execution.prompt,providerID:h.execution.providerID,modelID:h.execution.modelID,...h.execution.variant.trim()?{variant:h.execution.variant.trim()}:{},...h.execution.agent.trim()?{agent:h.execution.agent.trim()}:{}},...h.state?{state:h.state}:{}};S(!0);try{await o(pe),r(!1)}catch(_e){ae.error(_e instanceof Error?_e.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[h,r,o,i]),Me=et.useId(),Re=et.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),Ne=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),Be=i("sessions.scheduledTasks.editor.description"),se=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ar,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(kn,{id:"sched-name",value:h.name,onChange:A=>N(K=>({...K,name:A.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Bn,{value:h.schedule.kind,onValueChange:A=>{N(K=>({...K,schedule:{...K.schedule,kind:A}}))},children:[s.jsx(Vn,{className:"w-fit max-w-full",children:s.jsx(Pn,{children:A=>i(A==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":A==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs($n,{children:[s.jsx(qs,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(qs,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(qs,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),h.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:Z,children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(A=>!A),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(I,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Ov(h.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),v?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>te(A=>Vd(A,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:ve,children:s.jsx(I,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}).format(F)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>te(A=>Vd(A,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:G.map((A,K)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:A},`${A}-${K}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:_v(F,re).map(({date:A,inCurrentMonth:K})=>{const pe=Bd(A),_e=pe===h.schedule.onceDate,We=Hd(A,le),Le=A.getTime()<le.getTime(),rt=_e?"bg-interactive-selection text-interactive-selection-foreground":Le?"text-muted-foreground/40":K?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{Le||(Ae(pe),j(!1))},disabled:Le,className:["h-8 rounded-md typography-ui-label",rt,We&&!_e?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",Le?"cursor-not-allowed opacity-45":""].join(" "),children:A.getDate()},pe)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:ue||""}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:()=>{Ae(Bd(le)),te(new Date(le.getFullYear(),le.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(Wd,{value:h.schedule.onceTime,use24Hour:Se,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:A=>N(K=>({...K,schedule:{...K.schedule,onceTime:A}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Bn,{value:h.schedule.timezone,onValueChange:A=>{N(K=>({...K,schedule:{...K.schedule,timezone:A}}))},children:[s.jsx(Vn,{className:"w-fit max-w-full",children:s.jsx(Pn,{})}),s.jsx($n,{children:Od.map(A=>s.jsx(qs,{value:A,children:A},A))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[h.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:L.map(A=>{const K=h.schedule.weekdays.includes(A.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",K?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(yi,{checked:K,onChange:pe=>de(A.value,pe),ariaLabel:A.label}),s.jsx("button",{type:"button",onClick:()=>de(A.value,!K),className:"group-hover:text-foreground",children:A.label})]},A.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((A,K)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Wd,{value:A,use24Hour:Se,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:pe=>we(K,pe)}),h.schedule.times.length>1?s.jsx(ze,{type:"button",size:"icon",variant:"ghost",onClick:()=>be(K),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]},K))}),s.jsx("div",{children:s.jsxs(ze,{type:"button",size:"sm",variant:"outline",onClick:De,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Bn,{value:h.schedule.timezone,onValueChange:A=>{N(K=>({...K,schedule:{...K.schedule,timezone:A}}))},children:[s.jsx(Vn,{className:"w-fit max-w-full",children:s.jsx(Pn,{})}),s.jsx($n,{children:Od.map(A=>s.jsx(qs,{value:A,children:A},A))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(ar,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Su,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(A,K)=>{N(pe=>({...pe,execution:{...pe.execution,providerID:A,modelID:K,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Bn,{value:he,disabled:!q,onValueChange:A=>{N(K=>({...K,execution:{...K.execution,variant:A==="__default"?"":A}}))},children:[s.jsx(Vn,{className:"w-fit max-w-full",children:s.jsx(Pn,{children:A=>A==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):A})}),s.jsxs($n,{children:[s.jsx(qs,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),$.map(A=>s.jsx(qs,{value:A,children:A},A))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(ar,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Nu,{agentName:h.execution.agent,filter:A=>ku(A.mode),onChange:A=>N(K=>({...K,execution:{...K.execution,agent:A}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ar,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(fi,{id:"sched-prompt",ref:ne,value:h.execution.prompt,onChange:A=>{const K=A.target.value;fe(K);const pe=A.target.selectionStart??K.length;ce(K,pe)},onKeyDown:Oe,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),P?s.jsx(Lu,{ref:ie,searchQuery:M,onCommandSelect:B,onClose:()=>E(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,k?s.jsx(Ou,{ref:U,searchQuery:T,onFileSelect:Ee,onAgentSelect:me,onClose:()=>D(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,R?s.jsx(_u,{ref:oe,searchQuery:z,onSnippetSelect:ye,onClose:()=>_(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),O=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(yi,{checked:h.enabled,onChange:A=>N(K=>({...K,enabled:A})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:w,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ze,{type:"button",size:"sm",onClick:Q,disabled:w,children:i(w?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return b?s.jsx(xa,{open:e,title:Ne,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:A=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:Ne}),A]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:Be})]}),footer:O,children:se}):s.jsx(Ks,{open:e,onOpenChange:A=>{!A&&Re()||r(A)},children:s.jsxs(Gs,{"aria-describedby":Me,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(cn,{id:Me,className:"sr-only",children:Be}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(Ys,{className:"typography-ui-label font-medium text-foreground",children:Ne}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:Be})]})}),s.jsx(ba,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:se})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:O})})]})})}function Jv(t){return Ki(t,{min:0,max:23})}function Qv(t,e){return Ki(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function Xv(t,e){const n=Number(t),r=Number(e),o=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,i=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(o).padStart(2,"0")}:${String(i).padStart(2,"0")}`}const Zv=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,o)=>r.localeCompare(o))},e0=(t,e)=>{const n=Zv(t).join(", ")||"--:--",r=o=>e(o===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":o===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":o===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":o===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":o===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":o===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":o===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const o=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(i=>r(i)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:o,time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:o,time:n})}if(t.schedule.kind==="once"){const o=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),i=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:o,time:i,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:o,time:i})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},t0=(t,e)=>!t||!Number.isFinite(t)?"":xu(t,e),Kd=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),o=6e4,i=60*o,c=24*i,l=n>=0;if(r<o)return e(l?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const f=Math.round(r/o);return l?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:f}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:f})}if(r<c){const f=Math.floor(r/i),g=Math.round(r%i/o),x=g>0?`${f}h ${g}m`:`${f}h`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:x}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:x})}const u=Math.floor(r/c),m=Math.round(r%c/i),d=m>0?`${u}d ${m}h`:`${u}d`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:d}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:d})},s0={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},n0=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function r0(){const{t}=Tt(),e=Fe(R=>R.isScheduledTasksDialogOpen),n=Fe(R=>R.setScheduledTasksDialogOpen),r=Fe(R=>R.isMobile),o=Fe(R=>R.timeFormatPreference),i=Es(R=>R.projects),c=Es(R=>R.getActiveProject()),l=sn(R=>R.homeDirectory),{currentTheme:u}=Tr(),[m,d]=et.useState(""),[f,g]=et.useState([]),[x,p]=et.useState(!0),[y,b]=et.useState(!1),[h,N]=et.useState(null),[w,S]=et.useState(null),v=et.useMemo(()=>i.find(R=>R.id===m)||null,[i,m]),j=et.useCallback(R=>{const _=R.label?.trim()||wi(R.path,l||void 0),z=R.icon?Yl[R.icon]:null,V=R.color?Sa[R.color]:void 0,F=z?s.jsx(I,{name:z,className:"h-3.5 w-3.5 shrink-0",style:V?{color:V}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:V?{color:V}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[R.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:R.iconBackground?{backgroundColor:R.iconBackground}:void 0,children:s.jsx(Na,{project:{id:R.id,iconImage:R.iconImage??null},options:{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground},className:"h-full w-full object-contain",fallback:F})}):F,s.jsx("span",{className:"truncate",children:_})]})},[l,u.metadata.variant,u.colors.surface.foreground]),k=et.useCallback(async(R,_)=>{if(!R){g([]);return}_?.silent||p(!0);try{const z=await Mv(R);z.sort((V,F)=>{if(V.enabled!==F.enabled)return V.enabled?-1:1;const te=V.name.localeCompare(F.name);return te!==0?te:(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(F.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),g(z)}catch(z){ae.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),_?.silent||g([])}finally{_?.silent||p(!1)}},[t]);et.useEffect(()=>{if(!e)return;const R=c?.id||i[0]?.id||"";d(R),R?k(R):(g([]),p(!1))},[e,c,i,k]),et.useEffect(()=>{if(!e)return;let R=null;const _=Mm(z=>{z.type==="scheduled-task-ran"&&z.projectId===m&&(R&&clearTimeout(R),R=setTimeout(()=>{k(m,{silent:!0})},400))});return()=>{R&&clearTimeout(R),_()}},[e,m,k]);const D=et.useCallback(async R=>{if(!m)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Ld(m,R),await k(m),ae.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[m,k,t]),T=et.useCallback(async(R,_)=>{if(m){S(R.id),g(z=>z.map(V=>V.id===R.id?{...V,enabled:_}:V));try{await Ld(m,{...R,enabled:_}),await k(m,{silent:!0})}catch(z){ae.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await k(m,{silent:!0})}finally{S(null)}}},[m,k,t]),C=et.useCallback(async R=>{if(!(!m||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:R.name})))){S(R.id);try{await Fv(m,R.id),await k(m,{silent:!0}),ae.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(z){ae.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{S(null)}}},[m,k,t]),P=et.useCallback(async R=>{if(m){S(R.id);try{await Lv(m,R.id),await Promise.all([k(m,{silent:!0}),dl()]),ae.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(_){ae.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{S(null)}}},[m,k,t]),E=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(Bn,{value:m||"__none",onValueChange:R=>{const _=R==="__none"?"":R;d(_),_?k(_):g([])},children:[s.jsx(Vn,{className:r?"w-full":void 0,children:v?s.jsx(Pn,{children:j(v)}):s.jsx(Pn,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs($n,{children:[i.length===0?s.jsx(qs,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(R=>s.jsx(qs,{value:R.id,children:j(R)},R.id))]})]})]}),M=()=>{N(null),b(!0)},H=s.jsxs("div",{className:"space-y-4",children:[r?E:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[E,s.jsxs(ze,{onClick:M,disabled:!m,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:x?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):f.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(m?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:f.map(R=>{const _=w===R.id,z=R.state?.lastStatus||"idle",V=s0[z],F=t(z==="success"?"sessions.scheduledTasks.dialog.status.success":z==="error"?"sessions.scheduledTasks.dialog.status.error":z==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),te=R.state?.nextRunAt,Z=R.state?.lastRunAt;return s.jsxs("div",{className:Te("rounded-lg border border-border p-4 transition-opacity",!R.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:R.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:e0(R,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),te?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Kd(te,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:t0(te,o)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),z==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):Z?s.jsxs(s.Fragment,{children:[V.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${V.tone})`},children:[s.jsx(I,{name:V.Icon,className:"h-3.5 w-3.5"}),F]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Kd(Z,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),R.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:n0("error"),children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:R.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:Te("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",R.enabled?"text-foreground":"text-muted-foreground",_&&"cursor-not-allowed opacity-50"),children:[s.jsx(yi,{checked:R.enabled,onChange:ne=>{T(R,ne)},ariaLabel:R.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:R.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:R.name}),disabled:_}),R.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(ze,{variant:"outline",size:"sm",onClick:()=>{P(R)},disabled:_,children:[s.jsx(I,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ze,{variant:"outline",size:"sm",onClick:()=>{N(R),b(!0)},disabled:_,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:R.name}),children:[s.jsx(I,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ze,{variant:"destructive",size:"sm",onClick:()=>{C(R)},disabled:_,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:R.name}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},R.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(xa,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:R=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),R]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ze,{className:"w-full",onClick:M,disabled:!m,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:H}):s.jsx(Ks,{open:e,onOpenChange:n,children:s.jsxs(Gs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(Xs,{children:[s.jsx(Ys,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(cn,{children:t("sessions.scheduledTasks.dialog.description")})]}),H]})}),s.jsx(Yv,{open:y,task:h,onOpenChange:b,onSave:D})]})}const i0=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(l=>as(l.path)??l.path).filter(l=>!!l)]),i=(l=>l.filter(u=>po(u,t.normalizedPath,r)))(e.archivedSessions),c=e.sessions.filter(l=>l.time?.archived||as(l.directory??null)?!1:po(l,t.normalizedPath,r));return Vi([...i,...c])},o0=t=>{const e=gt.c(12),{normalizedProjects:n,sessions:r,archivedSessions:o,availableWorktreesByProject:i,isVSCode:c,isSessionsLoading:l,foldersMap:u,createFolder:m,addSessionToFolder:d,cleanupSessions:f}=t;let g,x;e[0]!==d||e[1]!==o||e[2]!==i||e[3]!==f||e[4]!==m||e[5]!==u||e[6]!==l||e[7]!==c||e[8]!==n||e[9]!==r?(g=()=>{l||n.forEach(p=>{const y=Jl(p.normalizedPath),b=i0(p,{sessions:r,archivedSessions:o,availableWorktreesByProject:i,isVSCode:c}),h=new Set(b.map(a0)),N=u[y]??[],w=new Map(N.map(l0));b.forEach(S=>{const v=dh(S,p.normalizedPath),j=v.toLowerCase();let k=w.get(j);k||(k=m(y,v),w.set(j,k)),k.sessionIds.includes(S.id)||d(y,k.id,S.id)}),f(y,h)})},x=[n,r,o,i,c,l,u,m,d,f],e[0]=d,e[1]=o,e[2]=i,e[3]=f,e[4]=m,e[5]=u,e[6]=l,e[7]=c,e[8]=n,e[9]=r,e[10]=g,e[11]=x):(g=e[10],x=e[11]),a.useEffect(g,x)};function a0(t){return t.id}function l0(t){return[t.name.toLowerCase(),t]}const c0=t=>{const e=gt.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:o,availableWorktreesByProject:i,projectRepoStatus:c,projectRootBranches:l,lastRepoStatus:u,buildGroupedSessions:m,hasSessionSearchQuery:d,normalizedSessionSearchQuery:f,filterSessionNodesForSearch:g,buildGroupSearchText:x,foldersMap:p}=t;let y;if(e[0]!==i||e[1]!==m||e[2]!==o||e[3]!==r||e[4]!==u||e[5]!==n||e[6]!==c||e[7]!==l){let C;e[9]!==i||e[10]!==m||e[11]!==o||e[12]!==r||e[13]!==u||e[14]!==c||e[15]!==l?(C=P=>{const E=Vi([...r(P),...o(P)]),M=i.get(P.normalizedPath)??[],H=c.has(P.id)?!!c.get(P.id):u,R=m(E,P.normalizedPath,M,l.get(P.id)??null,H);return{project:P,groups:R}},e[9]=i,e[10]=m,e[11]=o,e[12]=r,e[13]=u,e[14]=c,e[15]=l,e[16]=C):C=e[16],y=n.map(C),e[0]=i,e[1]=m,e[2]=o,e[3]=r,e[4]=u,e[5]=n,e[6]=c,e[7]=l,e[8]=y}else y=e[8];const b=y,h=b;let N;if(e[17]!==x||e[18]!==g||e[19]!==p||e[20]!==d||e[21]!==f||e[22]!==h){e:{const C=new WeakMap;if(!d){N=C;break e}const P=E=>E.reduce((M,H)=>M+1+P(H.children),0);h.forEach(E=>{E.groups.forEach(M=>{const H=g(M.sessions,f),R=P(H),_=x(M).includes(f),z=as(M.directory??null),F=(z?p[z]??[]:[]).filter(te=>te.name.toLowerCase().includes(f)).length;C.set(M,{filteredNodes:H,matchedSessionCount:R,folderNameMatchCount:F,groupMatches:_,hasMatch:_||R>0||F>0})})}),N=C}e[17]=x,e[18]=g,e[19]=p,e[20]=d,e[21]=f,e[22]=h,e[23]=N}else N=e[23];const w=N;let S;e:{if(!d){S=h;break e}let C;if(e[24]!==w||e[25]!==h){let P;e[27]!==w?(P=E=>({...E,groups:E.groups.filter(M=>w.get(M)?.hasMatch===!0)}),e[27]=w,e[28]=P):P=e[28],C=h.map(P).filter(d0),e[24]=w,e[25]=h,e[26]=C}else C=e[26];S=C}const v=S,j=d?v:h;let k;e:{if(!d){k=0;break e}let C;if(e[29]!==w||e[30]!==j){let P;e[32]!==w?(P=(E,M)=>E+M.groups.reduce((H,R)=>{const _=w.get(R);if(!_)return H;const z=_.folderNameMatchCount+(_.groupMatches?1:0);return H+_.matchedSessionCount+z},0),e[32]=w,e[33]=P):P=e[33],C=j.reduce(P,0),e[29]=w,e[30]=j,e[31]=C}else C=e[31];k=C}const D=k;let T;return e[34]!==w||e[35]!==b||e[36]!==D||e[37]!==v||e[38]!==j||e[39]!==h?(T={projectSections:b,visibleProjectSections:h,groupSearchDataByGroup:w,searchableProjectSections:v,sectionsForRender:j,searchMatchCount:D},e[34]=w,e[35]=b,e[36]=D,e[37]=v,e[38]=j,e[39]=h,e[40]=T):T=e[40],T};function d0(t){return t.groups.length>0}const u0=t=>{const e=gt.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:i,currentSessionId:c,handleSessionSelect:l,newSessionDraftOpen:u,mobileVariant:m,openNewSessionDraft:d,setActiveMainTab:f,setSessionSwitcherOpen:g,sessions:x,worktreeMetadata:p}=t;let y,b;if(e[0]!==n){b=new Map,y=new Map;const P=(E,M,H,R)=>{b.has(E)||b.set(E,new Map);const _=b.get(E);R.forEach(z=>{const V=as(z.worktree?.path??z.session.directory??H??M);_.set(z.session.id,{directory:V}),y.has(E)||y.set(E,{id:z.session.id,directory:V}),z.children.length>0&&P(E,M,V,z.children)})};n.forEach(E=>{E.groups.forEach(M=>{P(E.project.id,E.project.normalizedPath,M.directory,M.sessions)})}),e[0]=n,e[1]=y,e[2]=b}else y=e[1],b=e[2];let h;e[3]!==y||e[4]!==b?(h={metaByProject:b,firstSessionByProject:y},e[3]=y,e[4]=b,e[5]=h):h=e[5];const N=h,w=a.useRef(null);let S,v;e[6]!==r||e[7]!==o||e[8]!==c||e[9]!==l||e[10]!==m||e[11]!==u||e[12]!==d||e[13]!==n||e[14]!==N||e[15]!==f||e[16]!==i||e[17]!==g?(S=()=>{if(!r||u||w.current===r)return;const P=n.find(V=>V.project.id===r);if(!P)return;w.current=r;const E=N.metaByProject.get(r);if(c&&E&&E.has(c)){i(V=>{if(V.get(r)===c)return V;const F=new Map(V);return F.set(r,c),F});return}if(!E||E.size===0){f("chat"),m&&g(!1),d({directoryOverride:P.project.normalizedPath});return}const M=o.get(r),H=M&&E.has(M)?M:null,R=N.firstSessionByProject.get(r)?.id??null,_=H??R;if(!_||_===c)return;const z=E.get(_)?.directory??null;l(_,z,!1,r)},v=[r,o,c,l,u,m,d,n,N,f,g,i],e[6]=r,e[7]=o,e[8]=c,e[9]=l,e[10]=m,e[11]=u,e[12]=d,e[13]=n,e[14]=N,e[15]=f,e[16]=i,e[17]=g,e[18]=S,e[19]=v):(S=e[18],v=e[19]),a.useLayoutEffect(S,v);let j,k;e[20]!==r||e[21]!==c||e[22]!==N||e[23]!==i?(j=()=>{if(!r||!c)return;const P=N.metaByProject.get(r);!P||!P.has(c)||i(E=>{if(E.get(r)===c)return E;const M=new Map(E);return M.set(r,c),M})},k=[r,c,N,i],e[20]=r,e[21]=c,e[22]=N,e[23]=i,e[24]=j,e[25]=k):(j=e[24],k=e[25]),a.useEffect(j,k);let D;if(e[26]!==c||e[27]!==x||e[28]!==p){e:{if(!c){D=null;break e}const P=p.get(c)?.path;if(P){D=as(P)??P;break e}let E;e[30]!==c?(E=H=>H.id===c,e[30]=c,e[31]=E):E=e[31];const M=x.find(E);if(!M){D=null;break e}D=as(M.directory??null)}e[26]=c,e[27]=x,e[28]=p,e[29]=D}else D=e[29];const T=D;let C;return e[32]!==T?(C={currentSessionDirectory:T},e[32]=T,e[33]=C):C=e[33],C},m0=t=>{const e=gt.c(4);let n;e[0]!==t?(n=(i,c)=>{const l=t.get(i);if(!l||l.length===0)return c;const u=new Map(c.map(f0)),m=[];return l.forEach(d=>{const f=u.get(d);f&&(m.push(f),u.delete(d))}),c.forEach(d=>{u.has(d.id)&&m.push(d)}),m},e[0]=t,e[1]=n):n=e[1];const r=n;let o;return e[2]!==r?(o={getOrderedGroups:r},e[2]=r,e[3]=o):o=e[3],o};function f0(t){return[t.id,t]}const Eo=t=>!!t.time?.archived,h0=t=>{const{t:e}=Tt(),n=a.useCallback(c=>[c.label,c.branch??"",c.description??"",c.directory??""].join(" ").toLowerCase(),[]),r=a.useCallback(c=>{const l=as(c.directory??null)??"";return`${(c.title||e("sessions.sidebar.session.untitled")).trim()} ${l}`.toLowerCase()},[e]),o=a.useCallback((c,l)=>l?c.flatMap(u=>{if(r(u.session).includes(l))return[u];const d=o(u.children,l);return d.length===0?[]:[{...u,children:d}]}):c,[r]),i=a.useCallback((c,l,u,m,d)=>{const f=as(l??null),g=Vi(c).sort((P,E)=>Ti(P,E,t.pinnedSessionIds)),x=new Map(g.map(P=>[P.id,P])),p=new Map;g.forEach(P=>{const E=P.parentID;if(!E)return;const M=x.get(E);if(!M||Eo(M)!==Eo(P))return;const H=p.get(E)??[];H.push(P),p.set(E,H)}),p.forEach(P=>P.sort((E,M)=>Ti(E,M,t.pinnedSessionIds)));const y=new Map;u.forEach(P=>{if(P.path){const E=as(P.path)??P.path;y.set(E,P)}});const b=P=>{const E=as(P.directory??null),M=t.worktreeMetadata.get(P.id)??null;if(M)return M;if(E){const H=y.get(E)??null;if(H&&E!==f)return H}return null},h=P=>{const E=p.get(P.id)??[];return{session:P,children:E.map(M=>h(M)),worktree:b(P)}},N=g.filter(P=>{const E=P.parentID;if(!E)return!0;const M=x.get(E);return M?Eo(M)!==Eo(P):!0}),w=new Map,S="__archived__",v=P=>{if(P.time?.archived)return S;const M=as(t.worktreeMetadata.get(P.id)?.path??null)??hi(P);return M?M!==f&&y.has(M)?M:M===f?f??"__project_root__":S:S};N.forEach(P=>{const E=h(P),M=v(P);w.has(M)||w.set(M,[]),w.get(M)?.push(E)});const j=f??"__project_root__",k=[{id:"root",label:d&&m&&m!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:m}):e("sessions.sidebar.grouping.projectRoot"),branch:m??null,description:f?Zo(f,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:w.get(j)??[]}],D=new Map;u.forEach(P=>{const E=as(P.path)??P.path,M=w.get(E)??[],H=M.length>0,R=M.reduce((_,z)=>{const V=Number(z.session.time?.updated??z.session.time?.created??0);return Number.isFinite(V)?Math.max(_,V):_},0);D.set(E,{hasActiveSession:H,lastUpdatedAt:R})}),[...u].sort((P,E)=>{const M=as(P.path)??P.path,H=as(E.path)??E.path,R=D.get(M)??{hasActiveSession:!1,lastUpdatedAt:0},_=D.get(H)??{hasActiveSession:!1,lastUpdatedAt:0};if(R.hasActiveSession!==_.hasActiveSession)return R.hasActiveSession?-1:1;if(R.hasActiveSession&&_.hasActiveSession)return _.lastUpdatedAt-R.lastUpdatedAt;const z=(P.label||P.branch||P.name||P.path||"").toLowerCase(),V=(E.label||E.branch||E.name||E.path||"").toLowerCase();return z.localeCompare(V)}).forEach(P=>{const E=as(P.path)??P.path,M=t.gitBranches.get(E)?.trim()||null,H=P.branch?.trim()||null,_=!!(M&&H&&P.label&&Sc(P.label)===Sc(H))?M:P.label||P.name||wi(E,t.homeDirectory)||E;k.push({id:`worktree:${E}`,label:_,branch:M||H,description:Zo(E,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:P,directory:E,folderScopeKey:E,sessions:w.get(E)??[]})});const C=w.get(S)??[];return C.length>0&&k.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&f?Jl(f):null,sessions:C}),k},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:i}},p0=t=>{const e=gt.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:o,sessionSearchContainerRef:i}=t;let c,l;e[0]!==n||e[1]!==o?(c=()=>{if(!n||typeof window>"u")return;const d=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(d)},l=[n,o],e[0]=n,e[1]=o,e[2]=c,e[3]=l):(c=e[2],l=e[3]),a.useEffect(c,l);let u,m;e[4]!==n||e[5]!==i||e[6]!==r?(u=()=>{if(!n||typeof document>"u")return;const d=f=>{i.current&&(i.current.contains(f.target)||r(!1))};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},m=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=u,e[8]=m):(u=e[7],m=e[8]),a.useEffect(u,m)},g0=t=>{const e=gt.c(42),{t:n}=Tt(),[r,o]=a.useState(null),i=a.useRef(null);let c,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{i.current&&clearTimeout(i.current)},l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),a.useEffect(c,l);let u;e[2]!==t?(u=(_,z,V,F)=>{if(V)return;const te=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(F&&F!==t.activeProjectId&&t.setActiveProjectIdOnly(F),z&&z!==t.currentDirectory&&t.setDirectory(z,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),_===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(_),te();return}t.setCurrentSession(_,z??null),t.onSessionSelected?.(_),te()},e[2]=t,e[3]=u):u=e[3];const m=u;let d;e[4]!==t?(d=(_,z)=>{t.setEditingId(_),t.setEditTitle(z)},e[4]=t,e[5]=d):d=e[5];const f=d;let g;e[6]!==t?(g=async()=>{if(!t.editingId)return;const _=t.editTitle.trim();_&&await t.updateSessionTitle(t.editingId,_),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=g):g=e[7];const x=g;let p;e[8]!==t?(p=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=p):p=e[9];const y=p;let b;e[10]!==t||e[11]!==n?(b=async _=>{const z=await t.shareSession(_.id);z&&z.share?.url?ae.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):ae.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=b):b=e[12];const h=b;let N;e[13]!==n?(N=(_,z)=>{cr(_).then(V=>{if(!V.ok){ae.error(n("sessions.sidebar.session.share.copyUrlError"));return}o(z),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{o(null),i.current=null},2e3)}).catch(()=>{ae.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=N):N=e[14];const w=N;let S;e[15]!==t||e[16]!==n?(S=async _=>{await t.unshareSession(_)?ae.success(n("sessions.sidebar.session.unshare.success")):ae.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=S):S=e[17];const v=S;let j;e[18]!==t.childrenMap?(j=_=>{const z=[],V=F=>{(t.childrenMap.get(F)??[]).forEach(Z=>{z.push(Z),V(Z.id)})};return V(_),z},e[18]=t.childrenMap,e[19]=j):j=e[19];const k=j,D=b0;let T;e[20]!==t||e[21]!==k||e[22]!==n?(T=async(_,z,V)=>{const F=z?.archivedBucket===!0,te=V?.descendantIds??D(k(_.id),F).map(y0);if(te.length===0){(F?await t.deleteSession(_.id):await t.archiveSession(_.id))?ae.success(n(F?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):ae.error(n(F?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const Z=[_.id,...te];if(F){const{deletedIds:ie,failedIds:oe}=await t.deleteSessions(Z);ie.length>0&&ae.success(ie.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:ie.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:ie.length})),oe.length>0&&ae.error(oe.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:oe.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:oe.length}));return}const{archivedIds:ne,failedIds:U}=await t.archiveSessions(Z);ne.length>0&&ae.success(ne.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:ne.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:ne.length})),U.length>0&&ae.error(U.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:U.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:U.length}))},e[20]=t,e[21]=k,e[22]=n,e[23]=T):T=e[23];const C=T;let P;e[24]!==t||e[25]!==k||e[26]!==C?(P=(_,z)=>{const V=z?.archivedBucket===!0,F=D(k(_.id),V).map(w0);if(!t.showDeletionDialog){C(_,z,{descendantIds:F});return}t.setDeleteSessionConfirm({session:_,descendantCount:F.length,descendantIds:F,archivedBucket:V})},e[24]=t,e[25]=k,e[26]=C,e[27]=P):P=e[27];const E=P;let M;e[28]!==t||e[29]!==C?(M=async()=>{if(!t.deleteSessionConfirm)return;const{session:_,archivedBucket:z,descendantIds:V}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await C(_,{archivedBucket:z},{descendantIds:V})},e[28]=t,e[29]=C,e[30]=M):M=e[30];const H=M;let R;return e[31]!==H||e[32]!==r||e[33]!==y||e[34]!==w||e[35]!==E||e[36]!==x||e[37]!==f||e[38]!==m||e[39]!==h||e[40]!==v?(R={copiedSessionId:r,handleSessionSelect:m,handleSessionDoubleClick:f,handleSaveEdit:x,handleCancelEdit:y,handleShareSession:h,handleCopyShareUrl:w,handleUnshareSession:v,handleDeleteSession:E,confirmDeleteSession:H},e[31]=H,e[32]=r,e[33]=y,e[34]=w,e[35]=E,e[36]=x,e[37]=f,e[38]=m,e[39]=h,e[40]=v,e[41]=R):R=e[41],R};function x0(t){return!t.time?.archived}function b0(t,e){return e?t:t.filter(x0)}function y0(t){return t.id}function w0(t){return t.id}const v0=["project:active:","project:archived:","recent:active:","recent:archived:"],j0=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:o,sessions:i,setPinnedSessionIds:c,groupOrderByProject:l,activeSessionByProject:u,collapsedGroups:m,setExpandedParents:d,setCollapsedProjects:f}=t,g=a.useRef(null),x=a.useRef(null),p=a.useCallback(()=>{if(e)return;const b=x.current;if(x.current=null,g.current=null,!b)return;const{projects:h}=Es.getState(),N=h.map(w=>({...w,sidebarCollapsed:b.has(w.id)}));ua({projects:N}).catch(()=>{})},[e]),y=a.useCallback(b=>{typeof window>"u"||e||(x.current=b,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{p()},700))},[e,p]);return a.useEffect(()=>()=>{typeof window<"u"&&g.current!==null&&window.clearTimeout(g.current),g.current=null,x.current=null},[]),a.useEffect(()=>{try{const b=r.getItem(o.sessionExpanded);if(b){const N=JSON.parse(b);Array.isArray(N)&&d(new Set(N.filter(w=>typeof w=="string")))}else{const N=r.getItem(o.sessionExpandedLegacy);if(N){try{const w=JSON.parse(N);if(Array.isArray(w)){const S=new Set;if(w.forEach(v=>{typeof v!="string"||v.length===0||v0.forEach(j=>S.add(`${j}${v}`))}),S.size>0){d(S);try{r.setItem(o.sessionExpanded,JSON.stringify(Array.from(S)))}catch{}}}}catch{}try{r.removeItem?.(o.sessionExpandedLegacy)}catch{}}}const h=r.getItem(o.projectCollapse);if(h){const N=JSON.parse(h);Array.isArray(N)&&f(new Set(N.filter(w=>typeof w=="string")))}}catch{}},[o.projectCollapse,o.sessionExpanded,o.sessionExpandedLegacy,r,f,d]),a.useEffect(()=>{if(!n)return;const b=new Set(i.map(h=>h.id));c(h=>{let N=!1;const w=new Set;return h.forEach(S=>{b.has(S)?w.add(S):N=!0}),N?w:h})},[n,i,c]),a.useEffect(()=>{try{const b=Object.fromEntries(l.entries());r.setItem(o.groupOrder,JSON.stringify(b))}catch{}},[l,o.groupOrder,r]),a.useEffect(()=>{try{const b=Object.fromEntries(u.entries());r.setItem(o.projectActiveSession,JSON.stringify(b))}catch{}},[u,o.projectActiveSession,r]),a.useEffect(()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(m)))}catch{}},[m,o.groupCollapse,r]),{scheduleCollapsedProjectsPersist:y}},S0=t=>{const e=gt.c(26),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:o,setProjectRootBranches:i}=t,{git:c}=Wn(),l=_s(N0);let u,m;e[0]!==l||e[1]!==c||e[2]!==n||e[3]!==o?(u=()=>{if(!c||n.length===0){o(new Map);return}n.forEach(N=>{l(N.normalizedPath,c)})},m=[n,c,l,o],e[0]=l,e[1]=c,e[2]=n,e[3]=o,e[4]=u,e[5]=m):(u=e[4],m=e[5]),a.useEffect(u,m);let d,f;e[6]!==r||e[7]!==n||e[8]!==o?(d=()=>{const N=new Map;n.forEach(w=>{N.set(w.id,r.get(w.normalizedPath)?.isGitRepo??null)}),o(N)},f=[n,r,o],e[6]=r,e[7]=n,e[8]=o,e[9]=d,e[10]=f):(d=e[9],f=e[10]),a.useEffect(d,f);let g;if(e[11]!==r||e[12]!==n){let N;e[14]!==r?(N=w=>{const S=r.get(w.normalizedPath)?.branch??"";return`${w.id}:${S}`},e[14]=r,e[15]=N):N=e[15],g=n.map(N).join("|"),e[11]=r,e[12]=n,e[13]=g}else g=e[13];const x=g;let p;e[16]===Symbol.for("react.memo_cache_sentinel")?(p=new Map,e[16]=p):p=e[16];const y=a.useRef(p);let b;e[17]!==r||e[18]!==n||e[19]!==i?(b=()=>{let N=!1;const w=setTimeout(()=>{(async()=>{const v=new Set(n.map(k0));for(const T of y.current.keys())v.has(T)||y.current.delete(T);const j=n.filter(T=>{const C=r.get(T.normalizedPath);if(C?.isGitRepo===!1)return y.current.delete(T.id),!1;if(C?.isGitRepo!==!0||C.branch===null)return!1;const P=C.branch.trim(),E=`${T.normalizedPath}\0${P}`,M=y.current.get(T.id);return M===void 0||M!==E});if(j.length===0)return;const k=await nm(j,2,async T=>{const C=r.get(T.normalizedPath)?.branch?.trim()??"",P=`${T.normalizedPath}\0${C}`,E=await wa(T.normalizedPath,C?{knownBranch:C}:void 0).catch(C0);return{id:T.id,inputKey:P,branch:E}});if(N)return;const D=k.filter(A0);D.length!==0&&(i(T=>{const C=new Map(T);return D.forEach(P=>{const{id:E,branch:M}=P;M&&C.set(E,M)}),C}),D.forEach(T=>{const{id:C,inputKey:P}=T;y.current.set(C,P)}))})()},150);return()=>{N=!0,clearTimeout(w)}},e[17]=r,e[18]=n,e[19]=i,e[20]=b):b=e[20];let h;e[21]!==r||e[22]!==n||e[23]!==x||e[24]!==i?(h=[n,x,r,i],e[21]=r,e[22]=n,e[23]=x,e[24]=i,e[25]=h):h=e[25],a.useEffect(b,h)};function N0(t){return t.ensureStatus}function k0(t){return t.id}function C0(){return null}function A0(t){return t.branch}const D0=t=>{const e=gt.c(14),{isVSCode:n,sessions:r,archivedSessions:o,availableWorktreesByProject:i}=t;let c;e[0]!==r?(c=new Map,r.forEach(x=>{const p=hi(x);if(!p)return;const y=c.get(p)??[];y.push(x),c.set(p,y)}),e[0]=r,e[1]=c):c=e[1];const l=c;let u;e[2]!==i||e[3]!==n||e[4]!==l?(u=x=>{const p=n?[]:i.get(x.normalizedPath)??[],y=[x.normalizedPath,...p.map(I0).filter(P0)],b=new Set,h=[];return y.forEach(N=>{(l.get(N)??[]).forEach(S=>{b.has(S.id)||(b.add(S.id),h.push(S))})}),h},e[2]=i,e[3]=n,e[4]=l,e[5]=u):u=e[5];const m=u;let d;e[6]!==o||e[7]!==i||e[8]!==n||e[9]!==r?(d=x=>{if(n){const w=o.filter(v=>{const j=as(v.directory??null),k=as(v.project?.worktree??null);return j?j===x.normalizedPath:k===x.normalizedPath}),S=r.filter(v=>v.time?.archived||as(v.directory??null)?!1:as(v.project?.worktree??null)===x.normalizedPath);return Vi([...w,...S])}const p=n?[]:i.get(x.normalizedPath)??[],y=new Set([x.normalizedPath,...p.map(T0).filter(E0)]),h=(w=>w.filter(S=>po(S,x.normalizedPath,y)))(o),N=r.filter(w=>{if(w.time?.archived||as(w.directory??null))return!1;const v=as(w.project?.worktree??null);return v?v===x.normalizedPath||v.startsWith(`${x.normalizedPath}/`):!1});return Vi([...h,...N])},e[6]=o,e[7]=i,e[8]=n,e[9]=r,e[10]=d):d=e[10];const f=d;let g;return e[11]!==f||e[12]!==m?(g={getSessionsForProject:m,getArchivedSessionsForProject:f},e[11]=f,e[12]=m,e[13]=g):g=e[13],g};function I0(t){return as(t.path)??t.path}function P0(t){return!!t}function T0(t){return as(t.path)??t.path}function E0(t){return!!t}const R0=t=>{const e=gt.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:o,normalizedProjects:i,isVSCode:c,availableWorktreesByProject:l,cleanupSessions:u}=t;let m,d;e[0]!==o||e[1]!==l||e[2]!==u||e[3]!==n||e[4]!==c||e[5]!==i||e[6]!==r?(m=()=>{if(n)return;const f=new Map;r.forEach(p=>{const y=as(p.directory??null);if(!y)return;const b=f.get(y);if(b){b.add(p.id);return}f.set(y,new Set([p.id]))}),i.forEach(p=>{const y=Jl(p.normalizedPath),b=c?[]:l.get(p.normalizedPath)??[],h=new Set([p.normalizedPath,...b.map(M0).filter(F0)]),N=Vi([...o,...r.filter(w=>w.time?.archived||as(w.directory??null)?!1:po(w,p.normalizedPath,h))]).filter(w=>po(w,p.normalizedPath,h));f.set(y,new Set(N.map(L0)))});const g=En.getState().foldersMap;new Set([...Object.keys(g),...f.keys()]).forEach(p=>{u(p,f.get(p)??new Set)})},d=[o,l,u,n,c,i,r],e[0]=o,e[1]=l,e[2]=u,e[3]=n,e[4]=c,e[5]=i,e[6]=r,e[7]=m,e[8]=d):(m=e[7],d=e[8]),a.useEffect(m,d)};function M0(t){return as(t.path)??t.path}function F0(t){return!!t}function L0(t){return t.id}const O0=t=>{const e=gt.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:o}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[c,l]=a.useState(i);let u;e[1]!==n||e[2]!==o?(u=()=>{if(!n)return;const d=new IntersectionObserver(f=>{f.forEach(g=>{const x=g.target.dataset.projectId;x&&l(p=>{const y=new Set(p);return g.isIntersecting?y.delete(x):y.add(x),y})})},{threshold:0});return o.current.forEach(f=>{f&&d.observe(f)}),()=>d.disconnect()},e[1]=n,e[2]=o,e[3]=u):u=e[3];let m;return e[4]!==n||e[5]!==o||e[6]!==r?(m=[n,o,r],e[4]=n,e[5]=o,e[6]=r,e[7]=m):m=e[7],a.useEffect(u,m),c},_0=/^#(?:[\da-fA-F]{3}|[\da-fA-F]{6})$/,Ya=t=>{if(!t)return null;const e=t.trim();return e&&_0.test(e)?e.toLowerCase():null},B0=t=>{const e=gt.c(198),{open:n,onOpenChange:r,projectId:o,projectName:i,projectPath:c,initialIcon:l,initialColor:u,initialIconBackground:m,onSave:d}=t,f=l===void 0?null:l,g=u===void 0?null:u,x=m===void 0?null:m,{t:p}=Tt(),y=Es(V0),b=Es($0),h=Es(z0);let N;e[0]!==o?(N=Wt=>Wt.projects.find(gs=>gs.id===o)?.iconImage??null,e[0]=o,e[1]=N):N=e[1];const w=Es(N),{currentTheme:S}=Tr(),[v,j]=a.useState(i),[k,D]=a.useState(f),[T,C]=a.useState(g);let P;e[2]!==x?(P=Ya(x),e[2]=x,e[3]=P):P=e[3];const[E,M]=a.useState(P),[H,R]=a.useState(!1),[_,z]=a.useState(!1),[V,F]=a.useState(!1),[te,Z]=a.useState(!1),[ne,U]=a.useState(null),[ie,oe]=a.useState(null),[ge,je]=a.useState(!1),Se=a.useRef(null);let re;e[4]===Symbol.for("react.memo_cache_sentinel")?(re=()=>{U(null),oe(W0)},e[4]=re):re=e[4];const L=re;let $,q;e[5]!==g||e[6]!==f||e[7]!==x||e[8]!==n||e[9]!==i?($=()=>{n&&(j(i),D(f),C(g),M(Ya(x)),Z(!1),L(),je(!1))},q=[n,i,f,g,x,L],e[5]=g,e[6]=f,e[7]=x,e[8]=n,e[9]=i,e[10]=$,e[11]=q):($=e[10],q=e[11]),a.useEffect($,q);let he,de;e[12]===Symbol.for("react.memo_cache_sentinel")?(de=()=>()=>{L()},he=[L],e[12]=he,e[13]=de):(he=e[12],de=e[13]),a.useEffect(de,he);let we,be,De;if(e[14]!==T||e[15]!==w||e[16]!==k||e[17]!==E||e[18]!==v||e[19]!==r||e[20]!==d||e[21]!==te||e[22]!==ne||e[23]!==o||e[24]!==b||e[25]!==p||e[26]!==y){let Wt;e[30]!==T||e[31]!==k||e[32]!==E||e[33]!==v||e[34]!==r||e[35]!==d||e[36]!==te||e[37]!==ne||e[38]!==o||e[39]!==b||e[40]!==p||e[41]!==y?(Wt=async()=>{const gs=v.trim();if(!gs)return;if(ne){R(!0);const Vt=await y(o,ne);if(R(!1),!Vt.ok){ae.error(Vt.error||p("projectEditDialog.toast.failedToUploadIcon"));return}ae.success(p("projectEditDialog.toast.iconUpdated")),L(),Z(!1)}const Ms=te&&De;if(Ms){z(!0);const Vt=await b(o);if(z(!1),!Vt.ok){ae.error(Vt.error||p("projectEditDialog.toast.failedToRemoveIcon"));return}ae.success(p("projectEditDialog.toast.iconRemoved")),Z(!1),M(null)}d({label:gs,icon:k,color:T,iconBackground:Ya(Ms?null:E)}),r(!1)},e[30]=T,e[31]=k,e[32]=E,e[33]=v,e[34]=r,e[35]=d,e[36]=te,e[37]=ne,e[38]=o,e[39]=b,e[40]=p,e[41]=y,e[42]=Wt):Wt=e[42],be=Wt,we=T?Sa[T]??null:null,De=!!w,e[14]=T,e[15]=w,e[16]=k,e[17]=E,e[18]=v,e[19]=r,e[20]=d,e[21]=te,e[22]=ne,e[23]=o,e[24]=b,e[25]=p,e[26]=y,e[27]=we,e[28]=be,e[29]=De}else we=e[27],be=e[28],De=e[29];const le=!!(ne&&ie),ke=w?.source==="custom",ue=De&&!te||le,ve=ue,Ae=!ge&&(le||De&&!te);let ce;e[43]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>{je(!1)},e[43]=ce):ce=e[43];const fe=w?.updatedAt;let Ee;e[44]!==o||e[45]!==fe?(Ee=[o,fe],e[44]=o,e[45]=fe,e[46]=Ee):Ee=e[46],a.useEffect(ce,Ee);let me;e[47]!==H||e[48]!==o?(me=Wt=>{!o||!Wt||H||(Z(!1),je(!1),U(Wt),oe(gs=>(gs&&URL.revokeObjectURL(gs),URL.createObjectURL(Wt))))},e[47]=H,e[48]=o,e[49]=me):me=e[49];const B=me;let ye;e[50]!==le||e[51]!==ve||e[52]!==De||e[53]!==_||e[54]!==o?(ye=()=>{!o||!ve||_||(le&&L(),Z(!!De),je(!1))},e[50]=le,e[51]=ve,e[52]=De,e[53]=_,e[54]=o,e[55]=ye):ye=e[55];const Oe=ye;let Q;e[56]!==h||e[57]!==V||e[58]!==o||e[59]!==p?(Q=async()=>{!o||V||(L(),Z(!1),je(!1),F(!0),h(o).then(Wt=>{if(!Wt.ok){ae.error(Wt.error||p("projectEditDialog.toast.failedToDiscoverIcon"));return}if(Wt.skipped){ae.success(p("projectEditDialog.toast.customIconAlreadySet"));return}ae.success(p("projectEditDialog.toast.iconDiscovered"))}).finally(()=>{F(!1)}))},e[56]=h,e[57]=V,e[58]=o,e[59]=p,e[60]=Q):Q=e[60];const Me=Q;let Re;e[61]!==p?(Re=p("projectEditDialog.title"),e[61]=p,e[62]=Re):Re=e[62];let Ne;e[63]!==Re?(Ne=s.jsx(Xs,{className:"min-w-0",children:s.jsx(Ys,{children:Re})}),e[63]=Re,e[64]=Ne):Ne=e[64];let Be;e[65]!==p?(Be=p("projectEditDialog.field.name"),e[65]=p,e[66]=Be):Be=e[66];let se;e[67]!==Be?(se=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:Be}),e[67]=Be,e[68]=se):se=e[68];let O;e[69]===Symbol.for("react.memo_cache_sentinel")?(O=Wt=>j(Wt.target.value),e[69]=O):O=e[69];let A;e[70]!==p?(A=p("projectEditDialog.field.namePlaceholder"),e[70]=p,e[71]=A):A=e[71];let K;e[72]!==be?(K=Wt=>{Wt.key==="Enter"&&(Wt.preventDefault(),be())},e[72]=be,e[73]=K):K=e[73];let pe;e[74]!==v||e[75]!==A||e[76]!==K?(pe=s.jsx(kn,{value:v,onChange:O,placeholder:A,onKeyDown:K,autoFocus:!0}),e[74]=v,e[75]=A,e[76]=K,e[77]=pe):pe=e[77];let _e;e[78]!==c?(_e=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:c,children:c}),e[78]=c,e[79]=_e):_e=e[79];let We;e[80]!==se||e[81]!==pe||e[82]!==_e?(We=s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[se,pe,_e]}),e[80]=se,e[81]=pe,e[82]=_e,e[83]=We):We=e[83];let Le;e[84]!==p?(Le=p("projectEditDialog.field.color"),e[84]=p,e[85]=Le):Le=e[85];let rt;e[86]!==Le?(rt=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:Le}),e[86]=Le,e[87]=rt):rt=e[87];let yt;e[88]===Symbol.for("react.memo_cache_sentinel")?(yt=()=>C(null),e[88]=yt):yt=e[88];const Dt=T===null?"border-foreground scale-110":"border-border hover:border-border/80";let st;e[89]!==Dt?(st=Te("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",Dt),e[89]=Dt,e[90]=st):st=e[90];let Pe;e[91]!==p?(Pe=p("projectEditDialog.option.none"),e[91]=p,e[92]=Pe):Pe=e[92];let tt;e[93]===Symbol.for("react.memo_cache_sentinel")?(tt=s.jsx("span",{className:"w-4 h-0.5 bg-muted-foreground/40 rotate-45 rounded-full"}),e[93]=tt):tt=e[93];let Ye;e[94]!==st||e[95]!==Pe?(Ye=s.jsx("button",{type:"button",onClick:yt,className:st,title:Pe,children:tt}),e[94]=st,e[95]=Pe,e[96]=Ye):Ye=e[96];let nt;e[97]!==T?(nt=uh.map(Wt=>s.jsx("button",{type:"button",onClick:()=>C(Wt.key),className:Te("w-8 h-8 rounded-lg border-2 transition-all",T===Wt.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:Wt.cssVar},title:Wt.label},Wt.key)),e[97]=T,e[98]=nt):nt=e[98];let ft;e[99]!==Ye||e[100]!==nt?(ft=s.jsxs("div",{className:"flex gap-2 flex-wrap",children:[Ye,nt]}),e[99]=Ye,e[100]=nt,e[101]=ft):ft=e[101];let mt;e[102]!==rt||e[103]!==ft?(mt=s.jsxs("div",{className:"min-w-0 space-y-2",children:[rt,ft]}),e[102]=rt,e[103]=ft,e[104]=mt):mt=e[104];let ot;e[105]!==p?(ot=p("projectEditDialog.field.icon"),e[105]=p,e[106]=ot):ot=e[106];let It;e[107]!==ot?(It=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:ot}),e[107]=ot,e[108]=It):It=e[108];let dt;e[109]!==B?(dt=s.jsx("input",{ref:Se,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:Wt=>{const gs=Wt.target.files?.[0]??null;B(gs),Wt.currentTarget.value=""}}),e[109]=B,e[110]=dt):dt=e[110];let bt;e[111]===Symbol.for("react.memo_cache_sentinel")?(bt=()=>D(null),e[111]=bt):bt=e[111];const He=k===null?"border-foreground scale-110 bg-[var(--surface-elevated)]":"border-border hover:border-border/80";let Ze;e[112]!==He?(Ze=Te("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",He),e[112]=He,e[113]=Ze):Ze=e[113];let Ue;e[114]!==p?(Ue=p("projectEditDialog.option.none"),e[114]=p,e[115]=Ue):Ue=e[115];let jt;e[116]===Symbol.for("react.memo_cache_sentinel")?(jt=s.jsx("span",{className:"w-4 h-0.5 bg-muted-foreground/40 rotate-45 rounded-full"}),e[116]=jt):jt=e[116];let Ge;e[117]!==Ze||e[118]!==Ue?(Ge=s.jsx("button",{type:"button",onClick:bt,className:Ze,title:Ue,children:jt}),e[117]=Ze,e[118]=Ue,e[119]=Ge):Ge=e[119];let it;e[120]!==we||e[121]!==k?(it=mh.map(Wt=>{const gs=Wt.Icon;return s.jsx("button",{type:"button",onClick:()=>D(Wt.key),className:Te("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",k===Wt.key?"border-foreground scale-110 bg-[var(--surface-elevated)]":"border-border hover:border-border/80"),title:Wt.label,children:s.jsx(I,{name:gs,className:"w-4 h-4",style:we?{color:we}:void 0})},Wt.key)}),e[120]=we,e[121]=k,e[122]=it):it=e[122];let Et;e[123]!==Ge||e[124]!==it?(Et=s.jsxs("div",{className:"flex gap-2 flex-wrap",children:[Ge,it]}),e[123]=Ge,e[124]=it,e[125]=Et):Et=e[125];let lt;e[126]!==w||e[127]!==S||e[128]!==ue||e[129]!==le||e[130]!==E||e[131]!==ie||e[132]!==o||e[133]!==Ae||e[134]!==p?(lt=ue&&Ae&&s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:p("projectEditDialog.field.preview")}),s.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-1",children:s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:E?{backgroundColor:E}:void 0,children:le&&ie?s.jsx("img",{src:ie,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>je(!0)}):s.jsx(Na,{project:{id:o,iconImage:w},options:{themeVariant:S.metadata.variant,iconColor:S.colors.surface.foreground},className:"h-full w-full object-contain",onError:()=>je(!0)})})})]}),e[126]=w,e[127]=S,e[128]=ue,e[129]=le,e[130]=E,e[131]=ie,e[132]=o,e[133]=Ae,e[134]=p,e[135]=lt):lt=e[135];let ct;e[136]!==Me||e[137]!==ke||e[138]!==V||e[139]!==H||e[140]!==p?(ct=!ke&&s.jsxs(s.Fragment,{children:[s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>Se.current?.click(),disabled:H,children:p(H?"projectEditDialog.actions.uploading":"projectEditDialog.actions.uploadIcon")}),s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>{Me()},disabled:V,children:p(V?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")})]}),e[136]=Me,e[137]=ke,e[138]=V,e[139]=H,e[140]=p,e[141]=ct):ct=e[141];let Bt;e[142]!==Oe||e[143]!==ve||e[144]!==_||e[145]!==p?(Bt=ve&&s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>{Oe()},disabled:_,children:p(_?"projectEditDialog.actions.removing":"projectEditDialog.actions.removeProjectIcon")}),e[142]=Oe,e[143]=ve,e[144]=_,e[145]=p,e[146]=Bt):Bt=e[146];let Ft;e[147]!==_||e[148]!==te||e[149]!==p?(Ft=te&&s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>Z(!1),disabled:_,children:p("projectEditDialog.actions.undoRemove")}),e[147]=_,e[148]=te,e[149]=p,e[150]=Ft):Ft=e[150];let qt;e[151]!==ct||e[152]!==Bt||e[153]!==Ft?(qt=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[ct,Bt,Ft]}),e[151]=ct,e[152]=Bt,e[153]=Ft,e[154]=qt):qt=e[154];let Ut;e[155]!==It||e[156]!==dt||e[157]!==Et||e[158]!==lt||e[159]!==qt?(Ut=s.jsxs("div",{className:"min-w-0 space-y-2",children:[It,dt,Et,lt,qt]}),e[155]=It,e[156]=dt,e[157]=Et,e[158]=lt,e[159]=qt,e[160]=Ut):Ut=e[160];let At;e[161]!==ue||e[162]!==E||e[163]!==p?(At=ue&&s.jsxs("div",{className:"min-w-0 space-y-2",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:p("projectEditDialog.field.iconBackground")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:E??"#000000",onChange:Wt=>M(Wt.target.value),className:"h-8 w-10 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":p("projectEditDialog.field.iconBackgroundAria")}),s.jsx(kn,{value:E??"",onChange:Wt=>M(Wt.target.value),placeholder:"#000000",className:"h-8 w-[8.5rem]"}),s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>M(null),children:p("projectEditDialog.actions.clear")})]})]}),e[161]=ue,e[162]=E,e[163]=p,e[164]=At):At=e[164];let Xt;e[165]!==We||e[166]!==mt||e[167]!==Ut||e[168]!==At?(Xt=s.jsxs("div",{className:"min-w-0 space-y-5 py-1",children:[We,mt,Ut,At]}),e[165]=We,e[166]=mt,e[167]=Ut,e[168]=At,e[169]=Xt):Xt=e[169];let ls;e[170]!==r?(ls=()=>r(!1),e[170]=r,e[171]=ls):ls=e[171];let es;e[172]!==p?(es=p("projectEditDialog.actions.cancel"),e[172]=p,e[173]=es):es=e[173];let Gt;e[174]!==ls||e[175]!==es?(Gt=s.jsx(ze,{variant:"ghost",onClick:ls,children:es}),e[174]=ls,e[175]=es,e[176]=Gt):Gt=e[176];let pt;e[177]!==_||e[178]!==H||e[179]!==v?(pt=!v.trim()||H||_,e[177]=_,e[178]=H,e[179]=v,e[180]=pt):pt=e[180];let Yt;e[181]!==p?(Yt=p("projectEditDialog.actions.save"),e[181]=p,e[182]=Yt):Yt=e[182];let us;e[183]!==be||e[184]!==pt||e[185]!==Yt?(us=s.jsx(ze,{onClick:be,disabled:pt,children:Yt}),e[183]=be,e[184]=pt,e[185]=Yt,e[186]=us):us=e[186];let Jt;e[187]!==Gt||e[188]!==us?(Jt=s.jsxs(tr,{children:[Gt,us]}),e[187]=Gt,e[188]=us,e[189]=Jt):Jt=e[189];let ss;e[190]!==Ne||e[191]!==Xt||e[192]!==Jt?(ss=s.jsxs(Gs,{className:"max-w-md",children:[Ne,Xt,Jt]}),e[190]=Ne,e[191]=Xt,e[192]=Jt,e[193]=ss):ss=e[193];let hs;return e[194]!==r||e[195]!==n||e[196]!==ss?(hs=s.jsx(Ks,{open:n,onOpenChange:r,children:ss}),e[194]=r,e[195]=n,e[196]=ss,e[197]=hs):hs=e[197],hs};function V0(t){return t.uploadProjectIcon}function $0(t){return t.removeProjectIcon}function z0(t){return t.discoverProjectIcon}function W0(t){return t&&URL.revokeObjectURL(t),null}const U0=t=>{const e=gt.c(85),{folder:n,sessions:r,subFolderItems:o,isCollapsed:i,onToggle:c,onRename:l,onDelete:u,renderSessionNode:m,groupDirectory:d,projectId:f,mobileVariant:g,alwaysShowActions:x,isRenaming:p,renameDraft:y,onRenameDraftChange:b,onRenameSave:h,onRenameCancel:N,droppableRef:w,isDropTarget:S,onNewSession:v,onNewSubFolder:j,depth:k,hideActions:D,archivedBucket:T}=t,P=x===void 0?g===void 0?!1:g:x,E=p===void 0?!1:p,M=y===void 0?"":y,H=S===void 0?!1:S,R=k===void 0?0:k,_=D===void 0?!1:D,z=T===void 0?!1:T,{t:V}=Tt(),[F,te]=a.useState(!1),[Z,ne]=a.useState(""),U=a.useRef(null),ie=E||F,oe=E?M:Z;let ge;e[0]!==n.name?(ge=()=>{ne(n.name),te(!0)},e[0]=n.name,e[1]=ge):ge=e[1];const je=ge;let Se;e[2]!==oe||e[3]!==n.name||e[4]!==E||e[5]!==l||e[6]!==h?(Se=()=>{const A=oe.trim();A&&A!==n.name&&l(A),E&&h&&h(),te(!1),ne("")},e[2]=oe,e[3]=n.name,e[4]=E,e[5]=l,e[6]=h,e[7]=Se):Se=e[7];const re=Se;let L;e[8]!==E||e[9]!==N?(L=()=>{E&&N&&N(),te(!1),ne("")},e[8]=E,e[9]=N,e[10]=L):L=e[10];const $=L;let q;e[11]!==E||e[12]!==b?(q=A=>{E&&b?b(A):ne(A)},e[11]=E,e[12]=b,e[13]=q):q=e[13];const he=q;let de,we;e[14]!==E?(de=()=>{if(!E)return;const A=()=>{const _e=U.current;_e&&(_e.focus(),_e.select())},K=requestAnimationFrame(A),pe=window.setTimeout(A,0);return()=>{cancelAnimationFrame(K),window.clearTimeout(pe)}},we=[E],e[14]=E,e[15]=de,e[16]=we):(de=e[15],we=e[16]),a.useEffect(de,we);const be=i?"folder":"folder-open",le=R>0&&"ml-3";let ke;e[17]!==le?(ke=Te("oc-folder",le),e[17]=le,e[18]=ke):ke=e[18];const ue=H&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ve;e[19]!==ue?(ve=Te("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",ue),e[19]=ue,e[20]=ve):ve=e[20];const G=ie?void 0:c,Ae=ie?void 0:"button",ce=ie?void 0:0;let fe;e[21]!==c||e[22]!==ie?(fe=ie?void 0:A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),c())},e[21]=c,e[22]=ie,e[23]=fe):fe=e[23];let Ee;e[24]!==n.name||e[25]!==i||e[26]!==V?(Ee=i?V("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):V("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=V,e[27]=Ee):Ee=e[27];const me=z?P?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let B;e[28]!==me?(B=Te("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",me),e[28]=me,e[29]=B):B=e[29];const ye=H?"text-primary":"text-muted-foreground";let Oe;e[30]!==ye?(Oe=Te("h-3.5 w-3.5 flex-shrink-0",ye),e[30]=ye,e[31]=Oe):Oe=e[31];let Q;e[32]!==be||e[33]!==Oe?(Q=s.jsx(I,{name:be,className:Oe}),e[32]=be,e[33]=Oe,e[34]=Q):Q=e[34];let Me;e[35]!==oe||e[36]!==n.name||e[37]!==$||e[38]!==he||e[39]!==re||e[40]!==i||e[41]!==H||e[42]!==ie||e[43]!==r||e[44]!==V?(Me=ie?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:G0,onMouseDown:K0,onSubmit:A=>{A.preventDefault(),re()},children:[s.jsx("input",{ref:U,value:oe,onChange:A=>he(A.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:V("sessions.sidebar.folderItem.namePlaceholder"),onClick:q0,onPointerDown:Y0,onMouseDown:J0,onKeyDown:A=>{if(A.key==="Escape"){A.stopPropagation(),$();return}(A.key===" "||A.key==="Enter")&&A.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:Q0,onPointerDown:X0,onMouseDown:Z0,children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),$()},onPointerDown:ej,onMouseDown:tj,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:Te("typography-ui-label font-semibold truncate",H?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=oe,e[36]=n.name,e[37]=$,e[38]=he,e[39]=re,e[40]=i,e[41]=H,e[42]=ie,e[43]=r,e[44]=V,e[45]=Me):Me=e[45];let Re;e[46]!==B||e[47]!==Q||e[48]!==Me?(Re=s.jsxs("div",{className:B,children:[Q,Me]}),e[46]=B,e[47]=Q,e[48]=Me,e[49]=Re):Re=e[49];let Ne;e[50]!==P||e[51]!==z||e[52]!==R||e[53]!==n.name||e[54]!==je||e[55]!==_||e[56]!==u||e[57]!==v||e[58]!==j||e[59]!==ie||e[60]!==V?(Ne=!ie&&(!_||z)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:Te("flex items-center gap-0.5 transition-opacity",P?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",z&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!z&&v?s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),v()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:V("sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,!z&&j&&R===0?s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),j()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:V("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(I,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,z?null:s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),je()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(I,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),u()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":z?V("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):V("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=P,e[51]=z,e[52]=R,e[53]=n.name,e[54]=je,e[55]=_,e[56]=u,e[57]=v,e[58]=j,e[59]=ie,e[60]=V,e[61]=Ne):Ne=e[61];let Be;e[62]!==w||e[63]!==ve||e[64]!==G||e[65]!==Ae||e[66]!==ce||e[67]!==fe||e[68]!==Ee||e[69]!==Re||e[70]!==Ne?(Be=s.jsxs("div",{ref:w,className:ve,onClick:G,role:Ae,tabIndex:ce,onKeyDown:fe,"aria-label":Ee,children:[Re,Ne]}),e[62]=w,e[63]=ve,e[64]=G,e[65]=Ae,e[66]=ce,e[67]=fe,e[68]=Ee,e[69]=Re,e[70]=Ne,e[71]=Be):Be=e[71];let se;e[72]!==z||e[73]!==d||e[74]!==i||e[75]!==f||e[76]!==m||e[77]!==r||e[78]!==o||e[79]!==V?(se=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[o,r.length>0?r.map(A=>m(A,0,d??null,f??null,z)):o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:V("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=z,e[73]=d,e[74]=i,e[75]=f,e[76]=m,e[77]=r,e[78]=o,e[79]=V,e[80]=se):se=e[80];let O;return e[81]!==ke||e[82]!==Be||e[83]!==se?(O=s.jsxs("div",{className:ke,children:[Be,se]}),e[81]=ke,e[82]=Be,e[83]=se,e[84]=O):O=e[84],O},H0=a.memo(U0);function G0(t){return t.stopPropagation()}function K0(t){return t.stopPropagation()}function q0(t){return t.stopPropagation()}function Y0(t){return t.stopPropagation()}function J0(t){return t.stopPropagation()}function Q0(t){return t.stopPropagation()}function X0(t){return t.stopPropagation()}function Z0(t){return t.stopPropagation()}function ej(t){return t.stopPropagation()}function tj(t){return t.stopPropagation()}const sj=t=>{const e=gt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:i}=t,c=`session-drag:${n}`;let l;e[0]!==r||e[1]!==n||e[2]!==o?(l={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=l):l=e[3];let u;e[4]!==c||e[5]!==l?(u={id:c,data:l},e[4]=c,e[5]=l,e[6]=u):u=e[6];const{attributes:m,listeners:d,setNodeRef:f,isDragging:g}=sf(u);let x;e[7]!==d?(x=h=>{h.stopPropagation(),d?.onPointerDown&&d.onPointerDown(h)},e[7]=d,e[8]=x):x=e[8];const p=x,y=g?"opacity-30":void 0;let b;return e[9]!==m||e[10]!==i||e[11]!==p||e[12]!==f||e[13]!==y?(b=s.jsx("div",{ref:f,...m,onPointerDown:p,className:y,children:i}),e[9]=m,e[10]=i,e[11]=p,e[12]=f,e[13]=y,e[14]=b):b=e[14],b},nj=t=>{const e=gt.c(11),{folderId:n,children:r}=t,o=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let c;e[2]!==o||e[3]!==i?(c={id:o,data:i},e[2]=o,e[3]=i,e[4]=c):c=e[4];const{setNodeRef:l,isOver:u}=nf(c);let m;e[5]!==r||e[6]!==u||e[7]!==l?(m=r(l,u),e[5]=r,e[6]=u,e[7]=l,e[8]=m):m=e[8];let d;return e[9]!==m?(d=s.jsx(s.Fragment,{children:m}),e[9]=m,e[10]=d):d=e[10],d},rj=t=>{const e=gt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:i}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[0]=c):c=e[0];const l=qo(ro(Yo,c)),[u,m]=a.useState(null),[d,f]=a.useState("Session"),[g,x]=a.useState(null),[p,y]=a.useState(null);if(!n){let k;return e[1]!==i?(k=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=k):k=e[2],k}let b;e[3]!==o?(b=k=>{m(null),x(null),y(null);const{active:D,over:T}=k;if(!T)return;const C=D.data.current,P=T.data.current;C?.type==="session"&&C.sessionId&&P?.type==="folder"&&P.folderId&&o(C.sessionId,P.folderId)},e[3]=o,e[4]=b):b=e[4];const h=b;let N,w;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=k=>{const D=k.active.data.current;if(D?.type==="session"&&D.sessionId){m(D.sessionId),f(D.sessionTitle??"Session");const T=k.active.rect.current.initial?.width,C=k.active.rect.current.initial?.height;x(typeof T=="number"?T:null),y(typeof C=="number"?C:null)}},w=()=>{m(null),x(null),y(null)},e[5]=N,e[6]=w):(N=e[5],w=e[6]);let S;e[7]!==p||e[8]!==u||e[9]!==d||e[10]!==g||e[11]!==r?(S=u&&r?s.jsxs("div",{style:{width:g?`${g}px`:"auto",height:p?`${p}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(I,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:d})]}):null,e[7]=p,e[8]=u,e[9]=d,e[10]=g,e[11]=r,e[12]=S):S=e[12];let v;e[13]!==S?(v=s.jsx(ol,{children:S}),e[13]=S,e[14]=v):v=e[14];let j;return e[15]!==i||e[16]!==h||e[17]!==l||e[18]!==v?(j=s.jsxs(Jo,{sensors:l,collisionDetection:Qo,onDragStart:N,onDragCancel:w,onDragEnd:h,children:[i,v]}),e[15]=i,e[16]=h,e[17]=l,e[18]=v,e[19]=j):j=e[19],j},Ar=vi()(El(t=>({displayMode:"default",showRecentSection:!0,showArchivedSessions:!0,setDisplayMode:e=>t({displayMode:e}),setShowRecentSection:e=>t({showRecentSection:e}),setShowArchivedSessions:e=>t({showArchivedSessions:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection})),toggleArchivedSessions:()=>t(e=>({showArchivedSessions:!e.showArchivedSessions}))}),{name:"session-display-mode"})),ij=50,oj=28;function aj(t){const{t:e}=Tt(),{group:n,groupKey:r,projectId:o,hideGroupLabel:i,hasSessionSearchQuery:c,normalizedSessionSearchQuery:l,groupSearchDataByGroup:u,visibleSessionCount:m,collapsedGroups:d,hideDirectoryControls:f,collapsedFolderIds:g,toggleFolderCollapse:x,renameFolder:p,deleteFolder:y,showDeletionDialog:b,setDeleteFolderConfirm:h,renderSessionNode:N,projectRepoStatus:w,lastRepoStatus:S,showMoreGroupSessions:v,resetGroupSessionLimit:j,mobileVariant:k,alwaysShowActions:D,activeProjectId:T,setActiveProjectIdOnly:C,setActiveMainTab:P,setSessionSwitcherOpen:E,openNewSessionDraft:M,addSessionToFolder:H,createFolderAndStartRename:R,renamingFolderId:_,renameFolderDraft:z,setRenameFolderDraft:V,setRenamingFolderId:F,pinnedSessionIds:te,sessionOrderIndex:Z,prVisualStateByDirectoryBranch:ne,onToggleCollapsedGroup:U,dragHandleProps:ie,compactBodyPadding:oe=!1}=t,ge=a.useCallback((Ge,it)=>{const Et=Z.get(Ge.session.id),lt=Z.get(it.session.id);if(Et!==void 0||lt!==void 0){if(Et===void 0)return 1;if(lt===void 0)return-1;if(Et!==lt)return Et-lt}return Ti(Ge.session,it.session,te)},[te,Z]),je=c?u.get(n):null,Se=Ar(Ge=>Ge.displayMode),re=En(Ge=>Ge.foldersMap),L=Se==="minimal",$=c?!1:d.has(r),q=f?10:5,he=Math.max(q,m??q),de=c?je?.groupMatches===!0:!1,we=c,be=a.useMemo(()=>[...we?je?.filteredNodes??[]:n.sessions].sort(ge),[ge,n.sessions,je?.filteredNodes,we]),De=n.folderScopeKey??as(n.directory??null),le=a.useMemo(()=>De?re[De]??[]:[],[De,re]),ke=a.useMemo(()=>{const Ge=new Map,it=Et=>{Et.forEach(lt=>{Ge.set(lt.session.id,lt),lt.children.length>0&&it(lt.children)})};return it(be),Ge},[be]),ue=a.useMemo(()=>le.map(Ge=>{const it=Ge.sessionIds.map(Et=>ke.get(Et)).filter(Et=>!!Et).sort(ge);return{folder:Ge,nodes:it}}),[le,ke,ge]),ve=a.useMemo(()=>{const Ge=new Map(ue.map(ct=>[ct.folder.id,ct])),it=new Map;for(const{folder:ct}of ue){if(!ct.parentId)continue;const Bt=it.get(ct.parentId);Bt?Bt.push(ct.id):it.set(ct.parentId,[ct.id])}const Et=new Map,lt=ct=>{const Bt=Et.get(ct);if(Bt!==void 0)return Bt;const Ft=Ge.get(ct);if(!Ft)return Et.set(ct,!1),!1;const qt=it.get(ct)??[];if(n.isArchivedBucket&&Ft.nodes.length===0){const Xt=qt.some(ls=>lt(ls));return Et.set(ct,Xt),Xt}if(!c||Ft.folder.name.toLowerCase().includes(l)||Ft.nodes.length>0)return Et.set(ct,!0),!0;const At=qt.some(Xt=>lt(Xt));return Et.set(ct,At),At};return ue.filter(({folder:ct})=>lt(ct.id))},[ue,n.isArchivedBucket,c,l]),G=a.useMemo(()=>new Set(ve.flatMap(Ge=>Ge.folder.sessionIds)),[ve]),Ae=a.useMemo(()=>be.filter(Ge=>!G.has(Ge.session.id)),[be,G]),ce=a.useMemo(()=>ve.filter(({folder:Ge})=>!Ge.parentId),[ve]),fe=Ae.length,Ee=n.isArchivedBucket||c?Ae:Ae.slice(0,he),me=fe-Ee.length,B=!n.isArchivedBucket&&!c&&fe>q&&me===0,ye=n.isArchivedBucket===!0&&!c&&Ee.length>=ij,Oe=a.useRef(null),[Q,Me]=a.useState(null),[Re,Ne]=a.useState(0),Be=rf({count:Ee.length,getScrollElement:()=>Q,estimateSize:()=>oj,overscan:8,enabled:ye&&Q!==null,scrollMargin:Re});a.useLayoutEffect(()=>{if(!ye){Q!==null&&Me(null),Re!==0&&Ne(0);return}const Ge=Oe.current;if(!Ge)return;let it=Q;if(!it||!it.contains(Ge)){let lt=Ge.parentElement;for(;lt;){const ct=window.getComputedStyle(lt);if(ct.overflowY==="auto"||ct.overflowY==="scroll"){it=lt;break}lt=lt.parentElement}if(it!==Q){Me(it);return}}if(!it)return;const Et=Ge.getBoundingClientRect().top-it.getBoundingClientRect().top+it.scrollTop;Ne(lt=>Math.abs(lt-Et)<1?lt:Et)}),a.useEffect(()=>{if(!ye||!Q)return;const Ge=new ResizeObserver(()=>{Be.measure()});return Ge.observe(Q),()=>Ge.disconnect()},[ye,Q,Be]);const se=Be.getTotalSize(),O=ye&&Q!==null?Be.getVirtualItems():[];if(c&&!de&&ce.length===0&&Ae.length===0)return null;const A=Ge=>{const it=[],Et=lt=>{lt.forEach(ct=>{it.push(ct.session),ct.children.length>0&&Et(ct.children)})};return Et(Ge),it},K=A(be),pe=o&&w.has(o)?!!w.get(o):S,_e=as(n.directory??null),We=n.branch?.trim()??null,Le=_e&&We?ne.get(`${_e}::${We}`)??null:null,rt=!!(Le&&n.branch),yt=!Le&&!n.isMain&&!!n.branch,Dt=Le?.visualState??null,st=Le&&Le.state==="open"&&Le.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Le.checks.success,total:Le.checks.total}):null,Pe=Le&&Le.state==="open"&&Le.checks?[Le.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Le.checks.failure}):null,Le.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Le.checks.pending}):null].filter(Ge=>!!Ge).join(", "):null,tt=Le&&Le.state==="open"?Le.mergeableState==="blocked"||Le.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Le.mergeableState==="clean"||Le.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,Ye=Le&&Le.state==="open"&&Le.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Le.mergeableState}):null,nt=Le?.base??null,ft=Le?.head??null,mt=(()=>{if(!Le)return n.branch&&fh(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Le.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Le.canMerge===!0||Le.mergeableState==="clean"||Le.checks?.state==="success"?{label:e("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:e("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"};case"blocked":return{label:Le.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),ot=mt?.color??(Dt?`var(--pr-${Dt})`:void 0),It=Ge=>{Ge.preventDefault(),Ge.stopPropagation();const it=Le?.url;it&&xi(it)},dt=(Ge,it,Et)=>{const lt=ve.filter(({folder:qt})=>qt.parentId===Ge.id),ct=lt.length>0?s.jsx(s.Fragment,{children:lt.map(({folder:qt,nodes:Ut})=>dt(qt,Ut,Et+1))}):void 0,Bt=qt=>{const Ut=ve.find(({folder:Xt})=>Xt.id===qt)?.nodes??[],At=ve.filter(({folder:Xt})=>Xt.parentId===qt);return[...A(Ut),...At.flatMap(({folder:Xt})=>Bt(Xt.id))]},Ft=n.isArchivedBucket?Bt(Ge.id):[];return s.jsx(nj,{folderId:Ge.id,children:(qt,Ut)=>s.jsx(H0,{folder:Ge,sessions:it,subFolderItems:ct,isCollapsed:c?!1:g.has(Ge.id),onToggle:()=>x(Ge.id),onRename:At=>{De&&p(De,Ge.id,At)},onDelete:()=>{if(n.isArchivedBucket){Ir.requestDelete({sessions:Ft,mode:"session"});return}if(!De)return;if(!b){y(De,Ge.id);return}const At=ve.filter(({folder:ls})=>ls.parentId===Ge.id).length,Xt=it.length;h({scopeKey:De,folderId:Ge.id,folderName:Ge.name,subFolderCount:At,sessionCount:Xt})},renderSessionNode:N,groupDirectory:n.directory,projectId:o,mobileVariant:k,alwaysShowActions:D,isRenaming:_===Ge.id,renameDraft:_===Ge.id?z:void 0,onRenameDraftChange:At=>V(At),onRenameSave:()=>{const At=z.trim();At&&De&&p(De,Ge.id,At),F(null),V("")},onRenameCancel:()=>{F(null),V("")},droppableRef:qt,isDropTarget:Ut,depth:Et,onNewSession:()=>{o&&o!==T&&C(o),P("chat"),k&&E(!1),M({directoryOverride:n.directory,targetFolderId:Ge.id})},onNewSubFolder:Et===0?()=>{De&&R(De,Ge.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Ge.id)},bt=()=>ce.map(({folder:Ge,nodes:it})=>dt(Ge,it,0)),He=!!(!n.isMain&&n.worktree),Ze=D?He?"pr-14":"pr-7":L?He?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":He?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",Ue=s.jsxs(rj,{scopeKey:De,hasFolders:ve.length>0,onSessionDroppedOnFolder:(Ge,it)=>{De&&H(De,it,Ge)},children:[bt(),ye?s.jsx("div",{ref:Oe,style:{position:"relative",height:se>0?se:void 0,width:"100%"},children:O.map(Ge=>{const it=Ee[Ge.index];return it?s.jsx("div",{"data-index":Ge.index,ref:Be.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Ge.start-Re}px)`},children:N(it,0,n.directory,o,!0)},Ge.key):null})}):Ee.map(Ge=>N(Ge,0,n.directory,o,n.isArchivedBucket===!0)),fe===0&&ve.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,me>0?s.jsx("button",{type:"button",onClick:()=>v(r,Ee.length),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,B?s.jsx("button",{type:"button",onClick:()=>j(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),jt=oe?"pb-2 pl-1":"pb-3 pl-4";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Te("oc-group-body",jt),children:Ue})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:Te("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>U(r),role:"button",tabIndex:0,onKeyDown:Ge=>{(Ge.key==="Enter"||Ge.key===" ")&&(Ge.preventDefault(),U(r))},"aria-label":$?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!$,children:[s.jsx("div",{ref:ie?.setActivatorNodeRef,className:Te("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",Ze),...ie?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:rt&&Le?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"git-branch",className:Te("h-3.5 w-3.5 shrink-0",D?"hidden":"group-hover/gh:hidden"),style:ot?{color:ot}:void 0}),s.jsx("span",{className:Te("text-muted-foreground h-3.5 w-3.5 items-center justify-center",D?"inline-flex":"hidden group-hover/gh:inline-flex"),children:$?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Le.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:Ge=>Ge.stopPropagation(),onClick:It,children:["#",Le.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Le.number]})]})}),s.jsx(_t,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[nt||ft?s.jsx("div",{className:"text-muted-foreground truncate",children:nt&&ft?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:nt}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:ft})]}):s.jsx("span",{children:nt??ft??""})}):null,Ye?s.jsx("div",{className:"text-muted-foreground truncate",children:Ye}):null,tt||st?s.jsxs("div",{className:"text-muted-foreground truncate",children:[tt??"",tt&&st?" • ":"",st??"",Pe?` (${Pe})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"archive",className:Te("h-3.5 w-3.5 shrink-0 text-muted-foreground",D?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Te("text-muted-foreground h-3.5 w-3.5 items-center justify-center",D?"inline-flex":"hidden group-hover/gh:inline-flex"),children:$?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:io(n.label,l)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"git-branch",className:Te("h-3.5 w-3.5 shrink-0 text-muted-foreground",D?"hidden":"group-hover/gh:hidden"),style:ot?{color:ot}:void 0}),s.jsx("span",{className:Te("text-muted-foreground h-3.5 w-3.5 items-center justify-center",D?"inline-flex":"hidden group-hover/gh:inline-flex"),children:$?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:io(n.label,l)})]}):io(n.label,l)}),yt&&mt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(I,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||pe?rt&&Le?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:ot?{color:ot}:void 0})})}),s.jsx(_t,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[nt||ft?s.jsx("div",{className:"text-muted-foreground truncate",children:nt&&ft?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:nt}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:ft})]}):s.jsx("span",{children:nt??ft??""})}):null,Ye?s.jsx("div",{className:"text-muted-foreground truncate",children:Ye}):null,tt||st?s.jsxs("div",{className:"text-muted-foreground truncate",children:[tt??"",tt&&st?" • ":"",st??"",Pe?` (${Pe})`:""]}):null]})})]}):s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:ot?{color:ot}:void 0}):null,s.jsx("span",{className:Te("min-w-0 truncate text-[11px] font-medium",!mt.color&&"text-muted-foreground/80"),style:mt.color?{color:mt.color}:void 0,children:mt.label})]}):null]})}),n.isArchivedBucket&&K.length>0?s.jsx("div",{className:Te("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",D?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ge=>{Ge.stopPropagation(),Ir.requestDelete({sessions:K,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Te("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",D?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ge=>{Ge.stopPropagation(),Ir.requestDelete({sessions:K,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Te("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",D?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ge=>{Ge.stopPropagation(),o&&o!==T&&C(o),P("chat"),k&&E(!1),M({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),$?null:s.jsx("div",{className:Te("oc-group-body",jt),children:Ue})]})}function lj(t){const e=gt.c(202),{t:n}=Tt(),{hideDirectoryControls:r,showRecentControls:o,handleOpenDirectoryDialog:i,openNewSessionDraft:c,canOpenMultiRun:l,openMultiRunLauncher:u,headerActionIconClass:m,headerActionButtonClass:d,isSessionSearchOpen:f,setIsSessionSearchOpen:g,sessionSearchInputRef:x,sessionSearchQuery:p,setSessionSearchQuery:y,hasSessionSearchQuery:b,searchMatchCount:h,collapseAllProjects:N,expandAllProjects:w,openScheduledTasksDialog:S,selectionModeEnabled:v,onToggleSelectionMode:j}=t,k=Ar(pj),D=Ar(hj),T=Ar(fj),C=Ar(mj),P=Ar(uj),E=Ar(dj);if(r)return null;let M;e[0]!==n?(M=n("sessions.sidebar.header.actions.addProject"),e[0]=n,e[1]=M):M=e[1];let H;e[2]!==m?(H=s.jsx(I,{name:"folder-add",className:m}),e[2]=m,e[3]=H):H=e[3];let R;e[4]!==i||e[5]!==d||e[6]!==M||e[7]!==H?(R=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:d,"aria-label":M,children:H})}),e[4]=i,e[5]=d,e[6]=M,e[7]=H,e[8]=R):R=e[8];let _;e[9]!==n?(_=n("sessions.sidebar.header.actions.addProject"),e[9]=n,e[10]=_):_=e[10];let z;e[11]!==_?(z=s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:_})}),e[11]=_,e[12]=z):z=e[12];let V;e[13]!==R||e[14]!==z?(V=s.jsxs(Lt,{children:[R,z]}),e[13]=R,e[14]=z,e[15]=V):V=e[15];let F;e[16]!==n?(F=n("sessions.sidebar.header.actions.newSession"),e[16]=n,e[17]=F):F=e[17];let te;e[18]!==m?(te=s.jsx(I,{name:"chat-new",className:m}),e[18]=m,e[19]=te):te=e[19];let Z;e[20]!==d||e[21]!==c||e[22]!==F||e[23]!==te?(Z=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:d,"aria-label":F,children:te})}),e[20]=d,e[21]=c,e[22]=F,e[23]=te,e[24]=Z):Z=e[24];let ne;e[25]!==n?(ne=n("sessions.sidebar.header.actions.newSession"),e[25]=n,e[26]=ne):ne=e[26];let U;e[27]!==ne?(U=s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ne})}),e[27]=ne,e[28]=U):U=e[28];let ie;e[29]!==U||e[30]!==Z?(ie=s.jsxs(Lt,{children:[Z,U]}),e[29]=U,e[30]=Z,e[31]=ie):ie=e[31];let oe;e[32]!==n?(oe=n("sessions.sidebar.header.actions.newMultiRun"),e[32]=n,e[33]=oe):oe=e[33];const ge=!l;let je;e[34]!==m?(je=s.jsx(hh,{className:m}),e[34]=m,e[35]=je):je=e[35];let Se;e[36]!==d||e[37]!==u||e[38]!==oe||e[39]!==ge||e[40]!==je?(Se=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:d,"aria-label":oe,disabled:ge,children:je})}),e[36]=d,e[37]=u,e[38]=oe,e[39]=ge,e[40]=je,e[41]=Se):Se=e[41];let re;e[42]!==n?(re=n("sessions.sidebar.header.actions.newMultiRun"),e[42]=n,e[43]=re):re=e[43];let L;e[44]!==re?(L=s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:re})}),e[44]=re,e[45]=L):L=e[45];let $;e[46]!==Se||e[47]!==L?($=s.jsxs(Lt,{children:[Se,L]}),e[46]=Se,e[47]=L,e[48]=$):$=e[48];let q;e[49]!==n?(q=n("sessions.sidebar.header.actions.scheduledTasks"),e[49]=n,e[50]=q):q=e[50];let he;e[51]!==m?(he=s.jsx(I,{name:"calendar-schedule",className:m}),e[51]=m,e[52]=he):he=e[52];let de;e[53]!==d||e[54]!==S||e[55]!==q||e[56]!==he?(de=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,className:d,"aria-label":q,children:he})}),e[53]=d,e[54]=S,e[55]=q,e[56]=he,e[57]=de):de=e[57];let we;e[58]!==n?(we=n("sessions.sidebar.header.actions.scheduledTasks"),e[58]=n,e[59]=we):we=e[59];let be;e[60]!==we?(be=s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:we})}),e[60]=we,e[61]=be):be=e[61];let De;e[62]!==de||e[63]!==be?(De=s.jsxs(Lt,{children:[de,be]}),e[62]=de,e[63]=be,e[64]=De):De=e[64];let le;e[65]!==ie||e[66]!==$||e[67]!==De||e[68]!==V?(le=s.jsxs("div",{className:"flex items-center gap-1.5",children:[V,ie,$,De]}),e[65]=ie,e[66]=$,e[67]=De,e[68]=V,e[69]=le):le=e[69];let ke;e[70]!==g?(ke=()=>g(cj),e[70]=g,e[71]=ke):ke=e[71];let ue;e[72]!==n?(ue=n("sessions.sidebar.header.actions.searchSessions"),e[72]=n,e[73]=ue):ue=e[73];let ve;e[74]!==m?(ve=s.jsx(I,{name:"search",className:m}),e[74]=m,e[75]=ve):ve=e[75];let G;e[76]!==d||e[77]!==f||e[78]!==ke||e[79]!==ue||e[80]!==ve?(G=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ke,className:d,"aria-label":ue,"aria-expanded":f,children:ve})}),e[76]=d,e[77]=f,e[78]=ke,e[79]=ue,e[80]=ve,e[81]=G):G=e[81];let Ae;e[82]!==n?(Ae=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=Ae):Ae=e[83];let ce;e[84]!==Ae?(ce=s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ae})}),e[84]=Ae,e[85]=ce):ce=e[85];let fe;e[86]!==G||e[87]!==ce?(fe=s.jsxs(Lt,{children:[G,ce]}),e[86]=G,e[87]=ce,e[88]=fe):fe=e[88];const Ee=v&&"bg-interactive-hover text-primary";let me;e[89]!==d||e[90]!==Ee?(me=Te(d,Ee),e[89]=d,e[90]=Ee,e[91]=me):me=e[91];let B;e[92]!==v||e[93]!==n?(B=n(v?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[92]=v,e[93]=n,e[94]=B):B=e[94];let ye;e[95]!==m?(ye=s.jsx(I,{name:"checkbox-multiple",className:m}),e[95]=m,e[96]=ye):ye=e[96];let Oe;e[97]!==j||e[98]!==v||e[99]!==me||e[100]!==B||e[101]!==ye?(Oe=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:me,"aria-label":B,"aria-pressed":v,children:ye})}),e[97]=j,e[98]=v,e[99]=me,e[100]=B,e[101]=ye,e[102]=Oe):Oe=e[102];let Q;e[103]!==v||e[104]!==n?(Q=n(v?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[103]=v,e[104]=n,e[105]=Q):Q=e[105];let Me;e[106]!==Q?(Me=s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Q})}),e[106]=Q,e[107]=Me):Me=e[107];let Re;e[108]!==Oe||e[109]!==Me?(Re=s.jsxs(Lt,{children:[Oe,Me]}),e[108]=Oe,e[109]=Me,e[110]=Re):Re=e[110];let Ne;e[111]!==n?(Ne=n("sessions.sidebar.header.actions.sessionDisplayMode"),e[111]=n,e[112]=Ne):Ne=e[112];let Be;e[113]!==m?(Be=s.jsx(I,{name:"equalizer-2",className:m}),e[113]=m,e[114]=Be):Be=e[114];let se;e[115]!==d||e[116]!==Ne||e[117]!==Be?(se=s.jsx(Ot,{asChild:!0,children:s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",className:d,"aria-label":Ne,children:Be})})}),e[115]=d,e[116]=Ne,e[117]=Be,e[118]=se):se=e[118];let O;e[119]!==n?(O=n("sessions.sidebar.header.displayMode.label"),e[119]=n,e[120]=O):O=e[120];let A;e[121]!==O?(A=s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:O})}),e[121]=O,e[122]=A):A=e[122];let K;e[123]!==se||e[124]!==A?(K=s.jsxs(Lt,{children:[se,A]}),e[123]=se,e[124]=A,e[125]=K):K=e[125];let pe;e[126]!==C?(pe=()=>C("default"),e[126]=C,e[127]=pe):pe=e[127];let _e;e[128]!==n?(_e=n("sessions.sidebar.header.displayMode.default"),e[128]=n,e[129]=_e):_e=e[129];let We;e[130]!==_e?(We=s.jsx("span",{children:_e}),e[130]=_e,e[131]=We):We=e[131];let Le;e[132]!==k?(Le=k==="default"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null,e[132]=k,e[133]=Le):Le=e[133];let rt;e[134]!==pe||e[135]!==We||e[136]!==Le?(rt=s.jsxs(zt,{onClick:pe,className:"flex items-center justify-between",children:[We,Le]}),e[134]=pe,e[135]=We,e[136]=Le,e[137]=rt):rt=e[137];let yt;e[138]!==C?(yt=()=>C("minimal"),e[138]=C,e[139]=yt):yt=e[139];let Dt;e[140]!==n?(Dt=n("sessions.sidebar.header.displayMode.minimal"),e[140]=n,e[141]=Dt):Dt=e[141];let st;e[142]!==Dt?(st=s.jsx("span",{children:Dt}),e[142]=Dt,e[143]=st):st=e[143];let Pe;e[144]!==k?(Pe=k==="minimal"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null,e[144]=k,e[145]=Pe):Pe=e[145];let tt;e[146]!==yt||e[147]!==st||e[148]!==Pe?(tt=s.jsxs(zt,{onClick:yt,className:"flex items-center justify-between",children:[st,Pe]}),e[146]=yt,e[147]=st,e[148]=Pe,e[149]=tt):tt=e[149];let Ye;e[150]!==T||e[151]!==o||e[152]!==D||e[153]!==n||e[154]!==E||e[155]!==P?(Ye=o?s.jsxs(s.Fragment,{children:[s.jsx(Mn,{}),s.jsxs(zt,{onClick:P,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),D?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(zt,{onClick:E,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showArchived")}),T?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]})]}):null,e[150]=T,e[151]=o,e[152]=D,e[153]=n,e[154]=E,e[155]=P,e[156]=Ye):Ye=e[156];let nt;e[157]===Symbol.for("react.memo_cache_sentinel")?(nt=s.jsx(Mn,{}),e[157]=nt):nt=e[157];let ft;e[158]===Symbol.for("react.memo_cache_sentinel")?(ft=s.jsx(I,{name:"contract-up-down",className:"h-4 w-4"}),e[158]=ft):ft=e[158];let mt;e[159]!==n?(mt=n("sessions.sidebar.header.displayMode.collapseAll"),e[159]=n,e[160]=mt):mt=e[160];let ot;e[161]!==mt?(ot=s.jsx("span",{children:mt}),e[161]=mt,e[162]=ot):ot=e[162];let It;e[163]!==N||e[164]!==ot?(It=s.jsxs(zt,{onClick:N,className:"flex items-center gap-2",children:[ft,ot]}),e[163]=N,e[164]=ot,e[165]=It):It=e[165];let dt;e[166]===Symbol.for("react.memo_cache_sentinel")?(dt=s.jsx(I,{name:"expand-up-down",className:"h-4 w-4"}),e[166]=dt):dt=e[166];let bt;e[167]!==n?(bt=n("sessions.sidebar.header.displayMode.expandAll"),e[167]=n,e[168]=bt):bt=e[168];let He;e[169]!==bt?(He=s.jsx("span",{children:bt}),e[169]=bt,e[170]=He):He=e[170];let Ze;e[171]!==w||e[172]!==He?(Ze=s.jsxs(zt,{onClick:w,className:"flex items-center gap-2",children:[dt,He]}),e[171]=w,e[172]=He,e[173]=Ze):Ze=e[173];let Ue;e[174]!==rt||e[175]!==tt||e[176]!==Ye||e[177]!==It||e[178]!==Ze?(Ue=s.jsxs(rn,{align:"end",className:"min-w-[160px]",children:[rt,tt,Ye,nt,It,Ze]}),e[174]=rt,e[175]=tt,e[176]=Ye,e[177]=It,e[178]=Ze,e[179]=Ue):Ue=e[179];let jt;e[180]!==K||e[181]!==Ue?(jt=s.jsxs(on,{children:[K,Ue]}),e[180]=K,e[181]=Ue,e[182]=jt):jt=e[182];let Ge;e[183]!==fe||e[184]!==Re||e[185]!==jt?(Ge=s.jsxs("div",{className:"flex items-center gap-1.5",children:[fe,Re,jt]}),e[183]=fe,e[184]=Re,e[185]=jt,e[186]=Ge):Ge=e[186];let it;e[187]!==le||e[188]!==Ge?(it=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[le,Ge]}),e[187]=le,e[188]=Ge,e[189]=it):it=e[189];let Et;e[190]!==b||e[191]!==f||e[192]!==h||e[193]!==x||e[194]!==p||e[195]!==g||e[196]!==y||e[197]!==n?(Et=f?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[b?s.jsx("span",{children:h===1?n("sessions.sidebar.header.search.matchCountSingle",{count:h}):n("sessions.sidebar.header.search.matchCountPlural",{count:h})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:x,value:p,onChange:ct=>y(ct.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:ct=>{ct.key==="Escape"&&(ct.stopPropagation(),b?y(""):g(!1))}}),p.length>0?s.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[190]=b,e[191]=f,e[192]=h,e[193]=x,e[194]=p,e[195]=g,e[196]=y,e[197]=n,e[198]=Et):Et=e[198];let lt;return e[199]!==it||e[200]!==Et?(lt=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[it,Et]})}),e[199]=it,e[200]=Et,e[201]=lt):lt=e[201],lt}function cj(t){return!t}function dj(t){return t.toggleArchivedSessions}function uj(t){return t.toggleRecentSection}function mj(t){return t.setDisplayMode}function fj(t){return t.showArchivedSessions}function hj(t){return t.showRecentSection}function pj(t){return t.displayMode}const qd=7;function gj(t){const e=gt.c(20),{sections:n,renderSessionNode:r}=t,{t:o}=Tt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[c,l]=a.useState(i);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=new Set,e[1]=u):u=e[1];const[m,d]=a.useState(u);let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=w=>{l(S=>{const v=new Set(S);return v.has(w)?v.delete(w):v.add(w),v})},e[2]=f):f=e[2];const g=f;let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=w=>{d(S=>{const v=new Set(S);return v.has(w)?v.delete(w):v.add(w),v})},e[3]=x):x=e[3];const p=x;let y,b,h;if(e[4]!==c||e[5]!==m||e[6]!==r||e[7]!==n||e[8]!==o){h=Symbol.for("react.early_return_sentinel");e:{const w=n.filter(xj);if(w.length===0){h=null;break e}y="space-y-2 pb-2 pt-1";let S;e[12]!==c||e[13]!==m||e[14]!==r||e[15]!==o?(S=v=>{const j=c.has(v.key),k=m.has(v.key),D=k?v.items:v.items.slice(0,qd),T=v.items.length-D.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>g(v.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:v.title})]}),j?null:s.jsxs("div",{className:Te("space-y-0.5 pl-7"),children:[D.map(C=>r(C.node,0,C.groupDirectory,C.projectId,!1,C.secondaryMeta,"recent")),T>0&&!k?s.jsx("button",{type:"button",onClick:()=>p(v.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:T===1?o("sessions.sidebar.group.showMoreSingle",{count:T}):o("sessions.sidebar.group.showMorePlural",{count:T})}):null,k&&v.items.length>qd?s.jsx("button",{type:"button",onClick:()=>p(v.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showFewer")}):null]})]},v.key)},e[12]=c,e[13]=m,e[14]=r,e[15]=o,e[16]=S):S=e[16],b=w.map(S)}e[4]=c,e[5]=m,e[6]=r,e[7]=n,e[8]=o,e[9]=y,e[10]=b,e[11]=h}else y=e[9],b=e[10],h=e[11];if(h!==Symbol.for("react.early_return_sentinel"))return h;let N;return e[17]!==y||e[18]!==b?(N=s.jsx("div",{className:y,children:b}),e[17]=y,e[18]=b,e[19]=N):N=e[19],N}function xj(t){return t.items.length>0}const Ja="inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50";function bj(t){const e=gt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:i,showRuntimeButtons:c,showUpdateButton:l}=t,u=c===void 0?!0:c,m=l===void 0?!0:l,{t:d}=Tt();let f;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==u||e[4]!==d?(f=u?s.jsxs(s.Fragment,{children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Ja,"aria-label":d("sessions.sidebar.footer.actions.settings"),children:s.jsx(I,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:d("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Ja,"aria-label":d("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(I,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:d("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:Ja,"aria-label":d("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(I,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:d("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=u,e[4]=d,e[5]=f):f=e[5];let g;e[6]!==i||e[7]!==m||e[8]!==d?(g=m?s.jsx(ze,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:d("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=m,e[8]=d,e[9]=g):g=e[9];let x;return e[10]!==f||e[11]!==g?(x=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[f,g]}),e[10]=f,e[11]=g,e[12]=x):x=e[12],x}const yj=t=>{const e=gt.c(50),{id:n,projectLabel:r,projectDescription:o,projectIcon:i,projectColor:c,projectIconImage:l,projectIconBackground:u,isCollapsed:m,isActiveProject:d,isRepo:f,isDesktopShell:g,isStuck:x,hideDirectoryControls:p,alwaysShowActions:y,onToggle:b,onNewSession:h,onNewWorktreeSession:N,onRenameStart:w,onClose:S,sentinelRef:v,children:j,showCreateButtons:k,hideHeader:D,openSidebarMenuKey:T,setOpenSidebarMenuKey:C}=t,P=k===void 0?!0:k,E=D===void 0?!1:D,{t:M}=Tt(),{currentTheme:H}=Tr();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:_,listeners:z,setNodeRef:V,transform:F,transition:te,isDragging:Z}=Rl(R),ne=a.useRef(!1),U=`project:${n}`,ie=T===U,oe=i?Yl[i]:null,ge=c?Sa[c]??null:null;let je;e[2]!==U||e[3]!==C?(je=G=>{C(G?U:null)},e[2]=U,e[3]=C,e[4]=je):je=e[4];const Se=je,re=jj,L=Sj,$=Nj;let q;e[5]===Symbol.for("react.memo_cache_sentinel")?(q=G=>{(G.button===2||G.button===0&&G.ctrlKey)&&(ne.current=!0)},e[5]=q):q=e[5];const he=q;let de;e[6]!==b?(de=()=>{if(ne.current){ne.current=!1;return}b()},e[6]=b,e[7]=de):de=e[7];const we=de;let be;e[8]!==F?(be=Ml.Transform.toString(F),e[8]=F,e[9]=be):be=e[9];let De;e[10]!==be||e[11]!==te?(De={transform:be,transition:te},e[10]=be,e[11]=te,e[12]=De):De=e[12];const le=Z&&"opacity-30";let ke;e[13]!==le?(ke=Te("relative",le),e[13]=le,e[14]=ke):ke=e[14];let ue;e[15]!==y||e[16]!==_||e[17]!==H||e[18]!==Se||e[19]!==we||e[20]!==p||e[21]!==E||e[22]!==ge||e[23]!==n||e[24]!==d||e[25]!==m||e[26]!==g||e[27]!==ie||e[28]!==f||e[29]!==x||e[30]!==z||e[31]!==S||e[32]!==h||e[33]!==N||e[34]!==w||e[35]!==o||e[36]!==u||e[37]!==l||e[38]!==oe||e[39]!==r||e[40]!==v||e[41]!==P||e[42]!==M?(ue=E?null:s.jsxs(s.Fragment,{children:[g&&s.jsx("div",{ref:v,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:Te("w-full text-left group/project select-none"),style:{backgroundColor:g&&x?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",..._,children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:he,onClick:we,...z,className:Te("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",f&&!p?y?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":y?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:Te("h-3.5 w-3.5 items-center justify-center text-muted-foreground",y?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:m?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),l?s.jsx("span",{className:Te("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",y?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:u?{backgroundColor:u}:void 0,children:s.jsx(Na,{project:{id:n,iconImage:l},options:{themeVariant:H.metadata.variant,iconColor:H.colors.surface.foreground},className:"h-full w-full object-contain",fallback:oe?s.jsx(I,{name:oe,className:"h-3.5 w-3.5",style:ge?{color:ge}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:ge?{color:ge}:void 0})})}):oe?s.jsx(I,{name:oe,className:Te("h-3.5 w-3.5",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:ge?{color:ge}:void 0}):s.jsx(I,{name:"folder",className:Te("h-3.5 w-3.5 text-muted-foreground/80",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:ge?{color:ge}:void 0})]}),s.jsx("span",{className:Te("text-[14px] font-normal truncate lowercase",d?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(_t,{side:"right",sideOffset:8,children:o})]}),s.jsxs("div",{className:Te("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",P?"right-7":"right-0.5"),children:[P&&f&&!p&&N?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:G=>{G.stopPropagation(),N()},className:Te("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(I,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(on,{open:ie,onOpenChange:Se,children:[s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",className:Te("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",ie?"opacity-100 pointer-events-auto":y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.projectMenu"),onPointerDown:L,onMouseDown:$,onClick:re,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(rn,{align:"end",className:"min-w-[180px]",children:[P&&!f&&!p&&h&&s.jsxs(zt,{onClick:h,children:[s.jsx(I,{name:"add",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.newSession")]}),s.jsxs(zt,{onClick:w,children:[s.jsx(I,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.closeProject")]})]})]})]}),P&&h?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:G=>{G.stopPropagation(),h()},className:Te("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[15]=y,e[16]=_,e[17]=H,e[18]=Se,e[19]=we,e[20]=p,e[21]=E,e[22]=ge,e[23]=n,e[24]=d,e[25]=m,e[26]=g,e[27]=ie,e[28]=f,e[29]=x,e[30]=z,e[31]=S,e[32]=h,e[33]=N,e[34]=w,e[35]=o,e[36]=u,e[37]=l,e[38]=oe,e[39]=r,e[40]=v,e[41]=P,e[42]=M,e[43]=ue):ue=e[43];let ve;return e[44]!==j||e[45]!==V||e[46]!==ke||e[47]!==ue||e[48]!==De?(ve=s.jsxs("div",{ref:V,style:De,className:ke,children:[ue,j]}),e[44]=j,e[45]=V,e[46]=ke,e[47]=ue,e[48]=De,e[49]=ve):ve=e[49],ve},wj=t=>{const e=gt.c(21),{id:n,disabled:r,children:o}=t,i=r===void 0?!1:r;let c;e[0]!==i||e[1]!==n?(c={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=c):c=e[2];const{listeners:l,setNodeRef:u,setActivatorNodeRef:m,transform:d,transition:f,isDragging:g}=Rl(c);let x;e[3]!==l||e[4]!==m?(x={listeners:l,setActivatorNodeRef:m},e[3]=l,e[4]=m,e[5]=x):x=e[5];const p=x;let y;e[6]!==d?(y=Ml.Transform.toString(d),e[6]=d,e[7]=y):y=e[7];let b;e[8]!==y||e[9]!==f?(b={transform:y,transition:f},e[8]=y,e[9]=f,e[10]=b):b=e[10];const h=g&&"opacity-50";let N;e[11]!==h?(N=Te("space-y-0.5 rounded-md",h),e[11]=h,e[12]=N):N=e[12];let w;e[13]!==o||e[14]!==p?(w=typeof o=="function"?o(p):o,e[13]=o,e[14]=p,e[15]=w):w=e[15];let S;return e[16]!==u||e[17]!==b||e[18]!==N||e[19]!==w?(S=s.jsx("div",{ref:u,style:b,className:N,children:w}),e[16]=u,e[17]=b,e[18]=N,e[19]=w,e[20]=S):S=e[20],S},vj=a.memo(wj);function jj(t){t.stopPropagation()}function Sj(t){t.stopPropagation()}function Nj(t){t.stopPropagation()}function kj(t){const e=gt.c(25),{t:n}=Tt();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o={coordinateGetter:af},e[1]=o):o=e[1];const i=qo(ro(Yo,r),ro(of,o));let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[2]=c):c=e[2];const l=qo(ro(Yo,c));if(t.projectSections.length===0){const g=(t.mobileVariant,"");let x;e[3]!==g?(x=Te("space-y-1 pb-1 pl-2.5 pr-2",g),e[3]=g,e[4]=x):x=e[4];let p;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==x?(p=s.jsxs(Fn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:x,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=x,e[8]=p):p=e[8],p}if(t.sectionsForRender.length===0){const g=(t.mobileVariant,"");let x;e[9]!==g?(x=Te("space-y-1 pb-1 pl-2.5 pr-2",g),e[9]=g,e[10]=x):x=e[10];let p;return e[11]!==t.searchEmptyState||e[12]!==x?(p=s.jsx(Fn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:x,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=x,e[13]=p):p=e[13],p}const u=(t.mobileVariant,"");let m;e[14]!==u?(m=Te("space-y-1 pb-1 pl-2.5 pr-2",u),e[14]=u,e[15]=m):m=e[15];let d;e[16]!==l||e[17]!==i||e[18]!==t||e[19]!==n?(d=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const g=t.sectionsForRender.find(b=>b.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!g)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const x=g.groups.find(Rj)??g.groups.find(Ej)??g.groups.find(Tj)??g.groups[0];if(!x)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const p=g.groups.find(Pj);return[x,...p&&p.id!==x.id?[p]:[]].map(b=>{const h=`${g.project.id}:${b.id}`,N=b.id===x.id;return s.jsx(a.Fragment,{children:t.renderGroupSessions(b,h,g.project.id,N,null,!0)},h)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Jo,{sensors:i,collisionDetection:Qo,onDragEnd:g=>{if(t.isInlineEditing)return;const{active:x,over:p}=g;if(!p||x.id===p.id)return;const y=t.sectionsForRender.findIndex(h=>h.project.id===x.id),b=t.sectionsForRender.findIndex(h=>h.project.id===p.id);y===-1||b===-1||y===b||t.reorderProjects(y,b)},children:[s.jsx(rl,{items:t.sectionsForRender.map(Ij),strategy:il,children:t.sectionsForRender.map(g=>{const x=g.project,p=x.id,y=Bu(x.label?.trim()||wi(x.normalizedPath,t.homeDirectory)||x.normalizedPath),b=Zo(x.normalizedPath,t.homeDirectory),h=t.collapsedProjects.has(p),N=p===t.activeProjectId,w=t.projectRepoStatus.get(p),S=t.getOrderedGroups(p,g.groups),v=S.find(Dj)??null,j=v?S.filter(k=>k.id!==v.id):S;return s.jsx(yj,{id:p,projectLabel:y,projectDescription:b,projectIcon:x.icon,projectColor:x.color,projectIconImage:x.iconImage,projectIconBackground:x.iconBackground,isCollapsed:h,isActiveProject:N,isRepo:!!w,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(p),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(p),onNewSession:()=>{p!==t.activeProjectId&&t.setActiveProjectIdOnly(p),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:x.normalizedPath})},onNewWorktreeSession:()=>{p!==t.activeProjectId&&t.setActiveProjectIdOnly(p),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(p),onClose:()=>t.removeProject(p),sentinelRef:k=>{t.projectHeaderSentinelRefs.current.set(p,k)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:h?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:g.groups.length>0?s.jsxs(Jo,{sensors:l,collisionDetection:Qo,onDragEnd:k=>{if(t.isInlineEditing)return;const{active:D,over:T}=k;if(!T||D.id===T.id)return;const C=j.findIndex(H=>H.id===D.id),P=j.findIndex(H=>H.id===T.id);if(C===-1||P===-1||C===P)return;const E=fu(j,C,P).map(Aj),M=v?[v.id,...E]:E;t.setGroupOrderByProject(H=>{const R=new Map(H);return R.set(p,M),R})},children:[v?t.renderGroupSessions(v,`${p}:${v.id}`,p,!0):null,s.jsx(rl,{items:j.map(Cj),strategy:il,children:j.map(k=>{const D=`${p}:${k.id}`;return s.jsx(vj,{id:k.id,disabled:t.isInlineEditing,children:T=>t.renderGroupSessions(k,D,p,!1,T)},k.id)})}),s.jsx(ol,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},p)})}),s.jsx(ol,{dropAnimation:null})]})}),e[16]=l,e[17]=i,e[18]=t,e[19]=n,e[20]=d):d=e[20];let f;return e[21]!==t.topContent||e[22]!==m||e[23]!==d?(f=s.jsxs(Fn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:m,children:[t.topContent,d]}),e[21]=t.topContent,e[22]=m,e[23]=d,e[24]=f):f=e[24],f}function Cj(t){return t.id}function Aj(t){return t.id}function Dj(t){return t.isMain}function Ij(t){return t.project.id}function Pj(t){return t.isArchivedBucket}function Tj(t){return t.isMain}function Ej(t){return t.sessions.length>0}function Rj(t){return t.isMain&&t.sessions.length>0}function Mj(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(void 0,{month:"short"}),r=e.getDate(),o=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),c=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${o}, ${i}:${c}`}function Fj(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function Lj(t){const e=t.info.role==="user"?"User":"Assistant",n=Mj(t.info.time?.created),r=Fj(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
161
+ `);E({sessionKey:ue,source:"preview-console",fileLabel:t||U||"preview",startLine:1,endLine:Math.max(1,S.length),code:`${ve}${G}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),ae.success(n("contextPanel.preview.console.attached"))},[E,S,C,U,P,t,n]),[K,he]=a.useState("unknown"),de=a.useRef(0),we=a.useRef(0),xe=15e3;a.useEffect(()=>{if(!ne){he("unknown"),de.current=0,we.current=0;return}let ue=!1;return de.current||(de.current=Date.now(),we.current=0),he("unknown"),(async()=>{const G=await(async()=>{try{return await Fs(ne,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(ue)return;if(!G){he("unreachable");return}if(G.status===403||G.status===404){$n.delete(V),m({status:"loading"}),l();return}if(G.status!==502){he("reachable");return}const Ae=de.current||Date.now();if(Date.now()-Ae<xe){he("starting"),we.current+=1;const fe=we.current,Te=Math.min(2e3,250*Math.pow(2,Math.min(4,fe)));setTimeout(()=>{ue||i()},Te).unref?.();return}he("unreachable")})(),()=>{ue=!0}},[V,ne,o]);const De=R&&u.status==="ready"&&(K==="unknown"||K==="starting"),le=R&&u.status==="ready"&&K==="unreachable",Ce=a.useCallback(ue=>{if(!R||u.status!=="ready"||typeof window>"u")return;const ve=ue.currentTarget.contentWindow;if(ve)try{const G=ve.location,Ae=Mm(ne);if(G.origin!==Ae||G.pathname.startsWith(u.proxyBasePath))return;const ce=`${u.proxyBasePath}${G.pathname}${G.search}${G.hash}`;ve.location.replace(ce)}catch{}},[R,ne,u]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:ie||t,children:ie||t||n("contextPanel.preview.empty")}),s.jsx(ze,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!U,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{te&&wi(te)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!te,children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})}),R?s.jsx(ze,{type:"button",size:"sm",variant:j?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>k(ue=>!ue),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!p,children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}):null,R?s.jsxs(ze,{type:"button",size:"sm",variant:b?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>h(ue=>!ue),title:n(p?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(p?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!p&&S.length===0,children:[s.jsx(I,{name:"terminal-box",className:"h-3.5 w-3.5"}),Se>0?s.jsx("span",{className:"typography-micro text-status-error",children:Se}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[De?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):le?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(ze,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):U&&(!R||K==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:g,src:U,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:F},onLoad:Ce,sandbox:R?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${U}:${o}`),j&&A?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:A.bounds.x,top:A.bounds.y,width:A.bounds.width,height:A.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[A.tag,A.text?` · ${A.text}`:""]})}):null]}):oe?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):pe?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),u.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:u.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),b?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:$,disabled:S.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:L,disabled:S.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:()=>v([]),disabled:S.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(ue=>s.jsx(ze,{type:"button",size:"xs",variant:N===ue?"secondary":"ghost",onClick:()=>w(ue),children:n(ue==="all"?"contextPanel.preview.console.filter.all":ue==="errors"?"contextPanel.preview.console.filter.errors":ue==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},ue))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:S.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):re.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):re.map(ue=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:Pe("shrink-0 uppercase",ue.level==="error"||ue.level==="runtime"||ue.level==="resource"?"text-status-error":ue.level==="warn"?"text-status-warning":"text-muted-foreground"),children:ue.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:ue.message})]})},ue.id))})]}):null]})]})},D1=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,I1=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=Tt(),o=a.useRef(null),i=Fe(L=>L.setContextPanelTabTargetPath),c=lo(t),l=c!=="about:blank"?c:"",[u,m]=a.useState(l),[d,f]=a.useState(l),[g,x]=a.useState(()=>l?[l]:[]),[p,y]=a.useState(()=>l?0:-1),[b,h]=a.useReducer(L=>L+1,0),[N,w]=a.useState(!!l),[S,v]=a.useState(!1),[j,k]=a.useState(null),[A,T]=a.useState({status:"idle"}),[C,P]=a.useState(""),E=jt(L=>L.currentSessionId),M=jt(L=>L.newSessionDraft?.open),H=ql(L=>L.addDraft),R=ti(L=>L.addAttachedFile),_=a.useCallback(L=>{!L||L==="about:blank"||!e||!n||i(e,n,L)},[e,n,i]),z=a.useCallback((L,$)=>{const K=lo(L),he=K!=="about:blank"?K:"";f(he),m(he),w(!!he),_(he),x(de=>{if(!he)return y(-1),[];if($?.replaceHistory)return de;const we=p>=0?de.slice(0,p+1):[];if(we[we.length-1]===he)return y(we.length-1),we;const De=[...we,he];return y(De.length-1),De})},[p,_]),V=a.useCallback(L=>{const $=g[L];$&&(y(L),f($),m($),w(!0),_($))},[g,_]),F=a.useCallback(()=>{if(d){w(!0);try{o.current?.contentWindow?.location.reload()}catch{h()}}},[d]);a.useEffect(()=>{if(!d){T({status:"idle"});return}const L=Xw(d),$=ac(L);if($?.previewToken){T({status:"ready",proxyBasePath:$.proxyBasePath,previewToken:$.previewToken,expiresAt:$.expiresAt});return}$&&$n.delete(L);let K=!1;return T({status:"loading"}),w(!0),(async()=>{try{const he=await Fs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:d,allowExternal:!0})});if(!he.ok){const le=await he.json().catch(()=>({})),Ce=typeof le?.error=="string"?le.error:`HTTP ${he.status}`;K||T({status:"error",message:Ce});return}const de=await he.json(),we=typeof de.proxyBasePath=="string"?de.proxyBasePath:"",xe=typeof de.previewToken=="string"?de.previewToken:"",De=typeof de.expiresAt=="number"?de.expiresAt:0;if(!we||!xe){K||T({status:"error",message:r("contextPanel.preview.proxyError")});return}$n.set(L,{proxyBasePath:we,previewToken:xe,expiresAt:De}),K||T({status:"ready",proxyBasePath:we,previewToken:xe,expiresAt:De})}catch(he){if(!K){const de=he instanceof Error?he.message:String(he);T({status:"error",message:de})}}})(),()=>{K=!0}},[d,r]);const te=d&&A.status==="ready"?`${A.proxyBasePath}|${A.previewToken||""}|${b}`:"";a.useEffect(()=>{if(!te){P("");return}let L=!1;return P(""),Ll(Xr()).then($=>{!L&&$&&P(te)}).catch(()=>{}),()=>{L=!0}},[te]);const Z=a.useMemo(()=>{if(C!==te||!d||A.status!=="ready")return"";try{const L=new URL(d),$=L.pathname||"/",K=new URLSearchParams(L.search);K.set("ocPreview",String(b)),K.set("oc_preview_token",A.previewToken||"");const he=K.toString();return Li().authenticatedAsset(`${A.proxyBasePath}${$}${he?`?${he}`:""}${L.hash}`)}catch{return""}},[d,A,te,b,C]),ne=Z||(A.status==="error"?d:""),U=a.useCallback(L=>{if(!L||!d||A.status!=="ready")return"";try{const $=new URL(L,window.location.origin),K=A.proxyBasePath.endsWith("/")?A.proxyBasePath.slice(0,-1):A.proxyBasePath;if($.origin!==window.location.origin||!$.pathname.startsWith(K))return"";const he=$.pathname.slice(K.length)||"/",de=new URL(d).origin;return new URL(`${he}${$.search}${$.hash}`,de).toString()}catch{return""}},[d,A]),ie=a.useCallback(L=>{if(!L||!d||A.status!=="ready")return"";try{const $=new URL(L,window.location.origin),K=new URL(d).origin;if($.origin!==window.location.origin||K===window.location.origin)return"";const he=A.proxyBasePath.endsWith("/")?A.proxyBasePath.slice(0,-1):A.proxyBasePath;return $.pathname.startsWith(he)?"":new URL(`${$.pathname}${$.search}${$.hash}`,K).toString()}catch{return""}},[d,A]),oe=a.useCallback(L=>{const $=o.current?.contentWindow;$&&$.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:L},window.location.origin)},[]),pe=a.useCallback(async L=>{const $=E??(M?"draft":null);if(!$){ae.error(r("contextPanel.preview.inspect.attachNoSession"));return}const K=o.current,he=K?.contentWindow,de=K?.getBoundingClientRect(),we={width:Number.isFinite(he?.innerWidth)?he?.innerWidth??de?.width??0:de?.width??0,height:Number.isFinite(he?.innerHeight)?he?.innerHeight??de?.height??0:de?.height??0},xe=K?await Sm(K,L):null,De=!!xe;xe&&await R(xe),H({sessionKey:$,source:"preview-annotation",fileLabel:d||"browser",startLine:1,endLine:1,code:ic({pageUrl:d,viewport:we,devicePixelRatio:window.devicePixelRatio||1,target:L,screenshotAttached:De,intro:r(De?"contextPanel.preview.inspect.attachAnnotationWithScreenshot":"contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),ae.success(r("contextPanel.preview.inspect.attached"))},[R,H,E,d,M,r]),je=a.useCallback(()=>{const L=o.current;k(null),oe(!1),L&&Md(L,Wo).catch(()=>{})},[oe]);a.useEffect(()=>{if(!S)return;const L=$=>{$.key==="Escape"&&($.preventDefault(),$.stopImmediatePropagation(),v(!1),je())};return window.addEventListener("keydown",L,!0),()=>window.removeEventListener("keydown",L,!0)},[je,S]),a.useEffect(()=>()=>je(),[je]),a.useEffect(()=>{const L=$=>{if($.source!==o.current?.contentWindow)return;const K=$.data;if(!(!K||K.source!=="openchamber-preview-bridge"||K.version!==1)){if(K.type==="ready"){const he=typeof K.url=="string"?K.url:"",de=U(he);de&&de!==d&&z(de);return}if(K.type==="hover"){k(Ei(K.target)?K.target:null);return}if(K.type==="select"&&Ei(K.target)){k(null),v(!1),oe(!1),pe(K.target);return}if(K.type==="navigate-preview"){const he=typeof K.url=="string"?K.url:"",de=ie(he);if(de){z(de);return}he&&z(he)}}};return window.addEventListener("message",L),()=>window.removeEventListener("message",L)},[z,pe,d,U,ie,oe]);const Se=a.useCallback(()=>{const L=o.current;if(!(!L||!d)){if(S){v(!1),je();return}if(Z){k(null),v(!0),oe(!0);return}v(!0),(async()=>{try{const $=await Md(L,Rm);if(v(!1),!$||!Ei($))return;await pe($)}catch{v(!1),ae.error(r("contextPanel.browser.inspectUnavailable"))}})()}},[pe,je,d,S,oe,Z,r]),re=a.useCallback(()=>{try{const L=o.current?.contentWindow?.location.href||"",$=ie(L);if($){w(!0),z($);return}}catch{}w(!1),S&&Z&&oe(!0)},[z,ie,S,oe,Z]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:p<=0,onClick:()=>V(p-1),children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:p<0||p>=g.length-1,onClick:()=>V(p+1),children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!d,onClick:F,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:L=>{L.preventDefault(),z(u)},children:s.jsx("input",{value:u,onChange:L=>m(L.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(ze,{type:"button",variant:S?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!d,onClick:Se,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!d,onClick:()=>{wi(d)},children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[ne?s.jsxs("div",{className:"absolute inset-0",children:[s.jsx("iframe",{ref:o,src:ne,title:r("contextPanel.browser.empty"),className:"absolute inset-0 h-full w-full border-0 bg-background",allow:"clipboard-read; clipboard-write; fullscreen",allowFullScreen:!0,onLoad:re},`${ne}:${b}`),S&&j?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:j.bounds.x,top:j.bounds.y,width:j.bounds.width,height:j.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[j.tag,j.text?` · ${j.text}`:""]})}):null]}):s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(ja,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")}),s.jsx("span",{className:"max-w-sm typography-micro text-muted-foreground",children:r("contextPanel.browser.emptyHint")}),s.jsx("span",{className:"max-w-md typography-micro leading-relaxed text-status-warning/70",children:r("contextPanel.browser.trustNotice")})]}),N?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},P1=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=Tt(),o=a.useRef(null),i=Fe(T=>T.setContextPanelTabTargetPath),c=lo(t),l=c!=="about:blank"?c:"",[u,m]=a.useState(l),[d,f]=a.useState(l),[g,x]=a.useState(!1),[p,y]=a.useState(!0),b=a.useRef(null),h=p,N=a.useCallback(T=>{!T||T==="about:blank"||!e||!n||i(e,n,T)},[e,n,i]),w=jt(T=>T.currentSessionId),S=jt(T=>T.newSessionDraft?.open),v=ql(T=>T.addDraft),j=ti(T=>T.addAttachedFile);a.useEffect(()=>{const T=o.current;if(!T)return;const C=()=>{try{const _=T.getURL();_&&_!=="about:blank"&&(f(_),m(_),N(_))}catch{}},P=_=>{const z=_.detail;typeof z?.url=="string"&&z.url&&(f(z.url),m(z.url),N(z.url))},E=()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>y(!0),200)},M=()=>{b.current&&clearTimeout(b.current),y(!1),C()},H=_=>{const z=_.detail;if(z?.disposition==="new-window"||z?.disposition==="foreground-tab"||z?.disposition==="background-tab"){_.preventDefault();const V=o.current;typeof V?.loadURL=="function"&&z.url&&V.loadURL(z.url)}},R=()=>{try{T.executeJavaScript?.(S1,!0).catch(()=>{})}catch{}};T.addEventListener("did-navigate",P),T.addEventListener("did-navigate-in-page",P),T.addEventListener("did-start-loading",E),T.addEventListener("did-stop-loading",M),T.addEventListener("new-window",H),T.addEventListener("dom-ready",R);try{T.isLoading()||(y(!1),C())}catch{}return R(),()=>{b.current&&clearTimeout(b.current),T.removeEventListener("did-navigate",P),T.removeEventListener("did-navigate-in-page",P),T.removeEventListener("did-start-loading",E),T.removeEventListener("did-stop-loading",M),T.removeEventListener("new-window",H),T.removeEventListener("dom-ready",R)}},[N]),a.useEffect(()=>{const T=setTimeout(()=>y(!1),3e4);return()=>clearTimeout(T)},[]),a.useEffect(()=>{if(!g)return;const T=C=>{if(C.key!=="Escape")return;C.preventDefault(),C.stopImmediatePropagation(),x(!1);const P=o.current;try{P?.executeJavaScript?.(Wo).catch(()=>{})}catch{}};return window.addEventListener("keydown",T,!0),()=>window.removeEventListener("keydown",T,!0)},[g]),a.useEffect(()=>{const T=o.current;return()=>{try{const C=T?.getURL?.();C&&C!=="about:blank"&&i(e,n,C)}catch{}try{T?.executeJavaScript?.(Wo).catch(()=>{})}catch{}}},[e,n,i]);const k=a.useCallback(T=>{const C=o.current;if(typeof C?.loadURL!="function")return;const P=lo(T);try{C.loadURL(P)}catch{}},[]),A=a.useCallback(()=>{const T=o.current;if(T){if(g){x(!1);try{T.executeJavaScript?.(Wo).catch(()=>{})}catch{}return}x(!0),T.executeJavaScript?.(Rm,!0).then(async C=>{if(x(!1),!C||!Ei(C))return;const P=w??(S?"draft":null);if(!P){ae.error(r("contextPanel.preview.inspect.attachNoSession"));return}const E=typeof T.getWebContentsId=="function"?T.getWebContentsId():null;if(E==null)return;const M=await lh("desktop_browser_capture_page",{webContentsId:E}),H=await T.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(H?.width)?H.width:M.width,_=Number.isFinite(H?.height)?H.height:M.height,z=await oc(M.base64,M.width,M.height,R,_,C),V=!!z;z&&await j(z),v({sessionKey:P,source:"preview-annotation",fileLabel:d||"browser",startLine:1,endLine:1,code:ic({pageUrl:d,viewport:{width:R,height:_},devicePixelRatio:window.devicePixelRatio||1,target:C,screenshotAttached:V,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),ae.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>x(!1))}},[j,v,w,d,g,S,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goBack?.()}catch{}},children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goForward?.()}catch{}},children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.reload?.()}catch{}},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:T=>{T.preventDefault(),k(u)},children:s.jsx("input",{value:u,onChange:T=>m(T.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(ze,{type:"button",variant:g?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:A,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{wi(d)},children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:o,src:lo(t),partition:"persist:openchamber-browser",allowpopups:!0,style:{width:"100%",height:"100%",border:"none"}}),(!d||d==="about:blank")&&!p?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(ja,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,h?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},T1=()=>{const{t}=Tt(),e=si()??"",n=a.useMemo(()=>p1(e),[e]),r=Fe(le=>n?le.contextPanelByDirectory[n]:void 0),o=Fe(le=>le.closeContextPanel),i=Fe(le=>le.closeContextPanelTab),c=Fe(le=>le.toggleContextPanelExpanded),l=Fe(le=>le.setContextPanelWidth),u=Fe(le=>le.setActiveContextPanelTab),m=Fe(le=>le.reorderContextPanelTabs),d=Nn(le=>le.setSelectedPath),f=Fe(le=>le.openContextPreview),{themeMode:g,lightThemeId:x,darkThemeId:p,currentTheme:y}=Tr(),b=a.useMemo(()=>r?.tabs??[],[r?.tabs]),h=b.find(le=>le.id===r?.activeTabId)??b[b.length-1]??null,N=!!(r?.isOpen&&h),w=!!(N&&r?.expanded),S=Em(r?.width??Tm),[v,j]=a.useState(!1),[k,A]=a.useState(!1),T=a.useRef(0),C=a.useRef(S),P=a.useRef(null),E=a.useRef(null),M=a.useRef(null),H=a.useRef(new Map),R=a.useRef(!1),_=a.useRef(N),z=a.useRef(null),V=a.useCallback(()=>{A(!0),z.current!==null&&window.cancelAnimationFrame(z.current),z.current=window.requestAnimationFrame(()=>{z.current=null,A(!1)})},[]);a.useEffect(()=>()=>{z.current!==null&&window.cancelAnimationFrame(z.current)},[]),a.useLayoutEffect(()=>{const le=_.current;if(_.current=N,!N){A(!1);return}le||V()},[N,V]),a.useEffect(()=>{if(!N||R.current){R.current=N;return}const le=window.requestAnimationFrame(()=>{M.current?.focus({preventScroll:!0})});return R.current=!0,()=>window.cancelAnimationFrame(le)},[N]);const F=a.useCallback(le=>{const Ce=M.current;Ce&&Ce.style.setProperty("--oc-context-panel-width",`${Ya(le,Ce)}px`)},[]),te=a.useCallback(le=>{if(!(!N||w||!n)){try{le.currentTarget.setPointerCapture(le.pointerId)}catch{}E.current=le.pointerId,j(!0),T.current=le.clientX,C.current=S,P.current=S,F(S),le.preventDefault()}},[F,n,w,N,S]),Z=a.useCallback(le=>{if(!v||E.current!==le.pointerId)return;const Ce=T.current-le.clientX,ue=Ya(C.current+Ce,M.current);P.current!==ue&&(P.current=ue,F(ue))},[F,v]),ne=a.useCallback(le=>{if(E.current!==le.pointerId||!n)return;try{le.currentTarget.releasePointerCapture(le.pointerId)}catch{}const Ce=Ya(P.current??S,M.current);V(),F(Ce),P.current=Ce,l(n,Ce),j(!1),E.current=null},[F,n,l,V,S]);a.useEffect(()=>{v||(P.current=null)},[v]);const U=a.useCallback(()=>{n&&o(n)},[o,n]),ie=a.useCallback(()=>{n&&c(n)},[n,c]),oe=a.useCallback(le=>{le.key==="Escape"&&(le.preventDefault(),le.stopPropagation(),U())},[U]);a.useEffect(()=>{if(!(!n||!h)&&h.mode==="file"&&h.targetPath){d(n,h.targetPath);return}},[h,n,d]);const pe=h?.mode==="chat"?h.id:null,je=a.useCallback(()=>{if(typeof window>"u")return;const le={themeMode:g,lightThemeId:x,darkThemeId:p,currentTheme:y};for(const Ce of H.current.values()){const ue=Ce.contentWindow;if(!ue)continue;const ve=ue.__openchamberApplyThemeSync;if(typeof ve=="function")try{ve(le);continue}catch{}ue.postMessage({type:"openchamber:theme-sync",payload:le},window.location.origin)}},[y,p,x,g]),Se=a.useCallback(()=>{if(!(typeof window>"u"))for(const[le,Ce]of H.current.entries()){const ue=Ce.contentWindow;if(!ue)continue;const ve={visible:pe===le},G=ue.__openchamberSetEmbeddedVisibility;if(typeof G=="function")try{G(ve);continue}catch{}ue.postMessage({type:"openchamber:embedded-visibility",payload:ve},window.location.origin)}},[pe]);a.useLayoutEffect(()=>{b.some(Ce=>Ce.mode==="chat")&&(je(),Se())},[p,x,Se,je,b,g]);const re=a.useMemo(()=>b.map(le=>{const Ce=w1(le,t),ue=k1(Ce,f1),ve=x1(le.targetPath,e);return{id:le.id,label:ue,icon:v1(le),title:ve?`${Ce}: ${ve}`:Ce,closeLabel:t("contextPanel.tab.closeTabAria",{label:ue})}}),[e,t,b]),L=h?.mode==="diff"?s.jsx(xm,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:h.stagedDiff?"staged":"working",targetFilePath:h.targetPath},h.id):h?.mode==="context"?s.jsx(Bw,{}):h?.mode==="plan"?s.jsx(jm,{targetPath:h.targetPath}):h?.mode==="preview"?s.jsx(A1,{rawUrl:h.targetPath??"",onNavigate:le=>f(e,le)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(I,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),$=a.useMemo(()=>b.filter(le=>le.mode==="chat"),[b]),K=a.useMemo(()=>b.filter(le=>le.mode==="browser"),[b]),he=D1()?P1:I1,de=a.useMemo(()=>b.some(le=>le.mode==="file"),[b]),we=h?.mode==="file",xe=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-transparent",children:[s.jsx(po,{items:re,activeId:h?.id??null,onSelect:le=>{n&&u(n,le)},onClose:le=>{n&&i(n,le)},onReorder:(le,Ce)=>{n&&m(n,le,Ce)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:ie,className:"h-7 w-7 p-0",title:t(w?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(w?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:w?s.jsx(I,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:U,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),De=N?w?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",minWidth:`min(${Pm}px, 100%)`,maxWidth:"100%","--oc-context-panel-width":`${v?P.current??S:S}px`}:{"--oc-context-panel-width":`${v?P.current??S:S}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:"hidden",visibility:"hidden"};return s.jsxs("aside",{ref:M,"data-context-panel":"true",tabIndex:-1,inert:!N||void 0,className:Pe("flex min-h-0 flex-col overflow-hidden bg-background",!w&&"border-l border-border/40",w?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",!N&&"pointer-events-none",v||!N||k?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:oe,style:De,children:[!w&&s.jsx("div",{className:Pe("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",v&&"bg-[var(--interactive-border)]"),onPointerDown:te,onPointerMove:Z,onPointerUp:ne,onPointerCancel:ne,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),xe,s.jsxs("div",{className:Pe("relative min-h-0 flex-1 overflow-hidden",v&&"pointer-events-none"),children:[de?s.jsx("div",{className:Pe("absolute inset-0",we?"block":"hidden"),children:s.jsx(vm,{mode:"editor-only"})}):null,$.map(le=>{const Ce=j1(le.dedupeKey);if(!Ce)return null;const ue=N1(Ce,n||null,le.readOnly);return ue?s.jsx("iframe",{ref:ve=>{if(!ve){H.current.delete(le.id);return}H.current.set(le.id,ve)},src:ue,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:Ce}),className:Pe("absolute inset-0 h-full w-full border-0 bg-background",pe===le.id?"block":"hidden"),onLoad:()=>{je(),Se()}},le.id):null}),K.map(le=>s.jsx("div",{className:Pe("absolute inset-0",h?.id!==le.id&&"hidden"),children:s.jsx(he,{initialUrl:le.targetPath??"",directory:n,tabID:le.id})},le.id)),h?.mode!=="chat"&&!we&&h?.mode!=="browser"?L:null]})]})},Il=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const o=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!o&&!i&&(r=r.replace(/\/+$/,"")),r},E1=()=>{const t=pt.c(162),{t:e}=Tt(),n=Fe(R1),r=Fe(M1),o=Fe(F1),i=Fe(L1),c=Fe(O1),l=Fe(_1),u=Fe(B1),m=Fe(V1),d=Fe($1),f=Fe(z1),g=Fe(W1),x=Fe(U1),p=jt(H1),y=jt(G1),b=Zr(K1),h=tn(q1),N=Ms(Y1),w=si(),S=Hl(J1),{files:v,git:j}=Gn(),k=_s(Q1),{isMobile:A}=Pr();let T;t[0]!==w?(T=w?Il(w):null,t[0]=w,t[1]=T):T=t[1];const C=T,[P,E]=a.useState(""),M=va(P,200);let H;t[2]!==M?(H=M.trim(),t[2]=M,t[3]=H):H=t[3];const R=H;let _;t[4]!==P?(_=P.trim(),t[4]=P,t[5]=_):_=t[5];const z=_;let V,F;t[6]!==n?(V=()=>{n&&E("")},F=[n],t[6]=n,t[7]=V,t[8]=F):(V=t[7],F=t[8]),a.useEffect(V,F);let te,Z;t[9]!==b||t[10]!==k||t[11]!==j||t[12]!==n?(te=()=>{if(!n||!j)return;const Ke=setTimeout(()=>{const tt=new Set;for(const We of b){const gt=xi(We);!gt||tt.has(gt)||(tt.add(gt),k(gt,j))}},0);return()=>clearTimeout(Ke)},Z=[n,b,j,k],t[9]=b,t[10]=k,t[11]=j,t[12]=n,t[13]=te,t[14]=Z):(te=t[13],Z=t[14]),a.useEffect(te,Z);let ne;t[15]!==r?(ne=()=>r(!1),t[15]=r,t[16]=ne):ne=t[16];const U=ne;let ie;t[17]!==U?(ie=Ke=>()=>{U(),Ke()},t[17]=U,t[18]=ie):ie=t[18];const oe=ie;let pe;t[19]!==N?.id||t[20]!==N?.path||t[21]!==h||t[22]!==A||t[23]!==f||t[24]!==p||t[25]!==oe||t[26]!==o||t[27]!==l||t[28]!==i||t[29]!==e||t[30]!==d||t[31]!==m||t[32]!==u?(pe=()=>{const Ke=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(I,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:oe(()=>{o("chat"),l(!1),p()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(I,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:oe(X1)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:oe(Z1)},{id:"toggle-sidebar",title:e(A?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(I,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(A?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:oe(()=>{if(A){const{isSessionSwitcherOpen:tt}=Fe.getState();l(!tt)}else u()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(I,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:oe(()=>m())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(I,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:oe(()=>d())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(I,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:oe(()=>{h&&f(h)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(I,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:oe(()=>i(!0))}];return _l()&&Ke.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(I,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:oe(()=>{hi("desktop_open_draft_mini_chat_window",{directory:Il(h||N?.path||""),projectId:N?.id??null}).catch(ev)})}),Ke},t[19]=N?.id,t[20]=N?.path,t[21]=h,t[22]=A,t[23]=f,t[24]=p,t[25]=oe,t[26]=o,t[27]=l,t[28]=i,t[29]=e,t[30]=d,t[31]=m,t[32]=u,t[33]=pe):pe=t[33],N?.id,N?.path;let je;t[34]!==pe?(je=pe(),t[34]=pe,t[35]=je):je=t[35];const Se=je;let re;t[36]===Symbol.for("react.memo_cache_sentinel")?(re=or(),t[36]=re):re=t[36];const L=re;let $;t[37]===Symbol.for("react.memo_cache_sentinel")?($={isVSCode:Hi(),isWeb:!L&&Yl(),isDesktop:L},t[37]=$):$=t[37];const K=$;let he;if(t[38]!==oe||t[39]!==i||t[40]!==c){let Ke;t[42]===Symbol.for("react.memo_cache_sentinel")?(Ke=tt=>tt.isAvailable?tt.isAvailable(K):!0,t[42]=Ke):Ke=t[42],he=Kp.filter(tv).filter(Ke).map(tt=>{const We=qp(tt.slug)??"settings-3",gt=(tt.keywords??[]).join(" ");return{id:`settings:${tt.slug}`,title:tt.title,icon:s.jsx(I,{name:We,className:"mr-2 h-4 w-4"}),searchText:`${tt.title} ${tt.group} ${gt}`,onSelect:oe(()=>{c(tt.slug),i(!0)})}}),t[38]=oe,t[39]=i,t[40]=c,t[41]=he}else he=t[41];const de=he,we=sv;let xe;if(t[43]!==b){let Ke;t[45]===Symbol.for("react.memo_cache_sentinel")?(Ke=(tt,We)=>we(We)-we(tt),t[45]=Ke):Ke=t[45],xe=[...b].sort(Ke),t[43]=b,t[44]=xe}else xe=t[44];const De=xe,le=Ou(),Ce=jt(nv);let ue;t[46]!==le||t[47]!==Ce?(ue=(Ke,tt)=>{const We=Ce.get(Ke);return We?.branch?We.branch.trim()||null:tt&&le.get(tt)?.trim()||null},t[46]=le,t[47]=Ce,t[48]=ue):ue=t[48];const ve=ue;let G;t[49]===Symbol.for("react.memo_cache_sentinel")?(G=[],t[49]=G):G=t[49];const[Ae,ce]=a.useState(G),[fe,Te]=a.useState(!1);let me,B;t[50]!==C||t[51]!==n||t[52]!==S||t[53]!==R?(me=()=>{if(!n){ce([]),Te(!1);return}if(!C||R.length===0){ce([]),Te(!1);return}let Ke=!1;return Te(!0),S(C,R,10,{type:"file"}).then(tt=>{Ke||ce(tt.map(rv))}).catch(()=>{Ke||ce([])}).finally(()=>{Ke||Te(!1)}),()=>{Ke=!0}},B=[n,C,R,S],t[50]=C,t[51]=n,t[52]=S,t[53]=R,t[54]=me,t[55]=B):(me=t[54],B=t[55]),a.useEffect(me,B);const ye=z.length>0;let _e;e:{if(!ye){let tt;t[56]!==Se?(tt=Se.map(iv),t[56]=Se,t[57]=tt):tt=t[57],_e=tt;break e}let Ke;t[58]!==Se||t[59]!==z?(Ke=ko(Se,z,ov,{limit:7,noFuzzy:!0}),t[58]=Se,t[59]=z,t[60]=Ke):Ke=t[60],_e=Ke}const J=_e;let Me;e:{if(!ye){let tt;t[61]===Symbol.for("react.memo_cache_sentinel")?(tt=[],t[61]=tt):tt=t[61],Me=tt;break e}let Ke;t[62]!==z||t[63]!==de?(Ke=ko(de,z,av,{limit:7,noFuzzy:!0}),t[62]=z,t[63]=de,t[64]=Ke):Ke=t[64],Me=Ke}const Ee=Me;let Ne;e:{if(!ye){let tt;t[65]!==De?(tt=De.slice(0,5).map(lv),t[65]=De,t[66]=tt):tt=t[66],Ne=tt;break e}let Ke;t[67]!==z||t[68]!==De?(Ke=ko(De,z,cv,{limit:7,threshold:.2}),t[67]=z,t[68]=De,t[69]=Ke):Ke=t[69],Ne=Ke}const Be=Ne;let se;e:{if(!ye||Ae.length===0){let tt;t[70]===Symbol.for("react.memo_cache_sentinel")?(tt=[],t[70]=tt):tt=t[70],se=tt;break e}let Ke;t[71]!==Ae||t[72]!==z?(Ke=ko(Ae,z,dv,{limit:10,threshold:.4}),t[71]=Ae,t[72]=z,t[73]=Ke):Ke=t[73],se=Ke}const O=se;let D,Y,be,Oe,$e,Re,ot,yt,At,mt,Le,Qe,Ye,rt,bt;if(t[74]!==ve||t[75]!==U||t[76]!==C||t[77]!==v||t[78]!==ye||t[79]!==n||t[80]!==g||t[81]!==P||t[82]!==J||t[83]!==O||t[84]!==Be||t[85]!==Ee||t[86]!==r||t[87]!==y||t[88]!==x||t[89]!==e){const Ke=J.map(uv),tt=Ee.map(mv),We=Be.map(fv);bt=ye?O.map(hv):[];let gt;e:{if(!ye){gt=["commands","sessions"];break e}const Yt=pv,ft=[{key:"commands",score:Yt(J)},{key:"settings",score:Yt(Ee)},{key:"sessions",score:Yt(Be)},{key:"files",score:Yt(O)}];ft.sort(gv),gt=ft.map(xv)}const He=gt;let st;t[105]!==U||t[106]!==y?(st=Yt=>{U(),y(Yt.id,xi(Yt))},t[105]=U,t[106]=y,t[107]=st):st=t[107];const Et=st;let at;t[108]!==U||t[109]!==C||t[110]!==v||t[111]!==g?(at=async Yt=>{if(!C)return;const ft=await nc(v,Yt);if(!ft.ok){ae.error(rc(ft.reason));return}g(C,Yt),U()},t[108]=U,t[109]=C,t[110]=v,t[111]=g,t[112]=at):at=t[112];const dt=at;let Ht;t[113]!==x?(Ht=Yt=>Vl(pi(Yt,x)),t[113]=x,t[114]=Ht):Ht=t[114];const Rt=Ht;Oe=Ks,Qe=n,Ye=r;let Wt;t[115]!==e?(Wt=e("commandPalette.title"),t[115]=e,t[116]=Wt):Wt=t[116];let qt;t[117]!==Wt?(qt=s.jsx(Ys,{children:Wt}),t[117]=Wt,t[118]=qt):qt=t[118];let Lt;t[119]!==e?(Lt=e("commandPalette.description"),t[119]=e,t[120]=Lt):Lt=t[120];let Gt;t[121]!==Lt?(Gt=s.jsx(dn,{children:Lt}),t[121]=Lt,t[122]=Gt):Gt=t[122],t[123]!==qt||t[124]!==Gt?(rt=s.jsxs(Qs,{className:"sr-only",children:[qt,Gt]}),t[123]=qt,t[124]=Gt,t[125]=rt):rt=t[125],be=Gs,mt="overflow-hidden p-0",Le=!0,Y=ma,ot=!1,yt="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let Qt;t[126]!==e?(Qt=e("commandPalette.input.placeholder"),t[126]=e,t[127]=Qt):Qt=t[127],t[128]!==P||t[129]!==Qt?(At=s.jsx(fa,{value:P,onValueChange:E,placeholder:Qt}),t[128]=P,t[129]=Qt,t[130]=At):At=t[130],D=ha;let rs;t[131]!==e?(rs=e("commandPalette.empty.noResults"),t[131]=e,t[132]=rs):rs=t[132],t[133]!==rs?($e=s.jsx(pa,{children:rs}),t[133]=rs,t[134]=$e):$e=t[134],Re=He.map(Yt=>Yt==="commands"&&Ke.length>0?s.jsx(Yr,{children:Ke.map(ft=>s.jsxs(ei,{value:ft.id,onSelect:ft.onSelect,children:[ft.icon,s.jsx("span",{children:ft.title}),ft.shortcutId?s.jsx(ch,{children:Rt(ft.shortcutId)}):null]},ft.id))},"commands"):Yt==="settings"&&tt.length>0?s.jsx(Yr,{children:tt.map(bv)},"settings"):Yt==="sessions"&&We.length>0?s.jsx(Yr,{children:We.map(ft=>{const Jt=ft.title||e("commandPalette.session.untitled"),ms=xi(ft),Xt=ve(ft.id,ms);return s.jsxs(ei,{value:`session:${ft.id}`,onSelect:()=>Et(ft),children:[s.jsx(I,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Jt}),Xt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Xt})]}):null]},ft.id)})},"sessions"):Yt==="files"&&bt.length>0?s.jsx(Yr,{children:bt.map(ft=>{const Jt=dh(ft.relativePath||ft.name,{maxLength:80});return s.jsxs(ei,{value:`file:${ft.path}`,onSelect:()=>{dt(ft.path)},children:[s.jsx(xr,{filePath:ft.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":ft.relativePath,children:Jt})]},`file:${ft.path}`)})},"files"):null),t[74]=ve,t[75]=U,t[76]=C,t[77]=v,t[78]=ye,t[79]=n,t[80]=g,t[81]=P,t[82]=J,t[83]=O,t[84]=Be,t[85]=Ee,t[86]=r,t[87]=y,t[88]=x,t[89]=e,t[90]=D,t[91]=Y,t[92]=be,t[93]=Oe,t[94]=$e,t[95]=Re,t[96]=ot,t[97]=yt,t[98]=At,t[99]=mt,t[100]=Le,t[101]=Qe,t[102]=Ye,t[103]=rt,t[104]=bt}else D=t[90],Y=t[91],be=t[92],Oe=t[93],$e=t[94],Re=t[95],ot=t[96],yt=t[97],At=t[98],mt=t[99],Le=t[100],Qe=t[101],Ye=t[102],rt=t[103],bt=t[104];let ct;t[135]!==ye||t[136]!==fe||t[137]!==e||t[138]!==bt?(ct=ye&&fe&&bt.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=ye,t[136]=fe,t[137]=e,t[138]=bt,t[139]=ct):ct=t[139];let nt;t[140]!==D||t[141]!==$e||t[142]!==Re||t[143]!==ct?(nt=s.jsxs(D,{children:[$e,Re,ct]}),t[140]=D,t[141]=$e,t[142]=Re,t[143]=ct,t[144]=nt):nt=t[144];let It;t[145]!==Y||t[146]!==ot||t[147]!==yt||t[148]!==At||t[149]!==nt?(It=s.jsxs(Y,{shouldFilter:ot,className:yt,children:[At,nt]}),t[145]=Y,t[146]=ot,t[147]=yt,t[148]=At,t[149]=nt,t[150]=It):It=t[150];let lt;t[151]!==be||t[152]!==mt||t[153]!==Le||t[154]!==It?(lt=s.jsx(be,{className:mt,showCloseButton:Le,children:It}),t[151]=be,t[152]=mt,t[153]=Le,t[154]=It,t[155]=lt):lt=t[155];let kt;return t[156]!==Oe||t[157]!==Qe||t[158]!==Ye||t[159]!==rt||t[160]!==lt?(kt=s.jsxs(Oe,{open:Qe,onOpenChange:Ye,children:[rt,lt]}),t[156]=Oe,t[157]=Qe,t[158]=Ye,t[159]=rt,t[160]=lt,t[161]=kt):kt=t[161],kt};function R1(t){return t.isCommandPaletteOpen}function M1(t){return t.setCommandPaletteOpen}function F1(t){return t.setActiveMainTab}function L1(t){return t.setSettingsDialogOpen}function O1(t){return t.setSettingsPage}function _1(t){return t.setSessionSwitcherOpen}function B1(t){return t.toggleSidebar}function V1(t){return t.toggleRightSidebar}function $1(t){return t.toggleBottomTerminal}function z1(t){return t.openContextOverview}function W1(t){return t.openContextFile}function U1(t){return t.shortcutOverrides}function H1(t){return t.openNewSessionDraft}function G1(t){return t.setCurrentSession}function K1(t){return t.activeSessions}function q1(t){return t.currentDirectory}function Y1(t){return t.getActiveProject()}function J1(t){return t.searchFiles}function Q1(t){return t.ensureStatus}function X1(){_u()}function Z1(){Ir.requestDirectoryDialog()}function ev(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function tv(t){return t.slug!=="home"}function sv(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function nv(t){return t.worktreeMetadata}function rv(t){return{path:Il(t.path),name:t.name,relativePath:t.relativePath}}function iv(t){return{item:t,score:0}}function ov(t){return t.searchText}function av(t){return t.searchText}function lv(t){return{item:t,score:0}}function cv(t){return t.title||""}function dv(t){return t.name}function uv(t){return t.item}function mv(t){return t.item}function fv(t){return t.item}function hv(t){return t.item}function pv(t){return t.length?t[0].score:1/0}function gv(t,e){return t.score-e.score}function xv(t){return t.key}function bv(t){return s.jsxs(ei,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Ld=(t,e,n)=>mh(t)?Vl(pi(t,n)):e,yv=()=>{const t=pt.c(68),{t:e}=Tt(),n=Fe(wv),r=Fe(vv),o=Fe(jv);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=uh(),t[0]=i):i=t[0];const c=i;let l,u,m,d,f,g,x,p,y;if(t[1]!==n||t[2]!==r||t[3]!==o||t[4]!==e){const R=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${c} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${c} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];u=Ks,p=n,y=r,l=Gs,g="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let _;t[14]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(I,{name:"settings-3",className:"h-5 w-5"}),t[14]=_):_=t[14];let z;t[15]!==e?(z=e("helpDialog.title"),t[15]=e,t[16]=z):z=t[16];let V;t[17]!==z?(V=s.jsxs(Ys,{className:"flex items-center gap-2",children:[_,z]}),t[17]=z,t[18]=V):V=t[18];let F;t[19]!==e?(F=e("helpDialog.description"),t[19]=e,t[20]=F):F=t[20];let te;t[21]!==F?(te=s.jsx(dn,{children:F}),t[21]=F,t[22]=te):te=t[22],t[23]!==V||t[24]!==te?(x=s.jsxs(Qs,{children:[V,te]}),t[23]=V,t[24]=te,t[25]=x):x=t[25],f="flex-1 overflow-y-auto mt-3 pr-1",m="space-y-4",d=R.map(Z=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(Z.categoryKey)}),s.jsx("div",{className:"space-y-1",children:Z.items.map(ne=>{const U=ne.id?Ld(ne.id,Array.isArray(ne.keys)?ne.keys[0]:ne.keys,o):Array.isArray(ne.keys)?ne.keys:ne.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ne.icon&&s.jsx(I,{name:ne.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(ne.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(U)?U:[U]).map((ie,oe)=>s.jsxs(a.Fragment,{children:[oe>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:ie})]},`${ie}-${oe}`))})]},ne.id||ne.descriptionKey)})})]},Z.categoryKey)),t[1]=n,t[2]=r,t[3]=o,t[4]=e,t[5]=l,t[6]=u,t[7]=m,t[8]=d,t[9]=f,t[10]=g,t[11]=x,t[12]=p,t[13]=y}else l=t[5],u=t[6],m=t[7],d=t[8],f=t[9],g=t[10],x=t[11],p=t[12],y=t[13];let b;t[26]!==m||t[27]!==d?(b=s.jsx("div",{className:m,children:d}),t[26]=m,t[27]=d,t[28]=b):b=t[28];let h;t[29]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(I,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=h):h=t[29];let N;t[30]!==e?(N=e("helpDialog.proTips.title"),t[30]=e,t[31]=N):N=t[31];let w;t[32]!==N?(w=s.jsx("p",{className:"font-medium mb-1",children:N}),t[32]=N,t[33]=w):w=t[33];let S;t[34]!==o||t[35]!==e?(S=e("helpDialog.proTips.commandPalette",{shortcut:Ld("open_command_palette",`${c} P`,o)}),t[34]=o,t[35]=e,t[36]=S):S=t[36];let v;t[37]!==S?(v=s.jsxs("li",{children:["• ",S]}),t[37]=S,t[38]=v):v=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let k;t[41]!==j?(k=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=k):k=t[42];let A;t[43]!==e?(A=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=A):A=t[44];let T;t[45]!==A?(T=s.jsxs("li",{children:["• ",A]}),t[45]=A,t[46]=T):T=t[46];let C;t[47]!==v||t[48]!==k||t[49]!==T?(C=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[v,k,T]}),t[47]=v,t[48]=k,t[49]=T,t[50]=C):C=t[50];let P;t[51]!==w||t[52]!==C?(P=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[h,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[w,C]})]})}),t[51]=w,t[52]=C,t[53]=P):P=t[53];let E;t[54]!==P||t[55]!==f||t[56]!==b?(E=s.jsxs("div",{className:f,children:[b,P]}),t[54]=P,t[55]=f,t[56]=b,t[57]=E):E=t[57];let M;t[58]!==l||t[59]!==E||t[60]!==g||t[61]!==x?(M=s.jsxs(l,{className:g,children:[x,E]}),t[58]=l,t[59]=E,t[60]=g,t[61]=x,t[62]=M):M=t[62];let H;return t[63]!==u||t[64]!==M||t[65]!==p||t[66]!==y?(H=s.jsx(u,{open:p,onOpenChange:y,children:M}),t[63]=u,t[64]=M,t[65]=p,t[66]=y,t[67]=H):H=t[67],H};function wv(t){return t.isHelpDialogOpen}function vv(t){return t.setHelpDialogOpen}function jv(t){return t.shortcutOverrides}const Sv=()=>{const t=pt.c(32),{t:e}=Tt(),n=Fe(Nv),r=Fe(kv),o=Fe(Cv);let i;t[0]!==o||t[1]!==e?(i=async()=>{if(!o)return;if((await ar(o)).ok){ae.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}ae.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=o,t[1]=e,t[2]=i):i=t[2];const c=i;let l;t[3]!==e?(l=e("openCodeStatusDialog.title"),t[3]=e,t[4]=l):l=t[4];let u;t[5]!==l?(u=s.jsx(Ys,{children:l}),t[5]=l,t[6]=u):u=t[6];let m;t[7]!==e?(m=e("openCodeStatusDialog.description"),t[7]=e,t[8]=m):m=t[8];let d;t[9]!==m?(d=s.jsx(dn,{children:m}),t[9]=m,t[10]=d):d=t[10];let f;t[11]!==u||t[12]!==d?(f=s.jsxs(Qs,{children:[u,d]}),t[11]=u,t[12]=d,t[13]=f):f=t[13];let g;t[14]!==e?(g=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=g):g=t[15];let x;t[16]!==c||t[17]!==g?(x=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:c,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:g})}),t[16]=c,t[17]=g,t[18]=x):x=t[18];let p;t[19]!==o||t[20]!==e?(p=o||e("openCodeStatusDialog.empty.noData"),t[19]=o,t[20]=e,t[21]=p):p=t[21];let y;t[22]!==p?(y=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:p}),t[22]=p,t[23]=y):y=t[23];let b;t[24]!==f||t[25]!==x||t[26]!==y?(b=s.jsxs(Gs,{className:"max-w-2xl",children:[f,x,y]}),t[24]=f,t[25]=x,t[26]=y,t[27]=b):b=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==b?(h=s.jsx(Ks,{open:n,onOpenChange:r,children:b}),t[28]=n,t[29]=r,t[30]=b,t[31]=h):h=t[31],h};function Nv(t){return t.isOpenCodeStatusDialogOpen}function kv(t){return t.setOpenCodeStatusDialogOpen}function Cv(t){return t.openCodeStatusText}const Av=180,Od=600,Dv=1,Iv=6,Pv=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const o=a.useRef(new Map),i=a.useRef([]),c=a.useRef(new Set),l=a.useMemo(()=>Hi(),[]),u=a.useCallback(()=>{if(!(l||typeof window>"u"))for(;c.current.size<Dv&&i.current.length>0;){const d=i.current.shift();if(!d)break;jt.getState().currentSessionId!==d&&(kc(d).renderable||(c.current.add(d),r(d).catch(()=>{}).finally(()=>{c.current.delete(d),u()})))}},[r,l]),m=a.useCallback(d=>{if(l||!d||d===t||typeof window>"u"||kc(d).renderable||c.current.has(d)||i.current.includes(d))return;i.current.length>=Iv&&i.current.shift();const f=o.current.get(d);f!==void 0&&window.clearTimeout(f);const g=window.setTimeout(()=>{o.current.delete(d),i.current.push(d),u()},Av);o.current.set(d,g)},[t,l,u]);a.useEffect(()=>{if(l||!t||e.length===0)return;const d=window.setTimeout(()=>{const f=e.findIndex(g=>g.id===t);f<0||(m(e[f-1]?.id),m(e[f+1]?.id))},Od);return()=>window.clearTimeout(d)},[t,l,m,e]),a.useEffect(()=>{if(l||!t||n.length===0)return;const d=window.setTimeout(()=>{const f=n.indexOf(t);f<0||(m(n[f-1]),m(n[f+1]))},Od);return()=>window.clearTimeout(d)},[t,l,n,m]),a.useEffect(()=>{const d=o.current;return()=>{d.forEach(f=>{clearTimeout(f)}),d.clear(),i.current=[]}},[])};let Mi=null,Fi=null,Uo=null,go=0,da=null;const yi=new Set,Tv=3e4,Ev=45e3,Fm=()=>{Uo&&(clearTimeout(Uo),Uo=null)},Lm=()=>{if(Fi||yi.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(go,5)),Tv);Fi=setTimeout(()=>{Fi=null,go+=1,lc()},t)},xo=()=>{Fm(),Mi&&Mi.close(),Mi=null},_d=()=>{Fm(),yi.size!==0&&(Uo=setTimeout(()=>{xo(),Lm()},Ev))},Rv=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},Mv=t=>{if(t.type==="openchamber:event-stream-ready"){go=0;return}if(t.type==="openchamber:heartbeat"||t.type!=="openchamber:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",o=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,c=i==="running"||i==="error"?i:"success";if(!n||!r)return;const l={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:o,status:c,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const u of yi)u(l)},lc=()=>{if(typeof window>"u"||yi.size===0||typeof EventSource!="function"||Mi&&Mi.readyState!==EventSource.CLOSED)return;xo();const t=new EventSource(Li().sse("/api/openchamber/events"));t.onopen=()=>{_d()},t.onmessage=e=>{_d();const n=Rv(e.data);n&&Mv(n)},t.onerror=()=>{xo(),Lm()},Mi=t},Fv=()=>{da||typeof window>"u"||(da=bu(()=>{xo(),go=0,lc()}))},Lv=()=>{da?.(),da=null},Om=t=>(yi.add(t),Fv(),lc(),()=>{yi.delete(t),yi.size===0&&(Fi&&(clearTimeout(Fi),Fi=null),go=0,xo(),Lv())}),Aa=async(t,e)=>{try{const n=await t.json();if(n&&typeof n.error=="string"&&n.error.trim().length>0)return n.error}catch{return e}return e},Wi=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},Ov=async t=>{const e=Wi(t),n=await Fs(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Aa(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Bd=async(t,e)=>{const n=Wi(t),r=await Fs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:e})});if(!r.ok)throw new Error(await Aa(r,"Failed to save scheduled task"));const o=await r.json().catch(()=>null);return!o||!Array.isArray(o.tasks)?[]:o.tasks},_v=async(t,e)=>{const n=Wi(t),r=Wi(e),o=await Fs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Aa(o,"Failed to delete scheduled task"));const i=await o.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},Bv=async(t,e)=>{const n=Wi(t),r=Wi(e),o=await Fs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Aa(o,"Failed to run scheduled task"));const i=await o.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0}},_m=[0,1,2,3,4,5,6],Vd=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?Intl.supportedValuesOf("timeZone"):["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],$d=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Ho=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),o=Number(e[3]),i=new Date(n,r-1,o);return Number.isNaN(i.getTime())||i.getFullYear()!==n||i.getMonth()!==r-1||i.getDate()!==o?null:i},zd=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Vv=(t,e,n)=>{const r=Ho(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Wd=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),$v=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),c=(new Date(n,r,1).getDay()-e+7)%7,l=new Date(n,r+1,0).getDate(),u=new Date(n,r,0).getDate(),m=[];for(let d=0;d<42;d+=1){const f=d-c+1;if(f<=0){const g=u+f;m.push({date:new Date(n,r-1,g),inCurrentMonth:!1});continue}if(f>l){m.push({date:new Date(n,r+1,f-l),inCurrentMonth:!1});continue}m.push({date:new Date(n,r,f),inCurrentMonth:!0})}return m},zv=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],o=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:o}},ci=(t,e,n)=>{const r=Number(t),o=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,c=Number.isFinite(o)?Math.min(59,Math.max(0,o)):0;let l=i%12;return n==="PM"&&(l+=12),`${String(l).padStart(2,"0")}:${String(c).padStart(2,"0")}`},Gi=(t,e)=>{const{max:n,min:r=0,loop:o=!1}=e;let i=Number.parseInt(t,10);return Number.isFinite(i)?(o?(i>n&&(i=r),i<r&&(i=n)):(i>n&&(i=n),i<r&&(i=r)),String(i).padStart(2,"0")):"00"},Ud=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:Gi(t,{min:1,max:12}),To=t=>/^[0-5][0-9]$/.test(t)?t:Gi(t,{max:59}),Wv=(t,e)=>Gi(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Hd=(t,e)=>Gi(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),Uv=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},Hv=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},Gv=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return _m.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},Kv=(t,e)=>[...t.slice(e),...t.slice(0,e)],ir=t=>{const e=pt.c(6),{htmlFor:n,required:r,children:o}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let c;return e[2]!==o||e[3]!==n||e[4]!==i?(c=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,i]})}),e[2]=o,e[3]=n,e[4]=i,e[5]=c):c=e[5],c},Gd=t=>{const e=pt.c(84),{value:n,onChange:r,use24Hour:o,hourAriaLabel:i,minuteAriaLabel:c,periodAriaLabel:l,amLabel:u,pmLabel:m}=t;let d;e[0]!==n?(d=zv(n),e[0]=n,e[1]=d):d=e[1];const f=d,g=et.useRef(null),x=et.useRef(null),[p,y]=et.useState(null),[b,h]=et.useState(null),N=et.useRef(null),w=et.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=G=>{N.current=G,y(G)},e[2]=S):S=e[2];const v=S;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=G=>{w.current=G,h(G)},e[3]=j):j=e[3];const k=j,A=Zv,T=e0,C=t0;let P;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==o?(P=G=>{const Ae=G.replace(/\D/g,"").slice(0,2);v(Ae),Ae.length===2&&(r(o?C(A(Ae),f.minute):ci(Ud(Ae),f.minute,f.meridiem)),v(null),x.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=o,e[8]=P):P=e[8];const E=P;let M;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==o?(M=()=>{const G=N.current;if(G!==null&&(v(null),G.length!==0)){if(o){r(C(A(G.padStart(2,"0")),f.minute));return}r(ci(Ud(G.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=o,e[13]=M):M=e[13];const H=M;let R;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==o?(R=G=>{const Ae=G.replace(/\D/g,"").slice(0,2);k(Ae),Ae.length===2&&(r(o?C(f.hour24,To(Ae)):ci(f.hour12,To(Ae),f.meridiem)),k(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=o,e[19]=R):R=e[19];const _=R;let z;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==o?(z=()=>{const G=w.current;G!==null&&(k(null),G.length!==0&&r(o?C(f.hour24,To(G.padStart(2,"0"))):ci(f.hour12,To(G.padStart(2,"0")),f.meridiem)))},e[20]=r,e[21]=f.hour12,e[22]=f.hour24,e[23]=f.meridiem,e[24]=o,e[25]=z):z=e[25];const V=z;let F;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==o?(F=G=>r(o?C(T(f.hour24,G),f.minute):ci(Wv(f.hour12,G),f.minute,f.meridiem)),e[26]=r,e[27]=f.hour12,e[28]=f.hour24,e[29]=f.meridiem,e[30]=f.minute,e[31]=o,e[32]=F):F=e[32];const te=F;let Z;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==o?(Z=G=>r(o?C(f.hour24,Hd(f.minute,G)):ci(f.hour12,Hd(f.minute,G),f.meridiem)),e[33]=r,e[34]=f.hour12,e[35]=f.hour24,e[36]=f.meridiem,e[37]=f.minute,e[38]=o,e[39]=Z):Z=e[39];const ne=Z;let U;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(U=G=>{G!==f.meridiem&&r(ci(f.hour12,f.minute,G))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=U):U=e[44];const ie=U;let oe;e[45]!==H||e[46]!==te?(oe=G=>{if(G.key==="ArrowRight"){G.preventDefault(),H(),x.current?.focus();return}(G.key==="ArrowUp"||G.key==="ArrowDown")&&(G.preventDefault(),v(null),te(G.key==="ArrowUp"?1:-1))},e[45]=H,e[46]=te,e[47]=oe):oe=e[47];const pe=oe;let je;e[48]!==V||e[49]!==ne?(je=G=>{if(G.key==="ArrowLeft"&&(G.currentTarget.selectionStart??0)===0){G.preventDefault(),V(),g.current?.focus();return}(G.key==="ArrowUp"||G.key==="ArrowDown")&&(G.preventDefault(),k(null),ne(G.key==="ArrowUp"?1:-1))},e[48]=V,e[49]=ne,e[50]=je):je=e[50];const Se=je,re=o?"px-2":"pl-2 pr-1";let L;e[51]!==re?(L=Pe("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",re),e[51]=re,e[52]=L):L=e[52];const $=p??(o?f.hour24:f.hour12);let K;e[53]!==E?(K=G=>E(G.target.value),e[53]=E,e[54]=K):K=e[54];let he;e[55]===Symbol.for("react.memo_cache_sentinel")?(he=()=>v(""),e[55]=he):he=e[55];let de;e[56]!==H||e[57]!==i||e[58]!==pe||e[59]!==$||e[60]!==K?(de=s.jsx("input",{ref:g,inputMode:"numeric",value:$,onChange:K,onKeyDown:pe,onFocus:he,onBlur:H,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=H,e[57]=i,e[58]=pe,e[59]=$,e[60]=K,e[61]=de):de=e[61];let we;e[62]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=we):we=e[62];const xe=b??f.minute;let De;e[63]!==_?(De=G=>_(G.target.value),e[63]=_,e[64]=De):De=e[64];let le;e[65]===Symbol.for("react.memo_cache_sentinel")?(le=()=>k(""),e[65]=le):le=e[65];let Ce;e[66]!==V||e[67]!==c||e[68]!==Se||e[69]!==xe||e[70]!==De?(Ce=s.jsx("input",{ref:x,inputMode:"numeric",value:xe,onChange:De,onKeyDown:Se,onFocus:le,onBlur:V,maxLength:2,"aria-label":c,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=V,e[67]=c,e[68]=Se,e[69]=xe,e[70]=De,e[71]=Ce):Ce=e[71];let ue;e[72]!==u||e[73]!==f.meridiem||e[74]!==l||e[75]!==m||e[76]!==ie||e[77]!==o?(ue=o?null:s.jsxs(zn,{value:f.meridiem,onValueChange:G=>ie(G),children:[s.jsx(Wn,{"aria-label":l,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(En,{})}),s.jsxs(Un,{children:[s.jsx(qs,{value:"AM",children:u}),s.jsx(qs,{value:"PM",children:m})]})]}),e[72]=u,e[73]=f.meridiem,e[74]=l,e[75]=m,e[76]=ie,e[77]=o,e[78]=ue):ue=e[78];let ve;return e[79]!==L||e[80]!==de||e[81]!==Ce||e[82]!==ue?(ve=s.jsxs("div",{className:L,children:[de,we,Ce,ue]}),e[79]=L,e[80]=de,e[81]=Ce,e[82]=ue,e[83]=ve):ve=e[83],ve},Kd=t=>new Date(t.getFullYear(),t.getMonth(),1),qv=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},qd=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),Yv=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(o=>typeof o=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(o)).map(o=>o.trim()),r=Array.from(new Set(n)).sort((o,i)=>o.localeCompare(i));return r.length>0?r:["09:00"]},Yd=(t,e)=>{const n=Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC";return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:Yv(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:$d(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:t.schedule.timezone||n},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||""},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:$d(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},Jv=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},Qv=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))};function Xv(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:i,locale:c}=Tt(),l=ls(D=>D.loadProviders),u=ls(D=>D.loadAgents),m=ls(D=>D.providers),d=ls(D=>D.currentProviderId),f=ls(D=>D.currentModelId),g=ls(D=>D.currentVariant||""),x=ls(D=>D.currentAgentName||""),p=Fe(D=>D.timeFormatPreference),y=Fe(D=>D.weekStartPreference),b=Fe(D=>D.isMobile),[h,N]=et.useState(()=>Yd(n,{providerID:d,modelID:f,variant:g,agent:x})),[w,S]=et.useState(!1),[v,j]=et.useState(!1),[k,A]=et.useState(!1),[T,C]=et.useState(""),[P,E]=et.useState(!1),[M,H]=et.useState(""),[R,_]=et.useState(!1),[z,V]=et.useState(""),[F,te]=et.useState(()=>{const D=Ho(n?.schedule?.date||"")||new Date;return new Date(D.getFullYear(),D.getMonth(),1)}),Z=et.useRef(null),ne=et.useRef(null),U=et.useRef(null),ie=et.useRef(null),oe=et.useRef(null),pe=et.useMemo(()=>Hv(c),[c]),je=et.useMemo(()=>Uv(c),[c]),Se=et.useMemo(()=>p==="24h"?!0:p==="12h"?!1:pe,[p,pe]),re=et.useMemo(()=>y==="sunday"?0:y==="monday"?1:je,[y,je]),L=et.useMemo(()=>{const D=Gv(c);return Kv(_m.map(Y=>({value:Y,label:D[Y]||""})),re)},[c,re]);et.useEffect(()=>{e&&(l({source:"scheduledTaskEditor"}),u({source:"scheduledTaskEditor"}))},[e,l,u]),et.useEffect(()=>{if(!e)return;N(Yd(n,{providerID:d,modelID:f,variant:g,agent:x}));const D=Ho(n?.schedule?.date||"")||new Date;te(new Date(D.getFullYear(),D.getMonth(),1)),j(!1),E(!1),A(!1),H(""),C("")},[e,n,d,f,g,x]),et.useEffect(()=>{if(!v)return;const D=Y=>{Z.current&&!Z.current.contains(Y.target)&&j(!1)};return document.addEventListener("mousedown",D),()=>{document.removeEventListener("mousedown",D)}},[v]);const $=et.useMemo(()=>{const Y=m.find(be=>be.id===h.execution.providerID)?.models?.find(be=>be.id===h.execution.modelID);return Y?.variants?Object.keys(Y.variants):[]},[m,h.execution.providerID,h.execution.modelID]),K=$.length>0,he=et.useMemo(()=>!K||!h.execution.variant?"__default":$.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,K,$]);et.useEffect(()=>{K||!h.execution.variant||N(D=>({...D,execution:{...D.execution,variant:""}}))},[K,h.execution.variant]);const de=et.useCallback((D,Y)=>{N(be=>{const Oe=new Set(be.schedule.weekdays);return Y?Oe.add(D):Oe.delete(D),{...be,schedule:{...be.schedule,weekdays:Array.from(Oe).sort(($e,Re)=>$e-Re)}}})},[]),we=et.useCallback((D,Y)=>{N(be=>{const Oe=be.schedule.times.slice();return Oe[D]=Y,{...be,schedule:{...be.schedule,times:Oe}}})},[]),xe=et.useCallback(D=>{N(Y=>{const be=Y.schedule.times.filter((Oe,$e)=>$e!==D);return{...Y,schedule:{...Y.schedule,times:be.length>0?be:["09:00"]}}})},[]),De=et.useCallback(()=>{N(D=>({...D,schedule:{...D.schedule,times:[...D.schedule.times,"12:00"]}}))},[]),le=et.useMemo(()=>qv(),[]),Ce=et.useMemo(()=>Kd(le),[le]),ue=et.useMemo(()=>{const D=Ho(h.schedule.onceDate);return D?qd(D,le)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format(D):null},[h.schedule.onceDate,c,i,le]),ve=et.useMemo(()=>Kd(F).getTime()<=Ce.getTime(),[F,Ce]),G=et.useMemo(()=>L.map(D=>D.label),[L]),Ae=et.useCallback(D=>{N(Y=>({...Y,schedule:{...Y.schedule,onceDate:D}}))},[]),ce=et.useCallback((D,Y)=>{if(D.startsWith("/")){const Re=D.indexOf(" "),ot=D.indexOf(`
162
+ `),yt=Math.min(Re===-1?D.length:Re,ot===-1?D.length:ot);if(Y<=yt&&Re===-1){H(D.substring(1,yt)),E(!0),A(!1),_(!1);return}}E(!1);const be=D.substring(0,Y),Oe=be.lastIndexOf("#");if(Oe!==-1){const Re=Oe>0?be[Oe-1]:null,ot=be.substring(Oe+1);if((!Re||/\s/.test(Re))&&!ot.includes(" ")&&!ot.includes(`
163
+ `)){V(ot),_(!0),A(!1);return}}_(!1);const $e=be.lastIndexOf("@");if($e!==-1){const Re=$e>0?be[$e-1]:null,ot=be.substring($e+1);(!Re||/\s/.test(Re))&&!ot.includes(" ")&&!ot.includes(`
164
+ `)?(C(ot),A(!0)):A(!1);return}A(!1)},[]),fe=et.useCallback(D=>{N(Y=>({...Y,execution:{...Y.execution,prompt:D}}))},[]),Te=et.useCallback(D=>{const Y=h.execution.prompt,Oe=ne.current?.selectionStart??Y.length,Re=Y.substring(0,Oe).lastIndexOf("@"),ot=D.relativePath&&D.relativePath.trim().length>0?D.relativePath.trim():D.path||D.name,yt=Re!==-1?Re:Oe,At=`${Y.substring(0,yt)}@${ot} ${Y.substring(Oe)}`,mt=yt+ot.length+2;fe(At),A(!1),C(""),requestAnimationFrame(()=>{const Le=ne.current;Le&&(Le.selectionStart=mt,Le.selectionEnd=mt,Le.focus()),ce(At,mt)})},[h.execution.prompt,fe,ce]),me=et.useCallback(D=>{const Y=h.execution.prompt,Oe=ne.current?.selectionStart??Y.length,Re=Y.substring(0,Oe).lastIndexOf("@"),ot=Re!==-1?Re:Oe,yt=`${Y.substring(0,ot)}@${D} ${Y.substring(Oe)}`,At=ot+D.length+2;fe(yt),A(!1),C(""),requestAnimationFrame(()=>{const mt=ne.current;mt&&(mt.selectionStart=At,mt.selectionEnd=At,mt.focus()),ce(yt,At)})},[h.execution.prompt,fe,ce]),B=et.useCallback(D=>{const Y=`/${D.name} `;fe(Y),E(!1),H(""),_(!1),requestAnimationFrame(()=>{const be=ne.current;be&&(be.focus(),be.selectionStart=be.value.length,be.selectionEnd=be.value.length),ce(Y,Y.length)})},[fe,ce]),ye=et.useCallback((D,Y)=>{const be=h.execution.prompt,$e=ne.current?.selectionStart??be.length,ot=be.substring(0,$e).lastIndexOf("#"),yt=ot!==-1?ot:$e,At=`${be.substring(0,yt)}#${Y} ${be.substring($e)}`,mt=yt+Y.length+2;fe(At),_(!1),V(""),requestAnimationFrame(()=>{const Le=ne.current;Le&&(Le.selectionStart=mt,Le.selectionEnd=mt,Le.focus()),ce(At,mt)})},[h.execution.prompt,fe,ce]),_e=et.useCallback(D=>{if(P&&ie.current&&(D.key==="Enter"||D.key==="ArrowUp"||D.key==="ArrowDown"||D.key==="Escape"||D.key==="Tab")){D.preventDefault(),ie.current.handleKeyDown(D.key);return}k&&U.current&&(D.key==="Enter"||D.key==="ArrowUp"||D.key==="ArrowDown"||D.key==="Escape"||D.key==="Tab")&&(D.preventDefault(),U.current.handleKeyDown(D.key)),R&&oe.current&&(D.key==="Enter"||D.key==="ArrowUp"||D.key==="ArrowDown"||D.key==="Escape"||D.key==="Tab")&&(D.preventDefault(),oe.current.handleKeyDown(D.key))},[P,k,R]),J=et.useCallback(async()=>{const D=Jv(h,i);if(D){ae.error(D);return}const Y=Qv(h.schedule.times),be={...h.id?{id:h.id}:{},name:h.name.trim(),enabled:h.enabled,schedule:{kind:h.schedule.kind,timezone:h.schedule.timezone.trim(),...h.schedule.kind==="once"?{date:h.schedule.onceDate,time:h.schedule.onceTime}:{times:Y,...h.schedule.kind==="weekly"?{weekdays:h.schedule.weekdays}:{}}},execution:{prompt:h.execution.prompt,providerID:h.execution.providerID,modelID:h.execution.modelID,...h.execution.variant.trim()?{variant:h.execution.variant.trim()}:{},...h.execution.agent.trim()?{agent:h.execution.agent.trim()}:{}},...h.state?{state:h.state}:{}};S(!0);try{await o(be),r(!1)}catch(Oe){ae.error(Oe instanceof Error?Oe.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[h,r,o,i]),Me=et.useId(),Ee=et.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),Ne=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),Be=i("sessions.scheduledTasks.editor.description"),se=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ir,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(kn,{id:"sched-name",value:h.name,onChange:D=>N(Y=>({...Y,name:D.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(zn,{value:h.schedule.kind,onValueChange:D=>{N(Y=>({...Y,schedule:{...Y.schedule,kind:D}}))},children:[s.jsx(Wn,{className:"w-fit max-w-full",children:s.jsx(En,{children:D=>i(D==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":D==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(Un,{children:[s.jsx(qs,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(qs,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(qs,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),h.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:Z,children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(D=>!D),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(I,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Vv(h.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),v?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>te(D=>Wd(D,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:ve,children:s.jsx(I,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}).format(F)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>te(D=>Wd(D,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:G.map((D,Y)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:D},`${D}-${Y}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:$v(F,re).map(({date:D,inCurrentMonth:Y})=>{const be=zd(D),Oe=be===h.schedule.onceDate,$e=qd(D,le),Re=D.getTime()<le.getTime(),ot=Oe?"bg-interactive-selection text-interactive-selection-foreground":Re?"text-muted-foreground/40":Y?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{Re||(Ae(be),j(!1))},disabled:Re,className:["h-8 rounded-md typography-ui-label",ot,$e&&!Oe?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",Re?"cursor-not-allowed opacity-45":""].join(" "),children:D.getDate()},be)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:ue||""}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:()=>{Ae(zd(le)),te(new Date(le.getFullYear(),le.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(Gd,{value:h.schedule.onceTime,use24Hour:Se,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:D=>N(Y=>({...Y,schedule:{...Y.schedule,onceTime:D}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(zn,{value:h.schedule.timezone,onValueChange:D=>{N(Y=>({...Y,schedule:{...Y.schedule,timezone:D}}))},children:[s.jsx(Wn,{className:"w-fit max-w-full",children:s.jsx(En,{})}),s.jsx(Un,{children:Vd.map(D=>s.jsx(qs,{value:D,children:D},D))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[h.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:L.map(D=>{const Y=h.schedule.weekdays.includes(D.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",Y?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(ji,{checked:Y,onChange:be=>de(D.value,be),ariaLabel:D.label}),s.jsx("button",{type:"button",onClick:()=>de(D.value,!Y),className:"group-hover:text-foreground",children:D.label})]},D.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((D,Y)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Gd,{value:D,use24Hour:Se,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:be=>we(Y,be)}),h.schedule.times.length>1?s.jsx(ze,{type:"button",size:"icon",variant:"ghost",onClick:()=>xe(Y),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]},Y))}),s.jsx("div",{children:s.jsxs(ze,{type:"button",size:"sm",variant:"outline",onClick:De,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(zn,{value:h.schedule.timezone,onValueChange:D=>{N(Y=>({...Y,schedule:{...Y.schedule,timezone:D}}))},children:[s.jsx(Wn,{className:"w-fit max-w-full",children:s.jsx(En,{})}),s.jsx(Un,{children:Vd.map(D=>s.jsx(qs,{value:D,children:D},D))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(ir,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Cu,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(D,Y)=>{N(be=>({...be,execution:{...be.execution,providerID:D,modelID:Y,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(zn,{value:he,disabled:!K,onValueChange:D=>{N(Y=>({...Y,execution:{...Y.execution,variant:D==="__default"?"":D}}))},children:[s.jsx(Wn,{className:"w-fit max-w-full",children:s.jsx(En,{children:D=>D==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):D})}),s.jsxs(Un,{children:[s.jsx(qs,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),$.map(D=>s.jsx(qs,{value:D,children:D},D))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(ir,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Au,{agentName:h.execution.agent,filter:D=>Du(D.mode),onChange:D=>N(Y=>({...Y,execution:{...Y.execution,agent:D}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ir,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(gi,{id:"sched-prompt",ref:ne,value:h.execution.prompt,onChange:D=>{const Y=D.target.value;fe(Y);const be=D.target.selectionStart??Y.length;ce(Y,be)},onKeyDown:_e,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),P?s.jsx(Bu,{ref:ie,searchQuery:M,onCommandSelect:B,onClose:()=>E(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,k?s.jsx(Vu,{ref:U,searchQuery:T,onFileSelect:Te,onAgentSelect:me,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,R?s.jsx($u,{ref:oe,searchQuery:z,onSnippetSelect:ye,onClose:()=>_(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),O=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(ji,{checked:h.enabled,onChange:D=>N(Y=>({...Y,enabled:D})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:w,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ze,{type:"button",size:"sm",onClick:J,disabled:w,children:i(w?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return b?s.jsx(xa,{open:e,title:Ne,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:D=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:Ne}),D]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:Be})]}),footer:O,children:se}):s.jsx(Ks,{open:e,onOpenChange:D=>{!D&&Ee()||r(D)},children:s.jsxs(Gs,{"aria-describedby":Me,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(dn,{id:Me,className:"sr-only",children:Be}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(Ys,{className:"typography-ui-label font-medium text-foreground",children:Ne}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:Be})]})}),s.jsx(ba,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:se})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:O})})]})})}function Zv(t){return Gi(t,{min:0,max:23})}function e0(t,e){return Gi(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function t0(t,e){const n=Number(t),r=Number(e),o=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,i=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(o).padStart(2,"0")}:${String(i).padStart(2,"0")}`}const s0=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,o)=>r.localeCompare(o))},n0=(t,e)=>{const n=s0(t).join(", ")||"--:--",r=o=>e(o===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":o===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":o===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":o===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":o===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":o===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":o===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const o=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(i=>r(i)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:o,time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:o,time:n})}if(t.schedule.kind==="once"){const o=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),i=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:o,time:i,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:o,time:i})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},r0=(t,e)=>!t||!Number.isFinite(t)?"":wu(t,e),Jd=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),o=6e4,i=60*o,c=24*i,l=n>=0;if(r<o)return e(l?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const f=Math.round(r/o);return l?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:f}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:f})}if(r<c){const f=Math.floor(r/i),g=Math.round(r%i/o),x=g>0?`${f}h ${g}m`:`${f}h`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:x}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:x})}const u=Math.floor(r/c),m=Math.round(r%c/i),d=m>0?`${u}d ${m}h`:`${u}d`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:d}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:d})},i0={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},o0=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function a0(){const{t}=Tt(),e=Fe(R=>R.isScheduledTasksDialogOpen),n=Fe(R=>R.setScheduledTasksDialogOpen),r=Fe(R=>R.isMobile),o=Fe(R=>R.timeFormatPreference),i=Ms(R=>R.projects),c=Ms(R=>R.getActiveProject()),l=tn(R=>R.homeDirectory),{currentTheme:u}=Tr(),[m,d]=et.useState(""),[f,g]=et.useState([]),[x,p]=et.useState(!0),[y,b]=et.useState(!1),[h,N]=et.useState(null),[w,S]=et.useState(null),v=et.useMemo(()=>i.find(R=>R.id===m)||null,[i,m]),j=et.useCallback(R=>{const _=R.label?.trim()||Si(R.path,l||void 0),z=R.icon?Jl[R.icon]:null,V=R.color?Sa[R.color]:void 0,F=z?s.jsx(I,{name:z,className:"h-3.5 w-3.5 shrink-0",style:V?{color:V}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:V?{color:V}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[R.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:R.iconBackground?{backgroundColor:R.iconBackground}:void 0,children:s.jsx(Na,{project:{id:R.id,iconImage:R.iconImage??null},options:{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground},className:"h-full w-full object-contain",fallback:F})}):F,s.jsx("span",{className:"truncate",children:_})]})},[l,u.metadata.variant,u.colors.surface.foreground]),k=et.useCallback(async(R,_)=>{if(!R){g([]);return}_?.silent||p(!0);try{const z=await Ov(R);z.sort((V,F)=>{if(V.enabled!==F.enabled)return V.enabled?-1:1;const te=V.name.localeCompare(F.name);return te!==0?te:(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(F.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),g(z)}catch(z){ae.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),_?.silent||g([])}finally{_?.silent||p(!1)}},[t]);et.useEffect(()=>{if(!e)return;const R=c?.id||i[0]?.id||"";d(R),R?k(R):(g([]),p(!1))},[e,c,i,k]),et.useEffect(()=>{if(!e)return;let R=null;const _=Om(z=>{z.type==="scheduled-task-ran"&&z.projectId===m&&(R&&clearTimeout(R),R=setTimeout(()=>{k(m,{silent:!0})},400))});return()=>{R&&clearTimeout(R),_()}},[e,m,k]);const A=et.useCallback(async R=>{if(!m)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Bd(m,R),await k(m),ae.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[m,k,t]),T=et.useCallback(async(R,_)=>{if(m){S(R.id),g(z=>z.map(V=>V.id===R.id?{...V,enabled:_}:V));try{await Bd(m,{...R,enabled:_}),await k(m,{silent:!0})}catch(z){ae.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await k(m,{silent:!0})}finally{S(null)}}},[m,k,t]),C=et.useCallback(async R=>{if(!(!m||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:R.name})))){S(R.id);try{await _v(m,R.id),await k(m,{silent:!0}),ae.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(z){ae.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{S(null)}}},[m,k,t]),P=et.useCallback(async R=>{if(m){S(R.id);try{await Bv(m,R.id),await Promise.all([k(m,{silent:!0}),ul()]),ae.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(_){ae.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{S(null)}}},[m,k,t]),E=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(zn,{value:m||"__none",onValueChange:R=>{const _=R==="__none"?"":R;d(_),_?k(_):g([])},children:[s.jsx(Wn,{className:r?"w-full":void 0,children:v?s.jsx(En,{children:j(v)}):s.jsx(En,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(Un,{children:[i.length===0?s.jsx(qs,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(R=>s.jsx(qs,{value:R.id,children:j(R)},R.id))]})]})]}),M=()=>{N(null),b(!0)},H=s.jsxs("div",{className:"space-y-4",children:[r?E:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[E,s.jsxs(ze,{onClick:M,disabled:!m,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:x?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):f.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(m?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:f.map(R=>{const _=w===R.id,z=R.state?.lastStatus||"idle",V=i0[z],F=t(z==="success"?"sessions.scheduledTasks.dialog.status.success":z==="error"?"sessions.scheduledTasks.dialog.status.error":z==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),te=R.state?.nextRunAt,Z=R.state?.lastRunAt;return s.jsxs("div",{className:Pe("rounded-lg border border-border p-4 transition-opacity",!R.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:R.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:n0(R,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),te?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Jd(te,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:r0(te,o)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),z==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):Z?s.jsxs(s.Fragment,{children:[V.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${V.tone})`},children:[s.jsx(I,{name:V.Icon,className:"h-3.5 w-3.5"}),F]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Jd(Z,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),R.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:o0("error"),children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:R.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:Pe("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",R.enabled?"text-foreground":"text-muted-foreground",_&&"cursor-not-allowed opacity-50"),children:[s.jsx(ji,{checked:R.enabled,onChange:ne=>{T(R,ne)},ariaLabel:R.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:R.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:R.name}),disabled:_}),R.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(ze,{variant:"outline",size:"sm",onClick:()=>{P(R)},disabled:_,children:[s.jsx(I,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ze,{variant:"outline",size:"sm",onClick:()=>{N(R),b(!0)},disabled:_,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:R.name}),children:[s.jsx(I,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ze,{variant:"destructive",size:"sm",onClick:()=>{C(R)},disabled:_,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:R.name}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},R.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(xa,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:R=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),R]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ze,{className:"w-full",onClick:M,disabled:!m,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:H}):s.jsx(Ks,{open:e,onOpenChange:n,children:s.jsxs(Gs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(Qs,{children:[s.jsx(Ys,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(dn,{children:t("sessions.scheduledTasks.dialog.description")})]}),H]})}),s.jsx(Xv,{open:y,task:h,onOpenChange:b,onSave:A})]})}const l0=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(l=>os(l.path)??l.path).filter(l=>!!l)]),i=(l=>l.filter(u=>ho(u,t.normalizedPath,r)))(e.archivedSessions),c=e.sessions.filter(l=>l.time?.archived||os(l.directory??null)?!1:ho(l,t.normalizedPath,r));return Bi([...i,...c])},c0=t=>{const e=pt.c(12),{normalizedProjects:n,sessions:r,archivedSessions:o,availableWorktreesByProject:i,isVSCode:c,isSessionsLoading:l,foldersMap:u,createFolder:m,addSessionToFolder:d,cleanupSessions:f}=t;let g,x;e[0]!==d||e[1]!==o||e[2]!==i||e[3]!==f||e[4]!==m||e[5]!==u||e[6]!==l||e[7]!==c||e[8]!==n||e[9]!==r?(g=()=>{l||n.forEach(p=>{const y=Ql(p.normalizedPath),b=l0(p,{sessions:r,archivedSessions:o,availableWorktreesByProject:i,isVSCode:c}),h=new Set(b.map(d0)),N=u[y]??[],w=new Map(N.map(u0));b.forEach(S=>{const v=fh(S,p.normalizedPath),j=v.toLowerCase();let k=w.get(j);k||(k=m(y,v),w.set(j,k)),k.sessionIds.includes(S.id)||d(y,k.id,S.id)}),f(y,h)})},x=[n,r,o,i,c,l,u,m,d,f],e[0]=d,e[1]=o,e[2]=i,e[3]=f,e[4]=m,e[5]=u,e[6]=l,e[7]=c,e[8]=n,e[9]=r,e[10]=g,e[11]=x):(g=e[10],x=e[11]),a.useEffect(g,x)};function d0(t){return t.id}function u0(t){return[t.name.toLowerCase(),t]}const m0=t=>{const e=pt.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:o,availableWorktreesByProject:i,projectRepoStatus:c,projectRootBranches:l,lastRepoStatus:u,buildGroupedSessions:m,hasSessionSearchQuery:d,normalizedSessionSearchQuery:f,filterSessionNodesForSearch:g,buildGroupSearchText:x,foldersMap:p}=t;let y;if(e[0]!==i||e[1]!==m||e[2]!==o||e[3]!==r||e[4]!==u||e[5]!==n||e[6]!==c||e[7]!==l){let C;e[9]!==i||e[10]!==m||e[11]!==o||e[12]!==r||e[13]!==u||e[14]!==c||e[15]!==l?(C=P=>{const E=Bi([...r(P),...o(P)]),M=i.get(P.normalizedPath)??[],H=c.has(P.id)?!!c.get(P.id):u,R=m(E,P.normalizedPath,M,l.get(P.id)??null,H);return{project:P,groups:R}},e[9]=i,e[10]=m,e[11]=o,e[12]=r,e[13]=u,e[14]=c,e[15]=l,e[16]=C):C=e[16],y=n.map(C),e[0]=i,e[1]=m,e[2]=o,e[3]=r,e[4]=u,e[5]=n,e[6]=c,e[7]=l,e[8]=y}else y=e[8];const b=y,h=b;let N;if(e[17]!==x||e[18]!==g||e[19]!==p||e[20]!==d||e[21]!==f||e[22]!==h){e:{const C=new WeakMap;if(!d){N=C;break e}const P=E=>E.reduce((M,H)=>M+1+P(H.children),0);h.forEach(E=>{E.groups.forEach(M=>{const H=g(M.sessions,f),R=P(H),_=x(M).includes(f),z=os(M.directory??null),F=(z?p[z]??[]:[]).filter(te=>te.name.toLowerCase().includes(f)).length;C.set(M,{filteredNodes:H,matchedSessionCount:R,folderNameMatchCount:F,groupMatches:_,hasMatch:_||R>0||F>0})})}),N=C}e[17]=x,e[18]=g,e[19]=p,e[20]=d,e[21]=f,e[22]=h,e[23]=N}else N=e[23];const w=N;let S;e:{if(!d){S=h;break e}let C;if(e[24]!==w||e[25]!==h){let P;e[27]!==w?(P=E=>({...E,groups:E.groups.filter(M=>w.get(M)?.hasMatch===!0)}),e[27]=w,e[28]=P):P=e[28],C=h.map(P).filter(f0),e[24]=w,e[25]=h,e[26]=C}else C=e[26];S=C}const v=S,j=d?v:h;let k;e:{if(!d){k=0;break e}let C;if(e[29]!==w||e[30]!==j){let P;e[32]!==w?(P=(E,M)=>E+M.groups.reduce((H,R)=>{const _=w.get(R);if(!_)return H;const z=_.folderNameMatchCount+(_.groupMatches?1:0);return H+_.matchedSessionCount+z},0),e[32]=w,e[33]=P):P=e[33],C=j.reduce(P,0),e[29]=w,e[30]=j,e[31]=C}else C=e[31];k=C}const A=k;let T;return e[34]!==w||e[35]!==b||e[36]!==A||e[37]!==v||e[38]!==j||e[39]!==h?(T={projectSections:b,visibleProjectSections:h,groupSearchDataByGroup:w,searchableProjectSections:v,sectionsForRender:j,searchMatchCount:A},e[34]=w,e[35]=b,e[36]=A,e[37]=v,e[38]=j,e[39]=h,e[40]=T):T=e[40],T};function f0(t){return t.groups.length>0}const h0=t=>{const e=pt.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:i,currentSessionId:c,handleSessionSelect:l,newSessionDraftOpen:u,mobileVariant:m,openNewSessionDraft:d,setActiveMainTab:f,setSessionSwitcherOpen:g,sessions:x,worktreeMetadata:p}=t;let y,b;if(e[0]!==n){b=new Map,y=new Map;const P=(E,M,H,R)=>{b.has(E)||b.set(E,new Map);const _=b.get(E);R.forEach(z=>{const V=os(z.worktree?.path??z.session.directory??H??M);_.set(z.session.id,{directory:V}),y.has(E)||y.set(E,{id:z.session.id,directory:V}),z.children.length>0&&P(E,M,V,z.children)})};n.forEach(E=>{E.groups.forEach(M=>{P(E.project.id,E.project.normalizedPath,M.directory,M.sessions)})}),e[0]=n,e[1]=y,e[2]=b}else y=e[1],b=e[2];let h;e[3]!==y||e[4]!==b?(h={metaByProject:b,firstSessionByProject:y},e[3]=y,e[4]=b,e[5]=h):h=e[5];const N=h,w=a.useRef(null);let S,v;e[6]!==r||e[7]!==o||e[8]!==c||e[9]!==l||e[10]!==m||e[11]!==u||e[12]!==d||e[13]!==n||e[14]!==N||e[15]!==f||e[16]!==i||e[17]!==g?(S=()=>{if(!r||u||w.current===r)return;const P=n.find(V=>V.project.id===r);if(!P)return;w.current=r;const E=N.metaByProject.get(r);if(c&&E&&E.has(c)){i(V=>{if(V.get(r)===c)return V;const F=new Map(V);return F.set(r,c),F});return}if(!E||E.size===0){f("chat"),m&&g(!1),d({directoryOverride:P.project.normalizedPath});return}const M=o.get(r),H=M&&E.has(M)?M:null,R=N.firstSessionByProject.get(r)?.id??null,_=H??R;if(!_||_===c)return;const z=E.get(_)?.directory??null;l(_,z,!1,r)},v=[r,o,c,l,u,m,d,n,N,f,g,i],e[6]=r,e[7]=o,e[8]=c,e[9]=l,e[10]=m,e[11]=u,e[12]=d,e[13]=n,e[14]=N,e[15]=f,e[16]=i,e[17]=g,e[18]=S,e[19]=v):(S=e[18],v=e[19]),a.useLayoutEffect(S,v);let j,k;e[20]!==r||e[21]!==c||e[22]!==N||e[23]!==i?(j=()=>{if(!r||!c)return;const P=N.metaByProject.get(r);!P||!P.has(c)||i(E=>{if(E.get(r)===c)return E;const M=new Map(E);return M.set(r,c),M})},k=[r,c,N,i],e[20]=r,e[21]=c,e[22]=N,e[23]=i,e[24]=j,e[25]=k):(j=e[24],k=e[25]),a.useEffect(j,k);let A;if(e[26]!==c||e[27]!==x||e[28]!==p){e:{if(!c){A=null;break e}const P=p.get(c)?.path;if(P){A=os(P)??P;break e}let E;e[30]!==c?(E=H=>H.id===c,e[30]=c,e[31]=E):E=e[31];const M=x.find(E);if(!M){A=null;break e}A=os(M.directory??null)}e[26]=c,e[27]=x,e[28]=p,e[29]=A}else A=e[29];const T=A;let C;return e[32]!==T?(C={currentSessionDirectory:T},e[32]=T,e[33]=C):C=e[33],C},p0=t=>{const e=pt.c(4);let n;e[0]!==t?(n=(i,c)=>{const l=t.get(i);if(!l||l.length===0)return c;const u=new Map(c.map(g0)),m=[];return l.forEach(d=>{const f=u.get(d);f&&(m.push(f),u.delete(d))}),c.forEach(d=>{u.has(d.id)&&m.push(d)}),m},e[0]=t,e[1]=n):n=e[1];const r=n;let o;return e[2]!==r?(o={getOrderedGroups:r},e[2]=r,e[3]=o):o=e[3],o};function g0(t){return[t.id,t]}const Eo=t=>!!t.time?.archived,x0=t=>{const{t:e}=Tt(),n=a.useCallback(c=>[c.label,c.branch??"",c.description??"",c.directory??""].join(" ").toLowerCase(),[]),r=a.useCallback(c=>{const l=os(c.directory??null)??"";return`${(c.title||e("sessions.sidebar.session.untitled")).trim()} ${l}`.toLowerCase()},[e]),o=a.useCallback((c,l)=>l?c.flatMap(u=>{if(r(u.session).includes(l))return[u];const d=o(u.children,l);return d.length===0?[]:[{...u,children:d}]}):c,[r]),i=a.useCallback((c,l,u,m,d)=>{const f=os(l??null),g=Bi(c).sort((P,E)=>Pi(P,E,t.pinnedSessionIds)),x=new Map(g.map(P=>[P.id,P])),p=new Map;g.forEach(P=>{const E=P.parentID;if(!E)return;const M=x.get(E);if(!M||Eo(M)!==Eo(P))return;const H=p.get(E)??[];H.push(P),p.set(E,H)}),p.forEach(P=>P.sort((E,M)=>Pi(E,M,t.pinnedSessionIds)));const y=new Map;u.forEach(P=>{if(P.path){const E=os(P.path)??P.path;y.set(E,P)}});const b=P=>{const E=os(P.directory??null),M=t.worktreeMetadata.get(P.id)??null;if(M)return M;if(E){const H=y.get(E)??null;if(H&&E!==f)return H}return null},h=P=>{const E=p.get(P.id)??[];return{session:P,children:E.map(M=>h(M)),worktree:b(P)}},N=g.filter(P=>{const E=P.parentID;if(!E)return!0;const M=x.get(E);return M?Eo(M)!==Eo(P):!0}),w=new Map,S="__archived__",v=P=>{if(P.time?.archived)return S;const M=os(t.worktreeMetadata.get(P.id)?.path??null)??xi(P);return M?M!==f&&y.has(M)?M:M===f?f??"__project_root__":S:S};N.forEach(P=>{const E=h(P),M=v(P);w.has(M)||w.set(M,[]),w.get(M)?.push(E)});const j=f??"__project_root__",k=[{id:"root",label:d&&m&&m!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:m}):e("sessions.sidebar.grouping.projectRoot"),branch:m??null,description:f?Zo(f,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:w.get(j)??[]}],A=new Map;u.forEach(P=>{const E=os(P.path)??P.path,M=w.get(E)??[],H=M.length>0,R=M.reduce((_,z)=>{const V=Number(z.session.time?.updated??z.session.time?.created??0);return Number.isFinite(V)?Math.max(_,V):_},0);A.set(E,{hasActiveSession:H,lastUpdatedAt:R})}),[...u].sort((P,E)=>{const M=os(P.path)??P.path,H=os(E.path)??E.path,R=A.get(M)??{hasActiveSession:!1,lastUpdatedAt:0},_=A.get(H)??{hasActiveSession:!1,lastUpdatedAt:0};if(R.hasActiveSession!==_.hasActiveSession)return R.hasActiveSession?-1:1;if(R.hasActiveSession&&_.hasActiveSession)return _.lastUpdatedAt-R.lastUpdatedAt;const z=(P.label||P.branch||P.name||P.path||"").toLowerCase(),V=(E.label||E.branch||E.name||E.path||"").toLowerCase();return z.localeCompare(V)}).forEach(P=>{const E=os(P.path)??P.path,M=t.gitBranches.get(E)?.trim()||null,H=P.branch?.trim()||null,_=!!(M&&H&&P.label&&Cc(P.label)===Cc(H))?M:P.label||P.name||Si(E,t.homeDirectory)||E;k.push({id:`worktree:${E}`,label:_,branch:M||H,description:Zo(E,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:P,directory:E,folderScopeKey:E,sessions:w.get(E)??[]})});const C=w.get(S)??[];return C.length>0&&k.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&f?Ql(f):null,sessions:C}),k},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:i}},b0=t=>{const e=pt.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:o,sessionSearchContainerRef:i}=t;let c,l;e[0]!==n||e[1]!==o?(c=()=>{if(!n||typeof window>"u")return;const d=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(d)},l=[n,o],e[0]=n,e[1]=o,e[2]=c,e[3]=l):(c=e[2],l=e[3]),a.useEffect(c,l);let u,m;e[4]!==n||e[5]!==i||e[6]!==r?(u=()=>{if(!n||typeof document>"u")return;const d=f=>{i.current&&(i.current.contains(f.target)||r(!1))};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},m=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=u,e[8]=m):(u=e[7],m=e[8]),a.useEffect(u,m)},y0=t=>{const e=pt.c(42),{t:n}=Tt(),[r,o]=a.useState(null),i=a.useRef(null);let c,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{i.current&&clearTimeout(i.current)},l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),a.useEffect(c,l);let u;e[2]!==t?(u=(_,z,V,F)=>{if(V)return;const te=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(F&&F!==t.activeProjectId&&t.setActiveProjectIdOnly(F),z&&z!==t.currentDirectory&&t.setDirectory(z,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),_===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(_),te();return}t.setCurrentSession(_,z??null),t.onSessionSelected?.(_),te()},e[2]=t,e[3]=u):u=e[3];const m=u;let d;e[4]!==t?(d=(_,z)=>{t.setEditingId(_),t.setEditTitle(z)},e[4]=t,e[5]=d):d=e[5];const f=d;let g;e[6]!==t?(g=async()=>{if(!t.editingId)return;const _=t.editTitle.trim();_&&await t.updateSessionTitle(t.editingId,_),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=g):g=e[7];const x=g;let p;e[8]!==t?(p=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=p):p=e[9];const y=p;let b;e[10]!==t||e[11]!==n?(b=async _=>{const z=await t.shareSession(_.id);z&&z.share?.url?ae.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):ae.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=b):b=e[12];const h=b;let N;e[13]!==n?(N=(_,z)=>{ar(_).then(V=>{if(!V.ok){ae.error(n("sessions.sidebar.session.share.copyUrlError"));return}o(z),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{o(null),i.current=null},2e3)}).catch(()=>{ae.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=N):N=e[14];const w=N;let S;e[15]!==t||e[16]!==n?(S=async _=>{await t.unshareSession(_)?ae.success(n("sessions.sidebar.session.unshare.success")):ae.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=S):S=e[17];const v=S;let j;e[18]!==t.childrenMap?(j=_=>{const z=[],V=F=>{(t.childrenMap.get(F)??[]).forEach(Z=>{z.push(Z),V(Z.id)})};return V(_),z},e[18]=t.childrenMap,e[19]=j):j=e[19];const k=j,A=v0;let T;e[20]!==t||e[21]!==k||e[22]!==n?(T=async(_,z,V)=>{const F=z?.archivedBucket===!0,te=V?.descendantIds??A(k(_.id),F).map(j0);if(te.length===0){(F?await t.deleteSession(_.id):await t.archiveSession(_.id))?ae.success(n(F?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):ae.error(n(F?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const Z=[_.id,...te];if(F){const{deletedIds:ie,failedIds:oe}=await t.deleteSessions(Z);ie.length>0&&ae.success(ie.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:ie.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:ie.length})),oe.length>0&&ae.error(oe.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:oe.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:oe.length}));return}const{archivedIds:ne,failedIds:U}=await t.archiveSessions(Z);ne.length>0&&ae.success(ne.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:ne.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:ne.length})),U.length>0&&ae.error(U.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:U.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:U.length}))},e[20]=t,e[21]=k,e[22]=n,e[23]=T):T=e[23];const C=T;let P;e[24]!==t||e[25]!==k||e[26]!==C?(P=(_,z)=>{const V=z?.archivedBucket===!0,F=A(k(_.id),V).map(S0);if(!t.showDeletionDialog){C(_,z,{descendantIds:F});return}t.setDeleteSessionConfirm({session:_,descendantCount:F.length,descendantIds:F,archivedBucket:V})},e[24]=t,e[25]=k,e[26]=C,e[27]=P):P=e[27];const E=P;let M;e[28]!==t||e[29]!==C?(M=async()=>{if(!t.deleteSessionConfirm)return;const{session:_,archivedBucket:z,descendantIds:V}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await C(_,{archivedBucket:z},{descendantIds:V})},e[28]=t,e[29]=C,e[30]=M):M=e[30];const H=M;let R;return e[31]!==H||e[32]!==r||e[33]!==y||e[34]!==w||e[35]!==E||e[36]!==x||e[37]!==f||e[38]!==m||e[39]!==h||e[40]!==v?(R={copiedSessionId:r,handleSessionSelect:m,handleSessionDoubleClick:f,handleSaveEdit:x,handleCancelEdit:y,handleShareSession:h,handleCopyShareUrl:w,handleUnshareSession:v,handleDeleteSession:E,confirmDeleteSession:H},e[31]=H,e[32]=r,e[33]=y,e[34]=w,e[35]=E,e[36]=x,e[37]=f,e[38]=m,e[39]=h,e[40]=v,e[41]=R):R=e[41],R};function w0(t){return!t.time?.archived}function v0(t,e){return e?t:t.filter(w0)}function j0(t){return t.id}function S0(t){return t.id}const N0=["project:active:","project:archived:","recent:active:","recent:archived:"],k0=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:o,sessions:i,setPinnedSessionIds:c,groupOrderByProject:l,activeSessionByProject:u,collapsedGroups:m,setExpandedParents:d,setCollapsedProjects:f}=t,g=a.useRef(null),x=a.useRef(null),p=a.useCallback(()=>{if(e)return;const b=x.current;if(x.current=null,g.current=null,!b)return;const{projects:h}=Ms.getState(),N=h.map(w=>({...w,sidebarCollapsed:b.has(w.id)}));ua({projects:N}).catch(()=>{})},[e]),y=a.useCallback(b=>{typeof window>"u"||e||(x.current=b,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{p()},700))},[e,p]);return a.useEffect(()=>()=>{typeof window<"u"&&g.current!==null&&window.clearTimeout(g.current),g.current=null,x.current=null},[]),a.useEffect(()=>{try{const b=r.getItem(o.sessionExpanded);if(b){const N=JSON.parse(b);Array.isArray(N)&&d(new Set(N.filter(w=>typeof w=="string")))}else{const N=r.getItem(o.sessionExpandedLegacy);if(N){try{const w=JSON.parse(N);if(Array.isArray(w)){const S=new Set;if(w.forEach(v=>{typeof v!="string"||v.length===0||N0.forEach(j=>S.add(`${j}${v}`))}),S.size>0){d(S);try{r.setItem(o.sessionExpanded,JSON.stringify(Array.from(S)))}catch{}}}}catch{}try{r.removeItem?.(o.sessionExpandedLegacy)}catch{}}}const h=r.getItem(o.projectCollapse);if(h){const N=JSON.parse(h);Array.isArray(N)&&f(new Set(N.filter(w=>typeof w=="string")))}}catch{}},[o.projectCollapse,o.sessionExpanded,o.sessionExpandedLegacy,r,f,d]),a.useEffect(()=>{if(!n)return;const b=new Set(i.map(h=>h.id));c(h=>{let N=!1;const w=new Set;return h.forEach(S=>{b.has(S)?w.add(S):N=!0}),N?w:h})},[n,i,c]),a.useEffect(()=>{try{const b=Object.fromEntries(l.entries());r.setItem(o.groupOrder,JSON.stringify(b))}catch{}},[l,o.groupOrder,r]),a.useEffect(()=>{try{const b=Object.fromEntries(u.entries());r.setItem(o.projectActiveSession,JSON.stringify(b))}catch{}},[u,o.projectActiveSession,r]),a.useEffect(()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(m)))}catch{}},[m,o.groupCollapse,r]),{scheduleCollapsedProjectsPersist:y}},C0=t=>{const e=pt.c(26),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:o,setProjectRootBranches:i}=t,{git:c}=Gn(),l=_s(A0);let u,m;e[0]!==l||e[1]!==c||e[2]!==n||e[3]!==o?(u=()=>{if(!c||n.length===0){o(new Map);return}n.forEach(N=>{l(N.normalizedPath,c)})},m=[n,c,l,o],e[0]=l,e[1]=c,e[2]=n,e[3]=o,e[4]=u,e[5]=m):(u=e[4],m=e[5]),a.useEffect(u,m);let d,f;e[6]!==r||e[7]!==n||e[8]!==o?(d=()=>{const N=new Map;n.forEach(w=>{N.set(w.id,r.get(w.normalizedPath)?.isGitRepo??null)}),o(N)},f=[n,r,o],e[6]=r,e[7]=n,e[8]=o,e[9]=d,e[10]=f):(d=e[9],f=e[10]),a.useEffect(d,f);let g;if(e[11]!==r||e[12]!==n){let N;e[14]!==r?(N=w=>{const S=r.get(w.normalizedPath)?.branch??"";return`${w.id}:${S}`},e[14]=r,e[15]=N):N=e[15],g=n.map(N).join("|"),e[11]=r,e[12]=n,e[13]=g}else g=e[13];const x=g;let p;e[16]===Symbol.for("react.memo_cache_sentinel")?(p=new Map,e[16]=p):p=e[16];const y=a.useRef(p);let b;e[17]!==r||e[18]!==n||e[19]!==i?(b=()=>{let N=!1;const w=setTimeout(()=>{(async()=>{const v=new Set(n.map(D0));for(const T of y.current.keys())v.has(T)||y.current.delete(T);const j=n.filter(T=>{const C=r.get(T.normalizedPath);if(C?.isGitRepo===!1)return y.current.delete(T.id),!1;if(C?.isGitRepo!==!0||C.branch===null)return!1;const P=C.branch.trim(),E=`${T.normalizedPath}\0${P}`,M=y.current.get(T.id);return M===void 0||M!==E});if(j.length===0)return;const k=await om(j,2,async T=>{const C=r.get(T.normalizedPath)?.branch?.trim()??"",P=`${T.normalizedPath}\0${C}`,E=await wa(T.normalizedPath,C?{knownBranch:C}:void 0).catch(I0);return{id:T.id,inputKey:P,branch:E}});if(N)return;const A=k.filter(P0);A.length!==0&&(i(T=>{const C=new Map(T);return A.forEach(P=>{const{id:E,branch:M}=P;M&&C.set(E,M)}),C}),A.forEach(T=>{const{id:C,inputKey:P}=T;y.current.set(C,P)}))})()},150);return()=>{N=!0,clearTimeout(w)}},e[17]=r,e[18]=n,e[19]=i,e[20]=b):b=e[20];let h;e[21]!==r||e[22]!==n||e[23]!==x||e[24]!==i?(h=[n,x,r,i],e[21]=r,e[22]=n,e[23]=x,e[24]=i,e[25]=h):h=e[25],a.useEffect(b,h)};function A0(t){return t.ensureStatus}function D0(t){return t.id}function I0(){return null}function P0(t){return t.branch}const T0=t=>{const e=pt.c(14),{isVSCode:n,sessions:r,archivedSessions:o,availableWorktreesByProject:i}=t;let c;e[0]!==r?(c=new Map,r.forEach(x=>{const p=xi(x);if(!p)return;const y=c.get(p)??[];y.push(x),c.set(p,y)}),e[0]=r,e[1]=c):c=e[1];const l=c;let u;e[2]!==i||e[3]!==n||e[4]!==l?(u=x=>{const p=n?[]:i.get(x.normalizedPath)??[],y=[x.normalizedPath,...p.map(E0).filter(R0)],b=new Set,h=[];return y.forEach(N=>{(l.get(N)??[]).forEach(S=>{b.has(S.id)||(b.add(S.id),h.push(S))})}),h},e[2]=i,e[3]=n,e[4]=l,e[5]=u):u=e[5];const m=u;let d;e[6]!==o||e[7]!==i||e[8]!==n||e[9]!==r?(d=x=>{if(n){const w=o.filter(v=>{const j=os(v.directory??null),k=os(v.project?.worktree??null);return j?j===x.normalizedPath:k===x.normalizedPath}),S=r.filter(v=>v.time?.archived||os(v.directory??null)?!1:os(v.project?.worktree??null)===x.normalizedPath);return Bi([...w,...S])}const p=n?[]:i.get(x.normalizedPath)??[],y=new Set([x.normalizedPath,...p.map(M0).filter(F0)]),h=(w=>w.filter(S=>ho(S,x.normalizedPath,y)))(o),N=r.filter(w=>{if(w.time?.archived||os(w.directory??null))return!1;const v=os(w.project?.worktree??null);return v?v===x.normalizedPath||v.startsWith(`${x.normalizedPath}/`):!1});return Bi([...h,...N])},e[6]=o,e[7]=i,e[8]=n,e[9]=r,e[10]=d):d=e[10];const f=d;let g;return e[11]!==f||e[12]!==m?(g={getSessionsForProject:m,getArchivedSessionsForProject:f},e[11]=f,e[12]=m,e[13]=g):g=e[13],g};function E0(t){return os(t.path)??t.path}function R0(t){return!!t}function M0(t){return os(t.path)??t.path}function F0(t){return!!t}const L0=t=>{const e=pt.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:o,normalizedProjects:i,isVSCode:c,availableWorktreesByProject:l,cleanupSessions:u}=t;let m,d;e[0]!==o||e[1]!==l||e[2]!==u||e[3]!==n||e[4]!==c||e[5]!==i||e[6]!==r?(m=()=>{if(n)return;const f=new Map;r.forEach(p=>{const y=os(p.directory??null);if(!y)return;const b=f.get(y);if(b){b.add(p.id);return}f.set(y,new Set([p.id]))}),i.forEach(p=>{const y=Ql(p.normalizedPath),b=c?[]:l.get(p.normalizedPath)??[],h=new Set([p.normalizedPath,...b.map(O0).filter(_0)]),N=Bi([...o,...r.filter(w=>w.time?.archived||os(w.directory??null)?!1:ho(w,p.normalizedPath,h))]).filter(w=>ho(w,p.normalizedPath,h));f.set(y,new Set(N.map(B0)))});const g=Fn.getState().foldersMap;new Set([...Object.keys(g),...f.keys()]).forEach(p=>{u(p,f.get(p)??new Set)})},d=[o,l,u,n,c,i,r],e[0]=o,e[1]=l,e[2]=u,e[3]=n,e[4]=c,e[5]=i,e[6]=r,e[7]=m,e[8]=d):(m=e[7],d=e[8]),a.useEffect(m,d)};function O0(t){return os(t.path)??t.path}function _0(t){return!!t}function B0(t){return t.id}const V0=t=>{const e=pt.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:o}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[c,l]=a.useState(i);let u;e[1]!==n||e[2]!==o?(u=()=>{if(!n)return;const d=new IntersectionObserver(f=>{f.forEach(g=>{const x=g.target.dataset.projectId;x&&l(p=>{const y=new Set(p);return g.isIntersecting?y.delete(x):y.add(x),y})})},{threshold:0});return o.current.forEach(f=>{f&&d.observe(f)}),()=>d.disconnect()},e[1]=n,e[2]=o,e[3]=u):u=e[3];let m;return e[4]!==n||e[5]!==o||e[6]!==r?(m=[n,o,r],e[4]=n,e[5]=o,e[6]=r,e[7]=m):m=e[7],a.useEffect(u,m),c},$0=/^#(?:[\da-fA-F]{3}|[\da-fA-F]{6})$/,Ja=t=>{if(!t)return null;const e=t.trim();return e&&$0.test(e)?e.toLowerCase():null},z0=t=>{const e=pt.c(198),{open:n,onOpenChange:r,projectId:o,projectName:i,projectPath:c,initialIcon:l,initialColor:u,initialIconBackground:m,onSave:d}=t,f=l===void 0?null:l,g=u===void 0?null:u,x=m===void 0?null:m,{t:p}=Tt(),y=Ms(W0),b=Ms(U0),h=Ms(H0);let N;e[0]!==o?(N=$t=>$t.projects.find(as=>as.id===o)?.iconImage??null,e[0]=o,e[1]=N):N=e[1];const w=Ms(N),{currentTheme:S}=Tr(),[v,j]=a.useState(i),[k,A]=a.useState(f),[T,C]=a.useState(g);let P;e[2]!==x?(P=Ja(x),e[2]=x,e[3]=P):P=e[3];const[E,M]=a.useState(P),[H,R]=a.useState(!1),[_,z]=a.useState(!1),[V,F]=a.useState(!1),[te,Z]=a.useState(!1),[ne,U]=a.useState(null),[ie,oe]=a.useState(null),[pe,je]=a.useState(!1),Se=a.useRef(null);let re;e[4]===Symbol.for("react.memo_cache_sentinel")?(re=()=>{U(null),oe(G0)},e[4]=re):re=e[4];const L=re;let $,K;e[5]!==g||e[6]!==f||e[7]!==x||e[8]!==n||e[9]!==i?($=()=>{n&&(j(i),A(f),C(g),M(Ja(x)),Z(!1),L(),je(!1))},K=[n,i,f,g,x,L],e[5]=g,e[6]=f,e[7]=x,e[8]=n,e[9]=i,e[10]=$,e[11]=K):($=e[10],K=e[11]),a.useEffect($,K);let he,de;e[12]===Symbol.for("react.memo_cache_sentinel")?(de=()=>()=>{L()},he=[L],e[12]=he,e[13]=de):(he=e[12],de=e[13]),a.useEffect(de,he);let we,xe,De;if(e[14]!==T||e[15]!==w||e[16]!==k||e[17]!==E||e[18]!==v||e[19]!==r||e[20]!==d||e[21]!==te||e[22]!==ne||e[23]!==o||e[24]!==b||e[25]!==p||e[26]!==y){let $t;e[30]!==T||e[31]!==k||e[32]!==E||e[33]!==v||e[34]!==r||e[35]!==d||e[36]!==te||e[37]!==ne||e[38]!==o||e[39]!==b||e[40]!==p||e[41]!==y?($t=async()=>{const as=v.trim();if(!as)return;if(ne){R(!0);const Ut=await y(o,ne);if(R(!1),!Ut.ok){ae.error(Ut.error||p("projectEditDialog.toast.failedToUploadIcon"));return}ae.success(p("projectEditDialog.toast.iconUpdated")),L(),Z(!1)}const $s=te&&De;if($s){z(!0);const Ut=await b(o);if(z(!1),!Ut.ok){ae.error(Ut.error||p("projectEditDialog.toast.failedToRemoveIcon"));return}ae.success(p("projectEditDialog.toast.iconRemoved")),Z(!1),M(null)}d({label:as,icon:k,color:T,iconBackground:Ja($s?null:E)}),r(!1)},e[30]=T,e[31]=k,e[32]=E,e[33]=v,e[34]=r,e[35]=d,e[36]=te,e[37]=ne,e[38]=o,e[39]=b,e[40]=p,e[41]=y,e[42]=$t):$t=e[42],xe=$t,we=T?Sa[T]??null:null,De=!!w,e[14]=T,e[15]=w,e[16]=k,e[17]=E,e[18]=v,e[19]=r,e[20]=d,e[21]=te,e[22]=ne,e[23]=o,e[24]=b,e[25]=p,e[26]=y,e[27]=we,e[28]=xe,e[29]=De}else we=e[27],xe=e[28],De=e[29];const le=!!(ne&&ie),Ce=w?.source==="custom",ue=De&&!te||le,ve=ue,Ae=!pe&&(le||De&&!te);let ce;e[43]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>{je(!1)},e[43]=ce):ce=e[43];const fe=w?.updatedAt;let Te;e[44]!==o||e[45]!==fe?(Te=[o,fe],e[44]=o,e[45]=fe,e[46]=Te):Te=e[46],a.useEffect(ce,Te);let me;e[47]!==H||e[48]!==o?(me=$t=>{!o||!$t||H||(Z(!1),je(!1),U($t),oe(as=>(as&&URL.revokeObjectURL(as),URL.createObjectURL($t))))},e[47]=H,e[48]=o,e[49]=me):me=e[49];const B=me;let ye;e[50]!==le||e[51]!==ve||e[52]!==De||e[53]!==_||e[54]!==o?(ye=()=>{!o||!ve||_||(le&&L(),Z(!!De),je(!1))},e[50]=le,e[51]=ve,e[52]=De,e[53]=_,e[54]=o,e[55]=ye):ye=e[55];const _e=ye;let J;e[56]!==h||e[57]!==V||e[58]!==o||e[59]!==p?(J=async()=>{!o||V||(L(),Z(!1),je(!1),F(!0),h(o).then($t=>{if(!$t.ok){ae.error($t.error||p("projectEditDialog.toast.failedToDiscoverIcon"));return}if($t.skipped){ae.success(p("projectEditDialog.toast.customIconAlreadySet"));return}ae.success(p("projectEditDialog.toast.iconDiscovered"))}).finally(()=>{F(!1)}))},e[56]=h,e[57]=V,e[58]=o,e[59]=p,e[60]=J):J=e[60];const Me=J;let Ee;e[61]!==p?(Ee=p("projectEditDialog.title"),e[61]=p,e[62]=Ee):Ee=e[62];let Ne;e[63]!==Ee?(Ne=s.jsx(Qs,{className:"min-w-0",children:s.jsx(Ys,{children:Ee})}),e[63]=Ee,e[64]=Ne):Ne=e[64];let Be;e[65]!==p?(Be=p("projectEditDialog.field.name"),e[65]=p,e[66]=Be):Be=e[66];let se;e[67]!==Be?(se=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:Be}),e[67]=Be,e[68]=se):se=e[68];let O;e[69]===Symbol.for("react.memo_cache_sentinel")?(O=$t=>j($t.target.value),e[69]=O):O=e[69];let D;e[70]!==p?(D=p("projectEditDialog.field.namePlaceholder"),e[70]=p,e[71]=D):D=e[71];let Y;e[72]!==xe?(Y=$t=>{$t.key==="Enter"&&($t.preventDefault(),xe())},e[72]=xe,e[73]=Y):Y=e[73];let be;e[74]!==v||e[75]!==D||e[76]!==Y?(be=s.jsx(kn,{value:v,onChange:O,placeholder:D,onKeyDown:Y,autoFocus:!0}),e[74]=v,e[75]=D,e[76]=Y,e[77]=be):be=e[77];let Oe;e[78]!==c?(Oe=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:c,children:c}),e[78]=c,e[79]=Oe):Oe=e[79];let $e;e[80]!==se||e[81]!==be||e[82]!==Oe?($e=s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[se,be,Oe]}),e[80]=se,e[81]=be,e[82]=Oe,e[83]=$e):$e=e[83];let Re;e[84]!==p?(Re=p("projectEditDialog.field.color"),e[84]=p,e[85]=Re):Re=e[85];let ot;e[86]!==Re?(ot=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:Re}),e[86]=Re,e[87]=ot):ot=e[87];let yt;e[88]===Symbol.for("react.memo_cache_sentinel")?(yt=()=>C(null),e[88]=yt):yt=e[88];const At=T===null?"border-foreground scale-110":"border-border hover:border-border/80";let mt;e[89]!==At?(mt=Pe("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",At),e[89]=At,e[90]=mt):mt=e[90];let Le;e[91]!==p?(Le=p("projectEditDialog.option.none"),e[91]=p,e[92]=Le):Le=e[92];let Qe;e[93]===Symbol.for("react.memo_cache_sentinel")?(Qe=s.jsx("span",{className:"w-4 h-0.5 bg-muted-foreground/40 rotate-45 rounded-full"}),e[93]=Qe):Qe=e[93];let Ye;e[94]!==mt||e[95]!==Le?(Ye=s.jsx("button",{type:"button",onClick:yt,className:mt,title:Le,children:Qe}),e[94]=mt,e[95]=Le,e[96]=Ye):Ye=e[96];let rt;e[97]!==T?(rt=hh.map($t=>s.jsx("button",{type:"button",onClick:()=>C($t.key),className:Pe("w-8 h-8 rounded-lg border-2 transition-all",T===$t.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:$t.cssVar},title:$t.label},$t.key)),e[97]=T,e[98]=rt):rt=e[98];let bt;e[99]!==Ye||e[100]!==rt?(bt=s.jsxs("div",{className:"flex gap-2 flex-wrap",children:[Ye,rt]}),e[99]=Ye,e[100]=rt,e[101]=bt):bt=e[101];let ct;e[102]!==ot||e[103]!==bt?(ct=s.jsxs("div",{className:"min-w-0 space-y-2",children:[ot,bt]}),e[102]=ot,e[103]=bt,e[104]=ct):ct=e[104];let nt;e[105]!==p?(nt=p("projectEditDialog.field.icon"),e[105]=p,e[106]=nt):nt=e[106];let It;e[107]!==nt?(It=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:nt}),e[107]=nt,e[108]=It):It=e[108];let lt;e[109]!==B?(lt=s.jsx("input",{ref:Se,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:$t=>{const as=$t.target.files?.[0]??null;B(as),$t.currentTarget.value=""}}),e[109]=B,e[110]=lt):lt=e[110];let kt;e[111]===Symbol.for("react.memo_cache_sentinel")?(kt=()=>A(null),e[111]=kt):kt=e[111];const Ke=k===null?"border-foreground scale-110 bg-[var(--surface-elevated)]":"border-border hover:border-border/80";let tt;e[112]!==Ke?(tt=Pe("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",Ke),e[112]=Ke,e[113]=tt):tt=e[113];let We;e[114]!==p?(We=p("projectEditDialog.option.none"),e[114]=p,e[115]=We):We=e[115];let gt;e[116]===Symbol.for("react.memo_cache_sentinel")?(gt=s.jsx("span",{className:"w-4 h-0.5 bg-muted-foreground/40 rotate-45 rounded-full"}),e[116]=gt):gt=e[116];let He;e[117]!==tt||e[118]!==We?(He=s.jsx("button",{type:"button",onClick:kt,className:tt,title:We,children:gt}),e[117]=tt,e[118]=We,e[119]=He):He=e[119];let st;e[120]!==we||e[121]!==k?(st=ph.map($t=>{const as=$t.Icon;return s.jsx("button",{type:"button",onClick:()=>A($t.key),className:Pe("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",k===$t.key?"border-foreground scale-110 bg-[var(--surface-elevated)]":"border-border hover:border-border/80"),title:$t.label,children:s.jsx(I,{name:as,className:"w-4 h-4",style:we?{color:we}:void 0})},$t.key)}),e[120]=we,e[121]=k,e[122]=st):st=e[122];let Et;e[123]!==He||e[124]!==st?(Et=s.jsxs("div",{className:"flex gap-2 flex-wrap",children:[He,st]}),e[123]=He,e[124]=st,e[125]=Et):Et=e[125];let at;e[126]!==w||e[127]!==S||e[128]!==ue||e[129]!==le||e[130]!==E||e[131]!==ie||e[132]!==o||e[133]!==Ae||e[134]!==p?(at=ue&&Ae&&s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:p("projectEditDialog.field.preview")}),s.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-1",children:s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:E?{backgroundColor:E}:void 0,children:le&&ie?s.jsx("img",{src:ie,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>je(!0)}):s.jsx(Na,{project:{id:o,iconImage:w},options:{themeVariant:S.metadata.variant,iconColor:S.colors.surface.foreground},className:"h-full w-full object-contain",onError:()=>je(!0)})})})]}),e[126]=w,e[127]=S,e[128]=ue,e[129]=le,e[130]=E,e[131]=ie,e[132]=o,e[133]=Ae,e[134]=p,e[135]=at):at=e[135];let dt;e[136]!==Me||e[137]!==Ce||e[138]!==V||e[139]!==H||e[140]!==p?(dt=!Ce&&s.jsxs(s.Fragment,{children:[s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>Se.current?.click(),disabled:H,children:p(H?"projectEditDialog.actions.uploading":"projectEditDialog.actions.uploadIcon")}),s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>{Me()},disabled:V,children:p(V?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")})]}),e[136]=Me,e[137]=Ce,e[138]=V,e[139]=H,e[140]=p,e[141]=dt):dt=e[141];let Ht;e[142]!==_e||e[143]!==ve||e[144]!==_||e[145]!==p?(Ht=ve&&s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>{_e()},disabled:_,children:p(_?"projectEditDialog.actions.removing":"projectEditDialog.actions.removeProjectIcon")}),e[142]=_e,e[143]=ve,e[144]=_,e[145]=p,e[146]=Ht):Ht=e[146];let Rt;e[147]!==_||e[148]!==te||e[149]!==p?(Rt=te&&s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>Z(!1),disabled:_,children:p("projectEditDialog.actions.undoRemove")}),e[147]=_,e[148]=te,e[149]=p,e[150]=Rt):Rt=e[150];let Wt;e[151]!==dt||e[152]!==Ht||e[153]!==Rt?(Wt=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[dt,Ht,Rt]}),e[151]=dt,e[152]=Ht,e[153]=Rt,e[154]=Wt):Wt=e[154];let qt;e[155]!==It||e[156]!==lt||e[157]!==Et||e[158]!==at||e[159]!==Wt?(qt=s.jsxs("div",{className:"min-w-0 space-y-2",children:[It,lt,Et,at,Wt]}),e[155]=It,e[156]=lt,e[157]=Et,e[158]=at,e[159]=Wt,e[160]=qt):qt=e[160];let Lt;e[161]!==ue||e[162]!==E||e[163]!==p?(Lt=ue&&s.jsxs("div",{className:"min-w-0 space-y-2",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:p("projectEditDialog.field.iconBackground")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:E??"#000000",onChange:$t=>M($t.target.value),className:"h-8 w-10 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":p("projectEditDialog.field.iconBackgroundAria")}),s.jsx(kn,{value:E??"",onChange:$t=>M($t.target.value),placeholder:"#000000",className:"h-8 w-[8.5rem]"}),s.jsx(ze,{size:"sm",variant:"outline",onClick:()=>M(null),children:p("projectEditDialog.actions.clear")})]})]}),e[161]=ue,e[162]=E,e[163]=p,e[164]=Lt):Lt=e[164];let Gt;e[165]!==$e||e[166]!==ct||e[167]!==qt||e[168]!==Lt?(Gt=s.jsxs("div",{className:"min-w-0 space-y-5 py-1",children:[$e,ct,qt,Lt]}),e[165]=$e,e[166]=ct,e[167]=qt,e[168]=Lt,e[169]=Gt):Gt=e[169];let Qt;e[170]!==r?(Qt=()=>r(!1),e[170]=r,e[171]=Qt):Qt=e[171];let rs;e[172]!==p?(rs=p("projectEditDialog.actions.cancel"),e[172]=p,e[173]=rs):rs=e[173];let Yt;e[174]!==Qt||e[175]!==rs?(Yt=s.jsx(ze,{variant:"ghost",onClick:Qt,children:rs}),e[174]=Qt,e[175]=rs,e[176]=Yt):Yt=e[176];let ft;e[177]!==_||e[178]!==H||e[179]!==v?(ft=!v.trim()||H||_,e[177]=_,e[178]=H,e[179]=v,e[180]=ft):ft=e[180];let Jt;e[181]!==p?(Jt=p("projectEditDialog.actions.save"),e[181]=p,e[182]=Jt):Jt=e[182];let ms;e[183]!==xe||e[184]!==ft||e[185]!==Jt?(ms=s.jsx(ze,{onClick:xe,disabled:ft,children:Jt}),e[183]=xe,e[184]=ft,e[185]=Jt,e[186]=ms):ms=e[186];let Xt;e[187]!==Yt||e[188]!==ms?(Xt=s.jsxs(sr,{children:[Yt,ms]}),e[187]=Yt,e[188]=ms,e[189]=Xt):Xt=e[189];let ts;e[190]!==Ne||e[191]!==Gt||e[192]!==Xt?(ts=s.jsxs(Gs,{className:"max-w-md",children:[Ne,Gt,Xt]}),e[190]=Ne,e[191]=Gt,e[192]=Xt,e[193]=ts):ts=e[193];let ks;return e[194]!==r||e[195]!==n||e[196]!==ts?(ks=s.jsx(Ks,{open:n,onOpenChange:r,children:ts}),e[194]=r,e[195]=n,e[196]=ts,e[197]=ks):ks=e[197],ks};function W0(t){return t.uploadProjectIcon}function U0(t){return t.removeProjectIcon}function H0(t){return t.discoverProjectIcon}function G0(t){return t&&URL.revokeObjectURL(t),null}const K0=t=>{const e=pt.c(85),{folder:n,sessions:r,subFolderItems:o,isCollapsed:i,onToggle:c,onRename:l,onDelete:u,renderSessionNode:m,groupDirectory:d,projectId:f,mobileVariant:g,alwaysShowActions:x,isRenaming:p,renameDraft:y,onRenameDraftChange:b,onRenameSave:h,onRenameCancel:N,droppableRef:w,isDropTarget:S,onNewSession:v,onNewSubFolder:j,depth:k,hideActions:A,archivedBucket:T}=t,P=x===void 0?g===void 0?!1:g:x,E=p===void 0?!1:p,M=y===void 0?"":y,H=S===void 0?!1:S,R=k===void 0?0:k,_=A===void 0?!1:A,z=T===void 0?!1:T,{t:V}=Tt(),[F,te]=a.useState(!1),[Z,ne]=a.useState(""),U=a.useRef(null),ie=E||F,oe=E?M:Z;let pe;e[0]!==n.name?(pe=()=>{ne(n.name),te(!0)},e[0]=n.name,e[1]=pe):pe=e[1];const je=pe;let Se;e[2]!==oe||e[3]!==n.name||e[4]!==E||e[5]!==l||e[6]!==h?(Se=()=>{const D=oe.trim();D&&D!==n.name&&l(D),E&&h&&h(),te(!1),ne("")},e[2]=oe,e[3]=n.name,e[4]=E,e[5]=l,e[6]=h,e[7]=Se):Se=e[7];const re=Se;let L;e[8]!==E||e[9]!==N?(L=()=>{E&&N&&N(),te(!1),ne("")},e[8]=E,e[9]=N,e[10]=L):L=e[10];const $=L;let K;e[11]!==E||e[12]!==b?(K=D=>{E&&b?b(D):ne(D)},e[11]=E,e[12]=b,e[13]=K):K=e[13];const he=K;let de,we;e[14]!==E?(de=()=>{if(!E)return;const D=()=>{const Oe=U.current;Oe&&(Oe.focus(),Oe.select())},Y=requestAnimationFrame(D),be=window.setTimeout(D,0);return()=>{cancelAnimationFrame(Y),window.clearTimeout(be)}},we=[E],e[14]=E,e[15]=de,e[16]=we):(de=e[15],we=e[16]),a.useEffect(de,we);const xe=i?"folder":"folder-open",le=R>0&&"ml-3";let Ce;e[17]!==le?(Ce=Pe("oc-folder",le),e[17]=le,e[18]=Ce):Ce=e[18];const ue=H&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ve;e[19]!==ue?(ve=Pe("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",ue),e[19]=ue,e[20]=ve):ve=e[20];const G=ie?void 0:c,Ae=ie?void 0:"button",ce=ie?void 0:0;let fe;e[21]!==c||e[22]!==ie?(fe=ie?void 0:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),c())},e[21]=c,e[22]=ie,e[23]=fe):fe=e[23];let Te;e[24]!==n.name||e[25]!==i||e[26]!==V?(Te=i?V("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):V("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=V,e[27]=Te):Te=e[27];const me=z?P?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let B;e[28]!==me?(B=Pe("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",me),e[28]=me,e[29]=B):B=e[29];const ye=H?"text-primary":"text-muted-foreground";let _e;e[30]!==ye?(_e=Pe("h-3.5 w-3.5 flex-shrink-0",ye),e[30]=ye,e[31]=_e):_e=e[31];let J;e[32]!==xe||e[33]!==_e?(J=s.jsx(I,{name:xe,className:_e}),e[32]=xe,e[33]=_e,e[34]=J):J=e[34];let Me;e[35]!==oe||e[36]!==n.name||e[37]!==$||e[38]!==he||e[39]!==re||e[40]!==i||e[41]!==H||e[42]!==ie||e[43]!==r||e[44]!==V?(Me=ie?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:Y0,onMouseDown:J0,onSubmit:D=>{D.preventDefault(),re()},children:[s.jsx("input",{ref:U,value:oe,onChange:D=>he(D.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:V("sessions.sidebar.folderItem.namePlaceholder"),onClick:Q0,onPointerDown:X0,onMouseDown:Z0,onKeyDown:D=>{if(D.key==="Escape"){D.stopPropagation(),$();return}(D.key===" "||D.key==="Enter")&&D.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:ej,onPointerDown:tj,onMouseDown:sj,children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:D=>{D.stopPropagation(),$()},onPointerDown:nj,onMouseDown:rj,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:Pe("typography-ui-label font-semibold truncate",H?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=oe,e[36]=n.name,e[37]=$,e[38]=he,e[39]=re,e[40]=i,e[41]=H,e[42]=ie,e[43]=r,e[44]=V,e[45]=Me):Me=e[45];let Ee;e[46]!==B||e[47]!==J||e[48]!==Me?(Ee=s.jsxs("div",{className:B,children:[J,Me]}),e[46]=B,e[47]=J,e[48]=Me,e[49]=Ee):Ee=e[49];let Ne;e[50]!==P||e[51]!==z||e[52]!==R||e[53]!==n.name||e[54]!==je||e[55]!==_||e[56]!==u||e[57]!==v||e[58]!==j||e[59]!==ie||e[60]!==V?(Ne=!ie&&(!_||z)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:Pe("flex items-center gap-0.5 transition-opacity",P?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",z&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!z&&v?s.jsx("button",{type:"button",onClick:D=>{D.stopPropagation(),v()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:V("sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,!z&&j&&R===0?s.jsx("button",{type:"button",onClick:D=>{D.stopPropagation(),j()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:V("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(I,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,z?null:s.jsx("button",{type:"button",onClick:D=>{D.stopPropagation(),je()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(I,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:D=>{D.stopPropagation(),u()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":z?V("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):V("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=P,e[51]=z,e[52]=R,e[53]=n.name,e[54]=je,e[55]=_,e[56]=u,e[57]=v,e[58]=j,e[59]=ie,e[60]=V,e[61]=Ne):Ne=e[61];let Be;e[62]!==w||e[63]!==ve||e[64]!==G||e[65]!==Ae||e[66]!==ce||e[67]!==fe||e[68]!==Te||e[69]!==Ee||e[70]!==Ne?(Be=s.jsxs("div",{ref:w,className:ve,onClick:G,role:Ae,tabIndex:ce,onKeyDown:fe,"aria-label":Te,children:[Ee,Ne]}),e[62]=w,e[63]=ve,e[64]=G,e[65]=Ae,e[66]=ce,e[67]=fe,e[68]=Te,e[69]=Ee,e[70]=Ne,e[71]=Be):Be=e[71];let se;e[72]!==z||e[73]!==d||e[74]!==i||e[75]!==f||e[76]!==m||e[77]!==r||e[78]!==o||e[79]!==V?(se=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[o,r.length>0?r.map(D=>m(D,0,d??null,f??null,z)):o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:V("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=z,e[73]=d,e[74]=i,e[75]=f,e[76]=m,e[77]=r,e[78]=o,e[79]=V,e[80]=se):se=e[80];let O;return e[81]!==Ce||e[82]!==Be||e[83]!==se?(O=s.jsxs("div",{className:Ce,children:[Be,se]}),e[81]=Ce,e[82]=Be,e[83]=se,e[84]=O):O=e[84],O},q0=a.memo(K0);function Y0(t){return t.stopPropagation()}function J0(t){return t.stopPropagation()}function Q0(t){return t.stopPropagation()}function X0(t){return t.stopPropagation()}function Z0(t){return t.stopPropagation()}function ej(t){return t.stopPropagation()}function tj(t){return t.stopPropagation()}function sj(t){return t.stopPropagation()}function nj(t){return t.stopPropagation()}function rj(t){return t.stopPropagation()}const ij=t=>{const e=pt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:i}=t,c=`session-drag:${n}`;let l;e[0]!==r||e[1]!==n||e[2]!==o?(l={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=l):l=e[3];let u;e[4]!==c||e[5]!==l?(u={id:c,data:l},e[4]=c,e[5]=l,e[6]=u):u=e[6];const{attributes:m,listeners:d,setNodeRef:f,isDragging:g}=of(u);let x;e[7]!==d?(x=h=>{h.stopPropagation(),d?.onPointerDown&&d.onPointerDown(h)},e[7]=d,e[8]=x):x=e[8];const p=x,y=g?"opacity-30":void 0;let b;return e[9]!==m||e[10]!==i||e[11]!==p||e[12]!==f||e[13]!==y?(b=s.jsx("div",{ref:f,...m,onPointerDown:p,className:y,children:i}),e[9]=m,e[10]=i,e[11]=p,e[12]=f,e[13]=y,e[14]=b):b=e[14],b},oj=t=>{const e=pt.c(11),{folderId:n,children:r}=t,o=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let c;e[2]!==o||e[3]!==i?(c={id:o,data:i},e[2]=o,e[3]=i,e[4]=c):c=e[4];const{setNodeRef:l,isOver:u}=af(c);let m;e[5]!==r||e[6]!==u||e[7]!==l?(m=r(l,u),e[5]=r,e[6]=u,e[7]=l,e[8]=m):m=e[8];let d;return e[9]!==m?(d=s.jsx(s.Fragment,{children:m}),e[9]=m,e[10]=d):d=e[10],d},aj=t=>{const e=pt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:i}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[0]=c):c=e[0];const l=qo(no(Yo,c)),[u,m]=a.useState(null),[d,f]=a.useState("Session"),[g,x]=a.useState(null),[p,y]=a.useState(null);if(!n){let k;return e[1]!==i?(k=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=k):k=e[2],k}let b;e[3]!==o?(b=k=>{m(null),x(null),y(null);const{active:A,over:T}=k;if(!T)return;const C=A.data.current,P=T.data.current;C?.type==="session"&&C.sessionId&&P?.type==="folder"&&P.folderId&&o(C.sessionId,P.folderId)},e[3]=o,e[4]=b):b=e[4];const h=b;let N,w;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=k=>{const A=k.active.data.current;if(A?.type==="session"&&A.sessionId){m(A.sessionId),f(A.sessionTitle??"Session");const T=k.active.rect.current.initial?.width,C=k.active.rect.current.initial?.height;x(typeof T=="number"?T:null),y(typeof C=="number"?C:null)}},w=()=>{m(null),x(null),y(null)},e[5]=N,e[6]=w):(N=e[5],w=e[6]);let S;e[7]!==p||e[8]!==u||e[9]!==d||e[10]!==g||e[11]!==r?(S=u&&r?s.jsxs("div",{style:{width:g?`${g}px`:"auto",height:p?`${p}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(I,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:d})]}):null,e[7]=p,e[8]=u,e[9]=d,e[10]=g,e[11]=r,e[12]=S):S=e[12];let v;e[13]!==S?(v=s.jsx(al,{children:S}),e[13]=S,e[14]=v):v=e[14];let j;return e[15]!==i||e[16]!==h||e[17]!==l||e[18]!==v?(j=s.jsxs(Jo,{sensors:l,collisionDetection:Qo,onDragStart:N,onDragCancel:w,onDragEnd:h,children:[i,v]}),e[15]=i,e[16]=h,e[17]=l,e[18]=v,e[19]=j):j=e[19],j},Ar=Ni()(Rl(t=>({displayMode:"default",showRecentSection:!0,showArchivedSessions:!0,setDisplayMode:e=>t({displayMode:e}),setShowRecentSection:e=>t({showRecentSection:e}),setShowArchivedSessions:e=>t({showArchivedSessions:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection})),toggleArchivedSessions:()=>t(e=>({showArchivedSessions:!e.showArchivedSessions}))}),{name:"session-display-mode"})),lj=50,cj=28;function dj(t){const{t:e}=Tt(),{group:n,groupKey:r,projectId:o,hideGroupLabel:i,hasSessionSearchQuery:c,normalizedSessionSearchQuery:l,groupSearchDataByGroup:u,visibleSessionCount:m,collapsedGroups:d,hideDirectoryControls:f,collapsedFolderIds:g,toggleFolderCollapse:x,renameFolder:p,deleteFolder:y,showDeletionDialog:b,setDeleteFolderConfirm:h,renderSessionNode:N,projectRepoStatus:w,lastRepoStatus:S,showMoreGroupSessions:v,resetGroupSessionLimit:j,mobileVariant:k,alwaysShowActions:A,activeProjectId:T,setActiveProjectIdOnly:C,setActiveMainTab:P,setSessionSwitcherOpen:E,openNewSessionDraft:M,addSessionToFolder:H,createFolderAndStartRename:R,renamingFolderId:_,renameFolderDraft:z,setRenameFolderDraft:V,setRenamingFolderId:F,pinnedSessionIds:te,sessionOrderIndex:Z,prVisualStateByDirectoryBranch:ne,onToggleCollapsedGroup:U,dragHandleProps:ie,compactBodyPadding:oe=!1}=t,pe=a.useCallback((He,st)=>{const Et=Z.get(He.session.id),at=Z.get(st.session.id);if(Et!==void 0||at!==void 0){if(Et===void 0)return 1;if(at===void 0)return-1;if(Et!==at)return Et-at}return Pi(He.session,st.session,te)},[te,Z]),je=c?u.get(n):null,Se=Ar(He=>He.displayMode),re=Fn(He=>He.foldersMap),L=Se==="minimal",$=c?!1:d.has(r),K=f?10:5,he=Math.max(K,m??K),de=c?je?.groupMatches===!0:!1,we=c,xe=a.useMemo(()=>[...we?je?.filteredNodes??[]:n.sessions].sort(pe),[pe,n.sessions,je?.filteredNodes,we]),De=n.folderScopeKey??os(n.directory??null),le=a.useMemo(()=>De?re[De]??[]:[],[De,re]),Ce=a.useMemo(()=>{const He=new Map,st=Et=>{Et.forEach(at=>{He.set(at.session.id,at),at.children.length>0&&st(at.children)})};return st(xe),He},[xe]),ue=a.useMemo(()=>le.map(He=>{const st=He.sessionIds.map(Et=>Ce.get(Et)).filter(Et=>!!Et).sort(pe);return{folder:He,nodes:st}}),[le,Ce,pe]),ve=a.useMemo(()=>{const He=new Map(ue.map(dt=>[dt.folder.id,dt])),st=new Map;for(const{folder:dt}of ue){if(!dt.parentId)continue;const Ht=st.get(dt.parentId);Ht?Ht.push(dt.id):st.set(dt.parentId,[dt.id])}const Et=new Map,at=dt=>{const Ht=Et.get(dt);if(Ht!==void 0)return Ht;const Rt=He.get(dt);if(!Rt)return Et.set(dt,!1),!1;const Wt=st.get(dt)??[];if(n.isArchivedBucket&&Rt.nodes.length===0){const Gt=Wt.some(Qt=>at(Qt));return Et.set(dt,Gt),Gt}if(!c||Rt.folder.name.toLowerCase().includes(l)||Rt.nodes.length>0)return Et.set(dt,!0),!0;const Lt=Wt.some(Gt=>at(Gt));return Et.set(dt,Lt),Lt};return ue.filter(({folder:dt})=>at(dt.id))},[ue,n.isArchivedBucket,c,l]),G=a.useMemo(()=>new Set(ve.flatMap(He=>He.folder.sessionIds)),[ve]),Ae=a.useMemo(()=>xe.filter(He=>!G.has(He.session.id)),[xe,G]),ce=a.useMemo(()=>ve.filter(({folder:He})=>!He.parentId),[ve]),fe=Ae.length,Te=n.isArchivedBucket||c?Ae:Ae.slice(0,he),me=fe-Te.length,B=!n.isArchivedBucket&&!c&&fe>K&&me===0,ye=n.isArchivedBucket===!0&&!c&&Te.length>=lj,_e=a.useRef(null),[J,Me]=a.useState(null),[Ee,Ne]=a.useState(0),Be=lf({count:Te.length,getScrollElement:()=>J,estimateSize:()=>cj,overscan:8,enabled:ye&&J!==null,scrollMargin:Ee});a.useLayoutEffect(()=>{if(!ye){J!==null&&Me(null),Ee!==0&&Ne(0);return}const He=_e.current;if(!He)return;let st=J;if(!st||!st.contains(He)){let at=He.parentElement;for(;at;){const dt=window.getComputedStyle(at);if(dt.overflowY==="auto"||dt.overflowY==="scroll"){st=at;break}at=at.parentElement}if(st!==J){Me(st);return}}if(!st)return;const Et=He.getBoundingClientRect().top-st.getBoundingClientRect().top+st.scrollTop;Ne(at=>Math.abs(at-Et)<1?at:Et)}),a.useEffect(()=>{if(!ye||!J)return;const He=new ResizeObserver(()=>{Be.measure()});return He.observe(J),()=>He.disconnect()},[ye,J,Be]);const se=Be.getTotalSize(),O=ye&&J!==null?Be.getVirtualItems():[];if(c&&!de&&ce.length===0&&Ae.length===0)return null;const D=He=>{const st=[],Et=at=>{at.forEach(dt=>{st.push(dt.session),dt.children.length>0&&Et(dt.children)})};return Et(He),st},Y=D(xe),be=o&&w.has(o)?!!w.get(o):S,Oe=os(n.directory??null),$e=n.branch?.trim()??null,Re=Oe&&$e?ne.get(`${Oe}::${$e}`)??null:null,ot=!!(Re&&n.branch),yt=!Re&&!n.isMain&&!!n.branch,At=Re?.visualState??null,mt=Re&&Re.state==="open"&&Re.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Re.checks.success,total:Re.checks.total}):null,Le=Re&&Re.state==="open"&&Re.checks?[Re.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Re.checks.failure}):null,Re.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Re.checks.pending}):null].filter(He=>!!He).join(", "):null,Qe=Re&&Re.state==="open"?Re.mergeableState==="blocked"||Re.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Re.mergeableState==="clean"||Re.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,Ye=Re&&Re.state==="open"&&Re.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Re.mergeableState}):null,rt=Re?.base??null,bt=Re?.head??null,ct=(()=>{if(!Re)return n.branch&&gh(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Re.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Re.canMerge===!0||Re.mergeableState==="clean"||Re.checks?.state==="success"?{label:e("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:e("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"};case"blocked":return{label:Re.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),nt=ct?.color??(At?`var(--pr-${At})`:void 0),It=He=>{He.preventDefault(),He.stopPropagation();const st=Re?.url;st&&wi(st)},lt=(He,st,Et)=>{const at=ve.filter(({folder:Wt})=>Wt.parentId===He.id),dt=at.length>0?s.jsx(s.Fragment,{children:at.map(({folder:Wt,nodes:qt})=>lt(Wt,qt,Et+1))}):void 0,Ht=Wt=>{const qt=ve.find(({folder:Gt})=>Gt.id===Wt)?.nodes??[],Lt=ve.filter(({folder:Gt})=>Gt.parentId===Wt);return[...D(qt),...Lt.flatMap(({folder:Gt})=>Ht(Gt.id))]},Rt=n.isArchivedBucket?Ht(He.id):[];return s.jsx(oj,{folderId:He.id,children:(Wt,qt)=>s.jsx(q0,{folder:He,sessions:st,subFolderItems:dt,isCollapsed:c?!1:g.has(He.id),onToggle:()=>x(He.id),onRename:Lt=>{De&&p(De,He.id,Lt)},onDelete:()=>{if(n.isArchivedBucket){Ir.requestDelete({sessions:Rt,mode:"session"});return}if(!De)return;if(!b){y(De,He.id);return}const Lt=ve.filter(({folder:Qt})=>Qt.parentId===He.id).length,Gt=st.length;h({scopeKey:De,folderId:He.id,folderName:He.name,subFolderCount:Lt,sessionCount:Gt})},renderSessionNode:N,groupDirectory:n.directory,projectId:o,mobileVariant:k,alwaysShowActions:A,isRenaming:_===He.id,renameDraft:_===He.id?z:void 0,onRenameDraftChange:Lt=>V(Lt),onRenameSave:()=>{const Lt=z.trim();Lt&&De&&p(De,He.id,Lt),F(null),V("")},onRenameCancel:()=>{F(null),V("")},droppableRef:Wt,isDropTarget:qt,depth:Et,onNewSession:()=>{o&&o!==T&&C(o),P("chat"),k&&E(!1),M({directoryOverride:n.directory,targetFolderId:He.id})},onNewSubFolder:Et===0?()=>{De&&R(De,He.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},He.id)},kt=()=>ce.map(({folder:He,nodes:st})=>lt(He,st,0)),Ke=!!(!n.isMain&&n.worktree),tt=A?Ke?"pr-14":"pr-7":L?Ke?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":Ke?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",We=s.jsxs(aj,{scopeKey:De,hasFolders:ve.length>0,onSessionDroppedOnFolder:(He,st)=>{De&&H(De,st,He)},children:[kt(),ye?s.jsx("div",{ref:_e,style:{position:"relative",height:se>0?se:void 0,width:"100%"},children:O.map(He=>{const st=Te[He.index];return st?s.jsx("div",{"data-index":He.index,ref:Be.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${He.start-Ee}px)`},children:N(st,0,n.directory,o,!0)},He.key):null})}):Te.map(He=>N(He,0,n.directory,o,n.isArchivedBucket===!0)),fe===0&&ve.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,me>0?s.jsx("button",{type:"button",onClick:()=>v(r,Te.length),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,B?s.jsx("button",{type:"button",onClick:()=>j(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),gt=oe?"pb-2 pl-1":"pb-3 pl-4";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Pe("oc-group-body",gt),children:We})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:Pe("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>U(r),role:"button",tabIndex:0,onKeyDown:He=>{(He.key==="Enter"||He.key===" ")&&(He.preventDefault(),U(r))},"aria-label":$?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!$,children:[s.jsx("div",{ref:ie?.setActivatorNodeRef,className:Pe("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",tt),...ie?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:ot&&Re?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"git-branch",className:Pe("h-3.5 w-3.5 shrink-0",A?"hidden":"group-hover/gh:hidden"),style:nt?{color:nt}:void 0}),s.jsx("span",{className:Pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:$?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Re.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:He=>He.stopPropagation(),onClick:It,children:["#",Re.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Re.number]})]})}),s.jsx(Bt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[rt||bt?s.jsx("div",{className:"text-muted-foreground truncate",children:rt&&bt?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:rt}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:bt})]}):s.jsx("span",{children:rt??bt??""})}):null,Ye?s.jsx("div",{className:"text-muted-foreground truncate",children:Ye}):null,Qe||mt?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Qe??"",Qe&&mt?" • ":"",mt??"",Le?` (${Le})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"archive",className:Pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:$?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:ro(n.label,l)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"git-branch",className:Pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden"),style:nt?{color:nt}:void 0}),s.jsx("span",{className:Pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:$?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:ro(n.label,l)})]}):ro(n.label,l)}),yt&&ct?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(I,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||be?ot&&Re?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:nt?{color:nt}:void 0})})}),s.jsx(Bt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[rt||bt?s.jsx("div",{className:"text-muted-foreground truncate",children:rt&&bt?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:rt}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:bt})]}):s.jsx("span",{children:rt??bt??""})}):null,Ye?s.jsx("div",{className:"text-muted-foreground truncate",children:Ye}):null,Qe||mt?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Qe??"",Qe&&mt?" • ":"",mt??"",Le?` (${Le})`:""]}):null]})})]}):s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:nt?{color:nt}:void 0}):null,s.jsx("span",{className:Pe("min-w-0 truncate text-[11px] font-medium",!ct.color&&"text-muted-foreground/80"),style:ct.color?{color:ct.color}:void 0,children:ct.label})]}):null]})}),n.isArchivedBucket&&Y.length>0?s.jsx("div",{className:Pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:He=>{He.stopPropagation(),Ir.requestDelete({sessions:Y,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Pe("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:He=>{He.stopPropagation(),Ir.requestDelete({sessions:Y,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:He=>{He.stopPropagation(),o&&o!==T&&C(o),P("chat"),k&&E(!1),M({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),$?null:s.jsx("div",{className:Pe("oc-group-body",gt),children:We})]})}function uj(t){const e=pt.c(202),{t:n}=Tt(),{hideDirectoryControls:r,showRecentControls:o,handleOpenDirectoryDialog:i,openNewSessionDraft:c,canOpenMultiRun:l,openMultiRunLauncher:u,headerActionIconClass:m,headerActionButtonClass:d,isSessionSearchOpen:f,setIsSessionSearchOpen:g,sessionSearchInputRef:x,sessionSearchQuery:p,setSessionSearchQuery:y,hasSessionSearchQuery:b,searchMatchCount:h,collapseAllProjects:N,expandAllProjects:w,openScheduledTasksDialog:S,selectionModeEnabled:v,onToggleSelectionMode:j}=t,k=Ar(bj),A=Ar(xj),T=Ar(gj),C=Ar(pj),P=Ar(hj),E=Ar(fj);if(r)return null;let M;e[0]!==n?(M=n("sessions.sidebar.header.actions.addProject"),e[0]=n,e[1]=M):M=e[1];let H;e[2]!==m?(H=s.jsx(I,{name:"folder-add",className:m}),e[2]=m,e[3]=H):H=e[3];let R;e[4]!==i||e[5]!==d||e[6]!==M||e[7]!==H?(R=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:d,"aria-label":M,children:H})}),e[4]=i,e[5]=d,e[6]=M,e[7]=H,e[8]=R):R=e[8];let _;e[9]!==n?(_=n("sessions.sidebar.header.actions.addProject"),e[9]=n,e[10]=_):_=e[10];let z;e[11]!==_?(z=s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:_})}),e[11]=_,e[12]=z):z=e[12];let V;e[13]!==R||e[14]!==z?(V=s.jsxs(Ot,{children:[R,z]}),e[13]=R,e[14]=z,e[15]=V):V=e[15];let F;e[16]!==n?(F=n("sessions.sidebar.header.actions.newSession"),e[16]=n,e[17]=F):F=e[17];let te;e[18]!==m?(te=s.jsx(I,{name:"chat-new",className:m}),e[18]=m,e[19]=te):te=e[19];let Z;e[20]!==d||e[21]!==c||e[22]!==F||e[23]!==te?(Z=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:d,"aria-label":F,children:te})}),e[20]=d,e[21]=c,e[22]=F,e[23]=te,e[24]=Z):Z=e[24];let ne;e[25]!==n?(ne=n("sessions.sidebar.header.actions.newSession"),e[25]=n,e[26]=ne):ne=e[26];let U;e[27]!==ne?(U=s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ne})}),e[27]=ne,e[28]=U):U=e[28];let ie;e[29]!==U||e[30]!==Z?(ie=s.jsxs(Ot,{children:[Z,U]}),e[29]=U,e[30]=Z,e[31]=ie):ie=e[31];let oe;e[32]!==n?(oe=n("sessions.sidebar.header.actions.newMultiRun"),e[32]=n,e[33]=oe):oe=e[33];const pe=!l;let je;e[34]!==m?(je=s.jsx(xh,{className:m}),e[34]=m,e[35]=je):je=e[35];let Se;e[36]!==d||e[37]!==u||e[38]!==oe||e[39]!==pe||e[40]!==je?(Se=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:d,"aria-label":oe,disabled:pe,children:je})}),e[36]=d,e[37]=u,e[38]=oe,e[39]=pe,e[40]=je,e[41]=Se):Se=e[41];let re;e[42]!==n?(re=n("sessions.sidebar.header.actions.newMultiRun"),e[42]=n,e[43]=re):re=e[43];let L;e[44]!==re?(L=s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:re})}),e[44]=re,e[45]=L):L=e[45];let $;e[46]!==Se||e[47]!==L?($=s.jsxs(Ot,{children:[Se,L]}),e[46]=Se,e[47]=L,e[48]=$):$=e[48];let K;e[49]!==n?(K=n("sessions.sidebar.header.actions.scheduledTasks"),e[49]=n,e[50]=K):K=e[50];let he;e[51]!==m?(he=s.jsx(I,{name:"calendar-schedule",className:m}),e[51]=m,e[52]=he):he=e[52];let de;e[53]!==d||e[54]!==S||e[55]!==K||e[56]!==he?(de=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,className:d,"aria-label":K,children:he})}),e[53]=d,e[54]=S,e[55]=K,e[56]=he,e[57]=de):de=e[57];let we;e[58]!==n?(we=n("sessions.sidebar.header.actions.scheduledTasks"),e[58]=n,e[59]=we):we=e[59];let xe;e[60]!==we?(xe=s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:we})}),e[60]=we,e[61]=xe):xe=e[61];let De;e[62]!==de||e[63]!==xe?(De=s.jsxs(Ot,{children:[de,xe]}),e[62]=de,e[63]=xe,e[64]=De):De=e[64];let le;e[65]!==ie||e[66]!==$||e[67]!==De||e[68]!==V?(le=s.jsxs("div",{className:"flex items-center gap-1.5",children:[V,ie,$,De]}),e[65]=ie,e[66]=$,e[67]=De,e[68]=V,e[69]=le):le=e[69];let Ce;e[70]!==g?(Ce=()=>g(mj),e[70]=g,e[71]=Ce):Ce=e[71];let ue;e[72]!==n?(ue=n("sessions.sidebar.header.actions.searchSessions"),e[72]=n,e[73]=ue):ue=e[73];let ve;e[74]!==m?(ve=s.jsx(I,{name:"search",className:m}),e[74]=m,e[75]=ve):ve=e[75];let G;e[76]!==d||e[77]!==f||e[78]!==Ce||e[79]!==ue||e[80]!==ve?(G=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ce,className:d,"aria-label":ue,"aria-expanded":f,children:ve})}),e[76]=d,e[77]=f,e[78]=Ce,e[79]=ue,e[80]=ve,e[81]=G):G=e[81];let Ae;e[82]!==n?(Ae=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=Ae):Ae=e[83];let ce;e[84]!==Ae?(ce=s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ae})}),e[84]=Ae,e[85]=ce):ce=e[85];let fe;e[86]!==G||e[87]!==ce?(fe=s.jsxs(Ot,{children:[G,ce]}),e[86]=G,e[87]=ce,e[88]=fe):fe=e[88];const Te=v&&"bg-interactive-hover text-primary";let me;e[89]!==d||e[90]!==Te?(me=Pe(d,Te),e[89]=d,e[90]=Te,e[91]=me):me=e[91];let B;e[92]!==v||e[93]!==n?(B=n(v?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[92]=v,e[93]=n,e[94]=B):B=e[94];let ye;e[95]!==m?(ye=s.jsx(I,{name:"checkbox-multiple",className:m}),e[95]=m,e[96]=ye):ye=e[96];let _e;e[97]!==j||e[98]!==v||e[99]!==me||e[100]!==B||e[101]!==ye?(_e=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:me,"aria-label":B,"aria-pressed":v,children:ye})}),e[97]=j,e[98]=v,e[99]=me,e[100]=B,e[101]=ye,e[102]=_e):_e=e[102];let J;e[103]!==v||e[104]!==n?(J=n(v?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[103]=v,e[104]=n,e[105]=J):J=e[105];let Me;e[106]!==J?(Me=s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:J})}),e[106]=J,e[107]=Me):Me=e[107];let Ee;e[108]!==_e||e[109]!==Me?(Ee=s.jsxs(Ot,{children:[_e,Me]}),e[108]=_e,e[109]=Me,e[110]=Ee):Ee=e[110];let Ne;e[111]!==n?(Ne=n("sessions.sidebar.header.actions.sessionDisplayMode"),e[111]=n,e[112]=Ne):Ne=e[112];let Be;e[113]!==m?(Be=s.jsx(I,{name:"equalizer-2",className:m}),e[113]=m,e[114]=Be):Be=e[114];let se;e[115]!==d||e[116]!==Ne||e[117]!==Be?(se=s.jsx(_t,{asChild:!0,children:s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",className:d,"aria-label":Ne,children:Be})})}),e[115]=d,e[116]=Ne,e[117]=Be,e[118]=se):se=e[118];let O;e[119]!==n?(O=n("sessions.sidebar.header.displayMode.label"),e[119]=n,e[120]=O):O=e[120];let D;e[121]!==O?(D=s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:O})}),e[121]=O,e[122]=D):D=e[122];let Y;e[123]!==se||e[124]!==D?(Y=s.jsxs(Ot,{children:[se,D]}),e[123]=se,e[124]=D,e[125]=Y):Y=e[125];let be;e[126]!==C?(be=()=>C("default"),e[126]=C,e[127]=be):be=e[127];let Oe;e[128]!==n?(Oe=n("sessions.sidebar.header.displayMode.default"),e[128]=n,e[129]=Oe):Oe=e[129];let $e;e[130]!==Oe?($e=s.jsx("span",{children:Oe}),e[130]=Oe,e[131]=$e):$e=e[131];let Re;e[132]!==k?(Re=k==="default"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null,e[132]=k,e[133]=Re):Re=e[133];let ot;e[134]!==be||e[135]!==$e||e[136]!==Re?(ot=s.jsxs(zt,{onClick:be,className:"flex items-center justify-between",children:[$e,Re]}),e[134]=be,e[135]=$e,e[136]=Re,e[137]=ot):ot=e[137];let yt;e[138]!==C?(yt=()=>C("minimal"),e[138]=C,e[139]=yt):yt=e[139];let At;e[140]!==n?(At=n("sessions.sidebar.header.displayMode.minimal"),e[140]=n,e[141]=At):At=e[141];let mt;e[142]!==At?(mt=s.jsx("span",{children:At}),e[142]=At,e[143]=mt):mt=e[143];let Le;e[144]!==k?(Le=k==="minimal"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null,e[144]=k,e[145]=Le):Le=e[145];let Qe;e[146]!==yt||e[147]!==mt||e[148]!==Le?(Qe=s.jsxs(zt,{onClick:yt,className:"flex items-center justify-between",children:[mt,Le]}),e[146]=yt,e[147]=mt,e[148]=Le,e[149]=Qe):Qe=e[149];let Ye;e[150]!==T||e[151]!==o||e[152]!==A||e[153]!==n||e[154]!==E||e[155]!==P?(Ye=o?s.jsxs(s.Fragment,{children:[s.jsx(On,{}),s.jsxs(zt,{onClick:P,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),A?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(zt,{onClick:E,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showArchived")}),T?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]})]}):null,e[150]=T,e[151]=o,e[152]=A,e[153]=n,e[154]=E,e[155]=P,e[156]=Ye):Ye=e[156];let rt;e[157]===Symbol.for("react.memo_cache_sentinel")?(rt=s.jsx(On,{}),e[157]=rt):rt=e[157];let bt;e[158]===Symbol.for("react.memo_cache_sentinel")?(bt=s.jsx(I,{name:"contract-up-down",className:"h-4 w-4"}),e[158]=bt):bt=e[158];let ct;e[159]!==n?(ct=n("sessions.sidebar.header.displayMode.collapseAll"),e[159]=n,e[160]=ct):ct=e[160];let nt;e[161]!==ct?(nt=s.jsx("span",{children:ct}),e[161]=ct,e[162]=nt):nt=e[162];let It;e[163]!==N||e[164]!==nt?(It=s.jsxs(zt,{onClick:N,className:"flex items-center gap-2",children:[bt,nt]}),e[163]=N,e[164]=nt,e[165]=It):It=e[165];let lt;e[166]===Symbol.for("react.memo_cache_sentinel")?(lt=s.jsx(I,{name:"expand-up-down",className:"h-4 w-4"}),e[166]=lt):lt=e[166];let kt;e[167]!==n?(kt=n("sessions.sidebar.header.displayMode.expandAll"),e[167]=n,e[168]=kt):kt=e[168];let Ke;e[169]!==kt?(Ke=s.jsx("span",{children:kt}),e[169]=kt,e[170]=Ke):Ke=e[170];let tt;e[171]!==w||e[172]!==Ke?(tt=s.jsxs(zt,{onClick:w,className:"flex items-center gap-2",children:[lt,Ke]}),e[171]=w,e[172]=Ke,e[173]=tt):tt=e[173];let We;e[174]!==ot||e[175]!==Qe||e[176]!==Ye||e[177]!==It||e[178]!==tt?(We=s.jsxs(nn,{align:"end",className:"min-w-[160px]",children:[ot,Qe,Ye,rt,It,tt]}),e[174]=ot,e[175]=Qe,e[176]=Ye,e[177]=It,e[178]=tt,e[179]=We):We=e[179];let gt;e[180]!==Y||e[181]!==We?(gt=s.jsxs(rn,{children:[Y,We]}),e[180]=Y,e[181]=We,e[182]=gt):gt=e[182];let He;e[183]!==fe||e[184]!==Ee||e[185]!==gt?(He=s.jsxs("div",{className:"flex items-center gap-1.5",children:[fe,Ee,gt]}),e[183]=fe,e[184]=Ee,e[185]=gt,e[186]=He):He=e[186];let st;e[187]!==le||e[188]!==He?(st=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[le,He]}),e[187]=le,e[188]=He,e[189]=st):st=e[189];let Et;e[190]!==b||e[191]!==f||e[192]!==h||e[193]!==x||e[194]!==p||e[195]!==g||e[196]!==y||e[197]!==n?(Et=f?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[b?s.jsx("span",{children:h===1?n("sessions.sidebar.header.search.matchCountSingle",{count:h}):n("sessions.sidebar.header.search.matchCountPlural",{count:h})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:x,value:p,onChange:dt=>y(dt.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:dt=>{dt.key==="Escape"&&(dt.stopPropagation(),b?y(""):g(!1))}}),p.length>0?s.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[190]=b,e[191]=f,e[192]=h,e[193]=x,e[194]=p,e[195]=g,e[196]=y,e[197]=n,e[198]=Et):Et=e[198];let at;return e[199]!==st||e[200]!==Et?(at=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[st,Et]})}),e[199]=st,e[200]=Et,e[201]=at):at=e[201],at}function mj(t){return!t}function fj(t){return t.toggleArchivedSessions}function hj(t){return t.toggleRecentSection}function pj(t){return t.setDisplayMode}function gj(t){return t.showArchivedSessions}function xj(t){return t.showRecentSection}function bj(t){return t.displayMode}const Qd=7;function yj(t){const e=pt.c(20),{sections:n,renderSessionNode:r}=t,{t:o}=Tt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[c,l]=a.useState(i);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=new Set,e[1]=u):u=e[1];const[m,d]=a.useState(u);let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=w=>{l(S=>{const v=new Set(S);return v.has(w)?v.delete(w):v.add(w),v})},e[2]=f):f=e[2];const g=f;let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=w=>{d(S=>{const v=new Set(S);return v.has(w)?v.delete(w):v.add(w),v})},e[3]=x):x=e[3];const p=x;let y,b,h;if(e[4]!==c||e[5]!==m||e[6]!==r||e[7]!==n||e[8]!==o){h=Symbol.for("react.early_return_sentinel");e:{const w=n.filter(wj);if(w.length===0){h=null;break e}y="space-y-2 pb-2 pt-1";let S;e[12]!==c||e[13]!==m||e[14]!==r||e[15]!==o?(S=v=>{const j=c.has(v.key),k=m.has(v.key),A=k?v.items:v.items.slice(0,Qd),T=v.items.length-A.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>g(v.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:v.title})]}),j?null:s.jsxs("div",{className:Pe("space-y-0.5 pl-7"),children:[A.map(C=>r(C.node,0,C.groupDirectory,C.projectId,!1,C.secondaryMeta,"recent")),T>0&&!k?s.jsx("button",{type:"button",onClick:()=>p(v.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:T===1?o("sessions.sidebar.group.showMoreSingle",{count:T}):o("sessions.sidebar.group.showMorePlural",{count:T})}):null,k&&v.items.length>Qd?s.jsx("button",{type:"button",onClick:()=>p(v.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showFewer")}):null]})]},v.key)},e[12]=c,e[13]=m,e[14]=r,e[15]=o,e[16]=S):S=e[16],b=w.map(S)}e[4]=c,e[5]=m,e[6]=r,e[7]=n,e[8]=o,e[9]=y,e[10]=b,e[11]=h}else y=e[9],b=e[10],h=e[11];if(h!==Symbol.for("react.early_return_sentinel"))return h;let N;return e[17]!==y||e[18]!==b?(N=s.jsx("div",{className:y,children:b}),e[17]=y,e[18]=b,e[19]=N):N=e[19],N}function wj(t){return t.items.length>0}const Qa="inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50";function vj(t){const e=pt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:i,showRuntimeButtons:c,showUpdateButton:l}=t,u=c===void 0?!0:c,m=l===void 0?!0:l,{t:d}=Tt();let f;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==u||e[4]!==d?(f=u?s.jsxs(s.Fragment,{children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Qa,"aria-label":d("sessions.sidebar.footer.actions.settings"),children:s.jsx(I,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(Bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:d("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Qa,"aria-label":d("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(I,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(Bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:d("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:Qa,"aria-label":d("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(I,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(Bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:d("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=u,e[4]=d,e[5]=f):f=e[5];let g;e[6]!==i||e[7]!==m||e[8]!==d?(g=m?s.jsx(ze,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:d("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=m,e[8]=d,e[9]=g):g=e[9];let x;return e[10]!==f||e[11]!==g?(x=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[f,g]}),e[10]=f,e[11]=g,e[12]=x):x=e[12],x}const jj=t=>{const e=pt.c(50),{id:n,projectLabel:r,projectDescription:o,projectIcon:i,projectColor:c,projectIconImage:l,projectIconBackground:u,isCollapsed:m,isActiveProject:d,isRepo:f,isDesktopShell:g,isStuck:x,hideDirectoryControls:p,alwaysShowActions:y,onToggle:b,onNewSession:h,onNewWorktreeSession:N,onRenameStart:w,onClose:S,sentinelRef:v,children:j,showCreateButtons:k,hideHeader:A,openSidebarMenuKey:T,setOpenSidebarMenuKey:C}=t,P=k===void 0?!0:k,E=A===void 0?!1:A,{t:M}=Tt(),{currentTheme:H}=Tr();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:_,listeners:z,setNodeRef:V,transform:F,transition:te,isDragging:Z}=Ml(R),ne=a.useRef(!1),U=`project:${n}`,ie=T===U,oe=i?Jl[i]:null,pe=c?Sa[c]??null:null;let je;e[2]!==U||e[3]!==C?(je=G=>{C(G?U:null)},e[2]=U,e[3]=C,e[4]=je):je=e[4];const Se=je,re=kj,L=Cj,$=Aj;let K;e[5]===Symbol.for("react.memo_cache_sentinel")?(K=G=>{(G.button===2||G.button===0&&G.ctrlKey)&&(ne.current=!0)},e[5]=K):K=e[5];const he=K;let de;e[6]!==b?(de=()=>{if(ne.current){ne.current=!1;return}b()},e[6]=b,e[7]=de):de=e[7];const we=de;let xe;e[8]!==F?(xe=Fl.Transform.toString(F),e[8]=F,e[9]=xe):xe=e[9];let De;e[10]!==xe||e[11]!==te?(De={transform:xe,transition:te},e[10]=xe,e[11]=te,e[12]=De):De=e[12];const le=Z&&"opacity-30";let Ce;e[13]!==le?(Ce=Pe("relative",le),e[13]=le,e[14]=Ce):Ce=e[14];let ue;e[15]!==y||e[16]!==_||e[17]!==H||e[18]!==Se||e[19]!==we||e[20]!==p||e[21]!==E||e[22]!==pe||e[23]!==n||e[24]!==d||e[25]!==m||e[26]!==g||e[27]!==ie||e[28]!==f||e[29]!==x||e[30]!==z||e[31]!==S||e[32]!==h||e[33]!==N||e[34]!==w||e[35]!==o||e[36]!==u||e[37]!==l||e[38]!==oe||e[39]!==r||e[40]!==v||e[41]!==P||e[42]!==M?(ue=E?null:s.jsxs(s.Fragment,{children:[g&&s.jsx("div",{ref:v,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:Pe("w-full text-left group/project select-none"),style:{backgroundColor:g&&x?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",..._,children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:he,onClick:we,...z,className:Pe("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",f&&!p?y?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":y?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:Pe("h-3.5 w-3.5 items-center justify-center text-muted-foreground",y?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:m?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),l?s.jsx("span",{className:Pe("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",y?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:u?{backgroundColor:u}:void 0,children:s.jsx(Na,{project:{id:n,iconImage:l},options:{themeVariant:H.metadata.variant,iconColor:H.colors.surface.foreground},className:"h-full w-full object-contain",fallback:oe?s.jsx(I,{name:oe,className:"h-3.5 w-3.5",style:pe?{color:pe}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:pe?{color:pe}:void 0})})}):oe?s.jsx(I,{name:oe,className:Pe("h-3.5 w-3.5",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:pe?{color:pe}:void 0}):s.jsx(I,{name:"folder",className:Pe("h-3.5 w-3.5 text-muted-foreground/80",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:pe?{color:pe}:void 0})]}),s.jsx("span",{className:Pe("text-[14px] font-normal truncate lowercase",d?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Bt,{side:"right",sideOffset:8,children:o})]}),s.jsxs("div",{className:Pe("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",P?"right-7":"right-0.5"),children:[P&&f&&!p&&N?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:G=>{G.stopPropagation(),N()},className:Pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(I,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(rn,{open:ie,onOpenChange:Se,children:[s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",ie?"opacity-100 pointer-events-auto":y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.projectMenu"),onPointerDown:L,onMouseDown:$,onClick:re,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(nn,{align:"end",className:"min-w-[180px]",children:[P&&!f&&!p&&h&&s.jsxs(zt,{onClick:h,children:[s.jsx(I,{name:"add",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.newSession")]}),s.jsxs(zt,{onClick:w,children:[s.jsx(I,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.closeProject")]})]})]})]}),P&&h?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:G=>{G.stopPropagation(),h()},className:Pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(Bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[15]=y,e[16]=_,e[17]=H,e[18]=Se,e[19]=we,e[20]=p,e[21]=E,e[22]=pe,e[23]=n,e[24]=d,e[25]=m,e[26]=g,e[27]=ie,e[28]=f,e[29]=x,e[30]=z,e[31]=S,e[32]=h,e[33]=N,e[34]=w,e[35]=o,e[36]=u,e[37]=l,e[38]=oe,e[39]=r,e[40]=v,e[41]=P,e[42]=M,e[43]=ue):ue=e[43];let ve;return e[44]!==j||e[45]!==V||e[46]!==Ce||e[47]!==ue||e[48]!==De?(ve=s.jsxs("div",{ref:V,style:De,className:Ce,children:[ue,j]}),e[44]=j,e[45]=V,e[46]=Ce,e[47]=ue,e[48]=De,e[49]=ve):ve=e[49],ve},Sj=t=>{const e=pt.c(21),{id:n,disabled:r,children:o}=t,i=r===void 0?!1:r;let c;e[0]!==i||e[1]!==n?(c={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=c):c=e[2];const{listeners:l,setNodeRef:u,setActivatorNodeRef:m,transform:d,transition:f,isDragging:g}=Ml(c);let x;e[3]!==l||e[4]!==m?(x={listeners:l,setActivatorNodeRef:m},e[3]=l,e[4]=m,e[5]=x):x=e[5];const p=x;let y;e[6]!==d?(y=Fl.Transform.toString(d),e[6]=d,e[7]=y):y=e[7];let b;e[8]!==y||e[9]!==f?(b={transform:y,transition:f},e[8]=y,e[9]=f,e[10]=b):b=e[10];const h=g&&"opacity-50";let N;e[11]!==h?(N=Pe("space-y-0.5 rounded-md",h),e[11]=h,e[12]=N):N=e[12];let w;e[13]!==o||e[14]!==p?(w=typeof o=="function"?o(p):o,e[13]=o,e[14]=p,e[15]=w):w=e[15];let S;return e[16]!==u||e[17]!==b||e[18]!==N||e[19]!==w?(S=s.jsx("div",{ref:u,style:b,className:N,children:w}),e[16]=u,e[17]=b,e[18]=N,e[19]=w,e[20]=S):S=e[20],S},Nj=a.memo(Sj);function kj(t){t.stopPropagation()}function Cj(t){t.stopPropagation()}function Aj(t){t.stopPropagation()}function Dj(t){const e=pt.c(25),{t:n}=Tt();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o={coordinateGetter:df},e[1]=o):o=e[1];const i=qo(no(Yo,r),no(cf,o));let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[2]=c):c=e[2];const l=qo(no(Yo,c));if(t.projectSections.length===0){const g=(t.mobileVariant,"");let x;e[3]!==g?(x=Pe("space-y-1 pb-1 pl-2.5 pr-2",g),e[3]=g,e[4]=x):x=e[4];let p;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==x?(p=s.jsxs(_n,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:x,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=x,e[8]=p):p=e[8],p}if(t.sectionsForRender.length===0){const g=(t.mobileVariant,"");let x;e[9]!==g?(x=Pe("space-y-1 pb-1 pl-2.5 pr-2",g),e[9]=g,e[10]=x):x=e[10];let p;return e[11]!==t.searchEmptyState||e[12]!==x?(p=s.jsx(_n,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:x,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=x,e[13]=p):p=e[13],p}const u=(t.mobileVariant,"");let m;e[14]!==u?(m=Pe("space-y-1 pb-1 pl-2.5 pr-2",u),e[14]=u,e[15]=m):m=e[15];let d;e[16]!==l||e[17]!==i||e[18]!==t||e[19]!==n?(d=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const g=t.sectionsForRender.find(b=>b.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!g)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const x=g.groups.find(Lj)??g.groups.find(Fj)??g.groups.find(Mj)??g.groups[0];if(!x)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const p=g.groups.find(Rj);return[x,...p&&p.id!==x.id?[p]:[]].map(b=>{const h=`${g.project.id}:${b.id}`,N=b.id===x.id;return s.jsx(a.Fragment,{children:t.renderGroupSessions(b,h,g.project.id,N,null,!0)},h)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Jo,{sensors:i,collisionDetection:Qo,onDragEnd:g=>{if(t.isInlineEditing)return;const{active:x,over:p}=g;if(!p||x.id===p.id)return;const y=t.sectionsForRender.findIndex(h=>h.project.id===x.id),b=t.sectionsForRender.findIndex(h=>h.project.id===p.id);y===-1||b===-1||y===b||t.reorderProjects(y,b)},children:[s.jsx(il,{items:t.sectionsForRender.map(Ej),strategy:ol,children:t.sectionsForRender.map(g=>{const x=g.project,p=x.id,y=zu(x.label?.trim()||Si(x.normalizedPath,t.homeDirectory)||x.normalizedPath),b=Zo(x.normalizedPath,t.homeDirectory),h=t.collapsedProjects.has(p),N=p===t.activeProjectId,w=t.projectRepoStatus.get(p),S=t.getOrderedGroups(p,g.groups),v=S.find(Tj)??null,j=v?S.filter(k=>k.id!==v.id):S;return s.jsx(jj,{id:p,projectLabel:y,projectDescription:b,projectIcon:x.icon,projectColor:x.color,projectIconImage:x.iconImage,projectIconBackground:x.iconBackground,isCollapsed:h,isActiveProject:N,isRepo:!!w,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(p),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(p),onNewSession:()=>{p!==t.activeProjectId&&t.setActiveProjectIdOnly(p),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:x.normalizedPath})},onNewWorktreeSession:()=>{p!==t.activeProjectId&&t.setActiveProjectIdOnly(p),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(p),onClose:()=>t.removeProject(p),sentinelRef:k=>{t.projectHeaderSentinelRefs.current.set(p,k)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:h?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:g.groups.length>0?s.jsxs(Jo,{sensors:l,collisionDetection:Qo,onDragEnd:k=>{if(t.isInlineEditing)return;const{active:A,over:T}=k;if(!T||A.id===T.id)return;const C=j.findIndex(H=>H.id===A.id),P=j.findIndex(H=>H.id===T.id);if(C===-1||P===-1||C===P)return;const E=gu(j,C,P).map(Pj),M=v?[v.id,...E]:E;t.setGroupOrderByProject(H=>{const R=new Map(H);return R.set(p,M),R})},children:[v?t.renderGroupSessions(v,`${p}:${v.id}`,p,!0):null,s.jsx(il,{items:j.map(Ij),strategy:ol,children:j.map(k=>{const A=`${p}:${k.id}`;return s.jsx(Nj,{id:k.id,disabled:t.isInlineEditing,children:T=>t.renderGroupSessions(k,A,p,!1,T)},k.id)})}),s.jsx(al,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},p)})}),s.jsx(al,{dropAnimation:null})]})}),e[16]=l,e[17]=i,e[18]=t,e[19]=n,e[20]=d):d=e[20];let f;return e[21]!==t.topContent||e[22]!==m||e[23]!==d?(f=s.jsxs(_n,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:m,children:[t.topContent,d]}),e[21]=t.topContent,e[22]=m,e[23]=d,e[24]=f):f=e[24],f}function Ij(t){return t.id}function Pj(t){return t.id}function Tj(t){return t.isMain}function Ej(t){return t.project.id}function Rj(t){return t.isArchivedBucket}function Mj(t){return t.isMain}function Fj(t){return t.sessions.length>0}function Lj(t){return t.isMain&&t.sessions.length>0}function Oj(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(void 0,{month:"short"}),r=e.getDate(),o=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),c=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${o}, ${i}:${c}`}function _j(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function Bj(t){const e=t.info.role==="user"?"User":"Assistant",n=Oj(t.info.time?.created),r=_j(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
165
165
 
166
- *${o}*`:`**${e}**`}function Oj(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Lm(t){const e=Lj(t),n=Oj(t.parts).trim();return n?`${e}
166
+ *${o}*`:`**${e}**`}function Vj(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Bm(t){const e=Bj(t),n=Vj(t.parts).trim();return n?`${e}
167
167
 
168
- ${n}`:""}function Om(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",o=`${n} Sub-agent: ${t.title}${r}
168
+ ${n}`:""}function Vm(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",o=`${n} Sub-agent: ${t.title}${r}
169
169
 
170
170
  ---
171
171
 
172
- `,i=t.records.map(Lm).filter(Boolean).join(`
172
+ `,i=t.records.map(Bm).filter(Boolean).join(`
173
173
 
174
174
  ---
175
175
 
176
- `),c=[o+i];for(const l of t.children)c.push(Om(l,e+1));return c.join(`
176
+ `),c=[o+i];for(const l of t.children)c.push(Vm(l,e+1));return c.join(`
177
177
 
178
178
  ---
179
179
 
180
- `)}function _j(t,e,n){const r=e?.trim()||"Session",o=new Date().toISOString().split("T")[0],i=`# ${r}
180
+ `)}function $j(t,e,n){const r=e?.trim()||"Session",o=new Date().toISOString().split("T")[0],i=`# ${r}
181
181
 
182
182
  *Exported on ${o}*
183
183
 
184
184
  ---
185
185
 
186
- `,c=t.map(Lm).filter(Boolean).join(`
186
+ `,c=t.map(Bm).filter(Boolean).join(`
187
187
 
188
188
  ---
189
189
 
190
- `);let l=i+c;if(n&&n.length>0){const u=n.map(m=>Om(m,1)).join(`
190
+ `);let l=i+c;if(n&&n.length>0){const u=n.map(m=>Vm(m,1)).join(`
191
191
 
192
192
  ---
193
193
 
@@ -195,15 +195,15 @@ ${n}`:""}function Om(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${
195
195
 
196
196
  ---
197
197
 
198
- `+u}return l}function Bj(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}async function Vj(t,e){const n=await ph(e,t);if(n)return n;if(!Gi())return null;try{const r=await yo()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const o=typeof r.path=="string"?r.path.trim():"";return o.length>0?o:null}catch{return null}}async function $j(t){const e=yo()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await gh(t)?!0:Xo(t)}function zj(){return Hl()}function Wj(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",o=new Date().toISOString().split("T")[0];return`${r}-${o}.md`}const Uj=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const o of t){r.has(o)||(r.add(o),n.push(o));const i=e.get(o);if(i)for(const c of i)r.has(c)||(r.add(c),n.push(c))}return n},Zn=vi()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,o)=>{const i=e(),c=new Set(i.selectedIds);let l=i.scopeKey,u=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(c.clear(),l=r,u=null):l===null&&r!==null&&(l=r);const d=o&&o.length>0?[n,...o]:[n];if(c.has(n)){for(const g of d)c.delete(g);u===n&&(u=null)}else{for(const g of d)c.add(g);u=n}c.size===0?t({selectedIds:c,scopeKey:null,anchorId:null}):t({selectedIds:c,scopeKey:l,anchorId:u})},setRange:(n,r,o,i,c)=>{const l=e();if(o.length===0)return;const u=n&&o.includes(n)?n:o[0],m=o.indexOf(u),d=o.indexOf(r);if(m<0||d<0)return;const[f,g]=m<=d?[m,d]:[d,m],x=o.slice(f,g+1),p=Uj(x,c),b=i!==null&&l.scopeKey!==null&&i!==l.scopeKey?new Set:new Set(l.selectedIds);for(const h of p)b.add(h);t({selectedIds:b,scopeKey:i??l.scopeKey,anchorId:u})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const o=new Set(r.selectedIds);for(const i of n)o.delete(i);o.size!==r.selectedIds.size&&(o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o}))}})),Hj=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,_m=/^g[1-9]\d*$/,eo=(t,e,n,r,o)=>{if(!Hj.test(t)||e!==void 0&&!_m.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(o===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(o==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(o))return null;const i=Number.parseInt(o,10);return!Number.isSafeInteger(i)||i<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:i,fusion:!1}},Go=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return eo(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,l,u,m]=e;return _m.test(l)?eo(n,l,u,m,void 0):eo(n,void 0,l,u,m)}const[,r,o,i,c]=e;return r===""?eo(n,void 0,o,i,c):eo(n,r,o,i,c)},Gj=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},Kj=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},Bm=t=>{const e=gt.c(36),{value:n,onChange:r,className:o,disabled:i,id:c,portalToBody:l}=t,{t:u}=Tt(),m=cs(qj),d=cs(Yj),f=cs(Jj);let g;e[0]!==m?(g=m(),e[0]=m,e[1]=g):g=e[1];const x=g;let p;e[2]!==x?(p=x.filter(Qj),e[2]=x,e[3]=p):p=e[3];const y=p;let b,h;e[4]!==x.length||e[5]!==d?(b=()=>{x.length===0&&d()},h=[x.length,d],e[4]=x.length,e[5]=d,e[6]=b,e[7]=h):(b=e[6],h=e[7]),a.useEffect(b,h);let N,w;e[8]!==f||e[9]!==i||e[10]!==r||e[11]!==y||e[12]!==n?(N=()=>{if(i)return;const E=n.trim();if(E.length>0&&y.some(R=>R.name===E))return;const M=typeof f=="string"&&f.trim().length>0?f.trim():null;if(M&&y.some(R=>R.name===M)){r(M);return}const H=y[0]?.name;H&&r(H)},w=[f,i,r,y,n],e[8]=f,e[9]=i,e[10]=r,e[11]=y,e[12]=n,e[13]=N,e[14]=w):(N=e[13],w=e[14]),a.useEffect(N,w);const S=n.trim().length>0?n:void 0;let v;e[15]!==o?(v=Te("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",o),e[15]=o,e[16]=v):v=e[16];let j;e[17]!==u?(j=u("multirun.agentSelector.placeholder"),e[17]=u,e[18]=j):j=e[18];let k;e[19]!==j?(k=s.jsx(Pn,{placeholder:j}),e[19]=j,e[20]=k):k=e[20];let D;e[21]!==c||e[22]!==v||e[23]!==k?(D=s.jsx(Vn,{id:c,size:"lg",className:v,children:k}),e[21]=c,e[22]=v,e[23]=k,e[24]=D):D=e[24];let T;e[25]!==y?(T=y.length>0&&s.jsx(ul,{children:y.map(Xj)}),e[25]=y,e[26]=T):T=e[26];let C;e[27]!==l||e[28]!==T?(C=s.jsx($n,{fitContent:!0,portalToBody:l,children:T}),e[27]=l,e[28]=T,e[29]=C):C=e[29];let P;return e[30]!==i||e[31]!==r||e[32]!==S||e[33]!==D||e[34]!==C?(P=s.jsxs(Bn,{value:S,onValueChange:r,disabled:i,children:[D,C]}),e[30]=i,e[31]=r,e[32]=S,e[33]=D,e[34]=C,e[35]=P):P=e[35],P};function qj(t){return t.getVisibleAgents}function Yj(t){return t.loadAgents}function Jj(t){return t.currentAgentName}function Qj(t){return t.mode!=="subagent"}function Xj(t){return s.jsx(qs,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Vm="h-7",uo=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,Zj=t=>{const e=gt.c(12),{model:n,instanceIndex:r,totalSameModel:o,onRemove:i}=t,c=n.displayName||`${n.providerID}/${n.modelID}`,l=o>1?`${c} (${r})`:c;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Te("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Vm),e[0]=u):u=e[0];let m;e[1]!==n.providerID?(m=s.jsx(fo,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=m):m=e[2];let d;e[3]!==l?(d=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:l}),e[3]=l,e[4]=d):d=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(I,{name:"close",className:"h-3.5 w-3.5"}),e[5]=f):f=e[5];let g;e[6]!==i?(g=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=i,e[7]=g):g=e[7];let x;return e[8]!==m||e[9]!==d||e[10]!==g?(x=s.jsxs("div",{className:u,children:[m,d,g]}),e[8]=m,e[9]=d,e[10]=g,e[11]=x):x=e[11],x},$m=t=>{const e=gt.c(117),{selectedModels:n,onAdd:r,onRemove:o,onUpdate:i,minModels:c,addButtonLabel:l,showChips:u,maxModels:m,addButtonClassName:d,dropdownSide:f,dropdownClassName:g,containerClassName:x,triggerIcon:p}=t,y=u===void 0?!0:u,b=f===void 0?"top":f,{t:h}=Tt(),N=cs(eS),w=cs(tS),S=Fe(sS),v=Fe(nS),{favoriteModelsList:j,recentModelsList:k}=xh(),[D,T]=a.useState(!1),[C,P]=a.useState(""),[E,M]=a.useState(null),H=a.useRef(null),R=a.useRef(null),_=m===1,z=m===void 0||n.length<m||_;let V;if(e[0]!==n){V=new Map;for(const A of n){const K=`${A.providerID}:${A.modelID}`;V.set(K,(V.get(K)||0)+1)}e[0]=n,e[1]=V}else V=e[1];const F=V;let te;e[2]!==n?(te=A=>n.filter(pe=>pe.providerID===A.providerID&&pe.modelID===A.modelID).findIndex(pe=>pe.instanceId===A.instanceId)+1,e[2]=n,e[3]=te):te=e[3];const Z=te;let ne,U;e[4]!==b||e[5]!==D?(ne=()=>{if(!D||!R.current)return;const A=R.current.getBoundingClientRect();if(b==="bottom"){const rt=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-A.bottom-16-112;M(Math.max(160,Math.min(320,rt)));return}let K=R.current.parentElement;for(;K&&!(K.getAttribute("role")==="dialog"||K.hasAttribute("data-scroll-shadow"));){const We=getComputedStyle(K);if(We.overflow==="auto"||We.overflow==="hidden"||We.overflowY==="auto"||We.overflowY==="hidden")break;K=K.parentElement}const pe=K?K.getBoundingClientRect().top:0,_e=A.top-pe-16;M(Math.max(150,Math.min(300,_e)))},U=[b,D],e[4]=b,e[5]=D,e[6]=ne,e[7]=U):(ne=e[6],U=e[7]),a.useEffect(ne,U);let ie,oe;e[8]!==z||e[9]!==D?(ie=()=>{!z&&D&&(T(!1),P(""))},oe=[z,D],e[8]=z,e[9]=D,e[10]=ie,e[11]=oe):(ie=e[10],oe=e[11]),a.useEffect(ie,oe);let ge,je;e[12]!==D?(ge=()=>{if(!D)return;const A=K=>{H.current&&!H.current.contains(K.target)&&(T(!1),P(""))};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},je=[D],e[12]=D,e[13]=ge,e[14]=je):(ge=e[13],je=e[14]),a.useEffect(ge,je);let Se;e[15]!==_||e[16]!==r||e[17]!==i||e[18]!==n.length?(Se=A=>{const K={providerID:A.providerID,modelID:A.modelID,displayName:A.model.name||A.modelID,instanceId:uo()};_&&n.length>0&&i?i(0,K):r(K),_&&(T(!1),P(""))},e[15]=_,e[16]=r,e[17]=i,e[18]=n.length,e[19]=Se):Se=e[19];const re=Se;let L;e[20]!==h?(L=h("multirun.modelMultiSelect.search.placeholder"),e[20]=h,e[21]=L):L=e[21];let $;e[22]!==h?($=h("multirun.modelMultiSelect.search.noResults"),e[22]=h,e[23]=$):$=e[23];let q;e[24]!==h?(q=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=q):q=e[25];let he;e[26]!==h?(he=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=he):he=e[27];let de;e[28]!==h?(de=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=de):de=e[29];let we;e[30]!==h?(we=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=we):we=e[31];let be;e[32]!==h?(be=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=be):be=e[33];let De;e[34]!==h?(De=h("chat.modelControls.capabilities"),e[34]=h,e[35]=De):De=e[35];let le;e[36]!==h?(le=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=le):le=e[37];let ke;e[38]!==h?(ke=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=ke):ke=e[39];let ue;e[40]!==h?(ue=h("chat.modelControls.input"),e[40]=h,e[41]=ue):ue=e[41];let ve;e[42]!==h?(ve=h("chat.modelControls.output"),e[42]=h,e[43]=ve):ve=e[43];let G;e[44]!==h?(G=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=G):G=e[45];let Ae;e[46]!==L||e[47]!==$||e[48]!==q||e[49]!==he||e[50]!==de||e[51]!==we||e[52]!==be||e[53]!==De||e[54]!==le||e[55]!==ke||e[56]!==ue||e[57]!==ve||e[58]!==G?(Ae={searchPlaceholder:L,noResults:$,favorites:q,recent:he,keyboardHint:de,favorite:we,unfavorite:be,capabilities:De,capabilityToolCalling:le,capabilityReasoning:ke,input:ue,output:ve,costPerMillion:G},e[46]=L,e[47]=$,e[48]=q,e[49]=he,e[50]=de,e[51]=we,e[52]=be,e[53]=De,e[54]=le,e[55]=ke,e[56]=ue,e[57]=ve,e[58]=G,e[59]=Ae):Ae=e[59];const ce=Ae;let fe;e[60]!==x?(fe=Te("relative",x),e[60]=x,e[61]=fe):fe=e[61];let Ee;e[62]!==d?(Ee=Te(Vm,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),e[62]=d,e[63]=Ee):Ee=e[63];const me=!z;let B;e[64]!==D?(B=()=>{T(!D)},e[64]=D,e[65]=B):B=e[65];let ye;e[66]!==p?(ye=p??s.jsx(I,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=p,e[67]=ye):ye=e[67];let Oe;e[68]!==l||e[69]!==h?(Oe=l??h("multirun.modelMultiSelect.actions.addModel"),e[68]=l,e[69]=h,e[70]=Oe):Oe=e[70];let Q;e[71]!==Ee||e[72]!==me||e[73]!==B||e[74]!==ye||e[75]!==Oe?(Q=s.jsxs(ze,{ref:R,type:"button",variant:"outline",size:"sm",className:Ee,disabled:me,onClick:B,children:[ye,Oe]}),e[71]=Ee,e[72]=me,e[73]=B,e[74]=ye,e[75]=Oe,e[76]=Q):Q=e[76];let Me;e[77]!==E||e[78]!==z||e[79]!==g||e[80]!==b||e[81]!==j||e[82]!==re||e[83]!==v||e[84]!==D||e[85]!==ce||e[86]!==F||e[87]!==w||e[88]!==N||e[89]!==k||e[90]!==C||e[91]!==S?(Me=D?s.jsx("div",{className:Te("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",b==="top"?"bottom-full mb-1":"top-full mt-1",g),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(bh,{providers:N,favoriteModels:j,recentModels:k,modelsMetadata:w,searchQuery:C,onSearchQueryChange:P,onSelect:re,labels:ce,selectionCount:A=>F.get(`${A.providerID}:${A.modelID}`)||0,disabled:!z,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:E?`${E}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:D,isFavorite:A=>v(A.providerID,A.modelID),onToggleFavorite:A=>S(A.providerID,A.modelID),onEscape:()=>{T(!1),P("")}})}):null,e[77]=E,e[78]=z,e[79]=g,e[80]=b,e[81]=j,e[82]=re,e[83]=v,e[84]=D,e[85]=ce,e[86]=F,e[87]=w,e[88]=N,e[89]=k,e[90]=C,e[91]=S,e[92]=Me):Me=e[92];let Re;e[93]!==fe||e[94]!==Q||e[95]!==Me?(Re=s.jsxs("div",{className:fe,ref:H,children:[Q,Me]}),e[93]=fe,e[94]=Q,e[95]=Me,e[96]=Re):Re=e[96];let Ne;e[97]!==Z||e[98]!==F||e[99]!==o||e[100]!==i||e[101]!==N||e[102]!==n||e[103]!==y||e[104]!==h?(Ne=y&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((A,K)=>{const pe=`${A.providerID}:${A.modelID}`,_e=F.get(pe)||1,We=Z(A),rt=N.find(Pe=>Pe.id===A.providerID)?.models?.find(Pe=>Pe.id===A.modelID),yt=rt?.variants?Object.keys(rt.variants):[],Dt=yt.length>0,st=A.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Zj,{model:A,instanceIndex:We,totalSameModel:_e,onRemove:()=>o(K)}),Dt&&s.jsxs(Bn,{value:st,onValueChange:Pe=>{if(!i)return;i(K,{...A,variant:Pe==="__default__"?void 0:Pe})},children:[s.jsxs(Vn,{size:"chip",className:"px-2 gap-1.5 rounded-md !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground",children:[s.jsx(I,{name:"brain-ai-3",className:Te("h-3.5 w-3.5 flex-shrink-0",st==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Pn,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:Pe=>Pe==="__default__"?h("multirun.modelMultiSelect.variant.default"):Pe})]}),s.jsxs($n,{fitContent:!0,children:[s.jsx(qs,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),yt.map(rS)]})]})]},A.instanceId)})}),e[97]=Z,e[98]=F,e[99]=o,e[100]=i,e[101]=N,e[102]=n,e[103]=y,e[104]=h,e[105]=Ne):Ne=e[105];let Be;e[106]!==Re||e[107]!==Ne?(Be=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Re,Ne]}),e[106]=Re,e[107]=Ne,e[108]=Be):Be=e[108];let se;e[109]!==m||e[110]!==c||e[111]!==n.length||e[112]!==h?(se=c!==void 0&&n.length<c&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:m!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:c,max:m}):h("multirun.modelMultiSelect.validation.minOnly",{min:c})}),e[109]=m,e[110]=c,e[111]=n.length,e[112]=h,e[113]=se):se=e[113];let O;return e[114]!==Be||e[115]!==se?(O=s.jsxs("div",{className:"space-y-2",children:[Be,se]}),e[114]=Be,e[115]=se,e[116]=O):O=e[116],O};function eS(t){return t.providers}function tS(t){return t.modelsMetadata}function sS(t){return t.toggleFavoriteModel}function nS(t){return t.isFavoriteModel}function rS(t){return s.jsx(qs,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const iS=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
198
+ `+u}return l}function zj(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}async function Wj(t,e){const n=await bh(e,t);if(n)return n;if(!Hi())return null;try{const r=await bo()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const o=typeof r.path=="string"?r.path.trim():"";return o.length>0?o:null}catch{return null}}async function Uj(t){const e=bo()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await yh(t)?!0:Xo(t)}function Hj(){return Gl()}function Gj(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",o=new Date().toISOString().split("T")[0];return`${r}-${o}.md`}const Kj=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const o of t){r.has(o)||(r.add(o),n.push(o));const i=e.get(o);if(i)for(const c of i)r.has(c)||(r.add(c),n.push(c))}return n},er=Ni()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,o)=>{const i=e(),c=new Set(i.selectedIds);let l=i.scopeKey,u=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(c.clear(),l=r,u=null):l===null&&r!==null&&(l=r);const d=o&&o.length>0?[n,...o]:[n];if(c.has(n)){for(const g of d)c.delete(g);u===n&&(u=null)}else{for(const g of d)c.add(g);u=n}c.size===0?t({selectedIds:c,scopeKey:null,anchorId:null}):t({selectedIds:c,scopeKey:l,anchorId:u})},setRange:(n,r,o,i,c)=>{const l=e();if(o.length===0)return;const u=n&&o.includes(n)?n:o[0],m=o.indexOf(u),d=o.indexOf(r);if(m<0||d<0)return;const[f,g]=m<=d?[m,d]:[d,m],x=o.slice(f,g+1),p=Kj(x,c),b=i!==null&&l.scopeKey!==null&&i!==l.scopeKey?new Set:new Set(l.selectedIds);for(const h of p)b.add(h);t({selectedIds:b,scopeKey:i??l.scopeKey,anchorId:u})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const o=new Set(r.selectedIds);for(const i of n)o.delete(i);o.size!==r.selectedIds.size&&(o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o}))}})),qj=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,$m=/^g[1-9]\d*$/,Zi=(t,e,n,r,o)=>{if(!qj.test(t)||e!==void 0&&!$m.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(o===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(o==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(o))return null;const i=Number.parseInt(o,10);return!Number.isSafeInteger(i)||i<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:i,fusion:!1}},Go=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return Zi(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,l,u,m]=e;return $m.test(l)?Zi(n,l,u,m,void 0):Zi(n,void 0,l,u,m)}const[,r,o,i,c]=e;return r===""?Zi(n,void 0,o,i,c):Zi(n,r,o,i,c)},Yj=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},Jj=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},zm=t=>{const e=pt.c(36),{value:n,onChange:r,className:o,disabled:i,id:c,portalToBody:l}=t,{t:u}=Tt(),m=ls(Qj),d=ls(Xj),f=ls(Zj);let g;e[0]!==m?(g=m(),e[0]=m,e[1]=g):g=e[1];const x=g;let p;e[2]!==x?(p=x.filter(eS),e[2]=x,e[3]=p):p=e[3];const y=p;let b,h;e[4]!==x.length||e[5]!==d?(b=()=>{x.length===0&&d()},h=[x.length,d],e[4]=x.length,e[5]=d,e[6]=b,e[7]=h):(b=e[6],h=e[7]),a.useEffect(b,h);let N,w;e[8]!==f||e[9]!==i||e[10]!==r||e[11]!==y||e[12]!==n?(N=()=>{if(i)return;const E=n.trim();if(E.length>0&&y.some(R=>R.name===E))return;const M=typeof f=="string"&&f.trim().length>0?f.trim():null;if(M&&y.some(R=>R.name===M)){r(M);return}const H=y[0]?.name;H&&r(H)},w=[f,i,r,y,n],e[8]=f,e[9]=i,e[10]=r,e[11]=y,e[12]=n,e[13]=N,e[14]=w):(N=e[13],w=e[14]),a.useEffect(N,w);const S=n.trim().length>0?n:void 0;let v;e[15]!==o?(v=Pe("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",o),e[15]=o,e[16]=v):v=e[16];let j;e[17]!==u?(j=u("multirun.agentSelector.placeholder"),e[17]=u,e[18]=j):j=e[18];let k;e[19]!==j?(k=s.jsx(En,{placeholder:j}),e[19]=j,e[20]=k):k=e[20];let A;e[21]!==c||e[22]!==v||e[23]!==k?(A=s.jsx(Wn,{id:c,size:"lg",className:v,children:k}),e[21]=c,e[22]=v,e[23]=k,e[24]=A):A=e[24];let T;e[25]!==y?(T=y.length>0&&s.jsx(ml,{children:y.map(tS)}),e[25]=y,e[26]=T):T=e[26];let C;e[27]!==l||e[28]!==T?(C=s.jsx(Un,{fitContent:!0,portalToBody:l,children:T}),e[27]=l,e[28]=T,e[29]=C):C=e[29];let P;return e[30]!==i||e[31]!==r||e[32]!==S||e[33]!==A||e[34]!==C?(P=s.jsxs(zn,{value:S,onValueChange:r,disabled:i,children:[A,C]}),e[30]=i,e[31]=r,e[32]=S,e[33]=A,e[34]=C,e[35]=P):P=e[35],P};function Qj(t){return t.getVisibleAgents}function Xj(t){return t.loadAgents}function Zj(t){return t.currentAgentName}function eS(t){return t.mode!=="subagent"}function tS(t){return s.jsx(qs,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Wm="h-7",co=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,sS=t=>{const e=pt.c(12),{model:n,instanceIndex:r,totalSameModel:o,onRemove:i}=t,c=n.displayName||`${n.providerID}/${n.modelID}`,l=o>1?`${c} (${r})`:c;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Pe("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Wm),e[0]=u):u=e[0];let m;e[1]!==n.providerID?(m=s.jsx(mo,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=m):m=e[2];let d;e[3]!==l?(d=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:l}),e[3]=l,e[4]=d):d=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(I,{name:"close",className:"h-3.5 w-3.5"}),e[5]=f):f=e[5];let g;e[6]!==i?(g=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=i,e[7]=g):g=e[7];let x;return e[8]!==m||e[9]!==d||e[10]!==g?(x=s.jsxs("div",{className:u,children:[m,d,g]}),e[8]=m,e[9]=d,e[10]=g,e[11]=x):x=e[11],x},Um=t=>{const e=pt.c(117),{selectedModels:n,onAdd:r,onRemove:o,onUpdate:i,minModels:c,addButtonLabel:l,showChips:u,maxModels:m,addButtonClassName:d,dropdownSide:f,dropdownClassName:g,containerClassName:x,triggerIcon:p}=t,y=u===void 0?!0:u,b=f===void 0?"top":f,{t:h}=Tt(),N=ls(nS),w=ls(rS),S=Fe(iS),v=Fe(oS),{favoriteModelsList:j,recentModelsList:k}=wh(),[A,T]=a.useState(!1),[C,P]=a.useState(""),[E,M]=a.useState(null),H=a.useRef(null),R=a.useRef(null),_=m===1,z=m===void 0||n.length<m||_;let V;if(e[0]!==n){V=new Map;for(const D of n){const Y=`${D.providerID}:${D.modelID}`;V.set(Y,(V.get(Y)||0)+1)}e[0]=n,e[1]=V}else V=e[1];const F=V;let te;e[2]!==n?(te=D=>n.filter(be=>be.providerID===D.providerID&&be.modelID===D.modelID).findIndex(be=>be.instanceId===D.instanceId)+1,e[2]=n,e[3]=te):te=e[3];const Z=te;let ne,U;e[4]!==b||e[5]!==A?(ne=()=>{if(!A||!R.current)return;const D=R.current.getBoundingClientRect();if(b==="bottom"){const ot=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-D.bottom-16-112;M(Math.max(160,Math.min(320,ot)));return}let Y=R.current.parentElement;for(;Y&&!(Y.getAttribute("role")==="dialog"||Y.hasAttribute("data-scroll-shadow"));){const $e=getComputedStyle(Y);if($e.overflow==="auto"||$e.overflow==="hidden"||$e.overflowY==="auto"||$e.overflowY==="hidden")break;Y=Y.parentElement}const be=Y?Y.getBoundingClientRect().top:0,Oe=D.top-be-16;M(Math.max(150,Math.min(300,Oe)))},U=[b,A],e[4]=b,e[5]=A,e[6]=ne,e[7]=U):(ne=e[6],U=e[7]),a.useEffect(ne,U);let ie,oe;e[8]!==z||e[9]!==A?(ie=()=>{!z&&A&&(T(!1),P(""))},oe=[z,A],e[8]=z,e[9]=A,e[10]=ie,e[11]=oe):(ie=e[10],oe=e[11]),a.useEffect(ie,oe);let pe,je;e[12]!==A?(pe=()=>{if(!A)return;const D=Y=>{H.current&&!H.current.contains(Y.target)&&(T(!1),P(""))};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},je=[A],e[12]=A,e[13]=pe,e[14]=je):(pe=e[13],je=e[14]),a.useEffect(pe,je);let Se;e[15]!==_||e[16]!==r||e[17]!==i||e[18]!==n.length?(Se=D=>{const Y={providerID:D.providerID,modelID:D.modelID,displayName:D.model.name||D.modelID,instanceId:co()};_&&n.length>0&&i?i(0,Y):r(Y),_&&(T(!1),P(""))},e[15]=_,e[16]=r,e[17]=i,e[18]=n.length,e[19]=Se):Se=e[19];const re=Se;let L;e[20]!==h?(L=h("multirun.modelMultiSelect.search.placeholder"),e[20]=h,e[21]=L):L=e[21];let $;e[22]!==h?($=h("multirun.modelMultiSelect.search.noResults"),e[22]=h,e[23]=$):$=e[23];let K;e[24]!==h?(K=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=K):K=e[25];let he;e[26]!==h?(he=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=he):he=e[27];let de;e[28]!==h?(de=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=de):de=e[29];let we;e[30]!==h?(we=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=we):we=e[31];let xe;e[32]!==h?(xe=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=xe):xe=e[33];let De;e[34]!==h?(De=h("chat.modelControls.capabilities"),e[34]=h,e[35]=De):De=e[35];let le;e[36]!==h?(le=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=le):le=e[37];let Ce;e[38]!==h?(Ce=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=Ce):Ce=e[39];let ue;e[40]!==h?(ue=h("chat.modelControls.input"),e[40]=h,e[41]=ue):ue=e[41];let ve;e[42]!==h?(ve=h("chat.modelControls.output"),e[42]=h,e[43]=ve):ve=e[43];let G;e[44]!==h?(G=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=G):G=e[45];let Ae;e[46]!==L||e[47]!==$||e[48]!==K||e[49]!==he||e[50]!==de||e[51]!==we||e[52]!==xe||e[53]!==De||e[54]!==le||e[55]!==Ce||e[56]!==ue||e[57]!==ve||e[58]!==G?(Ae={searchPlaceholder:L,noResults:$,favorites:K,recent:he,keyboardHint:de,favorite:we,unfavorite:xe,capabilities:De,capabilityToolCalling:le,capabilityReasoning:Ce,input:ue,output:ve,costPerMillion:G},e[46]=L,e[47]=$,e[48]=K,e[49]=he,e[50]=de,e[51]=we,e[52]=xe,e[53]=De,e[54]=le,e[55]=Ce,e[56]=ue,e[57]=ve,e[58]=G,e[59]=Ae):Ae=e[59];const ce=Ae;let fe;e[60]!==x?(fe=Pe("relative",x),e[60]=x,e[61]=fe):fe=e[61];let Te;e[62]!==d?(Te=Pe(Wm,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),e[62]=d,e[63]=Te):Te=e[63];const me=!z;let B;e[64]!==A?(B=()=>{T(!A)},e[64]=A,e[65]=B):B=e[65];let ye;e[66]!==p?(ye=p??s.jsx(I,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=p,e[67]=ye):ye=e[67];let _e;e[68]!==l||e[69]!==h?(_e=l??h("multirun.modelMultiSelect.actions.addModel"),e[68]=l,e[69]=h,e[70]=_e):_e=e[70];let J;e[71]!==Te||e[72]!==me||e[73]!==B||e[74]!==ye||e[75]!==_e?(J=s.jsxs(ze,{ref:R,type:"button",variant:"outline",size:"sm",className:Te,disabled:me,onClick:B,children:[ye,_e]}),e[71]=Te,e[72]=me,e[73]=B,e[74]=ye,e[75]=_e,e[76]=J):J=e[76];let Me;e[77]!==E||e[78]!==z||e[79]!==g||e[80]!==b||e[81]!==j||e[82]!==re||e[83]!==v||e[84]!==A||e[85]!==ce||e[86]!==F||e[87]!==w||e[88]!==N||e[89]!==k||e[90]!==C||e[91]!==S?(Me=A?s.jsx("div",{className:Pe("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",b==="top"?"bottom-full mb-1":"top-full mt-1",g),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(vh,{providers:N,favoriteModels:j,recentModels:k,modelsMetadata:w,searchQuery:C,onSearchQueryChange:P,onSelect:re,labels:ce,selectionCount:D=>F.get(`${D.providerID}:${D.modelID}`)||0,disabled:!z,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:E?`${E}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:A,isFavorite:D=>v(D.providerID,D.modelID),onToggleFavorite:D=>S(D.providerID,D.modelID),onEscape:()=>{T(!1),P("")}})}):null,e[77]=E,e[78]=z,e[79]=g,e[80]=b,e[81]=j,e[82]=re,e[83]=v,e[84]=A,e[85]=ce,e[86]=F,e[87]=w,e[88]=N,e[89]=k,e[90]=C,e[91]=S,e[92]=Me):Me=e[92];let Ee;e[93]!==fe||e[94]!==J||e[95]!==Me?(Ee=s.jsxs("div",{className:fe,ref:H,children:[J,Me]}),e[93]=fe,e[94]=J,e[95]=Me,e[96]=Ee):Ee=e[96];let Ne;e[97]!==Z||e[98]!==F||e[99]!==o||e[100]!==i||e[101]!==N||e[102]!==n||e[103]!==y||e[104]!==h?(Ne=y&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((D,Y)=>{const be=`${D.providerID}:${D.modelID}`,Oe=F.get(be)||1,$e=Z(D),ot=N.find(Le=>Le.id===D.providerID)?.models?.find(Le=>Le.id===D.modelID),yt=ot?.variants?Object.keys(ot.variants):[],At=yt.length>0,mt=D.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(sS,{model:D,instanceIndex:$e,totalSameModel:Oe,onRemove:()=>o(Y)}),At&&s.jsxs(zn,{value:mt,onValueChange:Le=>{if(!i)return;i(Y,{...D,variant:Le==="__default__"?void 0:Le})},children:[s.jsxs(Wn,{size:"chip",className:"px-2 gap-1.5 rounded-md !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground",children:[s.jsx(I,{name:"brain-ai-3",className:Pe("h-3.5 w-3.5 flex-shrink-0",mt==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(En,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:Le=>Le==="__default__"?h("multirun.modelMultiSelect.variant.default"):Le})]}),s.jsxs(Un,{fitContent:!0,children:[s.jsx(qs,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),yt.map(aS)]})]})]},D.instanceId)})}),e[97]=Z,e[98]=F,e[99]=o,e[100]=i,e[101]=N,e[102]=n,e[103]=y,e[104]=h,e[105]=Ne):Ne=e[105];let Be;e[106]!==Ee||e[107]!==Ne?(Be=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Ee,Ne]}),e[106]=Ee,e[107]=Ne,e[108]=Be):Be=e[108];let se;e[109]!==m||e[110]!==c||e[111]!==n.length||e[112]!==h?(se=c!==void 0&&n.length<c&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:m!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:c,max:m}):h("multirun.modelMultiSelect.validation.minOnly",{min:c})}),e[109]=m,e[110]=c,e[111]=n.length,e[112]=h,e[113]=se):se=e[113];let O;return e[114]!==Be||e[115]!==se?(O=s.jsxs("div",{className:"space-y-2",children:[Be,se]}),e[114]=Be,e[115]=se,e[116]=O):O=e[116],O};function nS(t){return t.providers}function rS(t){return t.modelsMetadata}function iS(t){return t.toggleFavoriteModel}function oS(t){return t.isFavoriteModel}function aS(t){return s.jsx(qs,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const lS=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
199
199
 
200
200
  --- RESULT ${n+1}: ${r} ---
201
201
  ${e.trim()}
202
- --- END RESULT ${n+1} ---`},Yd=(t,e)=>vt.getState().getWorktreeMetadata(t)?.projectDirectory??e,oS=async t=>{const e=t.directory??void 0,n=yh(t.session.id,e);if(n.length===0&&t.directory){const o=(await zn.withDirectory(t.directory,()=>zn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=o.length-1;i>=0;i-=1){const c=o[i];if(c.info?.role==="assistant")return Nc(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return Nc(wh(o.id,e)).trim()}return""};function aS({session:t,open:e,onOpenChange:n}){const{t:r}=Tt(),o=Ll(),i=Xr(V=>V.activeSessions),c=Xr(V=>V.archivedSessions),l=cs(V=>V.providers),u=cs(V=>V.currentProviderId),m=cs(V=>V.currentModelId),d=cs(V=>V.currentAgentName),[f,g]=a.useState(u??""),[x,p]=a.useState(m??""),[y,b]=a.useState(()=>u&&m?[{providerID:u,modelID:m,instanceId:uo()}]:[]),[h,N]=a.useState(""),[w,S]=a.useState(d??""),[v,j]=a.useState([]),[k,D]=a.useState(!1),T=a.useMemo(()=>Go(t.title),[t.title]),C=a.useMemo(()=>{const V=new Map;for(const F of o)V.set(F.id,F);for(const F of i)V.set(F.id,F);for(const F of c)V.set(F.id,F);return t.id&&V.set(t.id,t),Array.from(V.values())},[i,c,o,t]);a.useEffect(()=>{if(!e||!T)return;const V=vt.getState().getDirectoryForSession(t.id),F=Yd(t.id,V),te=C.map(Z=>{const ne=Go(Z.title);if(!ne||ne.groupSlug!==T.groupSlug||ne.fusion||(ne.runGroup??null)!==(T.runGroup??null))return null;const U=vt.getState().getDirectoryForSession(Z.id)??hi(Z),ie=Yd(Z.id,U);return F&&ie&&F!==ie?null:{session:Z,directory:U,projectDirectory:ie}}).filter(Z=>Z!==null).sort((Z,ne)=>(Z.session.time?.created??0)-(ne.session.time?.created??0));j(te)},[C,e,T,t.id]);const E=l.find(V=>V.id===f)?.models.find(V=>V.id===x),M=E?.variants?Object.keys(E.variants):[],H=!!(T&&f&&x&&v.length>0&&!k),R=a.useCallback(V=>{b([V]),g(V.providerID),p(V.modelID),N("")},[]),_=y[0]?.displayName||y[0]?.modelID||r("multirun.fusion.model.placeholder"),z=async()=>{if(!(!T||!f||!x)){D(!0);try{const V=await Promise.all(v.map(oe=>oS(oe))),F=v.map((oe,ge)=>({source:oe,text:V[ge]??""})).filter(oe=>oe.text.trim().length>0);if(F.length===0){ae.error(r("multirun.fusion.toast.noOutputs"));return}const te=v[0]?.projectDirectory??v[0]?.directory??null,Z=Kj(T.groupSlug,f,x,T.runGroup),[ne,U]=await Promise.all([In("session.fusion.visible"),In("session.fusion.instructions")]),ie=await vt.getState().createSession(Z,te,null);if(!ie)throw new Error("Failed to create fusion session");vt.getState().setCurrentSession(ie.id,te),n(!1),await zn.sendMessage({id:ie.id,providerID:f,modelID:x,variant:h||void 0,agent:w||void 0,text:ne,additionalParts:[{text:U,synthetic:!0},...F.map((oe,ge)=>({text:iS(oe.source,oe.text,ge),synthetic:!0})),{text:`
202
+ --- END RESULT ${n+1} ---`},Xd=(t,e)=>jt.getState().getWorktreeMetadata(t)?.projectDirectory??e,cS=async t=>{const e=t.directory??void 0,n=jh(t.session.id,e);if(n.length===0&&t.directory){const o=(await Hn.withDirectory(t.directory,()=>Hn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=o.length-1;i>=0;i-=1){const c=o[i];if(c.info?.role==="assistant")return Ac(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return Ac(Sh(o.id,e)).trim()}return""};function dS({session:t,open:e,onOpenChange:n}){const{t:r}=Tt(),o=Ol(),i=Zr(V=>V.activeSessions),c=Zr(V=>V.archivedSessions),l=ls(V=>V.providers),u=ls(V=>V.currentProviderId),m=ls(V=>V.currentModelId),d=ls(V=>V.currentAgentName),[f,g]=a.useState(u??""),[x,p]=a.useState(m??""),[y,b]=a.useState(()=>u&&m?[{providerID:u,modelID:m,instanceId:co()}]:[]),[h,N]=a.useState(""),[w,S]=a.useState(d??""),[v,j]=a.useState([]),[k,A]=a.useState(!1),T=a.useMemo(()=>Go(t.title),[t.title]),C=a.useMemo(()=>{const V=new Map;for(const F of o)V.set(F.id,F);for(const F of i)V.set(F.id,F);for(const F of c)V.set(F.id,F);return t.id&&V.set(t.id,t),Array.from(V.values())},[i,c,o,t]);a.useEffect(()=>{if(!e||!T)return;const V=jt.getState().getDirectoryForSession(t.id),F=Xd(t.id,V),te=C.map(Z=>{const ne=Go(Z.title);if(!ne||ne.groupSlug!==T.groupSlug||ne.fusion||(ne.runGroup??null)!==(T.runGroup??null))return null;const U=jt.getState().getDirectoryForSession(Z.id)??xi(Z),ie=Xd(Z.id,U);return F&&ie&&F!==ie?null:{session:Z,directory:U,projectDirectory:ie}}).filter(Z=>Z!==null).sort((Z,ne)=>(Z.session.time?.created??0)-(ne.session.time?.created??0));j(te)},[C,e,T,t.id]);const E=l.find(V=>V.id===f)?.models.find(V=>V.id===x),M=E?.variants?Object.keys(E.variants):[],H=!!(T&&f&&x&&v.length>0&&!k),R=a.useCallback(V=>{b([V]),g(V.providerID),p(V.modelID),N("")},[]),_=y[0]?.displayName||y[0]?.modelID||r("multirun.fusion.model.placeholder"),z=async()=>{if(!(!T||!f||!x)){A(!0);try{const V=await Promise.all(v.map(oe=>cS(oe))),F=v.map((oe,pe)=>({source:oe,text:V[pe]??""})).filter(oe=>oe.text.trim().length>0);if(F.length===0){ae.error(r("multirun.fusion.toast.noOutputs"));return}const te=v[0]?.projectDirectory??v[0]?.directory??null,Z=Jj(T.groupSlug,f,x,T.runGroup),[ne,U]=await Promise.all([Tn("session.fusion.visible"),Tn("session.fusion.instructions")]),ie=await jt.getState().createSession(Z,te,null);if(!ie)throw new Error("Failed to create fusion session");jt.getState().setCurrentSession(ie.id,te),n(!1),await Hn.sendMessage({id:ie.id,providerID:f,modelID:x,variant:h||void 0,agent:w||void 0,text:ne,additionalParts:[{text:U,synthetic:!0},...F.map((oe,pe)=>({text:lS(oe.source,oe.text,pe),synthetic:!0})),{text:`
203
203
 
204
204
  --- FUSION INPUTS END ---
205
- Now write the final fused answer.`,synthetic:!0}],directory:te??zn.getDirectory()})}catch(V){console.error("[MultiRunFusion] Failed to start fusion",V),ae.error(r("multirun.fusion.toast.failed"))}finally{D(!1)}}};return s.jsx(Ks,{open:e,onOpenChange:n,children:s.jsxs(Gs,{className:"max-w-xl overflow-visible",children:[s.jsxs(Xs,{children:[s.jsx(Ys,{children:r("multirun.fusion.title")}),s.jsx(cn,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx($m,{selectedModels:y,onAdd:R,onUpdate:(V,F)=>R(F),onRemove:()=>{b([]),g(""),p(""),N("")},maxModels:1,addButtonLabel:_,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:f?s.jsx(fo,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(Bn,{value:h||"__default__",onValueChange:V=>N(V==="__default__"?"":V),children:[s.jsxs(Vn,{size:"lg",className:"h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5",children:[s.jsx(I,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Pn,{children:V=>V==="__default__"?r("multirun.modelMultiSelect.variant.default"):V})]}),s.jsxs($n,{fitContent:!0,portalToBody:!0,children:[s.jsx(qs,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map(V=>s.jsx(qs,{value:V,children:V},V))]})]}):null,s.jsx(Bm,{value:w,onChange:S,portalToBody:!0,className:"h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:v.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:v.map(V=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(fo,{providerId:Go(V.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.session.title||V.session.id}),s.jsx("button",{type:"button",onClick:()=>j(F=>F.filter(te=>te.session.id!==V.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},V.session.id))})]}),s.jsxs(tr,{children:[s.jsx(ze,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(ze,{onClick:z,disabled:!H,children:r(k?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function lS(t){const e=gt.c(7);let n,r,o,i,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),o=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),c=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=o,e[3]=i,e[4]=c):(n=e[0],r=e[1],o=e[2],i=e[3],c=e[4]);let l;return e[5]!==t?(l=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,o,i,c]}),e[5]=t,e[6]=l):l=e[6],l}const Jd=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),ci=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(ci(n,e))return!0;return!1},Il=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const i of t.children)if(Il(i,e,n,r))return!0;return!1},cS=(t,e)=>{const n=t.node.session,r=e.node.session,o=n.id,i=r.id;if(o!==i||t.node.session!==e.node.session||Jd(t.node)!==Jd(e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket)return!1;if(t.currentSessionId!==e.currentSessionId){const d=ci(t.node,t.currentSessionId),f=ci(e.node,e.currentSessionId);if(d||f)return!1}if(t.pinnedSessionIds.has(o)!==e.pinnedSessionIds.has(i))return!1;{const d=t.renderContext??"project",f=e.renderContext??"project",g=t.archivedBucket??!1,x=e.archivedBucket??!1,p=`${d}:${g?"archived":"active"}:${o}`,y=`${f}:${x?"archived":"active"}:${i}`;if(t.expandedParents.has(p)!==e.expandedParents.has(y))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const d=ci(t.node,t.editingId),f=ci(e.node,e.editingId);if(d||f)return!1}if(t.editTitle!==e.editTitle){const d=ci(t.node,t.editingId),f=ci(e.node,e.editingId);if(d||f)return!1}if(t.copiedSessionId===o!=(e.copiedSessionId===i))return!1;const c=Il(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),l=Il(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(c!==l)return!1;const u=as(n.directory??null)??as(t.groupDirectory??null),m=as(r.directory??null)??as(e.groupDirectory??null);return!(u!==m||(u?t.directoryStatus.get(u):null)!==(m?e.directoryStatus.get(m):null)||(t.secondaryMeta?.projectLabel??null)!==(e.secondaryMeta?.projectLabel??null)||(t.secondaryMeta?.branchLabel??null)!==(e.secondaryMeta?.branchLabel??null)||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||(t.renderContext??"project")!==(e.renderContext??"project")||t.renamingFolderId!==e.renamingFolderId)};function dS(t){const{t:e}=Tt(),{node:n,depth:r=0,groupDirectory:o,projectId:i,archivedBucket:c=!1,directoryStatus:l,currentSessionId:u,pinnedSessionIds:m,expandedParents:d,hasSessionSearchQuery:f,normalizedSessionSearchQuery:g,notifyOnSubtasks:x,editingId:p,setEditingId:y,editTitle:b,setEditTitle:h,handleSaveEdit:N,handleCancelEdit:w,toggleParent:S,handleSessionSelect:v,handleSessionDoubleClick:j,togglePinnedSession:k,handleShareSession:D,copiedSessionId:T,handleCopyShareUrl:C,handleUnshareSession:P,openSidebarMenuKey:E,setOpenSidebarMenuKey:M,renamingFolderId:H,getFoldersForScope:R,getSessionFolderId:_,removeSessionFromFolder:z,addSessionToFolder:V,createFolderAndStartRename:F,openContextPanelTab:te,handleDeleteSession:Z,mobileVariant:ne,alwaysShowActions:U,renderSessionNode:ie,secondaryMeta:oe,renderContext:ge="project"}=t,je=!!oe?.projectLabel,Se=!!oe?.branchLabel,L=Ar(W=>W.displayMode)==="minimal",$=a.useMemo(()=>Gi(),[]),q=a.useMemo(()=>Ol(),[]),he=a.useContext(vh),de=$?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",we=$?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",be=$,De=!c&&!ne,le=L?$?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":$?De&&be?"group-hover:pr-18":De||be?"group-hover:pr-12":"group-hover:pr-5":De?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",ke=De?"pr-13":"pr-7",ue=a.useRef(!1),[ve,G]=a.useState(!1),Ae=a.useRef(p);Ae.current=p;const ce=a.useRef(null),fe=a.useRef(N);fe.current=N;const Ee=a.useRef(null),me=n.session,ye=yu(me.id)??me,Oe=as(me.directory??null)??as(o??null),Q=jh(Oe??void 0),Me=Ql(),Re=Zn(W=>W.enabled),Ne=Zn(a.useCallback(W=>W.selectedIds.has(me.id),[me.id])),Be=Zn(W=>W.toggleSelected),se=Zn(W=>W.setRange),O=a.useCallback(W=>{const qe=[],Qe=ht=>{ht.children.forEach(Ct=>{qe.push(Ct.session.id),Qe(Ct)})};return Qe(W),qe},[]),[A,K]=a.useState(!1),[pe,_e]=a.useState(!0),We=`${ge}:${c?"archived":"active"}:${me.id}`,Le=Vu(a.useCallback(W=>!!W.sessionMemoryState.get(Sh(me.id))?.isZombie,[me.id])),rt=Nh(me.id),yt=kh(me.id,Oe??void 0),st=(Oe?l.get(Oe):null)==="missing",Pe=u===me.id,tt=ye.title||e("sessions.sidebar.session.untitled"),Ye=n.children.length>0,nt=m.has(me.id),ft=We,mt=f?!0:d.has(ft),ot=!!ye.parentID,dt=Ch(me.id)>0&&(!ot||x),bt=ye.summary,He=ju(bt),Ze=ye.time?.updated||ye.time?.created||Date.now(),Ue=Ah(Ze),jt=Th(Ze),Ge=E===We,it=a.useMemo(()=>Go(ye.title)!==null,[ye.title]),[Et,lt]=a.useState(!1),ct=a.useMemo(()=>O(n).length,[O,n]),Bt=a.useCallback(async W=>{const qe=[];let Qe=0;for(const ht of W)try{await Me.ensureSessionRenderable(ht.session.id);const Ct=kc(Q.getState(),ht.session.id).list,ut=ht.session.title||e("sessions.sidebar.session.export.untitledSubagent"),ts=ht.session.agent,js=await Bt(ht.children);Qe+=js.skipped,qe.push({title:ut,agent:ts,records:Ct,children:js.children})}catch{Qe+=O(ht).length+1}return{children:qe,skipped:Qe}},[O,Q,Me,e]),Ft=a.useCallback(W=>{W<=0||ae.warning(W===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:W}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:W}))},[e]),qt=a.useCallback(async W=>{if(!Oe){ae.error(e("sessions.sidebar.session.export.nothingToExport"));return}await Me.ensureSessionRenderable(me.id);const qe=kc(Q.getState(),me.id).list;if(qe.length===0){ae.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Qe,ht=0;if(W&&n.children.length>0){const js=await Bt(n.children);Qe=js.children,ht=js.skipped}const Ct=_j(qe,ye.title??null,Qe),ut=Wj(ye.title??null),ts=await Vj(Ct,ut);if(ts){ae.success(e("sessions.sidebar.session.export.success"),{action:{label:e(zj()),onClick:()=>{$j(ts).then(js=>{js||ae.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Ft(ht);return}Bj(Ct,ut),ae.success(e("sessions.sidebar.session.export.success")),Ft(ht)},[Bt,Q,n.children,ye.title,me.id,Oe,Ft,Me,e]),Ut=a.useCallback(async()=>{if(n.children.length>0){_e(!0),K(!0);return}await qt(!1)},[qt,n.children.length]),At=a.useCallback(()=>{Oe&&ui("desktop_open_session_mini_chat_window",{sessionId:me.id,directory:Oe,apiBaseUrl:Qr(),clientToken:al()}).catch(W=>{console.warn("[session-sidebar] failed to open mini chat window",W)})},[me.id,Oe]);if(a.useEffect(()=>{if(p!==me.id)return;const W=qe=>{Ee.current&&!Ee.current.contains(qe.target)&&fe.current()};return document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[p,me.id]),p===me.id)return s.jsx("div",{className:Te("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{ref:Ee,className:"flex w-full items-center gap-2",onSubmit:W=>{W.preventDefault(),N()},children:[s.jsx("input",{value:b,onChange:W=>h(W.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:W=>{if(W.key==="Escape"){W.stopPropagation(),w();return}(W.key===" "||W.key==="Enter")&&W.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:w,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"size-4"})})]}),L?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[Ye?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:mt?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:Ue}),He?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",He.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",He.deletions]})]}):null,je?s.jsx("span",{className:"truncate",children:oe?.projectLabel}):null,Se?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:oe?.branchLabel})]}):null]})})]})},me.id);const Xt=rt?.type??"idle",ls=Xt==="busy"||Xt==="retry",es=yt.length,pt=ls||!ls&&dt&&!Pe,Yt=ls?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-busy-pulse","aria-label":e("sessions.sidebar.session.status.active"),title:e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),us=pt||nt?s.jsxs("span",{className:Te("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",L?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",pt&&nt?"left-[-18px] w-6":"left-[-10px] w-3.5",Ye&&!U?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[pt?Yt:null,nt?s.jsx(I,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,Jt=Ye?s.jsx("span",{role:"button",tabIndex:0,onClick:W=>{W.stopPropagation(),S(ft)},onKeyDown:W=>{(W.key==="Enter"||W.key===" ")&&(W.preventDefault(),W.stopPropagation(),S(ft))},className:Te("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",L?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",L&&pt&&!U?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(mt?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:mt?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,ss=Le?s.jsx(I,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,hs=W=>{M(W?We:null)},Wt=W=>{if(!W&&ce.current){const{id:qe,title:Qe}=ce.current;ce.current=null,y(qe),h(Qe)}},gs=W=>{W.preventDefault(),W.stopPropagation(),M(Ge?null:We)},Ms=W=>{W.preventDefault(),W.stopPropagation()},Vt=W=>{W.preventDefault(),W.stopPropagation()},vs=W=>{W.preventDefault(),W.stopPropagation()},Ps=W=>{W.preventDefault(),W.stopPropagation()},Ns=W=>{W.preventDefault(),W.stopPropagation(),M(null),Z(me,{archivedBucket:c})},As=W=>{W.preventDefault(),W.stopPropagation()},Rt=W=>{W.preventDefault(),W.stopPropagation()},xt=W=>{W.preventDefault(),W.stopPropagation(),he?.vscode?.executeCommand("openchamber.openSessionInEditor",me.id,tt)},Kt=W=>{if(ue.current){ue.current=!1;return}if(Re){if(W?.preventDefault(),W?.stopPropagation(),W?.shiftKey){const Qe=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(ut=>ut.getAttribute("data-session-row")).filter(ut=>typeof ut=="string"&&ut.length>0),ht=Zn.getState().anchorId,Ct=new Map;Ct.set(me.id,O(n)),se(ht,me.id,Qe,Oe??null,Ct);return}Be(me.id,Oe??null,O(n));return}v(me.id,Oe,st,i)},Ht=W=>{(W.button===2||W.button===0&&W.ctrlKey&&!Re)&&(ue.current=!0)},ns=W=>{ne&&W.pointerType==="touch"&&G(!0)},rs=W=>{ne&&W.pointerType==="touch"&&G(!1)},ds=s.jsxs(rn,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(H||Ae.current),children:[s.jsxs(zt,{onClick:()=>{ce.current={id:me.id,title:tt}},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:()=>k(me.id),className:"[&>svg]:mr-1",children:[nt?s.jsx(I,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(I,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(nt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),ye.share?s.jsxs(s.Fragment,{children:[s.jsx(zt,{onClick:()=>{ye.share?.url&&C(ye.share.url,me.id)},className:"[&>svg]:mr-1",children:T===me.id?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(zt,{onClick:()=>P(me.id),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(zt,{onClick:()=>D(ye),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(zt,{onClick:()=>{Ut()},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),it?s.jsxs(zt,{onClick:()=>lt(!0),className:"[&>svg]:mr-1",children:[s.jsx(lS,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Oe&&!c?(()=>{const W=R(Oe),qe=_(Oe,me.id);return s.jsxs(s.Fragment,{children:[s.jsx(Mn,{}),s.jsxs(Dh,{children:[s.jsxs(Ih,{className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ph,{className:"min-w-[180px]",children:[W.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):W.map(Qe=>s.jsxs(zt,{onClick:()=>{qe===Qe.id?z(Oe,me.id):V(Oe,Qe.id,me.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Qe.name}),qe===Qe.id?s.jsx(I,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Qe.id)),s.jsx(Mn,{}),s.jsxs(zt,{onClick:()=>{const Qe=F(Oe);Qe&&V(Oe,Qe.id,me.id)},children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),qe?s.jsxs(zt,{onClick:()=>{z(Oe,me.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,$?null:s.jsxs(zt,{disabled:!Oe,onClick:()=>{Oe&&te(Oe,{mode:"chat",dedupeKey:`session:${me.id}`,label:tt})},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),q?s.jsxs(zt,{disabled:!Oe,onClick:At,className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Mn,{}),s.jsxs(zt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>Z(me,{archivedBucket:c}),children:[s.jsx(I,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(c?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(a.Fragment,{children:[s.jsx(sj,{sessionId:me.id,sessionDirectory:Oe??null,sessionTitle:tt,children:s.jsxs("div",{"data-session-row":me.id,"data-session-scope":Oe??"","data-session-archived":c?"1":"0",className:Te("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",st?"opacity-75":"",r>0&&"pl-[20px]",Ne&&"bg-primary/15"),children:[us,Jt,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:L?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",disabled:st,onPointerDown:ns,onPointerUp:rs,onPointerCancel:rs,onMouseDown:Ht,onClick:W=>Kt(W),onDoubleClick:W=>{W.stopPropagation(),j(me.id,tt)},className:Te("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ve&&"bg-interactive-hover/70",U?$?le:ke:le),children:s.jsxs("div",{className:Te("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:Te("block min-w-0 flex-1 truncate typography-ui-label font-normal",Pe?"text-primary":"text-foreground"),children:io(tt,g)}),U?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:jt}):null,U?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:Te("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",Ge?"opacity-0":we),children:jt})}),es>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:es})]}):null]})})}),s.jsx(_t,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:Te("flex items-center gap-3 text-left text-muted-foreground",oe?.projectLabel?"justify-between":"justify-start"),children:[oe?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:oe.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:Ue})]}),oe?.branchLabel||He?s.jsxs("div",{className:Te("flex items-center gap-3 text-left text-muted-foreground",oe?.branchLabel?"justify-between":"justify-start"),children:[oe?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:oe.branchLabel})]})}):null,He?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",He.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",He.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:st,onPointerDown:ns,onPointerUp:rs,onPointerCancel:rs,onMouseDown:Ht,onClick:W=>Kt(W),onDoubleClick:W=>{W.stopPropagation(),j(me.id,tt)},className:Te("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ve&&"bg-interactive-hover/70",U?$?le:ke:le),children:[s.jsxs("div",{className:Te("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:Te("block min-w-0 flex-1 truncate typography-ui-label font-normal",Pe?"text-primary":"text-foreground"),children:io(tt,g)}),es>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:es})]}):null]}),L?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:Ue}),He?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",He.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",He.deletions]})]}):null,je?s.jsx("span",{className:"truncate",children:oe?.projectLabel}):null,Se?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:oe?.branchLabel})]}):null]})})]})}),ss&&!ne?s.jsx("div",{className:Te("absolute top-1/2 -translate-y-1/2 z-10",L?"right-0":"right-[30px]"),children:ss}):null,s.jsxs("div",{className:Te("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Ge||U&&!$?"opacity-100":Te("opacity-0",de)),children:[De?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",className:Te("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",L&&!U?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:vs,onMouseDown:Ps,onClick:Ns,onKeyDown:W=>W.stopPropagation(),children:s.jsx(I,{name:"archive",className:Te(L&&!U?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(_t,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,be?s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",className:Te("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",L&&!U?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:As,onMouseDown:Rt,onClick:xt,onKeyDown:W=>W.stopPropagation(),children:s.jsx(I,{name:"external-link",className:Te(L&&!U?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(_t,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(on,{open:Ge,onOpenChange:hs,onOpenChangeComplete:Wt,children:[s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",className:Te("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",L&&!U?Ge?"h-4 w-4 opacity-100":Te("h-4 w-4 opacity-0",de):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Ms,onMouseDown:Vt,onClick:gs,onKeyDown:W=>W.stopPropagation(),children:s.jsx(I,{name:"more-2",className:Te(L&&!U?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),ds]})]})]})}),Ye&&mt?n.children.map(W=>ie(W,r+1,Oe??o,i,c,void 0,ge)):null,s.jsx(Ks,{open:A,onOpenChange:K,children:s.jsxs(Gs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Xs,{children:[s.jsx(Ys,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(cn,{children:ct===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:ct}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:ct})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:pe,onChange:W=>_e(W.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(tr,{children:[s.jsx(ze,{type:"button",onClick:()=>K(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{type:"button",onClick:()=>{K(!1),qt(pe)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),it?s.jsx(aS,{session:ye,open:Et,onOpenChange:lt}):null]},me.id)}const uS=a.memo(dS,cS);function mS(t){const e=gt.c(71),{t:n}=Tt(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:l}=t;let u,m,d,f,g,x,p,y,b,h;if(e[0]!==o||e[1]!==n||e[2]!==r){const F=n("sessions.sidebar.session.untitled");f=Ks,b=!!r,e[13]!==o?(h=Z=>{Z||o(null)},e[13]=o,e[14]=h):h=e[14],d=Gs,p=!1,y="max-w-sm gap-5",m=Xs;let te;e[15]!==n||e[16]!==r?.archivedBucket?(te=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=te):te=e[17],e[18]!==te?(x=s.jsx(Ys,{children:te}),e[18]=te,e[19]=x):x=e[19],u=cn,g=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||F,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||F,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||F,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||F,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||F}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||F}),e[0]=o,e[1]=n,e[2]=r,e[3]=u,e[4]=m,e[5]=d,e[6]=f,e[7]=g,e[8]=x,e[9]=p,e[10]=y,e[11]=b,e[12]=h}else u=e[3],m=e[4],d=e[5],f=e[6],g=e[7],x=e[8],p=e[9],y=e[10],b=e[11],h=e[12];let N;e[20]!==u||e[21]!==g?(N=s.jsx(u,{children:g}),e[20]=u,e[21]=g,e[22]=N):N=e[22];let w;e[23]!==m||e[24]!==x||e[25]!==N?(w=s.jsxs(m,{children:[x,N]}),e[23]=m,e[24]=x,e[25]=N,e[26]=w):w=e[26];let S;e[27]!==c||e[28]!==i?(S=()=>c(!i),e[27]=c,e[28]=i,e[29]=S):S=e[29];const v=!i;let j;e[30]!==i?(j=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=j):j=e[31];let k;e[32]!==n?(k=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=k):k=e[33];let D;e[34]!==j||e[35]!==k||e[36]!==S||e[37]!==v?(D=s.jsxs("button",{type:"button",onClick:S,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":v,children:[j,k]}),e[34]=j,e[35]=k,e[36]=S,e[37]=v,e[38]=D):D=e[38];let T;e[39]!==o?(T=()=>o(null),e[39]=o,e[40]=T):T=e[40];let C;e[41]!==n?(C=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=C):C=e[42];let P;e[43]!==T||e[44]!==C?(P=s.jsx("button",{type:"button",onClick:T,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:C}),e[43]=T,e[44]=C,e[45]=P):P=e[45];let E;e[46]!==l?(E=()=>{l()},e[46]=l,e[47]=E):E=e[47];let M;e[48]!==n||e[49]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=M):M=e[50];let H;e[51]!==E||e[52]!==M?(H=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:M}),e[51]=E,e[52]=M,e[53]=H):H=e[53];let R;e[54]!==P||e[55]!==H?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[P,H]}),e[54]=P,e[55]=H,e[56]=R):R=e[56];let _;e[57]!==D||e[58]!==R?(_=s.jsxs(tr,{className:"w-full sm:items-center sm:justify-between",children:[D,R]}),e[57]=D,e[58]=R,e[59]=_):_=e[59];let z;e[60]!==d||e[61]!==p||e[62]!==_||e[63]!==y||e[64]!==w?(z=s.jsxs(d,{showCloseButton:p,className:y,children:[w,_]}),e[60]=d,e[61]=p,e[62]=_,e[63]=y,e[64]=w,e[65]=z):z=e[65];let V;return e[66]!==f||e[67]!==z||e[68]!==b||e[69]!==h?(V=s.jsx(f,{open:b,onOpenChange:h,children:z}),e[66]=f,e[67]=z,e[68]=b,e[69]=h,e[70]=V):V=e[70],V}function fS(t){const e=gt.c(57),{t:n}=Tt(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:l}=t,u=r?.archivedBucket===!0,m=r?.sessionCount??0;let d;e[0]!==u||e[1]!==m||e[2]!==n?(d=n(u?m===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":m===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=u,e[1]=m,e[2]=n,e[3]=d):d=e[3];const f=d;let g;e[4]!==u||e[5]!==m||e[6]!==n?(g=u?m===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:m}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:m}):m===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:m}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:m}),e[4]=u,e[5]=m,e[6]=n,e[7]=g):g=e[7];const x=g,p=!!r;let y;e[8]!==o?(y=V=>{V||o(null)},e[8]=o,e[9]=y):y=e[9];let b;e[10]!==f?(b=s.jsx(Ys,{children:f}),e[10]=f,e[11]=b):b=e[11];let h;e[12]!==x?(h=s.jsx(cn,{children:x}),e[12]=x,e[13]=h):h=e[13];let N;e[14]!==b||e[15]!==h?(N=s.jsxs(Xs,{children:[b,h]}),e[14]=b,e[15]=h,e[16]=N):N=e[16];let w;e[17]!==c||e[18]!==i?(w=()=>c(!i),e[17]=c,e[18]=i,e[19]=w):w=e[19];const S=!i;let v;e[20]!==i?(v=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=v):v=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let k;e[24]!==j||e[25]!==w||e[26]!==S||e[27]!==v?(k=s.jsxs("button",{type:"button",onClick:w,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[v,j]}),e[24]=j,e[25]=w,e[26]=S,e[27]=v,e[28]=k):k=e[28];let D;e[29]!==o?(D=()=>o(null),e[29]=o,e[30]=D):D=e[30];let T;e[31]!==n?(T=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=T):T=e[32];let C;e[33]!==D||e[34]!==T?(C=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:T}),e[33]=D,e[34]=T,e[35]=C):C=e[35];let P;e[36]!==l?(P=()=>{l()},e[36]=l,e[37]=P):P=e[37];let E;e[38]!==u||e[39]!==n?(E=n(u?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=u,e[39]=n,e[40]=E):E=e[40];let M;e[41]!==P||e[42]!==E?(M=s.jsx("button",{type:"button",onClick:P,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:E}),e[41]=P,e[42]=E,e[43]=M):M=e[43];let H;e[44]!==C||e[45]!==M?(H=s.jsxs("div",{className:"flex items-center gap-2",children:[C,M]}),e[44]=C,e[45]=M,e[46]=H):H=e[46];let R;e[47]!==k||e[48]!==H?(R=s.jsxs(tr,{className:"w-full sm:items-center sm:justify-between",children:[k,H]}),e[47]=k,e[48]=H,e[49]=R):R=e[49];let _;e[50]!==R||e[51]!==N?(_=s.jsxs(Gs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[N,R]}),e[50]=R,e[51]=N,e[52]=_):_=e[52];let z;return e[53]!==p||e[54]!==_||e[55]!==y?(z=s.jsx(Ks,{open:p,onOpenChange:y,children:_}),e[53]=p,e[54]=_,e[55]=y,e[56]=z):z=e[56],z}function hS(t){const e=gt.c(36),{t:n}=Tt(),{value:r,setValue:o,onConfirm:i}=t,c=!!r;let l;e[0]!==o?(l=v=>{v||o(null)},e[0]=o,e[1]=l):l=e[1];let u;e[2]!==n?(u=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=u):u=e[3];let m;e[4]!==u?(m=s.jsx(Ys,{children:u}),e[4]=u,e[5]=m):m=e[5];let d;e[6]!==n||e[7]!==r?(d=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=d):d=e[8];let f;e[9]!==d?(f=s.jsx(cn,{children:d}),e[9]=d,e[10]=f):f=e[10];let g;e[11]!==m||e[12]!==f?(g=s.jsxs(Xs,{children:[m,f]}),e[11]=m,e[12]=f,e[13]=g):g=e[13];let x;e[14]!==o?(x=()=>o(null),e[14]=o,e[15]=x):x=e[15];let p;e[16]!==n?(p=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=p):p=e[17];let y;e[18]!==x||e[19]!==p?(y=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:p}),e[18]=x,e[19]=p,e[20]=y):y=e[20];let b;e[21]!==n?(b=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=b):b=e[22];let h;e[23]!==i||e[24]!==b?(h=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:b}),e[23]=i,e[24]=b,e[25]=h):h=e[25];let N;e[26]!==h||e[27]!==y?(N=s.jsxs(tr,{children:[y,h]}),e[26]=h,e[27]=y,e[28]=N):N=e[28];let w;e[29]!==N||e[30]!==g?(w=s.jsxs(Gs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[g,N]}),e[29]=N,e[30]=g,e[31]=w):w=e[31];let S;return e[32]!==c||e[33]!==l||e[34]!==w?(S=s.jsx(Ks,{open:c,onOpenChange:l,children:w}),e[32]=c,e[33]=l,e[34]=w,e[35]=S):S=e[35],S}const pS=t=>{const e=gt.c(46),{selectedCount:n,scopeKey:r,scopeFolders:o,archivedBucket:i,onMoveToFolder:c,onCreateFolderAndMove:l,onRemoveFromFolder:u,canRemoveFromFolder:m,onDelete:d,onDone:f}=t,{t:g}=Tt(),x=!!r&&!i;let p;e[0]!==i||e[1]!==g?(p=g(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=g,e[2]=p):p=e[2];const y=p;let b;e[3]!==n||e[4]!==g?(b=g("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=g,e[5]=b):b=e[5];let h;e[6]!==b?(h=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:b}),e[6]=b,e[7]=h):h=e[7];let N;e[8]!==x||e[9]!==m||e[10]!==l||e[11]!==c||e[12]!==u||e[13]!==o||e[14]!==g?(N=x?s.jsxs(on,{children:[s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(nn,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":g("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:g("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(rn,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:g("sessions.sidebar.folders.none")}):o.map(_=>s.jsx(zt,{onClick:()=>c(_.id),children:s.jsx("span",{className:"flex-1 truncate",children:_.name})},_.id)),s.jsx(Mn,{}),s.jsxs(zt,{onClick:l,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),g("sessions.sidebar.folders.newFolderEllipsis")]}),m?s.jsxs(zt,{onClick:u,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),g("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=x,e[9]=m,e[10]=l,e[11]=c,e[12]=u,e[13]=o,e[14]=g,e[15]=N):N=e[15];let w;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=Te("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=w):w=e[16];let S;e[17]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(I,{name:"delete-bin",className:"h-4 w-4"}),e[17]=S):S=e[17];let v;e[18]!==y||e[19]!==d?(v=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:w,"aria-label":y,children:S})}),e[18]=y,e[19]=d,e[20]=v):v=e[20];let j;e[21]!==y?(j=s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:y})}),e[21]=y,e[22]=j):j=e[22];let k;e[23]!==v||e[24]!==j?(k=s.jsxs(Lt,{children:[v,j]}),e[23]=v,e[24]=j,e[25]=k):k=e[25];let D;e[26]!==g?(D=g("sessions.sidebar.header.actions.exitSelection"),e[26]=g,e[27]=D):D=e[27];let T;e[28]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(I,{name:"close",className:"h-4 w-4"}),e[28]=T):T=e[28];let C;e[29]!==f||e[30]!==D?(C=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":D,children:T})}),e[29]=f,e[30]=D,e[31]=C):C=e[31];let P;e[32]!==g?(P=g("sessions.sidebar.header.actions.exitSelection"),e[32]=g,e[33]=P):P=e[33];let E;e[34]!==P?(E=s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:P})}),e[34]=P,e[35]=E):E=e[35];let M;e[36]!==C||e[37]!==E?(M=s.jsxs(Lt,{children:[C,E]}),e[36]=C,e[37]=E,e[38]=M):M=e[38];let H;e[39]!==M||e[40]!==N||e[41]!==k?(H=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[N,k,M]}),e[39]=M,e[40]=N,e[41]=k,e[42]=H):H=e[42];let R;return e[43]!==H||e[44]!==h?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[h,H]}),e[43]=H,e[44]=h,e[45]=R):R=e[45],R},zm="oc.sessions.activeNow",gS=2160*60*1e3,Wm=t=>!!t.parentID,lc=t=>!!t.time?.archived,Pl=t=>{const e=t.time?.updated,n=t.time?.created;return typeof e=="number"&&Number.isFinite(e)?e:typeof n=="number"&&Number.isFinite(n)?n:0},xS=t=>{try{const e=t.getItem(zm);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,o=[];return n.forEach(i=>{const c=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!c||r.has(c)||(r.add(c),o.push({sessionId:c}))}),o}catch{return[]}},Qa=(t,e)=>{try{t.setItem(zm,JSON.stringify(e))}catch{}},bS=(t,e,n=Date.now())=>{const r=n-gS;return t.filter(o=>{const i=e.get(o.sessionId);return i?lc(i)?!1:Pl(i)>=r:!0})},yS=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Um=t=>[...t].sort((e,n)=>Pl(n)-Pl(e)),wS=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!lc(r)).filter(r=>!Wm(r));return Um(n)},vS=(t,e)=>{const n=t.filter(r=>{if(lc(r)||Wm(r))return!1;const o=e[r.id];return o?.type==="busy"||o?.type==="retry"});return Um(n)},Ro=Dr(),Xa=vi((t,e)=>({entries:xS(Ro),setEntries:n=>{n!==e().entries&&(t({entries:n}),Qa(Ro,n))},addSession:n=>{const r=yS(e().entries,n);r!==e().entries&&(t({entries:r}),Qa(Ro,r))},prune:n=>{const r=e().entries,o=bS(r,n);o.length===r.length&&o.every((i,c)=>i.sessionId===r[c]?.sessionId)||(t({entries:o}),Qa(Ro,o))}})),Mo="oc.sessions.projectCollapse",Qd="oc.sessions.groupOrder",Xd="oc.sessions.groupCollapse",Zd="oc.sessions.activeSessionByProject",Za="oc.sessions.expandedParents.v2",jS="oc.sessions.expandedParents",SS="oc.sessions.pinned",NS=(t,e)=>{const n=new Set;for(const r of t){const o=as(r.path)?.toLowerCase();o&&n.add(o)}for(const r of e.values())for(const o of r){const i=as(o.path)?.toLowerCase();i&&n.add(i)}return n},kS=(t,e)=>{if(t.time?.archived)return!0;const n=as(hi(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},CS=5*6e4,eu=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:o=!1})=>{const{t:i}=Tt(),[c,l]=a.useState(!1),[u,m]=a.useState(""),d=a.useRef(null),f=a.useRef(null),g=a.useRef(new Set),[x,p]=a.useState(null),[y,b]=a.useState(""),[h,N]=a.useState(null),[w,S]=a.useState(new Set),[v]=a.useState(()=>new Map),j=a.useMemo(()=>Dr(),[]),k=Xa(X=>X.entries),D=Xa(X=>X.addSession),T=Xa(X=>X.prune),[C,P]=a.useState(new Set),[E,M]=a.useState(new Map),[H,R]=a.useState(new Map),[_,z]=a.useState(!1),[V,F]=a.useState(!1),[te,Z]=a.useState(null),[ne,U]=a.useState(null),[ie,oe]=a.useState(""),[ge,je]=a.useState(null),[Se,re]=a.useState(null),[L,$]=a.useState(null),q=Ra(X=>X.ids),he=Ra(X=>X.setIds),de=Ra(X=>X.toggle),[we,be]=a.useState(()=>{try{const X=Dr().getItem(Xd);if(!X)return new Set;const Xe=JSON.parse(X);return new Set(Array.isArray(Xe)?Xe.filter(Ke=>typeof Ke=="string"):[])}catch{return new Set}}),[De,le]=a.useState(()=>{try{const X=Dr().getItem(Qd);if(!X)return new Map;const Xe=JSON.parse(X),Ke=new Map;return Object.entries(Xe).forEach(([Pt,Zt])=>{Array.isArray(Zt)&&Ke.set(Pt,Zt.filter(ys=>typeof ys=="string"))}),Ke}catch{return new Map}}),[ke,ue]=a.useState(()=>{try{const X=Dr().getItem(Zd);if(!X)return new Map;const Xe=JSON.parse(X),Ke=new Map;return Object.entries(Xe).forEach(([Pt,Zt])=>{typeof Zt=="string"&&Zt.length>0&&Ke.set(Pt,Zt)}),Ke}catch{return new Map}}),[ve,G]=a.useState(new Map),Ae=a.useRef(new Map),ce=a.useRef(0),fe=sn(X=>X.homeDirectory),Ee=sn(X=>X.currentDirectory),me=sn(X=>X.setDirectory),B=Es(X=>X.projects),ye=Es(X=>X.activeProjectId),Oe=Es(X=>X.removeProject),Q=Es(X=>X.setActiveProjectIdOnly),Me=Es(X=>X.updateProjectMeta),Re=Es(X=>X.reorderProjects),Ne=Fe(X=>X.setActiveMainTab),Be=Fe(X=>X.openContextPanelTab),se=Fe(X=>X.setSettingsDialogOpen),O=Fe(X=>X.toggleHelpDialog),A=Fe(X=>X.setAboutDialogOpen),K=Fe(X=>X.setSessionSwitcherOpen),pe=Fe(X=>X.setScheduledTasksDialogOpen),_e=Fe(X=>X.openMultiRunLauncher),We=Fe(X=>X.notifyOnSubtasks),Le=Fe(X=>X.showDeletionDialog),rt=Fe(X=>X.setShowDeletionDialog),yt=va(u,120),Dt=a.useMemo(()=>yt.trim().toLowerCase(),[yt]),st=Dt.length>0,Pe=En(X=>X.collapsedFolderIds),tt=En(X=>X.foldersMap),Ye=En(X=>X.getFoldersForScope),nt=En(X=>X.createFolder),ft=En(X=>X.renameFolder),mt=En(X=>X.deleteFolder),ot=En(X=>X.addSessionToFolder),It=En(X=>X.addSessionsToFolder),dt=En(X=>X.removeSessionFromFolder),bt=En(X=>X.removeSessionsFromFolders),He=En(X=>X.toggleFolderCollapse),Ze=En(X=>X.cleanupSessions),Ue=En(X=>X.getSessionFolderId);p0({isSessionSearchOpen:c,setIsSessionSearchOpen:l,sessionSearchInputRef:f,sessionSearchContainerRef:d});const jt=Mu(),Ge=Ql(),it=Ll(),Et=Eh(),lt=Xr(X=>X.hasLoaded),ct=Xr(X=>X.activeSessions),Bt=Xr(X=>X.archivedSessions),Ft=vt(X=>X.currentSessionId),qt=vt(X=>!!X.newSessionDraft?.open),Ut=vt(X=>X.setCurrentSession),At=vt(X=>X.updateSessionTitle),Xt=vt(X=>X.shareSession),ls=vt(X=>X.unshareSession),es=vt(X=>X.worktreeMetadata),Gt=vt(X=>X.availableWorktreesByProject),pt=vt(X=>X.openNewSessionDraft),Yt=Ei(hu(X=>({checkForUpdates:X.checkForUpdates,available:X.available,runtimeType:X.runtimeType,info:X.info,downloading:X.downloading,downloaded:X.downloaded,progress:X.progress,error:X.error,downloadUpdate:X.downloadUpdate,restartToUpdate:X.restartToUpdate}))),us=a.useMemo(()=>NS(B,Gt),[Gt,B]),Jt=a.useMemo(()=>{const X=new Map(it.map(Pt=>[Pt.id,Pt])),Xe=ct.map(Pt=>{const Zt=X.get(Pt.id);return Zt?Rh(Zt,Pt):Pt}),Ke=new Set(Xe.map(Pt=>Pt.id));return it.forEach(Pt=>{Ke.has(Pt.id)||Xe.push(Pt)}),Xe.filter(Pt=>kS(Pt,us))},[ct,us,it]),ss=a.useMemo(()=>it.map(X=>{const Xe=as(X.directory??null)??"";return`${X.id}:${X.title??""}:${X.time?.archived?1:0}:${Xe}`}).join("|"),[it]),hs=a.useRef(it);a.useEffect(()=>{hs.current=it},[ss,it]);const Wt=a.useMemo(()=>B.map(X=>`${X.id}:${as(X.path)??""}`).join("|"),[B]),gs=a.useRef(!1);a.useEffect(()=>{gs.current||(gs.current=!0,dl(hs.current))},[]),a.useEffect(()=>{let X=!1;return(async()=>{const Ke=Es.getState().projects;if(Ke.length===0)return;const Pt=new Map,Zt=[];await Promise.all(Ke.map(async ys=>{const bn=as(ys.path);if(bn)try{if(!(_s.getState().directories.get(bn)?.isGitRepo??await Hi(()=>import("./useAppFontEffects-DEZpweZZ.js").then(fn=>fn.fy),__vite__mapDeps([0,1,2,3,4])).then(fn=>fn.checkIsGitRepository(bn))))return;const Sn=await Lh({id:ys.id,path:bn});if(X||Sn.length===0)return;Pt.set(bn,Sn),Zt.push(...Sn)}catch{}})),!X&&vt.setState({availableWorktrees:Zt,availableWorktreesByProject:Pt})})(),()=>{X=!0}},[Wt]),a.useEffect(()=>{let X=null;const Xe=Mm(Ke=>{Ke.type==="scheduled-task-ran"&&(X&&clearTimeout(X),X=setTimeout(()=>{dl(hs.current)},500))});return()=>{X&&clearTimeout(X),Xe()}},[]);const Ms=a.useMemo(()=>lr(),[]),Vt=a.useMemo(()=>Gi(),[]),{isTablet:vs}=Pr(),Ps=t||vs,{buildGroupSearchText:Ns,filterSessionNodesForSearch:As,buildGroupedSessions:Rt}=h0({homeDirectory:fe,worktreeMetadata:es,pinnedSessionIds:q,gitBranches:jt,isVSCode:Vt}),{scheduleCollapsedProjectsPersist:xt}=j0({isVSCode:Vt,hasLoadedGlobalSessions:lt,safeStorage:j,keys:{sessionExpanded:Za,sessionExpandedLegacy:jS,projectCollapse:Mo,sessionPinned:SS,groupOrder:Qd,projectActiveSession:Zd,groupCollapse:Xd},sessions:Jt,setPinnedSessionIds:he,groupOrderByProject:De,activeSessionByProject:ke,collapsedGroups:we,setExpandedParents:S,setCollapsedProjects:P}),Kt=a.useMemo(()=>[...Jt].sort((X,Xe)=>Ti(X,Xe,q)),[Jt,q]),Ht=a.useMemo(()=>new Map(Kt.map((X,Xe)=>[X.id,Xe])),[Kt]),ns=a.useMemo(()=>{const X=new Map;return Kt.forEach(Xe=>{const Ke=Xe.parentID;if(!Ke)return;const Pt=X.get(Ke)??[];Pt.push(Xe),X.set(Ke,Pt)}),X.forEach(Xe=>Xe.sort((Ke,Pt)=>Ti(Ke,Pt,q))),X},[Kt,q]),rs=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noSessions.description")})]}),ds=a.useMemo(()=>B.find(X=>X.id===h)??null,[B,h]),W=a.useCallback(X=>{h&&(Me(h,X),N(null))},[h,Me]),qe=a.useCallback(()=>{z(!0)},[]),Qe=a.useCallback(()=>{const X=Ei.getState();if(X.available&&X.info){F(!0);return}Yt.checkForUpdates().then(()=>{const{available:Xe,error:Ke}=Ei.getState();if(Ke){ae.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:Ke});return}if(!Xe){ae.success(i("sessions.sidebar.updateCheck.latestVersion"));return}F(!0)})},[i,Yt]),ht=a.useCallback(()=>{t&&K(!1),se(!0)},[t,K,se]),Ct=Yt.available&&(Yt.runtimeType==="desktop"||Yt.runtimeType==="web"),ut=vt(X=>X.deleteSession),ts=vt(X=>X.deleteSessions),js=vt(X=>X.archiveSession),xs=vt(X=>X.archiveSessions),{copiedSessionId:Bs,handleSessionSelect:Ts,handleSessionDoubleClick:dn,handleSaveEdit:Ds,handleCancelEdit:Vs,handleShareSession:Us,handleCopyShareUrl:bs,handleUnshareSession:wr,handleDeleteSession:yn,confirmDeleteSession:ks}=g0({activeProjectId:ye,currentDirectory:Ee,currentSessionId:Ft,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:c,sessionSearchQuery:u,setSessionSearchQuery:m,setIsSessionSearchOpen:l,setActiveProjectIdOnly:Q,setDirectory:me,setActiveMainTab:Ne,setSessionSwitcherOpen:K,setCurrentSession:Ut,updateSessionTitle:At,shareSession:Xt,unshareSession:ls,deleteSession:ut,deleteSessions:ts,archiveSession:js,archiveSessions:xs,childrenMap:ns,showDeletionDialog:Le,setDeleteSessionConfirm:je,deleteSessionConfirm:ge,setEditingId:p,setEditTitle:b,editingId:x,editTitle:y}),ln=a.useCallback(()=>{if(!Se)return;const{scopeKey:X,folderId:Xe}=Se;re(null),mt(X,Xe)},[Se,mt]),Tn=a.useCallback(()=>{Ir.requestDirectoryDialog()},[]);a.useEffect(()=>{if(!Ft)return;const Xe=Jt.find(Pt=>Pt.id===Ft)?.parentID;if(!Xe)return;const Ke=[`project:active:${Xe}`,`project:archived:${Xe}`,`recent:active:${Xe}`,`recent:archived:${Xe}`];S(Pt=>{if(Ke.every(ys=>Pt.has(ys)))return Pt;const Zt=new Set(Pt);Ke.forEach(ys=>Zt.add(ys));try{j.setItem(Za,JSON.stringify(Array.from(Zt)))}catch{}return Zt})},[Ft,Jt,j]);const un=a.useCallback(X=>{S(Xe=>{const Ke=new Set(Xe);Ke.has(X)?Ke.delete(X):Ke.add(X);try{j.setItem(Za,JSON.stringify(Array.from(Ke)))}catch{}return Ke})},[j]),Un=a.useCallback((X,Xe)=>{if(!X)return null;Xe&&Pe.has(Xe)&&He(Xe);const Ke=nt(X,i("sessions.sidebar.folder.newFolderName"),Xe);return U(Ke.id),oe(Ke.name),Ke},[Pe,He,nt,i]),wn=a.useCallback((X,Xe)=>{R(Ke=>{const Pt=new Map(Ke);return Pt.set(X,Xe+7),Pt})},[]),zs=a.useCallback(X=>{R(Xe=>{if(!Xe.has(X))return Xe;const Ke=new Map(Xe);return Ke.delete(X),Ke})},[]),is=a.useCallback(X=>{R(Xe=>{let Ke=!1;const Pt=new Map(Xe),Zt=`${X}:`;for(const ys of Pt.keys())ys.startsWith(Zt)&&(Pt.delete(ys),Ke=!0);return Ke?Pt:Xe})},[]),Fs=a.useCallback(()=>{ce.current=Date.now()+150,R(new Map),P(()=>{const X=new Set(B.map(Xe=>Xe.id));try{j.setItem(Mo,JSON.stringify(Array.from(X)))}catch{}return Vt||xt(X),X})},[B,Vt,j,xt]),dr=a.useCallback(()=>{ce.current=Date.now()+150,R(new Map),P(()=>{const X=new Set;try{j.setItem(Mo,JSON.stringify([]))}catch{}return Vt||xt(X),X})},[Vt,j,xt]),Cn=a.useCallback(X=>{ce.current=Date.now()+150,is(X),P(Xe=>{const Ke=new Set(Xe);Ke.has(X)?Ke.delete(X):Ke.add(X);try{j.setItem(Mo,JSON.stringify(Array.from(Ke)))}catch{}return Vt||xt(Ke),Ke})},[Vt,is,j,xt]),$s=a.useMemo(()=>B.map(X=>({...X,normalizedPath:as(X.path)})).filter(X=>!!X.normalizedPath),[B]),Hn=a.useMemo(()=>$s.map(X=>X.normalizedPath),[$s]),vr=a.useMemo(()=>{const X=new Set;return $s.forEach(Xe=>{Xe.normalizedPath&&X.add(Xe.normalizedPath),(Gt.get(Xe.normalizedPath)??[]).forEach(Pt=>{const Zt=as(Pt.path);Zt&&X.add(Zt)})}),[...X].sort()},[Gt,$s]),Er=a.useRef(null);a.useEffect(()=>{const X=new Set(vr),Xe=Er.current;if(Er.current=X,!Xe)return;const Ke=vr.filter(Pt=>!Xe.has(Pt));Ke.length!==0&&Mh(Ke,hs.current)},[vr]);const{github:jr}=Wn(),sr=bi(X=>X.status),nr=bi(X=>X.hasChecked),Sr=Fh(Hn),Rr=er(X=>X.ensureEntry),ee=er(X=>X.setParams),at=er(X=>X.refreshTargets);S0({normalizedProjects:$s,gitRepoStatus:Sr,setProjectRepoStatus:M,setProjectRootBranches:G});const St=vt(X=>X.isLoading);R0({isSessionsLoading:St,sessions:Jt,archivedSessions:Bt,normalizedProjects:$s,isVSCode:Vt,availableWorktreesByProject:Gt,cleanupSessions:Ze});const{getSessionsForProject:$t,getArchivedSessionsForProject:fs}=D0({isVSCode:Vt,sessions:Jt,archivedSessions:Bt,availableWorktreesByProject:Gt});o0({normalizedProjects:$s,sessions:Jt,archivedSessions:Bt,availableWorktreesByProject:Gt,isVSCode:Vt,isSessionsLoading:St,foldersMap:tt,createFolder:nt,addSessionToFolder:ot,cleanupSessions:Ze});const ms=a.useRef(!1);ye&&E.has(ye)&&(ms.current=!!E.get(ye));const{projectSections:Qt,groupSearchDataByGroup:Ws,sectionsForRender:Is,searchMatchCount:Gn}=c0({normalizedProjects:$s,getSessionsForProject:$t,getArchivedSessionsForProject:fs,availableWorktreesByProject:Gt,projectRepoStatus:E,projectRootBranches:ve,lastRepoStatus:ms.current,buildGroupedSessions:Rt,hasSessionSearchQuery:st,normalizedSessionSearchQuery:Dt,filterSessionNodesForSearch:As,buildGroupSearchText:Ns,foldersMap:tt}),ur=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noMatches.description")})]}),{currentSessionDirectory:_r}=u0({projectSections:Qt,activeProjectId:ye,activeSessionByProject:ke,setActiveSessionByProject:ue,currentSessionId:Ft,handleSessionSelect:Ts,newSessionDraftOpen:qt,mobileVariant:t,openNewSessionDraft:pt,setActiveMainTab:Ne,setSessionSwitcherOpen:K,sessions:Jt,worktreeMetadata:es}),{getOrderedGroups:pn}=m0(De),Ln=a.useRef(!1);a.useEffect(()=>{if(Ln.current||Qt.length===0)return;const X=Qt.flatMap(Xe=>Xe.groups.filter(Ke=>Ke.isArchivedBucket).map(Ke=>`${Xe.project.id}:${Ke.id}`));X.length>0&&be(Xe=>new Set([...Xe,...X])),Ln.current=!0},[Qt]);const mn=a.useMemo(()=>{const X=new Map,Xe=new Map;return Qt.forEach(Ke=>{const Pt=Bu(Ke.project.label?.trim()||wi(Ke.project.normalizedPath,fe)||Ke.project.normalizedPath);Ke.groups.forEach(Zt=>{const ys=Zt.branch&&Zt.branch!=="HEAD"&&Zt.branch!==Pt?Zt.branch:null,bn={projectLabel:Pt,branchLabel:ys},ir=Yn=>{Yn.forEach(Sn=>{const fn=Ke.project.normalizedPath.length,Ni=Xe.get(Sn.session.id)??-1;fn<Ni||(X.set(Sn.session.id,{node:Sn,projectId:Ke.project.id,groupDirectory:Zt.directory,secondaryMeta:bn}),Xe.set(Sn.session.id,fn),Sn.children.length>0&&ir(Sn.children))})};ir(Zt.sessions)})}),X},[Qt,fe]),ps=Ar(X=>X.showRecentSection),Zs=Ar(X=>X.showArchivedSessions),vn=a.useMemo(()=>ps?wS(k,new Map(Jt.map(X=>[X.id,X]))).sort((X,Xe)=>Ti(X,Xe,q)):[],[k,q,Jt,ps]),jn=a.useMemo(()=>ps?vS(Jt,Et):[],[Et,Jt,ps]);a.useEffect(()=>{!ps||jn.length===0||jn.forEach(X=>D(X.id))},[D,jn,ps]),a.useEffect(()=>{if(!ps)return;const X=new Map;[...Jt,...Bt].forEach(Xe=>{X.set(Xe.id,Xe)}),T(X)},[Bt,T,Jt,ps]);const Kn=a.useMemo(()=>{if(!ps)return[];const X=Xe=>{const Ke=mn.get(Xe.id),Pt=as(Xe.directory??null);return{node:Ke?.node??{session:Xe,children:[],worktree:null},projectId:Ke?.projectId??null,groupDirectory:Ke?.groupDirectory??Pt,secondaryMeta:Ke?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:vn.map(X)}]},[vn,mn,ps,i]),Nr=a.useMemo(()=>new Set(vn.map(X=>X.id)),[vn]),en=a.useMemo(()=>[...Nr],[Nr]);Av({currentSessionId:Ft,sortedSessions:Kt,recentSessionIds:en,ensureSessionRenderable:Ge.ensureSessionRenderable});const kr=a.useMemo(()=>Zs?Is:Is.map(X=>({...X,groups:X.groups.filter(Xe=>!Xe.isArchivedBucket)})),[Is,Zs]),qi=a.useMemo(()=>{const X=new Set;return kr.forEach(Xe=>{Xe.groups.forEach(Ke=>{const Pt=as(Ke.directory??null),Zt=Ke.branch?.trim()||jt.get(Pt||"")?.trim();!Pt||!Zt||X.add(ao(Pt,Zt))})}),[...X]},[jt,kr]),ji=hb(qi);a.useEffect(()=>{if(!nr||!sr?.connected||!jr)return;const X=[],Xe=Date.now();if(kr.forEach(Pt=>{C.has(Pt.project.id)||Pt.groups.forEach(Zt=>{const ys=as(Zt.directory??null),bn=Zt.branch?.trim()||jt.get(ys||"")?.trim();if(!ys||!bn)return;const ir=ao(ys,bn),Yn=er.getState().entries[ir],Sn=!!Yn?.status?.pr,fn=`${ys}::${bn}`,Ni=Math.max(Yn?.lastRefreshAt??0,Yn?.lastDiscoveryPollAt??0),ki=!!(Yn?.isInitialStatusResolved&&!Sn&&(!g.current.has(fn)||Xe-Ni>=CS));(!Yn||!Yn.isInitialStatusResolved||ki)&&(ki&&g.current.add(fn),X.push({directory:ys,branch:bn}))})}),X.length===0)return;const Ke=new Map;X.forEach(Pt=>{const Zt=ao(Pt.directory,Pt.branch,Pt.remoteName??null);Ke.has(Zt)||Ke.set(Zt,Pt)}),Ke.forEach((Pt,Zt)=>{Rr(Zt),ee(Zt,{directory:Pt.directory,branch:Pt.branch,remoteName:Pt.remoteName??null,canShow:!0,github:jr,githubAuthChecked:nr,githubConnected:sr.connected})}),at([...Ke.values()],{silent:!0,markInitialResolved:!0})},[C,Rr,jr,nr,sr?.connected,jt,at,kr,ee]);const rr=t?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",gn="h-4.5 w-4.5",Br=O0({isDesktopShellRuntime:Ms,projectSections:Qt,projectHeaderSentinelRefs:Ae}),Mr=a.useCallback((X,Xe=0,Ke,Pt,Zt=!1,ys,bn="project")=>s.jsx(uS,{node:X,depth:Xe,groupDirectory:Ke,projectId:Pt,archivedBucket:Zt,directoryStatus:v,currentSessionId:Ft,pinnedSessionIds:q,expandedParents:w,hasSessionSearchQuery:st,normalizedSessionSearchQuery:Dt,notifyOnSubtasks:We,editingId:x,setEditingId:p,editTitle:y,setEditTitle:b,handleSaveEdit:Ds,handleCancelEdit:Vs,toggleParent:un,handleSessionSelect:Ts,handleSessionDoubleClick:dn,togglePinnedSession:de,handleShareSession:Us,copiedSessionId:Bs,handleCopyShareUrl:bs,handleUnshareSession:wr,openSidebarMenuKey:te,setOpenSidebarMenuKey:Z,renamingFolderId:ne,getFoldersForScope:Ye,getSessionFolderId:Ue,removeSessionFromFolder:dt,addSessionToFolder:ot,createFolderAndStartRename:Un,openContextPanelTab:Be,handleDeleteSession:yn,mobileVariant:t,alwaysShowActions:Ps,renderSessionNode:Mr,secondaryMeta:ys,renderContext:bn}),[v,Ft,q,w,st,Dt,We,x,p,y,b,Ds,Vs,un,Ts,dn,de,Us,Bs,bs,wr,te,Z,ne,Ye,Ue,dt,ot,Un,Be,yn,t,Ps]),Js=a.useCallback(X=>{zs(X),be(Xe=>{const Ke=new Set(Xe);return Ke.has(X)?Ke.delete(X):Ke.add(X),Ke})},[zs]),mr=a.useMemo(()=>{const X=new Map;for(const[Xe,Ke]of ji)X.set(Xe,{visualState:Ke.visualState,number:Ke.number,url:Ke.url,state:Ke.prState,draft:Ke.draft,title:Ke.title,base:Ke.base,head:Ke.head,checks:Ke.checks,canMerge:Ke.canMerge,mergeableState:Ke.mergeableState,repo:Ke.repo});return X},[ji]),Si=a.useCallback((X,Xe,Ke,Pt,Zt,ys)=>s.jsx(aj,{group:X,groupKey:Xe,projectId:Ke,hideGroupLabel:Pt,compactBodyPadding:ys,hasSessionSearchQuery:st,normalizedSessionSearchQuery:Dt,groupSearchDataByGroup:Ws,visibleSessionCount:H.get(Xe),collapsedGroups:we,hideDirectoryControls:r,collapsedFolderIds:Pe,toggleFolderCollapse:He,renameFolder:ft,deleteFolder:mt,showDeletionDialog:Le,setDeleteFolderConfirm:re,renderSessionNode:Mr,currentSessionDirectory:_r,projectRepoStatus:E,lastRepoStatus:ms.current,showMoreGroupSessions:wn,resetGroupSessionLimit:zs,mobileVariant:t,alwaysShowActions:Ps,activeProjectId:ye,setActiveProjectIdOnly:Q,setActiveMainTab:Ne,setSessionSwitcherOpen:K,openNewSessionDraft:pt,addSessionToFolder:ot,createFolderAndStartRename:Un,renamingFolderId:ne,renameFolderDraft:ie,setRenameFolderDraft:oe,setRenamingFolderId:U,pinnedSessionIds:q,sessionOrderIndex:Ht,prVisualStateByDirectoryBranch:mr,onToggleCollapsedGroup:Js,dragHandleProps:Zt}),[st,Dt,Ws,H,we,r,Pe,He,ft,mt,Le,Mr,_r,E,wn,zs,t,Ps,ye,Q,Ne,K,pt,ot,Un,ne,ie,q,Ht,mr,Js]),Cr=ps&&!Vt&&!st?s.jsx(gj,{sections:Kn,renderSessionNode:Mr}):null,fr=!!(ne||x||h),Vr=Zn(X=>X.enabled),Ls=Zn(X=>X.selectedIds),xn=Zn(X=>X.scopeKey),hr=Zn,ni=a.useCallback(()=>{Zn.getState().toggleMode()},[]),ri=a.useCallback(()=>{Zn.getState().disable()},[]),$r=a.useMemo(()=>{if(Ls.size===0||typeof document>"u")return!1;let X=!1,Xe=!1;for(const Ke of Ls){const Pt=document.querySelectorAll(`[data-session-row="${CSS.escape(Ke)}"]`);for(const Zt of Pt)Zt.getAttribute("data-session-archived")==="1"?Xe=!0:X=!0}return Xe&&!X},[Ls]),Qs=a.useMemo(()=>{if(xn)return xn;if(Ls.size===0||typeof document>"u")return null;for(const X of Ls){const Ke=document.querySelector(`[data-session-row="${CSS.escape(X)}"]`)?.getAttribute("data-session-scope");if(Ke&&Ke.length>0)return Ke}return null},[Ls,xn]),J=a.useMemo(()=>Qs?tt[Qs]??[]:[],[tt,Qs]),xe=a.useMemo(()=>{if(!Qs||Ls.size===0)return!1;const X=tt[Qs]??[];for(const Xe of X)for(const Ke of Xe.sessionIds)if(Ls.has(Ke))return!0;return!1},[tt,Qs,Ls]),Ce=a.useCallback(X=>{!Qs||Ls.size===0||It(Qs,X,Array.from(Ls))},[It,Ls,Qs]),$e=a.useCallback(()=>{if(!Qs||Ls.size===0)return;const X=Un(Qs);X&&It(Qs,X.id,Array.from(Ls))},[It,Un,Ls,Qs]),wt=a.useCallback(()=>{!Qs||Ls.size===0||bt(Qs,Array.from(Ls))},[bt,Ls,Qs]),Nt=a.useCallback(async()=>{const X=Array.from(Ls);if(X.length!==0){if($r){const{deletedIds:Xe,failedIds:Ke}=await ts(X);Xe.length>0&&ae.success(Xe.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:Xe.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:Xe.length})),Ke.length>0&&ae.error(Ke.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Ke.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:Ke.length}))}else{const{archivedIds:Xe,failedIds:Ke}=await xs(X);Xe.length>0&&ae.success(Xe.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:Xe.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:Xe.length})),Ke.length>0&&ae.error(Ke.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Ke.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:Ke.length}))}Zn.getState().clear()}},[xs,$r,ts,Ls,i]),Ss=a.useCallback(()=>{const X=Ls.size;if(X!==0){if(!Le){Nt();return}$({sessionCount:X,archivedBucket:$r})}},[$r,Nt,Ls,Le]),Os=a.useCallback(async()=>{$(null),await Nt()},[Nt]);a.useEffect(()=>{if(!Vr)return;const X=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),Xe=Ke=>{if(fr)return;const Pt=Ke.target;if(Pt&&(Pt.tagName==="INPUT"||Pt.tagName==="TEXTAREA"||Pt.isContentEditable))return;const Zt=X?Ke.metaKey:Ke.ctrlKey;if(Ke.key==="Escape"){Ke.preventDefault(),Zn.getState().disable();return}if(Zt&&Ke.key==="Backspace"){Ke.preventDefault(),Ss();return}if(Zt&&(Ke.key==="a"||Ke.key==="A")){const ys=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(ys.length===0)return;Ke.preventDefault();const ir=hr.getState().scopeKey??ys[0]?.getAttribute("data-session-scope")??null,Yn=fn=>ir?fn.getAttribute("data-session-scope")===ir:!0,Sn=ys.filter(Yn).map(fn=>fn.getAttribute("data-session-row")).filter(fn=>typeof fn=="string"&&fn.length>0);if(Sn.length===0)return;hr.getState().replaceAll(Sn,ir||null)}};return window.addEventListener("keydown",Xe),()=>window.removeEventListener("keydown",Xe)},[Ss,fr,hr,Vr]);const qn=a.useCallback(()=>{Ne("chat"),t&&K(!1),_e()},[t,_e,Ne,K]),Da=a.useCallback(()=>{Ne("chat"),t&&K(!1),pt()},[t,pt,Ne,K]);return s.jsxs("div",{ref:d,className:Te("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[s.jsx(lj,{hideDirectoryControls:r,showRecentControls:!Vt,handleOpenDirectoryDialog:Tn,openNewSessionDraft:Da,canOpenMultiRun:B.length>0,openMultiRunLauncher:qn,headerActionIconClass:gn,headerActionButtonClass:rr,isSessionSearchOpen:c,setIsSessionSearchOpen:l,sessionSearchInputRef:f,sessionSearchQuery:u,setSessionSearchQuery:m,hasSessionSearchQuery:st,searchMatchCount:Gn,collapseAllProjects:Fs,expandAllProjects:dr,openScheduledTasksDialog:()=>pe(!0),selectionModeEnabled:Vr,onToggleSelectionMode:ni}),s.jsx(kj,{topContent:Cr,sectionsForRender:kr,projectSections:Qt,activeProjectId:ye,showOnlyMainWorkspace:o,hasSessionSearchQuery:st,emptyState:rs,searchEmptyState:ur,renderGroupSessions:Si,homeDirectory:fe,collapsedProjects:C,hideDirectoryControls:r,projectRepoStatus:E,isDesktopShellRuntime:Ms,stuckProjectHeaders:Br,mobileVariant:t,alwaysShowActions:Ps,toggleProject:Cn,setActiveProjectIdOnly:Q,setActiveMainTab:Ne,setSessionSwitcherOpen:K,openNewSessionDraft:pt,openNewWorktreeDialog:qe,openProjectEditDialog:N,removeProject:Oe,projectHeaderSentinelRefs:Ae,reorderProjects:Re,getOrderedGroups:pn,setGroupOrderByProject:le,openSidebarMenuKey:te,setOpenSidebarMenuKey:Z,isInlineEditing:fr}),Vr&&Ls.size>0?s.jsx(pS,{selectedCount:Ls.size,scopeKey:Qs,scopeFolders:J,archivedBucket:$r,onMoveToFolder:Ce,onCreateFolderAndMove:$e,onRemoveFromFolder:wt,canRemoveFromFolder:xe,onDelete:Ss,onDone:ri}):null,s.jsx(bj,{onOpenSettings:ht,onOpenShortcuts:O,onOpenAbout:()=>A(!0),onOpenUpdate:Qe,showRuntimeButtons:!Vt,showUpdateButton:Ct}),s.jsx(Gu,{open:V,onOpenChange:F,info:Yt.info,downloading:Yt.downloading,downloaded:Yt.downloaded,progress:Yt.progress,error:Yt.error,onDownload:Yt.downloadUpdate,onRestart:Yt.restartToUpdate,runtimeType:Yt.runtimeType}),ds?s.jsx(B0,{open:!!ds,onOpenChange:X=>{X||N(null)},projectId:ds.id,projectName:ds.label||wi(ds.path,fe),projectPath:ds.path,initialIcon:ds.icon,initialColor:ds.color,initialIconBackground:ds.iconBackground,onSave:W}):null,s.jsx(Gp,{open:_,onOpenChange:z,onWorktreeCreated:(X,Xe)=>{if(Ne("chat"),t&&K(!1),Xe?.sessionId){Ut(Xe.sessionId,X);return}pt({directoryOverride:X})}}),s.jsx(r0,{}),s.jsx(mS,{value:ge,setValue:je,showDeletionDialog:Le,setShowDeletionDialog:rt,onConfirm:ks}),s.jsx(hS,{value:Se,setValue:re,onConfirm:ln}),s.jsx(fS,{value:L,setValue:$,showDeletionDialog:Le,setShowDeletionDialog:rt,onConfirm:Os})]})},ai=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,gr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},AS=()=>{const{t}=Tt(),[e,n]=a.useState(!1),[r,o]=a.useState(!1),[i,c]=a.useState(null),[l,u]=a.useState([]),[m,d]=a.useState(!1),[f,g]=a.useState(!1),[x,p]=a.useState(!1),[y,b]=a.useState(!1),[h,N]=a.useState(new Set),w=vt(G=>G.getWorktreeMetadata),S=vt(G=>G.newSessionDraft),v=vt(G=>G.setNewSessionDraftTarget),j=vt(G=>G.setDraftBootstrapPendingDirectory),k=Oh,D=Vh,T=vt(G=>G.deleteSessions),C=vt(G=>G.archiveSessions),P=Fe(G=>G.showDeletionDialog),E=Fe(G=>G.setShowDeletionDialog),M=sn(G=>G.currentDirectory),H=sn(G=>G.homeDirectory),R=sn(G=>G.isHomeReady),_=Es(G=>G.projects),z=Es(G=>G.activeProjectId),{isMobile:V,isTablet:F,hasTouchInput:te}=Pr(),Z=V||F||te,ne=a.useMemo(()=>{const Ae=(z?_.find(ce=>ce.id===z)??null:null)?.path??M;return gr(Ae)},[z,M,_]),U=a.useCallback(G=>{const ce=gr(G.projectDirectory)||ne;return{id:(_.find(Ee=>gr(Ee.path)===ce)??null)?.id??`path:${ce}`,path:ce}},[ne,_]),ie=y&&h.size>0,oe=a.useMemo(()=>{const G=i?.worktree;return G&&typeof G.branch=="string"&&G.branch.trim().length>0?!0:l.length>0&&l.every(({metadata:Ae})=>typeof Ae.branch=="string"&&Ae.branch.trim().length>0)},[i?.worktree,l]),ge=i?.mode==="worktree",je=ge,Se=x||!ge||!oe,re=x||!ge;a.useEffect(()=>{r||!R||_.length>0||(o(!0),n(!0))},[r,R,_.length]);const L=a.useCallback(G=>{c({sessions:G.sessions,dateLabel:G.dateLabel,mode:G.mode??"session",worktree:G.worktree??null})},[]),$=a.useCallback(()=>{c(null),u([]),d(!1),g(!1),p(!1),b(!1),N(new Set)},[]),q=a.useCallback(async G=>{if(G.sessions.length===0)return;if(G.sessions.length===1){const Ee=G.sessions[0];await k(Ee.id)?ae.success(t("sessions.sidebar.session.delete.success")):ae.error(t("sessions.sidebar.session.delete.error"));return}const Ae=G.sessions.map(Ee=>Ee.id),{deletedIds:ce,failedIds:fe}=await T(Ae);if(ce.length>0){const Ee=fe.length>0?fe.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:fe.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:fe.length}):G.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:G.dateLabel}):void 0;ae.success(ce.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ce.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ce.length}),{description:ai(Ee)})}fe.length>0&&ae.error(fe.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:fe.length}),{description:ai(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[k,T,t]);a.useEffect(()=>Ir.onDeleteRequest(G=>{if(!P&&(G.mode??"session")==="session"){q(G);return}L(G)}),[L,P,q]),a.useEffect(()=>Ir.onDirectoryRequest(()=>{n(!0)}),[]),a.useEffect(()=>{if(!i){u([]),d(!1),g(!1),b(!1),N(new Set);return}const G=i.sessions.map(fe=>{const Ee=w(fe.id);return Ee?{session:fe,metadata:Ee}:null}).filter(fe=>!!fe);u(G),d(!1),b(!1),N(new Set);const Ae=new Map;if(i.worktree?.path&&Ae.set(gr(i.worktree.path),i.worktree),G.forEach(({metadata:fe})=>{fe.path&&Ae.set(gr(fe.path),fe)}),Ae.size===0){b(!0);return}let ce=!1;return(async()=>{const fe=new Map,Ee=new Set;await Promise.all(Array.from(Ae.entries()).map(async([me,B])=>{try{const ye=await _h(B.path);fe.set(me,ye),ye?.isDirty&&Ee.add(me)}catch{B.status&&(fe.set(me,B.status),B.status.isDirty&&Ee.add(me))}})).catch(me=>{console.warn("Failed to inspect worktree status before deletion:",me)}),!ce&&(N(Ee),b(!0),c(me=>{if(!me?.worktree?.path)return me;const B=gr(me.worktree.path),ye=fe.get(B);if(!ye)return me;const Oe=me.worktree.status;return Oe?.isDirty===ye.isDirty&&Oe?.ahead===ye.ahead&&Oe?.behind===ye.behind&&Oe?.upstream===ye.upstream?me:{...me,worktree:{...me.worktree,status:ye}}}),u(me=>me.map(B=>{const ye=gr(B.metadata.path),Oe=fe.get(ye);return Oe?{session:B.session,metadata:{...B.metadata,status:Oe}}:B})))})(),()=>{ce=!0}},[i,w]),a.useEffect(()=>{oe||d(!1)},[oe]);const he=a.useCallback(async(G,Ae)=>{const ce=m&&oe,fe=U(G),Ee=gr(G.path),me=gr(fe.path);try{await Bh(fe,G,{deleteRemoteBranch:ce,deleteLocalBranch:Ae});const B=gr(S?.directoryOverride);return S?.open&&Ee&&B===Ee&&me&&(j(null),v({projectId:fe.id,directoryOverride:me},{force:!0})),gr(M)===Ee&&me&&sn.getState().setDirectory(me,{showOverlay:!1}),!0}catch(B){return ae.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:ai(B instanceof Error?B.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[oe,M,m,U,S?.directoryOverride,S?.open,j,v,t]),de=a.useCallback(async()=>{if(i){p(!0);try{const G=je,Ae=G&&m,ce=G&&f;if(i.sessions.length===0&&ge&&i.worktree){if(!await he(i.worktree,ce)){$();return}const me=t(m&&oe?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");ae.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:ai(me)}),$();return}if(i.sessions.length===1){const fe=i.sessions[0];if(!(ge?await D(fe.id):await k(fe.id,{archiveWorktree:!1,deleteRemoteBranch:Ae,deleteLocalBranch:ce}))){ae.error(t(ge?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),p(!1);return}const me=!ge&&G?t(Ae?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;ae.success(t(ge?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:ai(me),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const fe=i.sessions.map(B=>B.id);let Ee=[],me=[];if(ge){const B=await C(fe);Ee=B.archivedIds,me=B.failedIds}else{const B=await T(fe);Ee=B.deletedIds,me=B.failedIds}if(ge&&i.worktree&&me.length===0&&await he(i.worktree,ce),Ee.length>0){const B=!ge&&G?t(Ae?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Oe=[me.length>0?ge?me.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:me.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:me.length}):me.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:me.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:me.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,B].filter(Boolean).join(" ");ae.success(ge?Ee.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:Ee.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:Ee.length}):Ee.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ee.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ee.length}),{description:ai(Oe||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(me.length>0&&(ae.error(ge?me.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:me.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:me.length}):me.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:me.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:me.length}),{description:ai(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),Ee.length===0)){p(!1);return}}ge&&i.sessions.length===1&&i.worktree&&await he(i.worktree,ce),$()}finally{p(!1)}}},[i,m,f,k,T,D,C,$,je,ge,oe,he,t]),we=i?.worktree??l[0]?.metadata??null,be=i?i.mode==="worktree"?i.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):i.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:i.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:i.sessions.length}):i.sessions.length===1?i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:i.sessions.length,dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:i.sessions.length}):"",De=i?s.jsxs("div",{className:Te(ge?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:Te(ge?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[ge&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:Te(ge?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(G=>s.jsxs("li",{className:Te(ge?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:Te(!ge&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:G.title||t("sessions.sidebar.session.untitled")})]},G.id)),i.sessions.length>5&&s.jsx("li",{className:Te(ge?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:i.sessions.length-5})})]})]}),ge?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),we?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:we.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:we?Zo(we.path,H):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),ie&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,le=ge?oe?s.jsxs("button",{type:"button",onClick:()=>{Se||d(G=>!G)},disabled:Se,className:Te("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",Se?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[m?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,ke=ge?s.jsxs("button",{type:"button",onClick:()=>{re||g(G=>!G)},disabled:re,className:Te("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",re?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ue=ge?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[ke,le]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{variant:"ghost",onClick:$,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{variant:"destructive",onClick:de,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>E(!P),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!P,children:[P?s.jsx(I,{name:"checkbox-blank",className:"size-4"}):s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{variant:"ghost",onClick:$,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{variant:"destructive",onClick:de,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ve=ge?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[Z?s.jsx(xa,{open:!!i,onClose:()=>{x||$()},title:ve,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ue}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[be&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:be}),De]})}):s.jsx(Ks,{open:!!i,onOpenChange:G=>{if(!G){if(x)return;$()}},children:s.jsxs(Gs,{className:Te(ge?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(Xs,{children:[s.jsxs(Ys,{className:Te(ge&&"flex items-center gap-2"),children:[ge&&s.jsx(I,{name:"delete-bin",className:"h-5 w-5"}),ve]}),be&&s.jsx(cn,{children:be})]}),s.jsx("div",{className:Te(ge&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:De}),s.jsx(tr,{className:"mt-2 gap-2 pt-1 pb-1",children:ue})]})}),s.jsx(Kp,{open:e,onOpenChange:n})]})},Tl=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),DS=(t,e)=>{const n=Tl(t),r=Tl(e);return`${n}-${r}`.substring(0,60)},tu=(t,e)=>`${t}/${e}`,IS=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},su=(t,e)=>{const n=IS(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Kh(t.id,n),vt.getState().markSessionAsOpenChamberCreated(t.id),Xr.getState().upsertSession(o);try{qh().ensureChild(n,{bootstrap:!1}).setState(c=>{const l=c.session.findIndex(m=>m.id===t.id);if(l>=0&&c.session[l]===o)return c;const u=l>=0?c.session.map((m,d)=>d===l?o:m):[...c.session,o].sort((m,d)=>m.id.localeCompare(d.id));return{session:u,sessionTotal:Math.max(c.sessionTotal,u.length),limit:Math.max(c.limit,u.length)}})}catch{}return o},PS=()=>{const t=Es.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(o=>o.id===e);if(n?.path)return{id:n.id,path:n.path};const r=sn.getState().currentDirectory??null;if(r&&r.trim().length>0){const o=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${o}`,path:o}}return null},el=vi()(uu(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:o,files:i,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let l=0;l<r.length;l++){if(!r[l].prompt.trim())return t({error:`Group ${l+1}: prompt is required`}),null;if(r[l].models.length<1)return t({error:`Group ${l+1}: select at least 1 model`}),null;if(r[l].models.length>5)return t({error:`Group ${l+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const l=PS();if(!l)return t({error:"Select a project",isLoading:!1}),null;const u=l.path,d=await $h(u)&&e.isolateRuns!==!1,f=Tl(n),g=d?await wa(u):void 0,x=d?await zh(u):null,p=[],y=c?.filter(S=>S.trim().length>0)??[];for(let S=0;S<r.length;S++){const v=r[S],j=v.prompt,k=new Map;for(const T of v.models){const C=`${T.providerID}:${T.modelID}`;k.set(C,(k.get(C)||0)+1)}const D=new Map;for(const T of v.models){const C=`${T.providerID}:${T.modelID}`,P=k.get(C)||1,E=(D.get(C)||0)+1;D.set(C,E);const M=DS(T.providerID,T.modelID),H=r.length>1?`g${S+1}`:void 0,R=P>1?tu(f,`${M}/${E}`):tu(f,M),_=H?`${H}/${R}`:R,z=Gj({groupSlug:f,runGroup:H,providerID:T.providerID,modelID:T.modelID,index:P>1?E:void 0});try{if(!d){const Z=await zn.withDirectory(u,()=>zn.createSession({title:z}));su(Z,u),p.push({sessionId:Z.id,worktreePath:u,providerID:T.providerID,modelID:T.modelID,variant:T.variant,prompt:j});continue}const V=await Wh(l,{preferredName:_,mode:"new",branchName:_,worktreeName:_,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:y},{resolvedRootTrackingRemote:x}),F={...V,createdFromBranch:g,kind:"standard"},te=await zn.withDirectory(V.path,()=>zn.createSession({title:z}));su(te,V.path),vt.getState().setWorktreeMetadata(te.id,F),p.push({sessionId:te.id,worktreePath:V.path,providerID:T.providerID,modelID:T.modelID,variant:T.variant,prompt:j})}catch(V){console.warn("[MultiRun] Failed to create session:",V)}}}const b=c?.filter(S=>S.trim().length>0)??[];b.length>0&&Uh(l,b).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=p.map(S=>S.sessionId),N=p[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const w=i?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{const S=Hh.getState().expandText;await Promise.allSettled(p.map(async v=>{try{const j=await S(v.prompt).catch(()=>v.prompt);await Gh({sessionId:v.sessionId,directory:v.worktreePath,content:j,providerID:v.providerID,modelID:v.modelID,variant:v.variant,agent:o,files:w})}catch(j){console.warn("[MultiRun] Failed to start run:",j)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:h,firstSessionId:N}}catch(l){return t({error:l instanceof Error?l.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),TS="oc:lastWorktreeSourceBranch";function Hm(t){const e=gt.c(30),{git:n}=Wn(),r=Du(t),o=zl(t),i=Wl(t),c=Yh(t),l=_s(LS),u=_s(FS);let m,d;e[0]!==t||e[1]!==u||e[2]!==n||e[3]!==o||e[4]!==i?(m=()=>{!t||!n||o!==null||i||u(t,n,{silent:!0})},d=[t,n,u,o,i],e[0]=t,e[1]=u,e[2]=n,e[3]=o,e[4]=i,e[5]=m,e[6]=d):(m=e[5],d=e[6]),a.useEffect(m,d);let f;e[7]!==r?.all||e[8]!==t||e[9]!==l||e[10]!==n||e[11]!==o?(f=()=>{!t||!n||o===!0&&(r?.all||l(t,n))},e[7]=r?.all,e[8]=t,e[9]=l,e[10]=n,e[11]=o,e[12]=f):f=e[12];const g=r?.all;let x;e[13]!==t||e[14]!==l||e[15]!==n||e[16]!==o||e[17]!==g?(x=[t,n,o,g,l],e[13]=t,e[14]=l,e[15]=n,e[16]=o,e[17]=g,e[18]=x):x=e[18],a.useEffect(f,x);const p=i||o===!0&&c;let y;e:{if(!r?.all){let k;e[19]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[19]=k):k=e[19],y=k;break e}let j;e[20]!==r.all?(j=r.all.filter(MS).sort(),e[20]=r.all,e[21]=j):j=e[21],y=j}const b=y;let h;e:{if(!r?.all){let k;e[22]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[22]=k):k=e[22],h=k;break e}let j;e[23]!==r.all?(j=r.all.filter(RS).map(ES).sort(),e[23]=r.all,e[24]=j):j=e[24],h=j}const N=h;let w;e:{if(!t){w=null;break e}if(o!==null){w=o;break e}if(p){w=null;break e}w=r?.all?!0:null}const S=w;let v;return e[25]!==S||e[26]!==p||e[27]!==b||e[28]!==N?(v={localBranches:b,remoteBranches:N,isLoading:p,isGitRepository:S},e[25]=S,e[26]=p,e[27]=b,e[28]=N,e[29]=v):v=e[29],v}function ES(t){return t.replace(/^remotes\//,"")}function RS(t){return t.startsWith("remotes/")}function MS(t){return!t.startsWith("remotes/")}function FS(t){return t.fetchStatus}function LS(t){return t.fetchBranches}const OS=({directory:t,value:e,onChange:n,className:r,disabled:o,id:i})=>{const{t:c}=Tt(),{localBranches:l,remoteBranches:u,isLoading:m,isGitRepository:d}=Hm(t),f=a.useMemo(()=>[...l,...u.map(x=>`remotes/${x}`)],[l,u]);a.useEffect(()=>{if(o||m||f.length===0||e&&f.includes(e))return;(async()=>{try{const p=t?await wa(t).catch(()=>null):null,y=localStorage.getItem(TS);y&&f.includes(y)?n(y):p&&f.includes(p)?n(p):f.includes("main")?n("main"):f.includes("master")?n("master"):f[0]&&n(f[0])}catch{}})()},[f,t,o,m,n,e]);const g=o||!d||m;return s.jsxs("div",{children:[s.jsxs(Bn,{value:e,onValueChange:n,disabled:g,children:[s.jsx(Vn,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(Pn,{placeholder:c(m?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx($n,{className:"max-h-[280px] max-w-[320px]",children:m?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.loadingBranches")}):l.length===0&&u.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[l.length>0&&s.jsxs(ul,{children:[s.jsx(Cc,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),l.map(x=>s.jsx(qs,{value:x,className:"whitespace-normal break-all",children:x},x))]}),l.length>0&&u.length>0&&s.jsx(Jh,{}),u.length>0&&s.jsxs(ul,{children:[s.jsx(Cc,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),u.map(x=>s.jsx(qs,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),d===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},_S=10*1024*1024,tl=5,Ko=t=>{const e=gt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let o;return e[1]!==n?(o=s.jsxs(Lt,{children:[r,s.jsx(_t,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=o):o=e[2],o},di=t=>{const e=gt.c(9),{htmlFor:n,required:r,children:o,info:i}=t;let c;e[0]!==r?(c=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=c):c=e[1];let l;e[2]!==o||e[3]!==n||e[4]!==c?(l=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,c]}),e[2]=o,e[3]=n,e[4]=c,e[5]=l):l=e[5];const u=i&&i;let m;return e[6]!==l||e[7]!==u?(m=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,u]}),e[6]=l,e[7]=u,e[8]=m):m=e[8],m},BS=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=Tt(),[i,c]=a.useState(""),[l,u]=a.useState(()=>[{id:uo(),prompt:"",models:[]}]),[m,d]=a.useState(""),[f,g]=a.useState([]),[x,p]=a.useState(!1),[y,b]=a.useState([]),[h,N]=a.useState(!1),[w,S]=a.useState(!1),[v,j]=a.useState(!0),k=a.useRef(null),D=sn(B=>B.currentDirectory??null),T=sn(B=>B.homeDirectory??null),C=a.useMemo(()=>{if(typeof window>"u")return null;const B=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof B=="string"&&B.trim().length>0?B.trim():null},[]),P=Es(B=>B.activeProjectId),E=Es(B=>B.setActiveProjectIdOnly),M=Es(B=>B.projects),[H,R]=a.useState(()=>P??null);a.useEffect(()=>{if(P){R(P);return}!H&&M.length>0&&R(M[0].id)},[P,M,H]);const _=a.useMemo(()=>H?M.find(B=>B.id===H)??null:null,[M,H]),z=_?.path??D,V=a.useCallback(B=>{R(B),B!==P&&E(B)},[P,E]),{currentTheme:F}=Tr(),te=a.useCallback(B=>{const ye=B.label?.trim()||wi(B.path,T),Oe=B.icon?Yl[B.icon]:null,Q=B.color?Sa[B.color]:void 0,Me=Oe?s.jsx(I,{name:Oe,className:"h-3.5 w-3.5 shrink-0",style:Q?{color:Q}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Q?{color:Q}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[B.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:B.iconBackground?{backgroundColor:B.iconBackground}:void 0,children:s.jsx(Na,{project:{id:B.id,iconImage:B.iconImage??null},options:{themeVariant:F.metadata.variant,iconColor:F.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Me})}):Me,s.jsx("span",{className:"truncate",children:ye})]})},[T,F.metadata.variant,F.colors.surface.foreground]),Z=a.useMemo(()=>{if(_?.path)return{id:_.id,path:_.path};const B=D??C;return B?{id:`path:${B}`,path:B}:null},[_,D,C]),[ne]=a.useState(()=>typeof window<"u"?lr():!1),U=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ie=wu(),oe=a.useMemo(()=>{if(typeof window>"u")return null;const B=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof B=="number"&&Number.isFinite(B)&&B>0)return B;if(typeof navigator>"u")return null;const ye=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ye)return null;const Oe=Number.parseInt(ye[1],10),Q=Number.parseInt(ye[2],10);return Number.isNaN(Oe)?null:Oe===10?Q:Oe},[]),ge=a.useMemo(()=>ne&&U||ie?"pl-[5.5rem]":"pl-3",[ne,U,ie]),je=a.useMemo(()=>!ne||!U||oe===null?"":oe>=26?"h-12":oe<=15?"h-14":"",[ne,U,oe]),Se=a.useCallback(async B=>{B.target.closest("button, a, input, select, textarea")||B.button===0&&ne&&await Qh()},[ne]);a.useEffect(()=>{if(!n)return;const B=ye=>{ye.key==="Escape"&&(ye.preventDefault(),ye.stopPropagation(),n())};return window.addEventListener("keydown",B,!0),()=>window.removeEventListener("keydown",B,!0)},[n]);const[re,L]=a.useState(""),{isLoading:$,isGitRepository:q}=Hm(z),he=a.useRef(!1),de=q===!0,we=de&&v;a.useEffect(()=>{if(q===!1){he.current=!0,j(!1);return}q===!0&&he.current&&(he.current=!1,j(!0))},[q]);const be=el(B=>B.createMultiRun),De=el(B=>B.error),le=el(B=>B.clearError);a.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&u(B=>{const ye=[...B];return ye.length>0&&!ye[0].prompt.trim()&&(ye[0]={...ye[0],prompt:t}),ye})},[t]),a.useEffect(()=>{if(!Z)return;let B=!1;return S(!0),(async()=>{try{const ye=await Xh(Z);B||b(ye)}catch{}finally{B||S(!1)}})(),()=>{B=!0}},[Z]);const ke=a.useCallback((B,ye)=>{u(Oe=>Oe.map(Q=>Q.id===B?{...Q,...ye}:Q))},[]),ue=a.useCallback(B=>{u(ye=>ye.filter(Oe=>Oe.id!==B))},[]),ve=a.useCallback(()=>{u(B=>[...B,{id:uo(),prompt:"",models:[]}])},[]),G=async B=>{const ye=B.target.files;if(!ye)return;let Oe=0;for(let Q=0;Q<ye.length;Q++){const Me=ye[Q];if(Me.size>_S){ae.error(o("multirun.launcher.toast.fileTooLarge",{fileName:Me.name}));continue}try{const Re=await new Promise((Ne,Be)=>{const se=new FileReader;se.onload=()=>Ne(se.result),se.onerror=Be,se.readAsDataURL(Me)});g(Ne=>[...Ne,{id:uo(),filename:Me.name,mimeType:Me.type||"application/octet-stream",size:Me.size,dataUrl:Re}]),Oe++}catch(Re){console.error("File attach failed",Re),ae.error(o("multirun.launcher.toast.attachFailed",{fileName:Me.name}))}}Oe>0&&ae.success(Oe===1?o("multirun.launcher.toast.attachedSingle",{count:Oe}):o("multirun.launcher.toast.attachedPlural",{count:Oe})),k.current&&(k.current.value="")},Ae=B=>{g(ye=>ye.filter(Oe=>Oe.id!==B))},ce=a.useMemo(()=>l.reduce((B,ye)=>B+ye.models.length,0),[l]),fe=async B=>{B.preventDefault();const ye=l.filter(Oe=>Oe.prompt.trim()&&Oe.models.length>=1);if(ye.length!==0&&!(ce<1)){p(!0),le();try{H&&H!==P&&E(H);const Oe=f.map(Be=>({mime:Be.mimeType,filename:Be.filename,url:Be.dataUrl})),Q=y.filter(Be=>Be.trim().length>0),Me=ye.map(Be=>({prompt:Be.prompt.trim(),models:Be.models.map(se=>({providerID:se.providerID,modelID:se.modelID,displayName:se.displayName,variant:se.variant}))})),Re={name:i.trim(),groups:Me,agent:m||void 0,worktreeBaseBranch:we?re:void 0,isolateRuns:we,files:Oe.length>0?Oe:void 0,setupCommands:Q.length>0?Q:void 0},Ne=await be(Re);Ne&&(Ne.firstSessionId&&vt.getState().setCurrentSession(Ne.firstSessionId),e?.())}finally{p(!1)}}},Ee=!!(i.trim()&&l.some(B=>B.prompt.trim()&&B.models.length>=1)&&ce>=1&&z&&!$&&(q===!1||!we||re)),me=y.filter(B=>B.trim()).length;return s.jsxs("form",{onSubmit:fe,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:Se,className:Te("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",ge,je),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:o("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":o("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})}),s.jsx(_t,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(ba,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(di,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),M.length>0?s.jsxs(Bn,{value:H??void 0,onValueChange:V,children:[s.jsx(Vn,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:_?s.jsx(Pn,{children:te(_)}):s.jsx(Pn,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx($n,{fitContent:!0,children:M.map(B=>s.jsx(qs,{value:B.id,className:"max-w-[24rem]",children:te(B)},B.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:o("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(di,{htmlFor:"group-name",required:!0,info:s.jsx(Ko,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(kn,{id:"group-name",value:i,onChange:B=>c(B.target.value),placeholder:o("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(di,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Ko,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(OS,{directory:z,value:re,onChange:L,disabled:!we,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(yi,{checked:v,onChange:j,disabled:!de,ariaLabel:o("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:o("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(di,{htmlFor:"multirun-agent",info:s.jsx(Ko,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(Bm,{value:m,onChange:d,id:"multirun-agent"})]})]}),s.jsxs($i,{open:h,onOpenChange:N,children:[s.jsxs(jo,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(I,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:o("multirun.launcher.setupCommands.label")}),me>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:me}),s.jsx(I,{name:"arrow-down-s",className:Te("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx(zi,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:w?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:o("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[y.map((B,ye)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(kn,{value:B,onChange:Oe=>{const Q=[...y];Q[ye]=Oe.target.value,b(Q)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>b(y.filter((Oe,Q)=>Q!==ye)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":o("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]},`${B}-${ye}`)),s.jsxs("button",{type:"button",onClick:()=>b([...y,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(I,{name:"add",className:"h-3 w-3"}),o("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(di,{htmlFor:"prompt",required:!0,children:o("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:k,type:"file",multiple:!0,className:"hidden",onChange:G,accept:"*/*"}),s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>k.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(I,{name:"attachment-2",className:"h-3 w-3"}),o("multirun.launcher.attachments.attach")]})}),s.jsx(_t,{children:o("multirun.launcher.attachments.tooltip")})]}),f.map(B=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[B.mimeType.startsWith("image/")?s.jsx(I,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(I,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:B.filename,children:B.filename}),s.jsx("button",{type:"button",onClick:()=>Ae(B.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(I,{name:"close",className:"h-3 w-3"})})]},B.id))]})]}),l.map((B,ye)=>s.jsx(VS,{group:B,groupIndex:ye,canRemove:l.length>1,onUpdate:ke,onRemove:ue},B.id)),s.jsxs("button",{type:"button",onClick:ve,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),o("multirun.launcher.groups.addGroup")]}),De&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:De})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!we&&q!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(I,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:o("multirun.launcher.project.gitRequired")})]}):null,s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:n,children:o("multirun.launcher.actions.cancel")}),s.jsx(ze,{type:"submit",size:"sm",disabled:!Ee||x,children:x?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:ce})})})]})})]})},VS=t=>{const e=gt.c(99),{group:n,groupIndex:r,canRemove:o,onUpdate:i,onRemove:c}=t,{t:l}=Tt(),[u,m]=a.useState(!1),[d,f]=a.useState(""),[g,x]=a.useState(!1),[p,y]=a.useState(""),[b,h]=a.useState(!1),[N,w]=a.useState(""),S=a.useRef(null),v=a.useRef(null),j=a.useRef(null),k=a.useRef(null);let D;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(D=Q=>{n.models.length>=tl||i(n.id,{models:[...n.models,Q]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=D):D=e[3];const T=D;let C;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(C=Q=>{i(n.id,{models:n.models.filter((Me,Re)=>Re!==Q)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=C):C=e[7];const P=C;let E;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(E=(Q,Me)=>{i(n.id,{models:n.models.map((Re,Ne)=>Ne===Q?Me:Re)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=E):E=e[11];const M=E;let H;e[12]===Symbol.for("react.memo_cache_sentinel")?(H=(Q,Me)=>{if(Q.startsWith("/")){const se=Q.indexOf(" "),O=Q.indexOf(`
206
- `),A=Math.min(se===-1?Q.length:se,O===-1?Q.length:O);if(Me<=A&&se===-1){y(Q.substring(1,A)),x(!0),m(!1),h(!1);return}}x(!1);const Re=Q.substring(0,Me),Ne=Re.lastIndexOf("#");if(Ne!==-1){const se=Ne>0?Re[Ne-1]:null,O=Re.substring(Ne+1);if((!se||/\s/.test(se))&&!O.includes(" ")&&!O.includes(`
207
- `)){w(O),h(!0),m(!1);return}}h(!1);const Be=Re.lastIndexOf("@");if(Be!==-1){const se=Be>0?Re[Be-1]:null,O=Re.substring(Be+1);(!se||/\s/.test(se))&&!O.includes(" ")&&!O.includes(`
208
- `)?(f(O),m(!0)):m(!1);return}m(!1)},e[12]=H):H=e[12];const R=H;let _;e[13]!==n.id||e[14]!==i?(_=Q=>{i(n.id,{prompt:Q})},e[13]=n.id,e[14]=i,e[15]=_):_=e[15];const z=_;let V;e[16]!==n.prompt||e[17]!==z?(V=Q=>{const Me=n.prompt,Ne=S.current?.selectionStart??Me.length,se=Me.substring(0,Ne).lastIndexOf("@"),O=Q.relativePath&&Q.relativePath.trim().length>0?Q.relativePath.trim():Q.path||Q.name,A=se!==-1?se:Ne,K=`${Me.substring(0,A)}@${O} ${Me.substring(Ne)}`,pe=A+O.length+2;z(K),m(!1),f(""),requestAnimationFrame(()=>{const _e=S.current;_e&&(_e.selectionStart=pe,_e.selectionEnd=pe,_e.focus()),R(K,pe)})},e[16]=n.prompt,e[17]=z,e[18]=V):V=e[18];const F=V;let te;e[19]!==n.prompt||e[20]!==z?(te=Q=>{const Me=n.prompt,Ne=S.current?.selectionStart??Me.length,se=Me.substring(0,Ne).lastIndexOf("@"),O=se!==-1?se:Ne,A=`${Me.substring(0,O)}@${Q} ${Me.substring(Ne)}`,K=O+Q.length+2;z(A),m(!1),f(""),requestAnimationFrame(()=>{const pe=S.current;pe&&(pe.selectionStart=K,pe.selectionEnd=K,pe.focus()),R(A,K)})},e[19]=n.prompt,e[20]=z,e[21]=te):te=e[21];const Z=te;let ne;e[22]!==z?(ne=Q=>{const Me=`/${Q.name} `;z(Me),x(!1),y(""),h(!1),requestAnimationFrame(()=>{const Re=S.current;Re&&(Re.focus(),Re.selectionStart=Re.value.length,Re.selectionEnd=Re.value.length),R(Me,Me.length)})},e[22]=z,e[23]=ne):ne=e[23];const U=ne;let ie;e[24]!==n.prompt||e[25]!==z?(ie=(Q,Me)=>{const Re=n.prompt,Be=S.current?.selectionStart??Re.length,O=Re.substring(0,Be).lastIndexOf("#"),A=O!==-1?O:Be,K=`${Re.substring(0,A)}#${Me} ${Re.substring(Be)}`,pe=A+Me.length+2;z(K),h(!1),w(""),requestAnimationFrame(()=>{const _e=S.current;_e&&(_e.selectionStart=pe,_e.selectionEnd=pe,_e.focus()),R(K,pe)})},e[24]=n.prompt,e[25]=z,e[26]=ie):ie=e[26];const oe=ie;let ge;e[27]!==g||e[28]!==u||e[29]!==b?(ge=Q=>{if(g&&j.current&&(Q.key==="Enter"||Q.key==="ArrowUp"||Q.key==="ArrowDown"||Q.key==="Escape"||Q.key==="Tab")){Q.preventDefault(),j.current.handleKeyDown(Q.key);return}u&&v.current&&(Q.key==="Enter"||Q.key==="ArrowUp"||Q.key==="ArrowDown"||Q.key==="Escape"||Q.key==="Tab")&&(Q.preventDefault(),v.current.handleKeyDown(Q.key)),b&&k.current&&(Q.key==="Enter"||Q.key==="ArrowUp"||Q.key==="ArrowDown"||Q.key==="Escape"||Q.key==="Tab")&&(Q.preventDefault(),k.current.handleKeyDown(Q.key))},e[27]=g,e[28]=u,e[29]=b,e[30]=ge):ge=e[30];const je=ge,Se=r+1;let re;e[31]!==l||e[32]!==Se?(re=l("multirun.launcher.groups.groupLabel",{index:Se}),e[31]=l,e[32]=Se,e[33]=re):re=e[33];let L;e[34]!==re?(L=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:re}),e[34]=re,e[35]=L):L=e[35];let $;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==l?($=o&&s.jsx("button",{type:"button",onClick:()=>c(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":l("multirun.launcher.groups.removeGroup"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=o,e[37]=n.id,e[38]=c,e[39]=l,e[40]=$):$=e[40];let q;e[41]!==L||e[42]!==$?(q=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[L,$]}),e[41]=L,e[42]=$,e[43]=q):q=e[43];let he;e[44]!==l?(he=l("multirun.launcher.groups.prompt.label"),e[44]=l,e[45]=he):he=e[45];let de;e[46]!==he?(de=s.jsx(di,{required:!0,children:he}),e[46]=he,e[47]=de):de=e[47];const we=n.prompt;let be;e[48]!==z?(be=Q=>{const Me=Q.target.value;z(Me);const Re=Q.target.selectionStart??Me.length;R(Me,Re)},e[48]=z,e[49]=be):be=e[49];let De;e[50]!==l?(De=l("multirun.launcher.groups.prompt.placeholder"),e[50]=l,e[51]=De):De=e[51];let le;e[52]!==n.prompt||e[53]!==je||e[54]!==be||e[55]!==De?(le=s.jsx(fi,{ref:S,value:we,onChange:be,onKeyDown:je,placeholder:De,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=je,e[54]=be,e[55]=De,e[56]=le):le=e[56];let ke;e[57]!==p||e[58]!==U||e[59]!==g?(ke=g?s.jsx(Lu,{ref:j,searchQuery:p,onCommandSelect:U,onClose:()=>x(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=p,e[58]=U,e[59]=g,e[60]=ke):ke=e[60];let ue;e[61]!==Z||e[62]!==F||e[63]!==d||e[64]!==u?(ue=u?s.jsx(Ou,{ref:v,searchQuery:d,onFileSelect:F,onAgentSelect:Z,onClose:()=>m(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=Z,e[62]=F,e[63]=d,e[64]=u,e[65]=ue):ue=e[65];let ve;e[66]!==oe||e[67]!==b||e[68]!==N?(ve=b?s.jsx(_u,{ref:k,searchQuery:N,onSnippetSelect:oe,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=oe,e[67]=b,e[68]=N,e[69]=ve):ve=e[69];let G;e[70]!==le||e[71]!==ke||e[72]!==ue||e[73]!==ve?(G=s.jsxs("div",{className:"relative",children:[le,ke,ue,ve]}),e[70]=le,e[71]=ke,e[72]=ue,e[73]=ve,e[74]=G):G=e[74];let Ae;e[75]!==de||e[76]!==G?(Ae=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[de,G]}),e[75]=de,e[76]=G,e[77]=Ae):Ae=e[77];let ce;e[78]!==l?(ce=l("multirun.launcher.models.info",{max:tl}),e[78]=l,e[79]=ce):ce=e[79];let fe;e[80]!==ce?(fe=s.jsx(Ko,{children:ce}),e[80]=ce,e[81]=fe):fe=e[81];let Ee;e[82]!==l?(Ee=l("multirun.launcher.models.label"),e[82]=l,e[83]=Ee):Ee=e[83];let me;e[84]!==fe||e[85]!==Ee?(me=s.jsx(di,{required:!0,info:fe,children:Ee}),e[84]=fe,e[85]=Ee,e[86]=me):me=e[86];let B;e[87]!==n.models||e[88]!==T||e[89]!==P||e[90]!==M?(B=s.jsx($m,{selectedModels:n.models,onAdd:T,onRemove:P,onUpdate:M,minModels:1,maxModels:tl}),e[87]=n.models,e[88]=T,e[89]=P,e[90]=M,e[91]=B):B=e[91];let ye;e[92]!==me||e[93]!==B?(ye=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[me,B]}),e[92]=me,e[93]=B,e[94]=ye):ye=e[94];let Oe;return e[95]!==q||e[96]!==Ae||e[97]!==ye?(Oe=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[q,Ae,ye]}),e[95]=q,e[96]=Ae,e[97]=ye,e[98]=Oe):Oe=e[98],Oe},$S=a.createContext(null),zS=t=>{const e=gt.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx($S.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},nu=vo(()=>Hi(()=>import("./TerminalView-D_ktT_L5.js"),__vite__mapDeps([5,1,2,0,3,4,6,7,8])).then(t=>({default:t.TerminalView}))),WS=vo(()=>Hi(()=>import("./NewWorktreeDialog-6y6rHfOQ.js").then(t=>t.a1),__vite__mapDeps([6,1,2,0,3,4,7])).then(t=>({default:t.SettingsView}))),US=vo(()=>Hi(()=>import("./SettingsWindow-Dll7W_Kd.js"),__vite__mapDeps([9,1,2,0,3,4,6,7])).then(t=>({default:t.SettingsWindow}))),HS=vo(()=>Hi(()=>import("./MultiRunWindow-BovvaCrr.js"),__vite__mapDeps([10,1,2,0,3,4,6,7,8])).then(t=>({default:t.MultiRunWindow}))),GS=280,KS=500,qS=360,YS=860,JS=()=>{const o=Fe(re=>re.isSidebarOpen),i=Fe(re=>re.isRightSidebarOpen),c=Fe(re=>re.isBottomTerminalOpen),l=Fe(re=>re.setRightSidebarOpen),u=Fe(re=>re.setBottomTerminalOpen),m=Fe(re=>re.activeMainTab),d=Fe(re=>re.setIsMobile),f=Fe(re=>re.isSessionSwitcherOpen),g=Fe(re=>re.isSettingsDialogOpen),x=Fe(re=>re.setSettingsDialogOpen),p=Fe(re=>re.isMultiRunLauncherOpen),y=Fe(re=>re.setMultiRunLauncherOpen),b=Fe(re=>re.multiRunLauncherPrefillPrompt),{isMobile:h,isTablet:N}=Pr(),w=Fe(re=>re.sidebarWidth),S=Fe(re=>re.rightSidebarWidth),v=a.useRef(!1),j=a.useRef(!1),k=a.useRef(!1),[D,T]=a.useState(!1),[C,P]=a.useState(!1),[E,M]=a.useState(!1),[H,R]=a.useState(!1),_=a.useCallback(re=>{T(re),Fe.getState().setSessionSwitcherOpen(re)},[]),z=a.useRef(!1),V=a.useRef(typeof window>"u"?0:window.innerWidth),F=uc(-V.current),te=et.useRef(0),Z=uc(V.current),ne=et.useRef(0);et.useEffect(()=>{h&&(te.current=window.innerWidth,ne.current=window.innerWidth)},[h]),et.useEffect(()=>{if(!h){M(!1);return}D&&M(!0),mc(F,D?0:-te.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[D,h,F]),et.useEffect(()=>{if(!h){R(!1);return}z.current=C,C&&R(!0),mc(Z,C?0:ne.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,C,Z]),et.useEffect(()=>{if(h)return F.on("change",re=>{const L=te.current||V.current,$=D||re>-L+.5;M(q=>q===$?q:$)})},[h,F,D]),et.useEffect(()=>{if(h)return Z.on("change",re=>{const L=ne.current||V.current,$=C||re<L-.5;R(q=>q===$?q:$)})},[h,C,Z]),et.useEffect(()=>{h&&!f&&D&&_(!1)},[f,h,D,_]),et.useEffect(()=>{if(!h){k.current=!1;return}k.current||(k.current=!0,_(!1),P(!1),Fe.getState().isRightSidebarOpen&&l(!1))},[h,_,l]),et.useEffect(()=>{if(!h||m!=="chat"||D||C||g)return;let re=!1,L;const $=q=>{L=window.setTimeout(()=>{if(re)return;const he=vt.getState(),de=Fe.getState();if(!(de.activeMainTab!=="chat"||de.isSettingsDialogOpen||he.currentSessionId||he.newSessionDraft?.open)){if(he.isLoading){$(250);return}he.openNewSessionDraft()}},q)};return $(500),()=>{re=!0,L!==void 0&&window.clearTimeout(L)}},[m,h,g,D,C]),et.useEffect(()=>{!h||!g||(_(!1),P(!1),i&&l(!1))},[h,g,i,_,l]);const U=Ei(re=>re.checkForUpdates);a.useEffect(()=>{let he=!1,de=null;const we=De=>{const le=Math.round(De*1e3);return Math.max(3e5,Math.min(864e5,le))},be=De=>{he||(de=window.setTimeout(async()=>{const le=await U(),ke=typeof le=="number"&&Number.isFinite(le)?we(le):36e5;be(ke)},De))};return be(3e3),()=>{he=!0,de!==null&&window.clearTimeout(de)}},[U]),a.useEffect(()=>{Fe.getState().isMobile!==h&&d(h)},[h,d]),a.useEffect(()=>{if(typeof window>"u")return;let re;const L=()=>{re===void 0&&(re=window.requestAnimationFrame(()=>{re=void 0,Fe.getState().updateProportionalSidebarWidths()}))};return window.addEventListener("resize",L),()=>{window.removeEventListener("resize",L),re!==void 0&&window.cancelAnimationFrame(re)}},[]),a.useEffect(()=>{if(typeof window>"u")return;let re;const L=()=>{const q=Fe.getState(),he=window.innerWidth,de=window.innerHeight;if(!h&&!N){const we=he<1140,be=he>=1220;we?q.isRightSidebarOpen&&(l(!1),v.current=!0):be&&v.current&&(l(!0),v.current=!1);const De=de<640,le=de>=700;De?q.isBottomTerminalOpen&&(u(!1),j.current=!0):le&&j.current&&(u(!0),j.current=!1)}},$=()=>{re===void 0&&(re=window.requestAnimationFrame(()=>{re=void 0,L()}))};return L(),window.addEventListener("resize",$),()=>{window.removeEventListener("resize",$),re!==void 0&&window.cancelAnimationFrame(re)}},[h,N,u,l]),a.useEffect(()=>{if(typeof window>"u")return;const re=Fe.subscribe((L,$)=>{const q=window.innerWidth,he=window.innerHeight,de=q>=1220,we=he>=700;L.isRightSidebarOpen!==$.isRightSidebarOpen&&de&&(v.current=!1),L.isBottomTerminalOpen!==$.isBottomTerminalOpen&&we&&(j.current=!1)});return()=>{re()}},[h,N,u,l]);const ie=a.useCallback(()=>{D&&_(!1),P(!C)},[D,C,_]),oe=a.useMemo(()=>{switch(m){case"plan":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(ym,{})});case"git":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(Sl,{})});case"diff":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(hm,{})});case"terminal":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(nu,{})});case"files":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(bm,{})});case"context":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(dm,{})});default:return null}},[m]),ge=m==="chat",je=a.useMemo(()=>Math.min(KS,Math.max(GS,w||yl)),[w]),Se=a.useMemo(()=>Math.min(YS,Math.max(qS,S||wl)),[S]);return s.jsx(qp,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:Te("main-content-safe-area",h?"flex h-[100dvh] flex-col":"flex h-[100dvh]","bg-background"),children:[s.jsx(I1,{}),s.jsx(gv,{}),s.jsx(wv,{}),s.jsx(AS,{}),h?s.jsxs(zS,{value:{leftDrawerOpen:D,rightDrawerOpen:C,toggleLeftDrawer:()=>{const re=!D;C&&P(!1),_(re)},toggleRightDrawer:ie,leftDrawerX:F,rightDrawerX:Z,leftDrawerWidth:te,rightDrawerWidth:ne,setMobileLeftDrawerOpen:_,setRightSidebarOpen:P},children:[!g&&s.jsx(Hc,{onToggleLeftDrawer:()=>{const re=!D;C&&P(!1),_(re)},onToggleRightDrawer:()=>{ie()},leftDrawerOpen:D,rightDrawerOpen:C}),s.jsx("div",{"data-page-scroll-lock":"true",className:Te("flex flex-1 overflow-hidden relative",g&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:Te("absolute inset-0",!ge&&"invisible"),children:s.jsx(an,{children:s.jsx(pl,{})})}),oe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(an,{children:oe})}),p&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(an,{children:s.jsx(BS,{initialPrompt:b,onCreated:()=>y(!1),onCancel:()=>y(!1)})})}),E&&s.jsx(fc.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:F},"aria-hidden":!D,children:s.jsx(an,{children:s.jsx(eu,{mobileVariant:!0})})}),H&&s.jsx(fc.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:Z},"aria-hidden":!C,children:s.jsx(an,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(Sl,{})})})})]})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(an,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(WS,{onClose:()=>x(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[s.jsx(Hc,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-sidebar","data-page-scroll-lock":"true",children:[s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute top-0 z-0 bg-sidebar transition-[left,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{left:`${o?je:0}px`,opacity:o?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-0 z-0 bg-sidebar transition-[left,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{left:`${o?je:0}px`,opacity:o?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute top-0 z-0 bg-sidebar transition-[right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{right:`${i?Se:0}px`,opacity:i?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-0 z-0 bg-sidebar transition-[right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{right:`${i?Se:0}px`,opacity:i?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}}),s.jsx(Yg,{isOpen:o,isMobile:h,className:"border-0",children:s.jsx(eu,{})}),s.jsxs("div",{className:Te("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-background","border border-border/50 rounded-[10px]",!o&&"border-l-transparent",!i&&"border-r-transparent"),"data-page-scroll-lock":"true",children:[s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:Te("absolute inset-0",!ge&&"invisible"),children:s.jsx(an,{children:s.jsx(pl,{})})}),oe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(an,{children:oe})})]}),s.jsx(D1,{})]})}),s.jsx(Ug,{isOpen:c,isMobile:h,children:c?s.jsx(an,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(nu,{})})}):null})]}),s.jsx(Jg,{isOpen:i,className:"border-0",children:s.jsx(an,{children:s.jsx(Iy,{})})})]})]}),s.jsx(a.Suspense,{fallback:null,children:s.jsx(US,{open:g,onOpenChange:x})}),s.jsx(a.Suspense,{fallback:null,children:s.jsx(HS,{open:p,onOpenChange:y,initialPrompt:b})})]})]})})},QS=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},Xn=t=>{const e=gt.c(8),{label:n,value:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=o):o=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let c;e[3]!==r?(c=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=c):c=e[4];let l;return e[5]!==i||e[6]!==c?(l=s.jsxs("div",{className:"rounded-md p-2",style:o,children:[i,c]}),e[5]=i,e[6]=c,e[7]=l):l=e[7],l},ru=t=>{const e=gt.c(43),{title:n,snapshot:r,emptyLabel:o}=t,{t:i}=Tt();let c;if(e[0]!==o||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const l=r.entries.slice(0,12);let u;e[8]!==r.entries?(u=r.entries.reduce(e2,0),e[8]=r.entries,e[9]=u):u=e[9];const m=u;let d;e[10]!==n?(d=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=d):d=e[11];let f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(f=r.startedAt?QS(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=f):f=e[15];let g;e[16]!==f?(g=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:f}),e[16]=f,e[17]=g):g=e[17];let x;e[18]!==d||e[19]!==g?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,g]}),e[18]=d,e[19]=g,e[20]=x):x=e[20];let p;e[21]!==i?(p=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=p):p=e[22];let y;e[23]!==r.entries.length||e[24]!==p?(y=s.jsx(Xn,{label:p,value:r.entries.length}),e[23]=r.entries.length,e[24]=p,e[25]=y):y=e[25];let b;e[26]!==i?(b=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=b):b=e[27];let h;e[28]!==b||e[29]!==m?(h=s.jsx(Xn,{label:b,value:m}),e[28]=b,e[29]=m,e[30]=h):h=e[30];let N;e[31]!==i?(N=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=N):N=e[32];let w;e[33]!==r.lastUpdatedAt||e[34]!==i?(w=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=w):w=e[35];let S;e[36]!==N||e[37]!==w?(S=s.jsx(Xn,{label:N,value:w}),e[36]=N,e[37]=w,e[38]=S):S=e[38];let v;e[39]!==h||e[40]!==S||e[41]!==y?(v=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[y,h,S]}),e[39]=h,e[40]=S,e[41]=y,e[42]=v):v=e[42],c=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,v,l.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:o}):s.jsx(Fn,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:l.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=o,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=c}else c=e[7];return c},XS=t=>{const e=gt.c(101),{onClose:n}=t,{t:r}=Tt(),[o,i]=a.useState("memory"),[c,l]=a.useState("idle"),u=vt(t2),m=Vu(s2),d=Gl(),f=Zh(n2),g=er(r2),[x,p]=a.useState(i2),[y,b]=a.useState(o2);let h;e[0]!==x.entries?(h=new Map,x.entries.forEach(ce=>{h.set(ce.metric,ce.count)}),e[0]=x.entries,e[1]=h):h=e[1];let N;e[2]!==h?(N=h.get("ui.message_list.render")??0,e[2]=h,e[3]=N):N=e[3];let w;e[4]!==h?(w=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=w):w=e[5];let S;e[6]!==h?(S=h.get("ui.chat_message.render")??0,e[6]=h,e[7]=S):S=e[7];let v;e[8]!==h?(v=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=v):v=e[9];let j;e[10]!==h?(j=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=j):j=e[11];let k;e[12]!==h?(k=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=k):k=e[13];let D;e[14]!==N||e[15]!==w||e[16]!==S||e[17]!==v||e[18]!==j||e[19]!==k?(D={messageListRender:N,messageListRenderStreaming:w,chatMessageRender:S,chatMessageRenderStreaming:v,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:k},e[14]=N,e[15]=w,e[16]=S,e[17]=v,e[18]=j,e[19]=k,e[20]=D):D=e[20];const T=D;let C,P;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const ce=()=>{p(Oo()),b(_o())};ce();const fe=window.setInterval(ce,500);return()=>window.clearInterval(fe)},P=[],e[21]=C,e[22]=P):(C=e[21],P=e[22]),a.useEffect(C,P);let E,M;e[23]!==c?(E=()=>{if(c==="idle")return;const ce=window.setTimeout(()=>{l("idle")},1500);return()=>window.clearTimeout(ce)},M=[c],e[23]=c,e[24]=E,e[25]=M):(E=e[24],M=e[25]),a.useEffect(E,M);let H=0,R;if(e[26]!==f?(R=Object.keys(f),e[26]=f,e[27]=R):R=e[27],e[28]!==f||e[29]!==R||e[30]!==H){for(const ce of R)H=H+(f[ce]?.length??0);e[28]=f,e[29]=R,e[30]=H,e[31]=H}else H=e[31];const _=H;let z;if(e[32]!==u||e[33]!==f||e[34]!==m||e[35]!==d||e[36]!==r){let ce;e[38]!==u||e[39]!==f||e[40]!==m||e[41]!==r?(ce=fe=>{const Ee=f[fe.id]?.length||0,me=m.get(fe.id);return{id:fe.id,title:fe.title||r("memoryDebugPanel.common.untitled"),messageCount:Ee,isStreaming:me?.isStreaming||!1,isZombie:me?.isZombie||!1,backgroundCount:me?.backgroundMessageCount||0,lastAccessed:me?.lastAccessedAt||0,isCurrent:fe.id===u}},e[38]=u,e[39]=f,e[40]=m,e[41]=r,e[42]=ce):ce=e[42],z=d.map(ce).sort(a2),e[32]=u,e[33]=f,e[34]=m,e[35]=d,e[36]=r,e[37]=z}else z=e[37];const V=z;let F;e[43]!==f?(F=Object.keys(f),e[43]=f,e[44]=F):F=e[44];const te=F.length;let Z;e[45]===Symbol.for("react.memo_cache_sentinel")?(Z=async()=>{try{const ce={generatedAt:new Date().toISOString(),ui:Oo(),vscode:_o()};await navigator.clipboard.writeText(JSON.stringify(ce,null,2)),l("copied")}catch{l("error")}},e[45]=Z):Z=e[45];const ne=Z;let U;e[46]===Symbol.for("react.memo_cache_sentinel")?(U={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=U):U=e[46];let ie;e[47]!==o?(ie=o==="memory"?s.jsx(I,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(I,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=o,e[48]=ie):ie=e[48];let oe;e[49]!==r?(oe=r("memoryDebugPanel.title"),e[49]=r,e[50]=oe):oe=e[50];let ge;e[51]!==oe?(ge=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:oe}),e[51]=oe,e[52]=ge):ge=e[52];let je;e[53]!==ie||e[54]!==ge?(je=s.jsxs("div",{className:"flex items-center gap-2",children:[ie,ge]}),e[53]=ie,e[54]=ge,e[55]=je):je=e[55];let Se;e[56]!==o?(Se=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ze,{size:"xs",variant:"ghost",onClick:ne,children:s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ze,{size:"xs",variant:"ghost",onClick:()=>{tp(),p(Oo()),b(_o())},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=o,e[57]=Se):Se=e[57];let re;e[58]!==n?(re=n?s.jsx(ze,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=re):re=e[59];let L;e[60]!==Se||e[61]!==re?(L=s.jsxs("div",{className:"flex items-center gap-1",children:[Se,re]}),e[60]=Se,e[61]=re,e[62]=L):L=e[62];let $;e[63]!==je||e[64]!==L?($=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[je,L]}),e[63]=je,e[64]=L,e[65]=$):$=e[65];let q;e[66]===Symbol.for("react.memo_cache_sentinel")?(q={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=q):q=e[66];const he=o==="memory"?"secondary":"ghost";let de;e[67]===Symbol.for("react.memo_cache_sentinel")?(de=()=>i("memory"),e[67]=de):de=e[67];let we;e[68]!==r?(we=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=we):we=e[69];let be;e[70]!==he||e[71]!==we?(be=s.jsx(ze,{size:"sm",variant:he,className:"flex-1",onClick:de,children:we}),e[70]=he,e[71]=we,e[72]=be):be=e[72];const De=o==="streaming"?"secondary":"ghost";let le;e[73]===Symbol.for("react.memo_cache_sentinel")?(le=()=>i("streaming"),e[73]=le):le=e[73];let ke;e[74]!==r?(ke=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ke):ke=e[75];let ue;e[76]!==De||e[77]!==ke?(ue=s.jsx(ze,{size:"sm",variant:De,className:"flex-1",onClick:le,children:ke}),e[76]=De,e[77]=ke,e[78]=ue):ue=e[78];let ve;e[79]!==be||e[80]!==ue?(ve=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:q,children:[be,ue]}),e[79]=be,e[80]=ue,e[81]=ve):ve=e[81];let G;e[82]!==o||e[83]!==te||e[84]!==c||e[85]!==u||e[86]!==f||e[87]!==m||e[88]!==V||e[89]!==d||e[90]!==T||e[91]!==x||e[92]!==r||e[93]!==g||e[94]!==_||e[95]!==y?(G=o==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(Xn,{label:r("memoryDebugPanel.metric.totalMessages"),value:_}),s.jsx(Xn,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${te} / ${Ac.MAX_SESSIONS}`})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:ep()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:Ac.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:g})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(Fn,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(ce=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:ce.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:ce.title}),ce.isStreaming?s.jsx(I,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,ce.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:ce.messageCount})}),ce.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",ce.backgroundCount]}):null]})]},ce.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Lt,{children:[s.jsx(Ot,{asChild:!0,children:s.jsx(ze,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:d.map(l2),currentSessionId:u,cachedSessions:Object.keys(f),memoryStates:Object.fromEntries(m)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(_t,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(c==="copied"?"memoryDebugPanel.streaming.copy.copied":c==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ze,{size:"xs",variant:"outline",onClick:ne,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(Xn,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(Xn,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:y.entries.length}),s.jsx(Xn,{label:r("memoryDebugPanel.metric.messageListRenders"),value:T.messageListRender}),s.jsx(Xn,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:T.messageListRenderStreaming}),s.jsx(Xn,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:T.chatMessageRender}),s.jsx(Xn,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:T.chatMessageRenderStreaming}),s.jsx(Xn,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:T.chatMessageRenderStaticDuringStream}),s.jsx(Xn,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:T.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(ru,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),y.entries.length>0?s.jsx(ru,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:y,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=o,e[83]=te,e[84]=c,e[85]=u,e[86]=f,e[87]=m,e[88]=V,e[89]=d,e[90]=T,e[91]=x,e[92]=r,e[93]=g,e[94]=_,e[95]=y,e[96]=G):G=e[96];let Ae;return e[97]!==$||e[98]!==ve||e[99]!==G?(Ae=s.jsxs(sp,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:U,children:[$,ve,G]}),e[97]=$,e[98]=ve,e[99]=G,e[100]=Ae):Ae=e[100],Ae},ZS=XS;function e2(t,e){return t+e.count}function t2(t){return t.currentSessionId}function s2(t){return t.sessionMemoryState}function n2(t){return t.message}function r2(t){return t.totalRequestCount}function i2(){return Oo()}function o2(){return _o()}function a2(t,e){return e.lastAccessed-t.lastAccessed}function l2(t){return{id:t.id,title:t.title}}const c2=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},d2=async()=>{const t=c2()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},iu="openchamber:menu-action",sl="openchamber:check-for-updates",u2=t=>{const e=vt(k=>k.openNewSessionDraft),n=Fe(k=>k.toggleCommandPalette),r=Fe(k=>k.setCommandPaletteOpen),o=Fe(k=>k.toggleHelpDialog),i=Fe(k=>k.toggleSidebar),c=Fe(k=>k.setSessionSwitcherOpen),l=Fe(k=>k.setActiveMainTab),u=Fe(k=>k.setSettingsDialogOpen),m=Fe(k=>k.setAboutDialogOpen),d=Fe(k=>k.toggleRightSidebar),f=Fe(k=>k.setRightSidebarOpen),g=Fe(k=>k.setRightSidebarTab),x=Fe(k=>k.toggleBottomTerminal),p=Fe(k=>k.setBottomTerminalExpanded),y=Ei(k=>k.checkForUpdates),{setThemeMode:b}=Tr(),h=a.useRef(!1),N=a.useCallback(()=>{h.current||(h.current=!0,y().then(()=>{const{available:k,error:D}=Ei.getState();if(D){ae.error("Failed to check for updates",{description:D});return}k||ae.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[y]),w=a.useCallback(()=>{Ir.requestDirectoryDialog()},[]),S=a.useCallback(k=>{const D=np();if(D.length===0)return;const T=vt.getState().currentSessionId,C=D.findIndex(M=>M.id===T);let P=k>0?0:D.length-1;C>=0&&(P=(C+k+D.length)%D.length);const E=D[P];E&&(l("chat"),c(!1),vt.getState().setCurrentSession(E.id))},[l,c]),v=a.useCallback(k=>{const{activeProjectId:D,projects:T,setActiveProject:C}=Es.getState();if(T.length===0)return;const P=T.findIndex(H=>H.id===D);let E=k>0?0:T.length-1;P>=0&&(E=(P+k+T.length)%T.length);const M=T[E];M&&C(M.id)},[]),j=a.useCallback(k=>{switch(k){case"about":m(!0);break;case"settings":u(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":l("chat"),c(!1),e();break;case"new-worktree-session":l("chat"),c(!1),Fu();break;case"change-workspace":w();break;case"toggle-right-sidebar":d();break;case"open-right-sidebar-git":f(!0),g("git");break;case"open-right-sidebar-files":f(!0),g("files");break;case"toggle-terminal":x();break;case"toggle-terminal-expanded":p(!Fe.getState().isBottomTerminalExpanded);break;case"copy":{const D=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(D)||d2();break}case"theme-light":b("light");break;case"theme-dark":b("dark");break;case"theme-system":b("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"go-back":sn.getState().goBack();break;case"go-forward":sn.getState().goForward();break;case"previous-session":S(-1);break;case"next-session":S(1);break;case"previous-project":v(-1);break;case"next-project":v(1);break;case"help-dialog":o();break;case"download-logs":{rp().catch(()=>{ae.error("Failed to collect OpenCode status")});break}}},[w,v,S,t,e,m,l,c,r,u,p,f,g,b,x,n,o,d,i]);a.useEffect(()=>{const k=T=>{const C=T.detail;C&&j(C)},D=()=>{N()};return window.addEventListener(iu,k),window.addEventListener(sl,D),()=>{window.removeEventListener(iu,k),window.removeEventListener(sl,D)}},[j,N]),a.useEffect(()=>{if(typeof window>"u")return;const D=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof D!="function")return;let T=null,C=null;return D("openchamber:menu-action",P=>{const E=P?.payload;typeof E=="string"&&j(E)}).then(P=>{T=P}).catch(()=>{}),D("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(sl))}).then(P=>{C=P}).catch(()=>{}),()=>{(async()=>{try{const E=T?.();E instanceof Promise&&await E}catch{}try{const E=C?.();E instanceof Promise&&await E}catch{}})()}},[j])},m2="/api/notifications/stream",f2=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),h2=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},p2=t=>{const e=gt.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||lr()||!ql()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(Oi().sse(m2));return i.onmessage=g2,()=>{i.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),a.useEffect(r,o)};function g2(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Fe.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&f2())return;const r=h2(e);if(!r)return;yo()?.notifications?.notifyAgentCompletion(r)}const x2=t=>!(t.dismissed==="true"||t.sessionShown==="true"||t.hasActiveToast),b2=t=>!(!t.version||t.seenVersions.has(t.version)||t.dismissedVersion!==null&&t.dismissedVersion===t.version),y2=t=>{if(t===null||typeof t!="object")return"";const e=t.version;return typeof e!="string"?"":e.trim()},w2=t=>!t||t.available!==!0||typeof t.latestVersion!="string"?"":t.latestVersion.trim(),ou="pwa-install-toast-shown",au="pwa-install-toast-dismissed",v2=()=>{const t=gt.c(6),{browserTab:e}=Yp(),{t:n}=Tt(),r=a.useRef(n);let o,i;t[0]!==n?(o=()=>{r.current=n},i=[n],t[0]=n,t[1]=o,t[2]=i):(o=t[1],i=t[2]),a.useEffect(o,i);let c,l;t[3]!==e?(c=()=>{if(typeof window>"u"||!ql()||!e)return;let u=null,m=null;const d=()=>{m!==null&&(ae.dismiss(m),m=null)},f=async()=>{if(!u)return;const p=u;u=null,d(),await p.prompt();const{outcome:y}=await p.userChoice;y==="accepted"&&ae.success(r.current("pwa.installPrompt.started"))},g=p=>{const y=p;if(typeof y.prompt!="function")return;y.preventDefault(),u=y;const b=Dr(),h=gu();x2({dismissed:b.getItem(au),sessionShown:h.getItem(ou),hasActiveToast:m!==null})&&(h.setItem(ou,"true"),m=ae.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{f()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Dr().setItem(au,"true"),d()}}}))},x=()=>{u=null,d(),ae.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",g),window.addEventListener("appinstalled",x),()=>{d(),window.removeEventListener("beforeinstallprompt",g),window.removeEventListener("appinstalled",x)}},l=[e],t[3]=e,t[4]=c,t[5]=l):(c=t[4],l=t[5]),a.useEffect(c,l)},j2=()=>{const t=gt.c(3),[e,n]=a.useState(S2),{isUpdating:r}=e;let o,i;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>op(n),i=[],t[0]=o,t[1]=i):(o=t[0],i=t[1]),a.useEffect(o,i),!r)return null;let c;return t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:s.jsx(ja,{width:80,height:80,isAnimated:!0})}),t[2]=c):c=t[2],c};function S2(){return ip()}const N2=({open:t,onOpenChange:e})=>{const{t:n}=Tt(),r=!1,[o,i]=a.useState(null),[c,l]=a.useState(null),[u,m]=a.useState(!1),[d,f]=a.useState(!1),[g,x]=a.useState(null),[p,y]=a.useState(!1);a.useCallback(async()=>{},[g,u,r,n]),a.useEffect(()=>{if(!t)return;(async()=>{try{const N=await Rs("/api/system/info");if(N.ok){const w=await N.json();if(typeof w.openchamberVersion=="string"&&w.openchamberVersion.trim()){i(w.openchamberVersion);return}}}catch{}i(await ap())})()},[t]),a.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const w=await Rs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!w.ok)return;const S=await w.json().catch(()=>null),v=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!h&&v&&l(v)}catch{}})(),()=>{h=!0}},[t]),a.useEffect(()=>{{x(null),y(!1);return}},[t,r]);const b=o;return s.jsx(Ks,{open:t,onOpenChange:e,children:s.jsx(Gs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(ja,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[b&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:b})}),c&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:c})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},nl=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},k2=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to OpenChamber and click Authorize again.":n},C2=()=>{const t=so(i=>i.completeAuth),[e,n]=a.useState("working"),[r,o]=a.useState("Completing MCP authorization...");return a.useEffect(()=>{if(typeof window>"u"){n("error"),o("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),c=nl(i,"code"),l=Jp(i),u=Qp(i),m=nl(i,"error"),d=nl(i,"error_description");if(m){u&&Rs(`/api/mcp/auth/pending?state=${encodeURIComponent(u)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(d??m);return}(async()=>{try{if(!c)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let f=l;if(!f&&u){const g=await Rs(`/api/mcp/auth/pending?state=${encodeURIComponent(u)}`);if(g.ok){const x=await g.json().catch(()=>null);x?.name?.trim()&&(f={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!f?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(f.name,c,f.directory),u&&await Rs(`/api/mcp/auth/pending?state=${encodeURIComponent(u)}`,{method:"DELETE"}).catch(()=>{}),n("success"),o("Authorization completed. You can close this tab and return to OpenChamber.")}catch(f){u&&await Rs(`/api/mcp/auth/pending?state=${encodeURIComponent(u)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(k2(f,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(ze,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},to="opencode-update-available",Fo="opencode-upgrade-progress",A2=5e3,D2=[1e4,6e4],lu="opencode-update-toast-dismissed-version",Gm=()=>{const{t}=Tt(),e=Fe(c=>c.showOpenCodeUpdateNotifications),n=et.useRef(new Set),r=et.useRef(!1);et.useEffect(()=>{e||ae.dismiss(to)},[e]);const o=et.useCallback(()=>{ae.dismiss(Fo),lp({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=et.useCallback(async()=>{if(!r.current){r.current=!0,ae.dismiss(to),ae.message(t("opencodeUpdate.toast.upgrading.title"),{id:Fo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(I,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const c=await Rs("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),l=await c.json().catch(()=>null);if(!c.ok||l?.success===!1)throw new Error(l?.error||c.statusText||t("opencodeUpdate.toast.failed.description"));ae.success(t("opencodeUpdate.toast.updated.title"),{id:Fo,description:l?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:l.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(I,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:o}})}catch(c){ae.error(t("opencodeUpdate.toast.failed.title"),{id:Fo,description:c instanceof Error?c.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[o,t]);return et.useEffect(()=>{const c=f=>{if(!Fe.getState().showOpenCodeUpdateNotifications){ae.dismiss(to);return}b2({version:f,dismissedVersion:Dr().getItem(lu),seenVersions:n.current})&&(n.current.add(f),ae.info(t("opencodeUpdate.toast.available.title"),{id:to,description:t("opencodeUpdate.toast.available.description",{version:f}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:t("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{Dr().setItem(lu,f),ua({openCodeUpdateToastDismissedVersion:f}),ae.dismiss(to)}}}))},l=f=>{const g=y2(f.detail);c(g)};let u=!1;const m=[],d=async f=>{try{const g=await Rs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!g.ok)throw new Error(g.statusText||"OpenCode upgrade status check failed");const x=await g.json().catch(()=>null),p=w2(x);!u&&p&&c(p)}catch{const g=D2[f];!u&&g!==void 0&&m.push(setTimeout(()=>{d(f+1)},g))}};return e&&m.push(setTimeout(()=>{d(0)},A2)),window.addEventListener("openchamber:opencode-update-available",l),()=>{u=!0;for(const f of m)clearTimeout(f);window.removeEventListener("openchamber:opencode-update-available",l)}},[i,e,t]),null},cu=vo(()=>Hi(()=>import("./OnboardingScreen-B1Ft9kmW.js"),__vite__mapDeps([11,1,2,0,3,4])).then(t=>({default:t.OnboardingScreen}))),I2=()=>{const t=gt.c(3),e=Fe(F2),n=Fe(L2);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(N2,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},P2=t=>{const e=gt.c(21),{onRetry:n,isRetrying:r}=t,{t:o}=Tt();let i;e[0]!==o?(i=o("startup.initRecovery.title"),e[0]=o,e[1]=i):i=e[1];let c;e[2]!==i?(c=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let l;e[4]!==o?(l=o("startup.initRecovery.description"),e[4]=o,e[5]=l):l=e[5];let u;e[6]!==l?(u=s.jsx("p",{className:"typography-body text-muted-foreground",children:l}),e[6]=l,e[7]=u):u=e[7];let m;e[8]!==c||e[9]!==u?(m=s.jsxs("div",{className:"flex flex-col gap-2",children:[c,u]}),e[8]=c,e[9]=u,e[10]=m):m=e[10];let d;e[11]!==r||e[12]!==o?(d=o(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=o,e[13]=d):d=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==d?(f=s.jsx(ze,{type:"button",onClick:n,disabled:r,children:d}),e[14]=r,e[15]=n,e[16]=d,e[17]=f):f=e[17];let g;return e[18]!==m||e[19]!==f?(g=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[m,f]})}),e[18]=m,e[19]=f,e[20]=g):g=e[20],g},du=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",T2=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),o=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:o,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},E2=()=>typeof window>"u"?!1:window.location.pathname===Zp,R2=t=>{const e=gt.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,i=sn(O2),c=vt(_2),l=vt(B2),u=Ql(),m=a.useRef(null);let d;e[0]!==n.directory?(d=du(n.directory),e[0]=n.directory,e[1]=d):d=e[1];const f=d;let g;e[2]!==i?(g=du(i),e[2]=i,e[3]=g):g=e[3];const x=g;let p,y;if(e[4]!==x||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==l||e[11]!==u?(p=()=>{if(r||f&&x!==f)return;const v=`${f}
209
- ${n.sessionId}`;m.current===v&&c===n.sessionId||(m.current=v,l(n.sessionId,n.directory),u.ensureSessionRenderable(n.sessionId,!0))},y=[x,c,n.directory,n.sessionId,f,r,l,u],e[4]=x,e[5]=c,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=l,e[11]=u,e[12]=p,e[13]=y):(p=e[12],y=e[13]),a.useEffect(p,y),f&&x!==f)return null;let b;e[14]!==o?(b=s.jsx($u,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=b):b=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Gm,{}),e[16]=h):h=e[16];let N;e[17]!==n.readOnly?(N=s.jsx(pl,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=N):N=e[18];let w;e[19]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(zu,{}),e[19]=w):w=e[19];let S;return e[20]!==b||e[21]!==N?(S=s.jsxs(s.Fragment,{children:[b,h,N,w]}),e[20]=b,e[21]=N,e[22]=S):S=e[22],S};function M2({apis:t}){a.useEffect(()=>{cp("App:mounted"),dp()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=cs($=>$.initializeApp),n=cs($=>$.isInitialized),r=cs($=>$.isConnected),o=cs($=>$.providers.length),i=cs($=>$.agents.length),c=cs($=>$.loadProviders),l=cs($=>$.loadAgents),u=vt($=>$.error),m=vt($=>$.clearError),d=sn($=>$.currentDirectory),f=sn($=>$.setDirectory),g=sn($=>$.isSwitchingDirectory),[x,p]=a.useState(!1),y=bi($=>$.refreshStatus),[b,h]=a.useState(()=>t.runtime.isVSCode),[N,w]=a.useState(!0),[S,v]=a.useState(!1),[j,k]=a.useState(0),[D,T]=a.useState(0),[C,P]=a.useState(!1),E=Fe($=>$.wideChatLayoutEnabled),M=Fe($=>$.mobileKeyboardMode),H=a.useMemo(()=>lr(),[]),R=_l($=>$.setPlanModeEnabled),[_,z]=a.useState(()=>Dc()),[V,F]=a.useState(()=>{const $=Ic();return $!==null?Pc({isDesktopShell:!0,bootOutcome:$}):null}),te=a.useRef(!1),Z=a.useMemo(()=>T2(),[]),ne=!Z||N,U=a.useMemo(()=>E2(),[]);a.useEffect(()=>(Tc(x),()=>{Tc(!1)}),[x]),a.useEffect(()=>{up(M)},[M]),a.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),a.useEffect(()=>pu($=>{vt.getState().prepareForRuntimeSwitch($.previousRuntimeKey),Fe.getState().prepareForRuntimeSwitch($.previousRuntimeKey),mf(),zn.reconnectToRuntimeBaseUrl(),cs.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),Es.getState().resetForRuntimeSwitch(),vt.getState().restoreForRuntimeSwitch($.runtimeKey),Fe.getState().restoreForRuntimeSwitch($.runtimeKey),mp(),T(q=>q+1),v(!1),k(q=>q+1)}),[]),a.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",E),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[E]),a.useEffect(()=>(Ec(t),()=>Ec(null)),[t]),a.useEffect(()=>{Z||y(t.github,{force:!0})},[t.github,Z,y]),fp();const ie=_==="valid",oe=V?.screen==="main";a.useEffect(()=>{if(!hp({isDesktopShell:H,isInitialized:n,bootOutcomeKnown:ie,bootViewIsMain:oe}))return;const $=setTimeout(()=>{const q=document.getElementById("initial-loading");q&&(q.classList.add("fade-out"),setTimeout(()=>{q.remove()},300))},150);return()=>clearTimeout($)},[H,n,ie,oe]),a.useEffect(()=>{if(!H||_!=="malformed")return;const $=document.getElementById("initial-loading");$&&($.textContent="Desktop startup failed — please restart the app.")},[H,_]),a.useEffect(()=>{if(H)return;const $=setTimeout(()=>{const q=document.getElementById("initial-loading");q&&!n&&(q.classList.add("fade-out"),setTimeout(()=>{q.remove()},300))},5e3);return()=>clearTimeout($)},[H,n]),a.useEffect(()=>{let $=!1;return(async()=>{const he=await Rs("/health",{method:"GET"}).catch(()=>null);if(!he||!he.ok||$)return;const de=await he.json().catch(()=>null);if(!de||$)return;const we=de.planModeExperimentalEnabled;R(we===!0||we===1||we==="1"||we==="true")})(),()=>{$=!0}},[R]),a.useEffect(()=>{b||e()},[e,b]),a.useEffect(()=>{if(b||n)return;let $=!0,q,he=0;const de=10,we=1e3,be=async()=>{if(!$)return;if(he>=de){v(!0);return}const De=cs.getState();if(De.isInitialized){v(!1);return}he+=1,await De.initializeApp();const le=cs.getState();if(!$)return;if(le.isInitialized){v(!1);return}if(he>=de){v(!0);return}const ke=Math.min(we*Math.pow(2,he-1),16e3);q=setTimeout(be,ke)};return q=setTimeout(be,we),()=>{$=!1,q&&clearTimeout(q)}},[j,n,b]),a.useEffect(()=>{n&&v(!1)},[n]),a.useEffect(()=>{if(!S)return;const $=document.getElementById("initial-loading");$&&($.classList.add("fade-out"),setTimeout(()=>{$.remove()},300))},[S]),a.useEffect(()=>{if(b||!r||o>0&&i>0)return;let $=!0,q=0;const he=15,de=async()=>{const be=cs.getState();if(!(be.providers.length>0&&be.agents.length>0))try{be.providers.length===0&&await c({source:"startupRecovery"}),cs.getState().agents.length===0&&await l({source:"startupRecovery"})}catch{}};de();const we=setInterval(()=>{if($){if(++q>=he){clearInterval(we);return}de()}},2e3);return()=>{$=!1,clearInterval(we)}},[r,b,l,c,o,i]),a.useEffect(()=>{g||b||r&&zn.setDirectory(d)},[d,g,r,b]),a.useEffect(()=>{if(!Z||typeof window>"u")return;const $=de=>{const we=de?.visible===!0;w(we)},q=de=>{if(de.origin!==window.location.origin)return;const we=de.data;we?.type==="openchamber:embedded-visibility"&&$(we.payload)},he=window;return he.__openchamberSetEmbeddedVisibility=$,window.addEventListener("message",q),()=>{window.removeEventListener("message",q),he.__openchamberSetEmbeddedVisibility===$&&delete he.__openchamberSetEmbeddedVisibility}},[Z]),a.useEffect(()=>{!Z?.directory||b||d!==Z.directory&&f(Z.directory,{showOverlay:!1})},[d,Z,b,f]),a.useEffect(()=>{if(!Z||typeof window>"u")return;const $=q=>{q.storageArea===window.localStorage&&q.key==="ui-store"&&Fe.persist.rehydrate()};return window.addEventListener("storage",$),()=>{window.removeEventListener("storage",$)}},[Z]),a.useEffect(()=>{if(typeof window>"u")return;const $=q=>{const he=q.detail,de=typeof he?.sessionId=="string"?he.sessionId.trim():"";if(!de)return;const we=typeof he?.directory=="string"&&he.directory.trim().length>0?he.directory.trim():null;Fe.getState().setActiveMainTab("chat"),vt.getState().setCurrentSession(de,we)};return window.addEventListener("openchamber:open-session",$),()=>window.removeEventListener("openchamber:open-session",$)},[]),a.useEffect(()=>{if(typeof window>"u")return;const $=q=>{const he=q.detail,de=typeof he?.directory=="string"&&he.directory.trim().length>0?he.directory.trim():null,we=typeof he?.projectId=="string"&&he.projectId.trim().length>0?he.projectId.trim():null;Fe.getState().setActiveMainTab("chat"),Fe.getState().setSessionSwitcherOpen(!1),vt.getState().openNewSessionDraft({selectedProjectId:we,directoryOverride:de,preserveDirectoryOverride:!!de})};return window.addEventListener("openchamber:open-draft-session",$),()=>window.removeEventListener("openchamber:open-draft-session",$)},[]),a.useEffect(()=>{if(typeof window>"u")return;const $=q=>{const he=q.detail,de=typeof he?.projectPath=="string"?he.projectPath.trim():"";if(!de)return;const we=Es.getState(),be=we.projects.find(De=>De.path===de);be?we.setActiveProject(be.id):we.addProject(de)};return window.addEventListener("openchamber:open-project",$),()=>window.removeEventListener("openchamber:open-project",$)},[]),a.useEffect(()=>{typeof window>"u"||!n||g||te.current||(te.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,g]),pp({enabled:ne}),p2({enabled:ne}),v2(),gp(),Xp();const ge=a.useCallback(()=>{p($=>!$)},[]);u2(ge),a.useEffect(()=>{if(Z)return;const $=q=>{Vl(q)&&q.shiftKey&&!q.altKey&&(q.code==="KeyD"||q.key.toLowerCase()==="d")&&(q.preventDefault(),p(de=>!de))};return window.addEventListener("keydown",$,!0),()=>window.removeEventListener("keydown",$,!0)},[Z]),a.useEffect(()=>{Z||u&&setTimeout(()=>m(),5e3)},[m,Z,u]),a.useEffect(()=>{if(!H||_!=="not-injected")return;let $=!1,q=0;const he=200,de=2e3,we=50,be=()=>{if($)return;q++;const De=Dc();if(De!=="not-injected"){if($=!0,z(De),De==="valid"){const ke=Ic();ke&&F(Pc({isDesktopShell:!0,bootOutcome:ke}))}return}const le=Math.min(he*Math.pow(1.1,q),de);if(q>=we){const ke=document.getElementById("initial-loading");ke&&!ke.textContent?.includes("taking longer")&&(ke.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(be,le)};return window.setTimeout(be,he),()=>{$=!0}},[H,_]);const je=a.useCallback(async()=>{if(xp({isDesktopShell:lr(),isDesktopLocalOriginActive:mo()})){await bp();return}window.location.reload()},[]),Se=a.useCallback(async()=>{if(!C){v(!1),P(!0);try{await cs.getState().initializeApp()}finally{P(!1)}cs.getState().isInitialized||k($=>$+1)}},[C]),re=$=>{if($.screen==="recovery")return $.variant};if(H&&V&&V.screen!=="main"){if(V.screen==="chooser")return s.jsx(an,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(a.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(cu,{mode:"first-launch",onCliAvailable:je,onChooseRemote:()=>{}})})})});const $=re(V),q=V.screen==="recovery"&&"url"in V?V.url:void 0;return s.jsx(an,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(a.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(cu,{mode:"recovery",recoveryVariant:$,recoveryHostUrl:q,recoveryHostLabel:void 0,onCliAvailable:je})})})})}if(Z)return s.jsx(an,{children:s.jsx(Rc,{sdk:zn.getSdkClient(),directory:d||"",children:s.jsx(Mc,{apis:t,children:s.jsx(Fc,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(R2,{embeddedSessionChat:Z,isVSCodeRuntime:b,embeddedBackgroundWorkEnabled:ne})})})})},D)});if(U)return s.jsx(an,{children:s.jsx(C2,{})});if(S&&!n&&!b&&!Z)return s.jsx(an,{children:s.jsx(P2,{onRetry:()=>{Se()},isRetrying:C})});const L=!n&&!H;return s.jsx(an,{children:s.jsx(Rc,{sdk:zn.getSdkClient(),directory:d||"",children:s.jsx(Mc,{apis:t,children:s.jsx(yx,{children:s.jsx(yp,{children:s.jsx(Fc,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:H?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx($u,{embeddedBackgroundWorkEnabled:ne}),s.jsx(Gm,{}),s.jsx(JS,{}),s.jsx(zu,{}),!L&&s.jsxs(s.Fragment,{children:[s.jsx(j2,{}),s.jsx(I2,{}),x&&s.jsx(ZS,{onClose:()=>p(!1)})]})]})})})})})},D)})}function F2(t){return t.isAboutDialogOpen}function L2(t){return t.setAboutDialogOpen}function O2(t){return t.currentDirectory}function _2(t){return t.currentSessionId}function B2(t){return t.setCurrentSession}const V2=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();wp();vp().then(()=>{Promise.all([jp(),Sp()]).catch(t=>{console.error("[main] settings init failed:",t)}),Np(),kp(),Cp()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Km=document.getElementById("root");if(!Km)throw new Error("Root element not found");lf.createRoot(Km).render(s.jsx(et.StrictMode,{children:s.jsx(Ap,{children:s.jsx(Dp,{children:s.jsx(Ip,{children:s.jsx(Pp,{children:s.jsx(M2,{apis:V2})})})})})}));const J2=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{BS as M,J2 as m,Hs as u};
205
+ Now write the final fused answer.`,synthetic:!0}],directory:te??Hn.getDirectory()})}catch(V){console.error("[MultiRunFusion] Failed to start fusion",V),ae.error(r("multirun.fusion.toast.failed"))}finally{A(!1)}}};return s.jsx(Ks,{open:e,onOpenChange:n,children:s.jsxs(Gs,{className:"max-w-xl overflow-visible",children:[s.jsxs(Qs,{children:[s.jsx(Ys,{children:r("multirun.fusion.title")}),s.jsx(dn,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx(Um,{selectedModels:y,onAdd:R,onUpdate:(V,F)=>R(F),onRemove:()=>{b([]),g(""),p(""),N("")},maxModels:1,addButtonLabel:_,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:f?s.jsx(mo,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(zn,{value:h||"__default__",onValueChange:V=>N(V==="__default__"?"":V),children:[s.jsxs(Wn,{size:"lg",className:"h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5",children:[s.jsx(I,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(En,{children:V=>V==="__default__"?r("multirun.modelMultiSelect.variant.default"):V})]}),s.jsxs(Un,{fitContent:!0,portalToBody:!0,children:[s.jsx(qs,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map(V=>s.jsx(qs,{value:V,children:V},V))]})]}):null,s.jsx(zm,{value:w,onChange:S,portalToBody:!0,className:"h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:v.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:v.map(V=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(mo,{providerId:Go(V.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.session.title||V.session.id}),s.jsx("button",{type:"button",onClick:()=>j(F=>F.filter(te=>te.session.id!==V.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},V.session.id))})]}),s.jsxs(sr,{children:[s.jsx(ze,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(ze,{onClick:z,disabled:!H,children:r(k?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function uS(t){const e=pt.c(7);let n,r,o,i,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),o=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),c=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=o,e[3]=i,e[4]=c):(n=e[0],r=e[1],o=e[2],i=e[3],c=e[4]);let l;return e[5]!==t?(l=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,o,i,c]}),e[5]=t,e[6]=l):l=e[6],l}const Zd=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),mi=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(mi(n,e))return!0;return!1},Pl=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const i of t.children)if(Pl(i,e,n,r))return!0;return!1},mS=(t,e)=>{const n=t.node.session,r=e.node.session,o=n.id,i=r.id;if(o!==i||t.node.session!==e.node.session||Zd(t.node)!==Zd(e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket)return!1;if(t.currentSessionId!==e.currentSessionId){const d=mi(t.node,t.currentSessionId),f=mi(e.node,e.currentSessionId);if(d||f)return!1}if(t.pinnedSessionIds.has(o)!==e.pinnedSessionIds.has(i))return!1;{const d=t.renderContext??"project",f=e.renderContext??"project",g=t.archivedBucket??!1,x=e.archivedBucket??!1,p=`${d}:${g?"archived":"active"}:${o}`,y=`${f}:${x?"archived":"active"}:${i}`;if(t.expandedParents.has(p)!==e.expandedParents.has(y))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const d=mi(t.node,t.editingId),f=mi(e.node,e.editingId);if(d||f)return!1}if(t.editTitle!==e.editTitle){const d=mi(t.node,t.editingId),f=mi(e.node,e.editingId);if(d||f)return!1}if(t.copiedSessionId===o!=(e.copiedSessionId===i))return!1;const c=Pl(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),l=Pl(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(c!==l)return!1;const u=os(n.directory??null)??os(t.groupDirectory??null),m=os(r.directory??null)??os(e.groupDirectory??null);return!(u!==m||(u?t.directoryStatus.get(u):null)!==(m?e.directoryStatus.get(m):null)||(t.secondaryMeta?.projectLabel??null)!==(e.secondaryMeta?.projectLabel??null)||(t.secondaryMeta?.branchLabel??null)!==(e.secondaryMeta?.branchLabel??null)||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||(t.renderContext??"project")!==(e.renderContext??"project")||t.renamingFolderId!==e.renamingFolderId)};function fS(t){const{t:e}=Tt(),{node:n,depth:r=0,groupDirectory:o,projectId:i,archivedBucket:c=!1,directoryStatus:l,currentSessionId:u,pinnedSessionIds:m,expandedParents:d,hasSessionSearchQuery:f,normalizedSessionSearchQuery:g,notifyOnSubtasks:x,editingId:p,setEditingId:y,editTitle:b,setEditTitle:h,handleSaveEdit:N,handleCancelEdit:w,toggleParent:S,handleSessionSelect:v,handleSessionDoubleClick:j,togglePinnedSession:k,handleShareSession:A,copiedSessionId:T,handleCopyShareUrl:C,handleUnshareSession:P,openSidebarMenuKey:E,setOpenSidebarMenuKey:M,renamingFolderId:H,getFoldersForScope:R,getSessionFolderId:_,removeSessionFromFolder:z,addSessionToFolder:V,createFolderAndStartRename:F,openContextPanelTab:te,handleDeleteSession:Z,mobileVariant:ne,alwaysShowActions:U,renderSessionNode:ie,secondaryMeta:oe,renderContext:pe="project"}=t,je=!!oe?.projectLabel,Se=!!oe?.branchLabel,L=Ar(W=>W.displayMode)==="minimal",$=a.useMemo(()=>Hi(),[]),K=a.useMemo(()=>_l(),[]),he=a.useContext(Nh),de=$?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",we=$?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",xe=$,De=!c&&!ne,le=L?$?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":$?De&&xe?"group-hover:pr-18":De||xe?"group-hover:pr-12":"group-hover:pr-5":De?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",Ce=De?"pr-13":"pr-7",ue=a.useRef(!1),[ve,G]=a.useState(!1),Ae=a.useRef(p);Ae.current=p;const ce=a.useRef(null),fe=a.useRef(N);fe.current=N;const Te=a.useRef(null),me=n.session,ye=ju(me.id)??me,_e=os(me.directory??null)??os(o??null),J=kh(_e??void 0),Me=Xl(),Ee=er(W=>W.enabled),Ne=er(a.useCallback(W=>W.selectedIds.has(me.id),[me.id])),Be=er(W=>W.toggleSelected),se=er(W=>W.setRange),O=a.useCallback(W=>{const Ge=[],Xe=ht=>{ht.children.forEach(Nt=>{Ge.push(Nt.session.id),Xe(Nt)})};return Xe(W),Ge},[]),[D,Y]=a.useState(!1),[be,Oe]=a.useState(!0),$e=`${pe}:${c?"archived":"active"}:${me.id}`,Re=Wu(a.useCallback(W=>!!W.sessionMemoryState.get(Ch(me.id))?.isZombie,[me.id])),ot=Ah(me.id),yt=Dh(me.id,_e??void 0),mt=(_e?l.get(_e):null)==="missing",Le=u===me.id,Qe=ye.title||e("sessions.sidebar.session.untitled"),Ye=n.children.length>0,rt=m.has(me.id),bt=$e,ct=f?!0:d.has(bt),nt=!!ye.parentID,lt=Ih(me.id)>0&&(!nt||x),kt=ye.summary,Ke=ku(kt),tt=ye.time?.updated||ye.time?.created||Date.now(),We=Ph(tt),gt=Mh(tt),He=E===$e,st=a.useMemo(()=>Go(ye.title)!==null,[ye.title]),[Et,at]=a.useState(!1),dt=a.useMemo(()=>O(n).length,[O,n]),Ht=a.useCallback(async W=>{const Ge=[];let Xe=0;for(const ht of W)try{await Me.ensureSessionRenderable(ht.session.id);const Nt=Dc(J.getState(),ht.session.id).list,ut=ht.session.title||e("sessions.sidebar.session.export.untitledSubagent"),ss=ht.session.agent,bs=await Ht(ht.children);Xe+=bs.skipped,Ge.push({title:ut,agent:ss,records:Nt,children:bs.children})}catch{Xe+=O(ht).length+1}return{children:Ge,skipped:Xe}},[O,J,Me,e]),Rt=a.useCallback(W=>{W<=0||ae.warning(W===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:W}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:W}))},[e]),Wt=a.useCallback(async W=>{if(!_e){ae.error(e("sessions.sidebar.session.export.nothingToExport"));return}await Me.ensureSessionRenderable(me.id);const Ge=Dc(J.getState(),me.id).list;if(Ge.length===0){ae.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Xe,ht=0;if(W&&n.children.length>0){const bs=await Ht(n.children);Xe=bs.children,ht=bs.skipped}const Nt=$j(Ge,ye.title??null,Xe),ut=Gj(ye.title??null),ss=await Wj(Nt,ut);if(ss){ae.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Hj()),onClick:()=>{Uj(ss).then(bs=>{bs||ae.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Rt(ht);return}zj(Nt,ut),ae.success(e("sessions.sidebar.session.export.success")),Rt(ht)},[Ht,J,n.children,ye.title,me.id,_e,Rt,Me,e]),qt=a.useCallback(async()=>{if(n.children.length>0){Oe(!0),Y(!0);return}await Wt(!1)},[Wt,n.children.length]),Lt=a.useCallback(()=>{_e&&hi("desktop_open_session_mini_chat_window",{sessionId:me.id,directory:_e,apiBaseUrl:Xr(),clientToken:ll()}).catch(W=>{console.warn("[session-sidebar] failed to open mini chat window",W)})},[me.id,_e]);if(a.useEffect(()=>{if(p!==me.id)return;const W=Ge=>{Te.current&&!Te.current.contains(Ge.target)&&fe.current()};return document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[p,me.id]),p===me.id)return s.jsx("div",{className:Pe("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{ref:Te,className:"flex w-full items-center gap-2",onSubmit:W=>{W.preventDefault(),N()},children:[s.jsx("input",{value:b,onChange:W=>h(W.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:W=>{if(W.key==="Escape"){W.stopPropagation(),w();return}(W.key===" "||W.key==="Enter")&&W.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:w,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"size-4"})})]}),L?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[Ye?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:ct?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:We}),Ke?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Ke.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Ke.deletions]})]}):null,je?s.jsx("span",{className:"truncate",children:oe?.projectLabel}):null,Se?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:oe?.branchLabel})]}):null]})})]})},me.id);const Gt=ot?.type??"idle",Qt=Gt==="busy"||Gt==="retry",rs=yt.length,ft=Qt||!Qt&&lt&&!Le,Jt=Qt?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-busy-pulse","aria-label":e("sessions.sidebar.session.status.active"),title:e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),ms=ft||rt?s.jsxs("span",{className:Pe("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",L?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",ft&&rt?"left-[-18px] w-6":"left-[-10px] w-3.5",Ye&&!U?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[ft?Jt:null,rt?s.jsx(I,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,Xt=Ye?s.jsx("span",{role:"button",tabIndex:0,onClick:W=>{W.stopPropagation(),S(bt)},onKeyDown:W=>{(W.key==="Enter"||W.key===" ")&&(W.preventDefault(),W.stopPropagation(),S(bt))},className:Pe("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",L?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",L&&ft&&!U?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(ct?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:ct?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,ts=Re?s.jsx(I,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,ks=W=>{M(W?$e:null)},$t=W=>{if(!W&&ce.current){const{id:Ge,title:Xe}=ce.current;ce.current=null,y(Ge),h(Xe)}},as=W=>{W.preventDefault(),W.stopPropagation(),M(He?null:$e)},$s=W=>{W.preventDefault(),W.stopPropagation()},Ut=W=>{W.preventDefault(),W.stopPropagation()},Es=W=>{W.preventDefault(),W.stopPropagation()},Ls=W=>{W.preventDefault(),W.stopPropagation()},gs=W=>{W.preventDefault(),W.stopPropagation(),M(null),Z(me,{archivedBucket:c})},Cs=W=>{W.preventDefault(),W.stopPropagation()},Mt=W=>{W.preventDefault(),W.stopPropagation()},xt=W=>{W.preventDefault(),W.stopPropagation(),he?.vscode?.executeCommand("openchamber.openSessionInEditor",me.id,Qe)},Zt=W=>{if(ue.current){ue.current=!1;return}if(Ee){if(W?.preventDefault(),W?.stopPropagation(),W?.shiftKey){const Xe=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(ut=>ut.getAttribute("data-session-row")).filter(ut=>typeof ut=="string"&&ut.length>0),ht=er.getState().anchorId,Nt=new Map;Nt.set(me.id,O(n)),se(ht,me.id,Xe,_e??null,Nt);return}Be(me.id,_e??null,O(n));return}v(me.id,_e,mt,i)},Ft=W=>{(W.button===2||W.button===0&&W.ctrlKey&&!Ee)&&(ue.current=!0)},is=W=>{ne&&W.pointerType==="touch"&&G(!0)},es=W=>{ne&&W.pointerType==="touch"&&G(!1)},fs=s.jsxs(nn,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(H||Ae.current),children:[s.jsxs(zt,{onClick:()=>{ce.current={id:me.id,title:Qe}},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:()=>k(me.id),className:"[&>svg]:mr-1",children:[rt?s.jsx(I,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(I,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(rt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),ye.share?s.jsxs(s.Fragment,{children:[s.jsx(zt,{onClick:()=>{ye.share?.url&&C(ye.share.url,me.id)},className:"[&>svg]:mr-1",children:T===me.id?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(zt,{onClick:()=>P(me.id),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(zt,{onClick:()=>A(ye),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(zt,{onClick:()=>{qt()},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),st?s.jsxs(zt,{onClick:()=>at(!0),className:"[&>svg]:mr-1",children:[s.jsx(uS,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,_e&&!c?(()=>{const W=R(_e),Ge=_(_e,me.id);return s.jsxs(s.Fragment,{children:[s.jsx(On,{}),s.jsxs(Th,{children:[s.jsxs(Eh,{className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Rh,{className:"min-w-[180px]",children:[W.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):W.map(Xe=>s.jsxs(zt,{onClick:()=>{Ge===Xe.id?z(_e,me.id):V(_e,Xe.id,me.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Xe.name}),Ge===Xe.id?s.jsx(I,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Xe.id)),s.jsx(On,{}),s.jsxs(zt,{onClick:()=>{const Xe=F(_e);Xe&&V(_e,Xe.id,me.id)},children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Ge?s.jsxs(zt,{onClick:()=>{z(_e,me.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,$?null:s.jsxs(zt,{disabled:!_e,onClick:()=>{_e&&te(_e,{mode:"chat",dedupeKey:`session:${me.id}`,label:Qe})},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),K?s.jsxs(zt,{disabled:!_e,onClick:Lt,className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(On,{}),s.jsxs(zt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>Z(me,{archivedBucket:c}),children:[s.jsx(I,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(c?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(a.Fragment,{children:[s.jsx(ij,{sessionId:me.id,sessionDirectory:_e??null,sessionTitle:Qe,children:s.jsxs("div",{"data-session-row":me.id,"data-session-scope":_e??"","data-session-archived":c?"1":"0",className:Pe("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",mt?"opacity-75":"",r>0&&"pl-[20px]",Ne&&"bg-primary/15"),children:[ms,Xt,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:L?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",disabled:mt,onPointerDown:is,onPointerUp:es,onPointerCancel:es,onMouseDown:Ft,onClick:W=>Zt(W),onDoubleClick:W=>{W.stopPropagation(),j(me.id,Qe)},className:Pe("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ve&&"bg-interactive-hover/70",U?$?le:Ce:le),children:s.jsxs("div",{className:Pe("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:Pe("block min-w-0 flex-1 truncate typography-ui-label font-normal",Le?"text-primary":"text-foreground"),children:ro(Qe,g)}),U?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:gt}):null,U?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:Pe("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",He?"opacity-0":we),children:gt})}),rs>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:rs})]}):null]})})}),s.jsx(Bt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:Pe("flex items-center gap-3 text-left text-muted-foreground",oe?.projectLabel?"justify-between":"justify-start"),children:[oe?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:oe.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:We})]}),oe?.branchLabel||Ke?s.jsxs("div",{className:Pe("flex items-center gap-3 text-left text-muted-foreground",oe?.branchLabel?"justify-between":"justify-start"),children:[oe?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:oe.branchLabel})]})}):null,Ke?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Ke.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Ke.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:mt,onPointerDown:is,onPointerUp:es,onPointerCancel:es,onMouseDown:Ft,onClick:W=>Zt(W),onDoubleClick:W=>{W.stopPropagation(),j(me.id,Qe)},className:Pe("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ve&&"bg-interactive-hover/70",U?$?le:Ce:le),children:[s.jsxs("div",{className:Pe("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:Pe("block min-w-0 flex-1 truncate typography-ui-label font-normal",Le?"text-primary":"text-foreground"),children:ro(Qe,g)}),rs>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:rs})]}):null]}),L?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:We}),Ke?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Ke.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ke.deletions]})]}):null,je?s.jsx("span",{className:"truncate",children:oe?.projectLabel}):null,Se?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:oe?.branchLabel})]}):null]})})]})}),ts&&!ne?s.jsx("div",{className:Pe("absolute top-1/2 -translate-y-1/2 z-10",L?"right-0":"right-[30px]"),children:ts}):null,s.jsxs("div",{className:Pe("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",He||U&&!$?"opacity-100":Pe("opacity-0",de)),children:[De?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",L&&!U?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:Es,onMouseDown:Ls,onClick:gs,onKeyDown:W=>W.stopPropagation(),children:s.jsx(I,{name:"archive",className:Pe(L&&!U?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Bt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,xe?s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",L&&!U?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:Cs,onMouseDown:Mt,onClick:xt,onKeyDown:W=>W.stopPropagation(),children:s.jsx(I,{name:"external-link",className:Pe(L&&!U?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Bt,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(rn,{open:He,onOpenChange:ks,onOpenChangeComplete:$t,children:[s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",L&&!U?He?"h-4 w-4 opacity-100":Pe("h-4 w-4 opacity-0",de):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:$s,onMouseDown:Ut,onClick:as,onKeyDown:W=>W.stopPropagation(),children:s.jsx(I,{name:"more-2",className:Pe(L&&!U?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),fs]})]})]})}),Ye&&ct?n.children.map(W=>ie(W,r+1,_e??o,i,c,void 0,pe)):null,s.jsx(Ks,{open:D,onOpenChange:Y,children:s.jsxs(Gs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Qs,{children:[s.jsx(Ys,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(dn,{children:dt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:dt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:dt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:be,onChange:W=>Oe(W.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(sr,{children:[s.jsx(ze,{type:"button",onClick:()=>Y(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{type:"button",onClick:()=>{Y(!1),Wt(be)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),st?s.jsx(dS,{session:ye,open:Et,onOpenChange:at}):null]},me.id)}const hS=a.memo(fS,mS);function pS(t){const e=pt.c(71),{t:n}=Tt(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:l}=t;let u,m,d,f,g,x,p,y,b,h;if(e[0]!==o||e[1]!==n||e[2]!==r){const F=n("sessions.sidebar.session.untitled");f=Ks,b=!!r,e[13]!==o?(h=Z=>{Z||o(null)},e[13]=o,e[14]=h):h=e[14],d=Gs,p=!1,y="max-w-sm gap-5",m=Qs;let te;e[15]!==n||e[16]!==r?.archivedBucket?(te=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=te):te=e[17],e[18]!==te?(x=s.jsx(Ys,{children:te}),e[18]=te,e[19]=x):x=e[19],u=dn,g=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||F,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||F,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||F,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||F,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||F}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||F}),e[0]=o,e[1]=n,e[2]=r,e[3]=u,e[4]=m,e[5]=d,e[6]=f,e[7]=g,e[8]=x,e[9]=p,e[10]=y,e[11]=b,e[12]=h}else u=e[3],m=e[4],d=e[5],f=e[6],g=e[7],x=e[8],p=e[9],y=e[10],b=e[11],h=e[12];let N;e[20]!==u||e[21]!==g?(N=s.jsx(u,{children:g}),e[20]=u,e[21]=g,e[22]=N):N=e[22];let w;e[23]!==m||e[24]!==x||e[25]!==N?(w=s.jsxs(m,{children:[x,N]}),e[23]=m,e[24]=x,e[25]=N,e[26]=w):w=e[26];let S;e[27]!==c||e[28]!==i?(S=()=>c(!i),e[27]=c,e[28]=i,e[29]=S):S=e[29];const v=!i;let j;e[30]!==i?(j=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=j):j=e[31];let k;e[32]!==n?(k=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=k):k=e[33];let A;e[34]!==j||e[35]!==k||e[36]!==S||e[37]!==v?(A=s.jsxs("button",{type:"button",onClick:S,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":v,children:[j,k]}),e[34]=j,e[35]=k,e[36]=S,e[37]=v,e[38]=A):A=e[38];let T;e[39]!==o?(T=()=>o(null),e[39]=o,e[40]=T):T=e[40];let C;e[41]!==n?(C=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=C):C=e[42];let P;e[43]!==T||e[44]!==C?(P=s.jsx("button",{type:"button",onClick:T,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:C}),e[43]=T,e[44]=C,e[45]=P):P=e[45];let E;e[46]!==l?(E=()=>{l()},e[46]=l,e[47]=E):E=e[47];let M;e[48]!==n||e[49]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=M):M=e[50];let H;e[51]!==E||e[52]!==M?(H=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:M}),e[51]=E,e[52]=M,e[53]=H):H=e[53];let R;e[54]!==P||e[55]!==H?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[P,H]}),e[54]=P,e[55]=H,e[56]=R):R=e[56];let _;e[57]!==A||e[58]!==R?(_=s.jsxs(sr,{className:"w-full sm:items-center sm:justify-between",children:[A,R]}),e[57]=A,e[58]=R,e[59]=_):_=e[59];let z;e[60]!==d||e[61]!==p||e[62]!==_||e[63]!==y||e[64]!==w?(z=s.jsxs(d,{showCloseButton:p,className:y,children:[w,_]}),e[60]=d,e[61]=p,e[62]=_,e[63]=y,e[64]=w,e[65]=z):z=e[65];let V;return e[66]!==f||e[67]!==z||e[68]!==b||e[69]!==h?(V=s.jsx(f,{open:b,onOpenChange:h,children:z}),e[66]=f,e[67]=z,e[68]=b,e[69]=h,e[70]=V):V=e[70],V}function gS(t){const e=pt.c(57),{t:n}=Tt(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:l}=t,u=r?.archivedBucket===!0,m=r?.sessionCount??0;let d;e[0]!==u||e[1]!==m||e[2]!==n?(d=n(u?m===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":m===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=u,e[1]=m,e[2]=n,e[3]=d):d=e[3];const f=d;let g;e[4]!==u||e[5]!==m||e[6]!==n?(g=u?m===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:m}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:m}):m===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:m}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:m}),e[4]=u,e[5]=m,e[6]=n,e[7]=g):g=e[7];const x=g,p=!!r;let y;e[8]!==o?(y=V=>{V||o(null)},e[8]=o,e[9]=y):y=e[9];let b;e[10]!==f?(b=s.jsx(Ys,{children:f}),e[10]=f,e[11]=b):b=e[11];let h;e[12]!==x?(h=s.jsx(dn,{children:x}),e[12]=x,e[13]=h):h=e[13];let N;e[14]!==b||e[15]!==h?(N=s.jsxs(Qs,{children:[b,h]}),e[14]=b,e[15]=h,e[16]=N):N=e[16];let w;e[17]!==c||e[18]!==i?(w=()=>c(!i),e[17]=c,e[18]=i,e[19]=w):w=e[19];const S=!i;let v;e[20]!==i?(v=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=v):v=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let k;e[24]!==j||e[25]!==w||e[26]!==S||e[27]!==v?(k=s.jsxs("button",{type:"button",onClick:w,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[v,j]}),e[24]=j,e[25]=w,e[26]=S,e[27]=v,e[28]=k):k=e[28];let A;e[29]!==o?(A=()=>o(null),e[29]=o,e[30]=A):A=e[30];let T;e[31]!==n?(T=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=T):T=e[32];let C;e[33]!==A||e[34]!==T?(C=s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:T}),e[33]=A,e[34]=T,e[35]=C):C=e[35];let P;e[36]!==l?(P=()=>{l()},e[36]=l,e[37]=P):P=e[37];let E;e[38]!==u||e[39]!==n?(E=n(u?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=u,e[39]=n,e[40]=E):E=e[40];let M;e[41]!==P||e[42]!==E?(M=s.jsx("button",{type:"button",onClick:P,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:E}),e[41]=P,e[42]=E,e[43]=M):M=e[43];let H;e[44]!==C||e[45]!==M?(H=s.jsxs("div",{className:"flex items-center gap-2",children:[C,M]}),e[44]=C,e[45]=M,e[46]=H):H=e[46];let R;e[47]!==k||e[48]!==H?(R=s.jsxs(sr,{className:"w-full sm:items-center sm:justify-between",children:[k,H]}),e[47]=k,e[48]=H,e[49]=R):R=e[49];let _;e[50]!==R||e[51]!==N?(_=s.jsxs(Gs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[N,R]}),e[50]=R,e[51]=N,e[52]=_):_=e[52];let z;return e[53]!==p||e[54]!==_||e[55]!==y?(z=s.jsx(Ks,{open:p,onOpenChange:y,children:_}),e[53]=p,e[54]=_,e[55]=y,e[56]=z):z=e[56],z}function xS(t){const e=pt.c(36),{t:n}=Tt(),{value:r,setValue:o,onConfirm:i}=t,c=!!r;let l;e[0]!==o?(l=v=>{v||o(null)},e[0]=o,e[1]=l):l=e[1];let u;e[2]!==n?(u=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=u):u=e[3];let m;e[4]!==u?(m=s.jsx(Ys,{children:u}),e[4]=u,e[5]=m):m=e[5];let d;e[6]!==n||e[7]!==r?(d=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=d):d=e[8];let f;e[9]!==d?(f=s.jsx(dn,{children:d}),e[9]=d,e[10]=f):f=e[10];let g;e[11]!==m||e[12]!==f?(g=s.jsxs(Qs,{children:[m,f]}),e[11]=m,e[12]=f,e[13]=g):g=e[13];let x;e[14]!==o?(x=()=>o(null),e[14]=o,e[15]=x):x=e[15];let p;e[16]!==n?(p=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=p):p=e[17];let y;e[18]!==x||e[19]!==p?(y=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:p}),e[18]=x,e[19]=p,e[20]=y):y=e[20];let b;e[21]!==n?(b=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=b):b=e[22];let h;e[23]!==i||e[24]!==b?(h=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:b}),e[23]=i,e[24]=b,e[25]=h):h=e[25];let N;e[26]!==h||e[27]!==y?(N=s.jsxs(sr,{children:[y,h]}),e[26]=h,e[27]=y,e[28]=N):N=e[28];let w;e[29]!==N||e[30]!==g?(w=s.jsxs(Gs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[g,N]}),e[29]=N,e[30]=g,e[31]=w):w=e[31];let S;return e[32]!==c||e[33]!==l||e[34]!==w?(S=s.jsx(Ks,{open:c,onOpenChange:l,children:w}),e[32]=c,e[33]=l,e[34]=w,e[35]=S):S=e[35],S}const bS=t=>{const e=pt.c(46),{selectedCount:n,scopeKey:r,scopeFolders:o,archivedBucket:i,onMoveToFolder:c,onCreateFolderAndMove:l,onRemoveFromFolder:u,canRemoveFromFolder:m,onDelete:d,onDone:f}=t,{t:g}=Tt(),x=!!r&&!i;let p;e[0]!==i||e[1]!==g?(p=g(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=g,e[2]=p):p=e[2];const y=p;let b;e[3]!==n||e[4]!==g?(b=g("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=g,e[5]=b):b=e[5];let h;e[6]!==b?(h=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:b}),e[6]=b,e[7]=h):h=e[7];let N;e[8]!==x||e[9]!==m||e[10]!==l||e[11]!==c||e[12]!==u||e[13]!==o||e[14]!==g?(N=x?s.jsxs(rn,{children:[s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(sn,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":g("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:g("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(nn,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:g("sessions.sidebar.folders.none")}):o.map(_=>s.jsx(zt,{onClick:()=>c(_.id),children:s.jsx("span",{className:"flex-1 truncate",children:_.name})},_.id)),s.jsx(On,{}),s.jsxs(zt,{onClick:l,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),g("sessions.sidebar.folders.newFolderEllipsis")]}),m?s.jsxs(zt,{onClick:u,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),g("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=x,e[9]=m,e[10]=l,e[11]=c,e[12]=u,e[13]=o,e[14]=g,e[15]=N):N=e[15];let w;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=Pe("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=w):w=e[16];let S;e[17]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(I,{name:"delete-bin",className:"h-4 w-4"}),e[17]=S):S=e[17];let v;e[18]!==y||e[19]!==d?(v=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:w,"aria-label":y,children:S})}),e[18]=y,e[19]=d,e[20]=v):v=e[20];let j;e[21]!==y?(j=s.jsx(Bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:y})}),e[21]=y,e[22]=j):j=e[22];let k;e[23]!==v||e[24]!==j?(k=s.jsxs(Ot,{children:[v,j]}),e[23]=v,e[24]=j,e[25]=k):k=e[25];let A;e[26]!==g?(A=g("sessions.sidebar.header.actions.exitSelection"),e[26]=g,e[27]=A):A=e[27];let T;e[28]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(I,{name:"close",className:"h-4 w-4"}),e[28]=T):T=e[28];let C;e[29]!==f||e[30]!==A?(C=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":A,children:T})}),e[29]=f,e[30]=A,e[31]=C):C=e[31];let P;e[32]!==g?(P=g("sessions.sidebar.header.actions.exitSelection"),e[32]=g,e[33]=P):P=e[33];let E;e[34]!==P?(E=s.jsx(Bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:P})}),e[34]=P,e[35]=E):E=e[35];let M;e[36]!==C||e[37]!==E?(M=s.jsxs(Ot,{children:[C,E]}),e[36]=C,e[37]=E,e[38]=M):M=e[38];let H;e[39]!==M||e[40]!==N||e[41]!==k?(H=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[N,k,M]}),e[39]=M,e[40]=N,e[41]=k,e[42]=H):H=e[42];let R;return e[43]!==H||e[44]!==h?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[h,H]}),e[43]=H,e[44]=h,e[45]=R):R=e[45],R},Hm="oc.sessions.activeNow",yS=2160*60*1e3,Gm=t=>!!t.parentID,cc=t=>!!t.time?.archived,Tl=t=>{const e=t.time?.updated,n=t.time?.created;return typeof e=="number"&&Number.isFinite(e)?e:typeof n=="number"&&Number.isFinite(n)?n:0},wS=t=>{try{const e=t.getItem(Hm);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,o=[];return n.forEach(i=>{const c=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!c||r.has(c)||(r.add(c),o.push({sessionId:c}))}),o}catch{return[]}},Xa=(t,e)=>{try{t.setItem(Hm,JSON.stringify(e))}catch{}},vS=(t,e,n=Date.now())=>{const r=n-yS;return t.filter(o=>{const i=e.get(o.sessionId);return i?cc(i)?!1:Tl(i)>=r:!0})},jS=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Km=t=>[...t].sort((e,n)=>Tl(n)-Tl(e)),SS=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!cc(r)).filter(r=>!Gm(r));return Km(n)},NS=(t,e)=>{const n=t.filter(r=>{if(cc(r)||Gm(r))return!1;const o=e[r.id];return o?.type==="busy"||o?.type==="retry"});return Km(n)},Ro=Dr(),Za=Ni((t,e)=>({entries:wS(Ro),setEntries:n=>{n!==e().entries&&(t({entries:n}),Xa(Ro,n))},addSession:n=>{const r=jS(e().entries,n);r!==e().entries&&(t({entries:r}),Xa(Ro,r))},prune:n=>{const r=e().entries,o=vS(r,n);o.length===r.length&&o.every((i,c)=>i.sessionId===r[c]?.sessionId)||(t({entries:o}),Xa(Ro,o))}})),Mo="oc.sessions.projectCollapse",eu="oc.sessions.groupOrder",tu="oc.sessions.groupCollapse",su="oc.sessions.activeSessionByProject",el="oc.sessions.expandedParents.v2",kS="oc.sessions.expandedParents",CS="oc.sessions.pinned",AS=(t,e)=>{const n=new Set;for(const r of t){const o=os(r.path)?.toLowerCase();o&&n.add(o)}for(const r of e.values())for(const o of r){const i=os(o.path)?.toLowerCase();i&&n.add(i)}return n},DS=(t,e)=>{if(t.time?.archived)return!0;const n=os(xi(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},IS=5*6e4,nu=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:o=!1})=>{const{t:i}=Tt(),[c,l]=a.useState(!1),[u,m]=a.useState(""),d=a.useRef(null),f=a.useRef(null),g=a.useRef(new Set),[x,p]=a.useState(null),[y,b]=a.useState(""),[h,N]=a.useState(null),[w,S]=a.useState(new Set),[v]=a.useState(()=>new Map),j=a.useMemo(()=>Dr(),[]),k=Za(X=>X.entries),A=Za(X=>X.addSession),T=Za(X=>X.prune),[C,P]=a.useState(new Set),[E,M]=a.useState(new Map),[H,R]=a.useState(new Map),[_,z]=a.useState(!1),[V,F]=a.useState(!1),[te,Z]=a.useState(null),[ne,U]=a.useState(null),[ie,oe]=a.useState(""),[pe,je]=a.useState(null),[Se,re]=a.useState(null),[L,$]=a.useState(null),K=Ma(X=>X.ids),he=Ma(X=>X.setIds),de=Ma(X=>X.toggle),[we,xe]=a.useState(()=>{try{const X=Dr().getItem(tu);if(!X)return new Set;const Ze=JSON.parse(X);return new Set(Array.isArray(Ze)?Ze.filter(qe=>typeof qe=="string"):[])}catch{return new Set}}),[De,le]=a.useState(()=>{try{const X=Dr().getItem(eu);if(!X)return new Map;const Ze=JSON.parse(X),qe=new Map;return Object.entries(Ze).forEach(([Pt,Kt])=>{Array.isArray(Kt)&&qe.set(Pt,Kt.filter(Ps=>typeof Ps=="string"))}),qe}catch{return new Map}}),[Ce,ue]=a.useState(()=>{try{const X=Dr().getItem(su);if(!X)return new Map;const Ze=JSON.parse(X),qe=new Map;return Object.entries(Ze).forEach(([Pt,Kt])=>{typeof Kt=="string"&&Kt.length>0&&qe.set(Pt,Kt)}),qe}catch{return new Map}}),[ve,G]=a.useState(new Map),Ae=a.useRef(new Map),ce=a.useRef(0),fe=tn(X=>X.homeDirectory),Te=tn(X=>X.currentDirectory),me=tn(X=>X.setDirectory),B=Ms(X=>X.projects),ye=Ms(X=>X.activeProjectId),_e=Ms(X=>X.removeProject),J=Ms(X=>X.setActiveProjectIdOnly),Me=Ms(X=>X.updateProjectMeta),Ee=Ms(X=>X.reorderProjects),Ne=Fe(X=>X.setActiveMainTab),Be=Fe(X=>X.openContextPanelTab),se=Fe(X=>X.setSettingsDialogOpen),O=Fe(X=>X.toggleHelpDialog),D=Fe(X=>X.setAboutDialogOpen),Y=Fe(X=>X.setSessionSwitcherOpen),be=Fe(X=>X.setScheduledTasksDialogOpen),Oe=Fe(X=>X.openMultiRunLauncher),$e=Fe(X=>X.notifyOnSubtasks),Re=Fe(X=>X.showDeletionDialog),ot=Fe(X=>X.setShowDeletionDialog),yt=va(u,120),At=a.useMemo(()=>yt.trim().toLowerCase(),[yt]),mt=At.length>0,Le=Fn(X=>X.collapsedFolderIds),Qe=Fn(X=>X.foldersMap),Ye=Fn(X=>X.getFoldersForScope),rt=Fn(X=>X.createFolder),bt=Fn(X=>X.renameFolder),ct=Fn(X=>X.deleteFolder),nt=Fn(X=>X.addSessionToFolder),It=Fn(X=>X.addSessionsToFolder),lt=Fn(X=>X.removeSessionFromFolder),kt=Fn(X=>X.removeSessionsFromFolders),Ke=Fn(X=>X.toggleFolderCollapse),tt=Fn(X=>X.cleanupSessions),We=Fn(X=>X.getSessionFolderId);b0({isSessionSearchOpen:c,setIsSessionSearchOpen:l,sessionSearchInputRef:f,sessionSearchContainerRef:d});const gt=Ou(),He=Xl(),st=Ol(),Et=Fh(),at=Zr(X=>X.hasLoaded),dt=Zr(X=>X.activeSessions),Ht=Zr(X=>X.archivedSessions),Rt=jt(X=>X.currentSessionId),Wt=jt(X=>!!X.newSessionDraft?.open),qt=jt(X=>X.setCurrentSession),Lt=jt(X=>X.updateSessionTitle),Gt=jt(X=>X.shareSession),Qt=jt(X=>X.unshareSession),rs=jt(X=>X.worktreeMetadata),Yt=jt(X=>X.availableWorktreesByProject),ft=jt(X=>X.openNewSessionDraft),Jt=Ti(xu(X=>({checkForUpdates:X.checkForUpdates,available:X.available,runtimeType:X.runtimeType,info:X.info,downloading:X.downloading,downloaded:X.downloaded,progress:X.progress,error:X.error,downloadUpdate:X.downloadUpdate,restartToUpdate:X.restartToUpdate}))),ms=a.useMemo(()=>AS(B,Yt),[Yt,B]),Xt=a.useMemo(()=>{const X=new Map(st.map(Pt=>[Pt.id,Pt])),Ze=dt.map(Pt=>{const Kt=X.get(Pt.id);return Kt?Lh(Kt,Pt):Pt}),qe=new Set(Ze.map(Pt=>Pt.id));return st.forEach(Pt=>{qe.has(Pt.id)||Ze.push(Pt)}),Ze.filter(Pt=>DS(Pt,ms))},[dt,ms,st]),ts=a.useMemo(()=>st.map(X=>{const Ze=os(X.directory??null)??"";return`${X.id}:${X.title??""}:${X.time?.archived?1:0}:${Ze}`}).join("|"),[st]),ks=a.useRef(st);a.useEffect(()=>{ks.current=st},[ts,st]);const $t=a.useMemo(()=>B.map(X=>`${X.id}:${os(X.path)??""}`).join("|"),[B]),as=a.useRef(!1);a.useEffect(()=>{as.current||(as.current=!0,ul(ks.current))},[]),a.useEffect(()=>{let X=!1;return(async()=>{const qe=Ms.getState().projects;if(qe.length===0)return;const Pt=new Map,Kt=[];await Promise.all(qe.map(async Ps=>{const wn=os(Ps.path);if(wn)try{if(!(_s.getState().directories.get(wn)?.isGitRepo??await Ui(()=>import("./useAppFontEffects-hYm-4PtP.js").then(jn=>jn.fy),__vite__mapDeps([0,1,2,3,4])).then(jn=>jn.checkIsGitRepository(wn))))return;const vn=await Bh({id:Ps.id,path:wn});if(X||vn.length===0)return;Pt.set(wn,vn),Kt.push(...vn)}catch{}})),!X&&jt.setState({availableWorktrees:Kt,availableWorktreesByProject:Pt})})(),()=>{X=!0}},[$t]),a.useEffect(()=>{let X=null;const Ze=Om(qe=>{qe.type==="scheduled-task-ran"&&(X&&clearTimeout(X),X=setTimeout(()=>{ul(ks.current)},500))});return()=>{X&&clearTimeout(X),Ze()}},[]);const $s=a.useMemo(()=>or(),[]),Ut=a.useMemo(()=>Hi(),[]),{isTablet:Es}=Pr(),Ls=t||Es,{buildGroupSearchText:gs,filterSessionNodesForSearch:Cs,buildGroupedSessions:Mt}=x0({homeDirectory:fe,worktreeMetadata:rs,pinnedSessionIds:K,gitBranches:gt,isVSCode:Ut}),{scheduleCollapsedProjectsPersist:xt}=k0({isVSCode:Ut,hasLoadedGlobalSessions:at,safeStorage:j,keys:{sessionExpanded:el,sessionExpandedLegacy:kS,projectCollapse:Mo,sessionPinned:CS,groupOrder:eu,projectActiveSession:su,groupCollapse:tu},sessions:Xt,setPinnedSessionIds:he,groupOrderByProject:De,activeSessionByProject:Ce,collapsedGroups:we,setExpandedParents:S,setCollapsedProjects:P}),Zt=a.useMemo(()=>[...Xt].sort((X,Ze)=>Pi(X,Ze,K)),[Xt,K]),Ft=a.useMemo(()=>new Map(Zt.map((X,Ze)=>[X.id,Ze])),[Zt]),is=a.useMemo(()=>{const X=new Map;return Zt.forEach(Ze=>{const qe=Ze.parentID;if(!qe)return;const Pt=X.get(qe)??[];Pt.push(Ze),X.set(qe,Pt)}),X.forEach(Ze=>Ze.sort((qe,Pt)=>Pi(qe,Pt,K))),X},[Zt,K]),es=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noSessions.description")})]}),fs=a.useMemo(()=>B.find(X=>X.id===h)??null,[B,h]),W=a.useCallback(X=>{h&&(Me(h,X),N(null))},[h,Me]),Ge=a.useCallback(()=>{z(!0)},[]),Xe=a.useCallback(()=>{const X=Ti.getState();if(X.available&&X.info){F(!0);return}Jt.checkForUpdates().then(()=>{const{available:Ze,error:qe}=Ti.getState();if(qe){ae.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:qe});return}if(!Ze){ae.success(i("sessions.sidebar.updateCheck.latestVersion"));return}F(!0)})},[i,Jt]),ht=a.useCallback(()=>{t&&Y(!1),se(!0)},[t,Y,se]),Nt=Jt.available&&(Jt.runtimeType==="desktop"||Jt.runtimeType==="web"),ut=jt(X=>X.deleteSession),ss=jt(X=>X.deleteSessions),bs=jt(X=>X.archiveSession),ys=jt(X=>X.archiveSessions),{copiedSessionId:Bs,handleSessionSelect:Rs,handleSessionDoubleClick:an,handleSaveEdit:Ss,handleCancelEdit:zs,handleShareSession:Ws,handleCopyShareUrl:hs,handleUnshareSession:br,handleDeleteSession:Rn,confirmDeleteSession:nr}=y0({activeProjectId:ye,currentDirectory:Te,currentSessionId:Rt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:c,sessionSearchQuery:u,setSessionSearchQuery:m,setIsSessionSearchOpen:l,setActiveProjectIdOnly:J,setDirectory:me,setActiveMainTab:Ne,setSessionSwitcherOpen:Y,setCurrentSession:qt,updateSessionTitle:Lt,shareSession:Gt,unshareSession:Qt,deleteSession:ut,deleteSessions:ss,archiveSession:bs,archiveSessions:ys,childrenMap:is,showDeletionDialog:Re,setDeleteSessionConfirm:je,deleteSessionConfirm:pe,setEditingId:p,setEditTitle:b,editingId:x,editTitle:y}),Kn=a.useCallback(()=>{if(!Se)return;const{scopeKey:X,folderId:Ze}=Se;re(null),ct(X,Ze)},[Se,ct]),As=a.useCallback(()=>{Ir.requestDirectoryDialog()},[]);a.useEffect(()=>{if(!Rt)return;const Ze=Xt.find(Pt=>Pt.id===Rt)?.parentID;if(!Ze)return;const qe=[`project:active:${Ze}`,`project:archived:${Ze}`,`recent:active:${Ze}`,`recent:archived:${Ze}`];S(Pt=>{if(qe.every(Ps=>Pt.has(Ps)))return Pt;const Kt=new Set(Pt);qe.forEach(Ps=>Kt.add(Ps));try{j.setItem(el,JSON.stringify(Array.from(Kt)))}catch{}return Kt})},[Rt,Xt,j]);const Xs=a.useCallback(X=>{S(Ze=>{const qe=new Set(Ze);qe.has(X)?qe.delete(X):qe.add(X);try{j.setItem(el,JSON.stringify(Array.from(qe)))}catch{}return qe})},[j]),Cn=a.useCallback((X,Ze)=>{if(!X)return null;Ze&&Le.has(Ze)&&Ke(Ze);const qe=rt(X,i("sessions.sidebar.folder.newFolderName"),Ze);return U(qe.id),oe(qe.name),qe},[Le,Ke,rt,i]),un=a.useCallback((X,Ze)=>{R(qe=>{const Pt=new Map(qe);return Pt.set(X,Ze+7),Pt})},[]),hn=a.useCallback(X=>{R(Ze=>{if(!Ze.has(X))return Ze;const qe=new Map(Ze);return qe.delete(X),qe})},[]),ds=a.useCallback(X=>{R(Ze=>{let qe=!1;const Pt=new Map(Ze),Kt=`${X}:`;for(const Ps of Pt.keys())Ps.startsWith(Kt)&&(Pt.delete(Ps),qe=!0);return qe?Pt:Ze})},[]),ws=a.useCallback(()=>{ce.current=Date.now()+150,R(new Map),P(()=>{const X=new Set(B.map(Ze=>Ze.id));try{j.setItem(Mo,JSON.stringify(Array.from(X)))}catch{}return Ut||xt(X),X})},[B,Ut,j,xt]),pn=a.useCallback(()=>{ce.current=Date.now()+150,R(new Map),P(()=>{const X=new Set;try{j.setItem(Mo,JSON.stringify([]))}catch{}return Ut||xt(X),X})},[Ut,j,xt]),Sn=a.useCallback(X=>{ce.current=Date.now()+150,ds(X),P(Ze=>{const qe=new Set(Ze);qe.has(X)?qe.delete(X):qe.add(X);try{j.setItem(Mo,JSON.stringify(Array.from(qe)))}catch{}return Ut||xt(qe),qe})},[Ut,ds,j,xt]),Os=a.useMemo(()=>B.map(X=>({...X,normalizedPath:os(X.path)})).filter(X=>!!X.normalizedPath),[B]),lr=a.useMemo(()=>Os.map(X=>X.normalizedPath),[Os]),cr=a.useMemo(()=>{const X=new Set;return Os.forEach(Ze=>{Ze.normalizedPath&&X.add(Ze.normalizedPath),(Yt.get(Ze.normalizedPath)??[]).forEach(Pt=>{const Kt=os(Pt.path);Kt&&X.add(Kt)})}),[...X].sort()},[Yt,Os]),qn=a.useRef(null);a.useEffect(()=>{const X=new Set(cr),Ze=qn.current;if(qn.current=X,!Ze)return;const qe=cr.filter(Pt=>!Ze.has(Pt));qe.length!==0&&Oh(qe,ks.current)},[cr]);const{github:Er}=Gn(),dr=vi(X=>X.status),yr=vi(X=>X.hasChecked),wr=_h(lr),ur=tr(X=>X.ensureEntry),ee=tr(X=>X.setParams),it=tr(X=>X.refreshTargets);C0({normalizedProjects:Os,gitRepoStatus:wr,setProjectRepoStatus:M,setProjectRootBranches:G});const wt=jt(X=>X.isLoading);L0({isSessionsLoading:wt,sessions:Xt,archivedSessions:Ht,normalizedProjects:Os,isVSCode:Ut,availableWorktreesByProject:Yt,cleanupSessions:tt});const{getSessionsForProject:Vt,getArchivedSessionsForProject:ps}=T0({isVSCode:Ut,sessions:Xt,archivedSessions:Ht,availableWorktreesByProject:Yt});c0({normalizedProjects:Os,sessions:Xt,archivedSessions:Ht,availableWorktreesByProject:Yt,isVSCode:Ut,isSessionsLoading:wt,foldersMap:Qe,createFolder:rt,addSessionToFolder:nt,cleanupSessions:tt});const us=a.useRef(!1);ye&&E.has(ye)&&(us.current=!!E.get(ye));const{projectSections:cs,groupSearchDataByGroup:Us,sectionsForRender:js,searchMatchCount:Mn}=m0({normalizedProjects:Os,getSessionsForProject:Vt,getArchivedSessionsForProject:ps,availableWorktreesByProject:Yt,projectRepoStatus:E,projectRootBranches:ve,lastRepoStatus:us.current,buildGroupedSessions:Mt,hasSessionSearchQuery:mt,normalizedSessionSearchQuery:At,filterSessionNodesForSearch:Cs,buildGroupSearchText:gs,foldersMap:Qe}),mn=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noMatches.description")})]}),{currentSessionDirectory:Rr}=h0({projectSections:cs,activeProjectId:ye,activeSessionByProject:Ce,setActiveSessionByProject:ue,currentSessionId:Rt,handleSessionSelect:Rs,newSessionDraftOpen:Wt,mobileVariant:t,openNewSessionDraft:ft,setActiveMainTab:Ne,setSessionSwitcherOpen:Y,sessions:Xt,worktreeMetadata:rs}),{getOrderedGroups:gn}=p0(De),Mr=a.useRef(!1);a.useEffect(()=>{if(Mr.current||cs.length===0)return;const X=cs.flatMap(Ze=>Ze.groups.filter(qe=>qe.isArchivedBucket).map(qe=>`${Ze.project.id}:${qe.id}`));X.length>0&&xe(Ze=>new Set([...Ze,...X])),Mr.current=!0},[cs]);const xn=a.useMemo(()=>{const X=new Map,Ze=new Map;return cs.forEach(qe=>{const Pt=zu(qe.project.label?.trim()||Si(qe.project.normalizedPath,fe)||qe.project.normalizedPath);qe.groups.forEach(Kt=>{const Ps=Kt.branch&&Kt.branch!=="HEAD"&&Kt.branch!==Pt?Kt.branch:null,wn={projectLabel:Pt,branchLabel:Ps},Dn=Bn=>{Bn.forEach(vn=>{const jn=qe.project.normalizedPath.length,Ki=Ze.get(vn.session.id)??-1;jn<Ki||(X.set(vn.session.id,{node:vn,projectId:qe.project.id,groupDirectory:Kt.directory,secondaryMeta:wn}),Ze.set(vn.session.id,jn),vn.children.length>0&&Dn(vn.children))})};Dn(Kt.sessions)})}),X},[cs,fe]),Vs=Ar(X=>X.showRecentSection),bn=Ar(X=>X.showArchivedSessions),Ds=a.useMemo(()=>Vs?SS(k,new Map(Xt.map(X=>[X.id,X]))).sort((X,Ze)=>Pi(X,Ze,K)):[],[k,K,Xt,Vs]),Zs=a.useMemo(()=>Vs?NS(Xt,Et):[],[Et,Xt,Vs]);a.useEffect(()=>{!Vs||Zs.length===0||Zs.forEach(X=>A(X.id))},[A,Zs,Vs]),a.useEffect(()=>{if(!Vs)return;const X=new Map;[...Xt,...Ht].forEach(Ze=>{X.set(Ze.id,Ze)}),T(X)},[Ht,T,Xt,Vs]);const vr=a.useMemo(()=>{if(!Vs)return[];const X=Ze=>{const qe=xn.get(Ze.id),Pt=os(Ze.directory??null);return{node:qe?.node??{session:Ze,children:[],worktree:null},projectId:qe?.projectId??null,groupDirectory:qe?.groupDirectory??Pt,secondaryMeta:qe?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:Ds.map(X)}]},[Ds,xn,Vs,i]),jr=a.useMemo(()=>new Set(Ds.map(X=>X.id)),[Ds]),Sr=a.useMemo(()=>[...jr],[jr]);Pv({currentSessionId:Rt,sortedSessions:Zt,recentSessionIds:Sr,ensureSessionRenderable:He.ensureSessionRenderable});const Nr=a.useMemo(()=>bn?js:js.map(X=>({...X,groups:X.groups.filter(Ze=>!Ze.isArchivedBucket)})),[js,bn]),ln=a.useMemo(()=>{const X=new Set;return Nr.forEach(Ze=>{Ze.groups.forEach(qe=>{const Pt=os(qe.directory??null),Kt=qe.branch?.trim()||gt.get(Pt||"")?.trim();!Pt||!Kt||X.add(oo(Pt,Kt))})}),[...X]},[gt,Nr]),ni=xb(ln);a.useEffect(()=>{if(!yr||!dr?.connected||!Er)return;const X=[],Ze=Date.now();if(Nr.forEach(Pt=>{C.has(Pt.project.id)||Pt.groups.forEach(Kt=>{const Ps=os(Kt.directory??null),wn=Kt.branch?.trim()||gt.get(Ps||"")?.trim();if(!Ps||!wn)return;const Dn=oo(Ps,wn),Bn=tr.getState().entries[Dn],vn=!!Bn?.status?.pr,jn=`${Ps}::${wn}`,Ki=Math.max(Bn?.lastRefreshAt??0,Bn?.lastDiscoveryPollAt??0),qi=!!(Bn?.isInitialStatusResolved&&!vn&&(!g.current.has(jn)||Ze-Ki>=IS));(!Bn||!Bn.isInitialStatusResolved||qi)&&(qi&&g.current.add(jn),X.push({directory:Ps,branch:wn}))})}),X.length===0)return;const qe=new Map;X.forEach(Pt=>{const Kt=oo(Pt.directory,Pt.branch,Pt.remoteName??null);qe.has(Kt)||qe.set(Kt,Pt)}),qe.forEach((Pt,Kt)=>{ur(Kt),ee(Kt,{directory:Pt.directory,branch:Pt.branch,remoteName:Pt.remoteName??null,canShow:!0,github:Er,githubAuthChecked:yr,githubConnected:dr.connected})}),it([...qe.values()],{silent:!0,markInitialResolved:!0})},[C,ur,Er,yr,dr?.connected,gt,it,Nr,ee]);const Yn=t?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",yn="h-4.5 w-4.5",Vr=V0({isDesktopShellRuntime:$s,projectSections:cs,projectHeaderSentinelRefs:Ae}),$r=a.useCallback((X,Ze=0,qe,Pt,Kt=!1,Ps,wn="project")=>s.jsx(hS,{node:X,depth:Ze,groupDirectory:qe,projectId:Pt,archivedBucket:Kt,directoryStatus:v,currentSessionId:Rt,pinnedSessionIds:K,expandedParents:w,hasSessionSearchQuery:mt,normalizedSessionSearchQuery:At,notifyOnSubtasks:$e,editingId:x,setEditingId:p,editTitle:y,setEditTitle:b,handleSaveEdit:Ss,handleCancelEdit:zs,toggleParent:Xs,handleSessionSelect:Rs,handleSessionDoubleClick:an,togglePinnedSession:de,handleShareSession:Ws,copiedSessionId:Bs,handleCopyShareUrl:hs,handleUnshareSession:br,openSidebarMenuKey:te,setOpenSidebarMenuKey:Z,renamingFolderId:ne,getFoldersForScope:Ye,getSessionFolderId:We,removeSessionFromFolder:lt,addSessionToFolder:nt,createFolderAndStartRename:Cn,openContextPanelTab:Be,handleDeleteSession:Rn,mobileVariant:t,alwaysShowActions:Ls,renderSessionNode:$r,secondaryMeta:Ps,renderContext:wn}),[v,Rt,K,w,mt,At,$e,x,p,y,b,Ss,zs,Xs,Rs,an,de,Ws,Bs,hs,br,te,Z,ne,Ye,We,lt,nt,Cn,Be,Rn,t,Ls]),Fr=a.useCallback(X=>{hn(X),xe(Ze=>{const qe=new Set(Ze);return qe.has(X)?qe.delete(X):qe.add(X),qe})},[hn]),ii=a.useMemo(()=>{const X=new Map;for(const[Ze,qe]of ni)X.set(Ze,{visualState:qe.visualState,number:qe.number,url:qe.url,state:qe.prState,draft:qe.draft,title:qe.title,base:qe.base,head:qe.head,checks:qe.checks,canMerge:qe.canMerge,mergeableState:qe.mergeableState,repo:qe.repo});return X},[ni]),fn=a.useCallback((X,Ze,qe,Pt,Kt,Ps)=>s.jsx(dj,{group:X,groupKey:Ze,projectId:qe,hideGroupLabel:Pt,compactBodyPadding:Ps,hasSessionSearchQuery:mt,normalizedSessionSearchQuery:At,groupSearchDataByGroup:Us,visibleSessionCount:H.get(Ze),collapsedGroups:we,hideDirectoryControls:r,collapsedFolderIds:Le,toggleFolderCollapse:Ke,renameFolder:bt,deleteFolder:ct,showDeletionDialog:Re,setDeleteFolderConfirm:re,renderSessionNode:$r,currentSessionDirectory:Rr,projectRepoStatus:E,lastRepoStatus:us.current,showMoreGroupSessions:un,resetGroupSessionLimit:hn,mobileVariant:t,alwaysShowActions:Ls,activeProjectId:ye,setActiveProjectIdOnly:J,setActiveMainTab:Ne,setSessionSwitcherOpen:Y,openNewSessionDraft:ft,addSessionToFolder:nt,createFolderAndStartRename:Cn,renamingFolderId:ne,renameFolderDraft:ie,setRenameFolderDraft:oe,setRenamingFolderId:U,pinnedSessionIds:K,sessionOrderIndex:Ft,prVisualStateByDirectoryBranch:ii,onToggleCollapsedGroup:Fr,dragHandleProps:Kt}),[mt,At,Us,H,we,r,Le,Ke,bt,ct,Re,$r,Rr,E,un,hn,t,Ls,ye,J,Ne,Y,ft,nt,Cn,ne,ie,K,Ft,ii,Fr]),kr=Vs&&!Ut&&!mt?s.jsx(yj,{sections:vr,renderSessionNode:$r}):null,zr=!!(ne||x||h),Jn=er(X=>X.enabled),Ns=er(X=>X.selectedIds),oi=er(X=>X.scopeKey),ai=er,An=a.useCallback(()=>{er.getState().toggleMode()},[]),Lr=a.useCallback(()=>{er.getState().disable()},[]),mr=a.useMemo(()=>{if(Ns.size===0||typeof document>"u")return!1;let X=!1,Ze=!1;for(const qe of Ns){const Pt=document.querySelectorAll(`[data-session-row="${CSS.escape(qe)}"]`);for(const Kt of Pt)Kt.getAttribute("data-session-archived")==="1"?Ze=!0:X=!0}return Ze&&!X},[Ns]),Js=a.useMemo(()=>{if(oi)return oi;if(Ns.size===0||typeof document>"u")return null;for(const X of Ns){const qe=document.querySelector(`[data-session-row="${CSS.escape(X)}"]`)?.getAttribute("data-session-scope");if(qe&&qe.length>0)return qe}return null},[Ns,oi]),Q=a.useMemo(()=>Js?Qe[Js]??[]:[],[Qe,Js]),ge=a.useMemo(()=>{if(!Js||Ns.size===0)return!1;const X=Qe[Js]??[];for(const Ze of X)for(const qe of Ze.sessionIds)if(Ns.has(qe))return!0;return!1},[Qe,Js,Ns]),ke=a.useCallback(X=>{!Js||Ns.size===0||It(Js,X,Array.from(Ns))},[It,Ns,Js]),Ue=a.useCallback(()=>{if(!Js||Ns.size===0)return;const X=Cn(Js);X&&It(Js,X.id,Array.from(Ns))},[It,Cn,Ns,Js]),vt=a.useCallback(()=>{!Js||Ns.size===0||kt(Js,Array.from(Ns))},[kt,Ns,Js]),St=a.useCallback(async()=>{const X=Array.from(Ns);if(X.length!==0){if(mr){const{deletedIds:Ze,failedIds:qe}=await ss(X);Ze.length>0&&ae.success(Ze.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:Ze.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:Ze.length})),qe.length>0&&ae.error(qe.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:qe.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:qe.length}))}else{const{archivedIds:Ze,failedIds:qe}=await ys(X);Ze.length>0&&ae.success(Ze.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:Ze.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:Ze.length})),qe.length>0&&ae.error(qe.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:qe.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:qe.length}))}er.getState().clear()}},[ys,mr,ss,Ns,i]),xs=a.useCallback(()=>{const X=Ns.size;if(X!==0){if(!Re){St();return}$({sessionCount:X,archivedBucket:mr})}},[mr,St,Ns,Re]),Is=a.useCallback(async()=>{$(null),await St()},[St]);a.useEffect(()=>{if(!Jn)return;const X=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),Ze=qe=>{if(zr)return;const Pt=qe.target;if(Pt&&(Pt.tagName==="INPUT"||Pt.tagName==="TEXTAREA"||Pt.isContentEditable))return;const Kt=X?qe.metaKey:qe.ctrlKey;if(qe.key==="Escape"){qe.preventDefault(),er.getState().disable();return}if(Kt&&qe.key==="Backspace"){qe.preventDefault(),xs();return}if(Kt&&(qe.key==="a"||qe.key==="A")){const Ps=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Ps.length===0)return;qe.preventDefault();const Dn=ai.getState().scopeKey??Ps[0]?.getAttribute("data-session-scope")??null,Bn=jn=>Dn?jn.getAttribute("data-session-scope")===Dn:!0,vn=Ps.filter(Bn).map(jn=>jn.getAttribute("data-session-row")).filter(jn=>typeof jn=="string"&&jn.length>0);if(vn.length===0)return;ai.getState().replaceAll(vn,Dn||null)}};return window.addEventListener("keydown",Ze),()=>window.removeEventListener("keydown",Ze)},[xs,zr,ai,Jn]);const Cr=a.useCallback(()=>{Ne("chat"),t&&Y(!1),Oe()},[t,Oe,Ne,Y]),Da=a.useCallback(()=>{Ne("chat"),t&&Y(!1),ft()},[t,ft,Ne,Y]);return s.jsxs("div",{ref:d,className:Pe("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[s.jsx(uj,{hideDirectoryControls:r,showRecentControls:!Ut,handleOpenDirectoryDialog:As,openNewSessionDraft:Da,canOpenMultiRun:B.length>0,openMultiRunLauncher:Cr,headerActionIconClass:yn,headerActionButtonClass:Yn,isSessionSearchOpen:c,setIsSessionSearchOpen:l,sessionSearchInputRef:f,sessionSearchQuery:u,setSessionSearchQuery:m,hasSessionSearchQuery:mt,searchMatchCount:Mn,collapseAllProjects:ws,expandAllProjects:pn,openScheduledTasksDialog:()=>be(!0),selectionModeEnabled:Jn,onToggleSelectionMode:An}),s.jsx(Dj,{topContent:kr,sectionsForRender:Nr,projectSections:cs,activeProjectId:ye,showOnlyMainWorkspace:o,hasSessionSearchQuery:mt,emptyState:es,searchEmptyState:mn,renderGroupSessions:fn,homeDirectory:fe,collapsedProjects:C,hideDirectoryControls:r,projectRepoStatus:E,isDesktopShellRuntime:$s,stuckProjectHeaders:Vr,mobileVariant:t,alwaysShowActions:Ls,toggleProject:Sn,setActiveProjectIdOnly:J,setActiveMainTab:Ne,setSessionSwitcherOpen:Y,openNewSessionDraft:ft,openNewWorktreeDialog:Ge,openProjectEditDialog:N,removeProject:_e,projectHeaderSentinelRefs:Ae,reorderProjects:Ee,getOrderedGroups:gn,setGroupOrderByProject:le,openSidebarMenuKey:te,setOpenSidebarMenuKey:Z,isInlineEditing:zr}),Jn&&Ns.size>0?s.jsx(bS,{selectedCount:Ns.size,scopeKey:Js,scopeFolders:Q,archivedBucket:mr,onMoveToFolder:ke,onCreateFolderAndMove:Ue,onRemoveFromFolder:vt,canRemoveFromFolder:ge,onDelete:xs,onDone:Lr}):null,s.jsx(vj,{onOpenSettings:ht,onOpenShortcuts:O,onOpenAbout:()=>D(!0),onOpenUpdate:Xe,showRuntimeButtons:!Ut,showUpdateButton:Nt}),s.jsx(Yu,{open:V,onOpenChange:F,info:Jt.info,downloading:Jt.downloading,downloaded:Jt.downloaded,progress:Jt.progress,error:Jt.error,onDownload:Jt.downloadUpdate,onRestart:Jt.restartToUpdate,runtimeType:Jt.runtimeType}),fs?s.jsx(z0,{open:!!fs,onOpenChange:X=>{X||N(null)},projectId:fs.id,projectName:fs.label||Si(fs.path,fe),projectPath:fs.path,initialIcon:fs.icon,initialColor:fs.color,initialIconBackground:fs.iconBackground,onSave:W}):null,s.jsx(Yp,{open:_,onOpenChange:z,onWorktreeCreated:(X,Ze)=>{if(Ne("chat"),t&&Y(!1),Ze?.sessionId){qt(Ze.sessionId,X);return}ft({directoryOverride:X})}}),s.jsx(a0,{}),s.jsx(pS,{value:pe,setValue:je,showDeletionDialog:Re,setShowDeletionDialog:ot,onConfirm:nr}),s.jsx(xS,{value:Se,setValue:re,onConfirm:Kn}),s.jsx(gS,{value:L,setValue:$,showDeletionDialog:Re,setShowDeletionDialog:ot,onConfirm:Is})]})},di=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,hr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},PS=()=>{const{t}=Tt(),[e,n]=a.useState(!1),[r,o]=a.useState(!1),[i,c]=a.useState(null),[l,u]=a.useState([]),[m,d]=a.useState(!1),[f,g]=a.useState(!1),[x,p]=a.useState(!1),[y,b]=a.useState(!1),[h,N]=a.useState(new Set),w=jt(G=>G.getWorktreeMetadata),S=jt(G=>G.newSessionDraft),v=jt(G=>G.setNewSessionDraftTarget),j=jt(G=>G.setDraftBootstrapPendingDirectory),k=Vh,A=Wh,T=jt(G=>G.deleteSessions),C=jt(G=>G.archiveSessions),P=Fe(G=>G.showDeletionDialog),E=Fe(G=>G.setShowDeletionDialog),M=tn(G=>G.currentDirectory),H=tn(G=>G.homeDirectory),R=tn(G=>G.isHomeReady),_=Ms(G=>G.projects),z=Ms(G=>G.activeProjectId),{isMobile:V,isTablet:F,hasTouchInput:te}=Pr(),Z=V||F||te,ne=a.useMemo(()=>{const Ae=(z?_.find(ce=>ce.id===z)??null:null)?.path??M;return hr(Ae)},[z,M,_]),U=a.useCallback(G=>{const ce=hr(G.projectDirectory)||ne;return{id:(_.find(Te=>hr(Te.path)===ce)??null)?.id??`path:${ce}`,path:ce}},[ne,_]),ie=y&&h.size>0,oe=a.useMemo(()=>{const G=i?.worktree;return G&&typeof G.branch=="string"&&G.branch.trim().length>0?!0:l.length>0&&l.every(({metadata:Ae})=>typeof Ae.branch=="string"&&Ae.branch.trim().length>0)},[i?.worktree,l]),pe=i?.mode==="worktree",je=pe,Se=x||!pe||!oe,re=x||!pe;a.useEffect(()=>{r||!R||_.length>0||(o(!0),n(!0))},[r,R,_.length]);const L=a.useCallback(G=>{c({sessions:G.sessions,dateLabel:G.dateLabel,mode:G.mode??"session",worktree:G.worktree??null})},[]),$=a.useCallback(()=>{c(null),u([]),d(!1),g(!1),p(!1),b(!1),N(new Set)},[]),K=a.useCallback(async G=>{if(G.sessions.length===0)return;if(G.sessions.length===1){const Te=G.sessions[0];await k(Te.id)?ae.success(t("sessions.sidebar.session.delete.success")):ae.error(t("sessions.sidebar.session.delete.error"));return}const Ae=G.sessions.map(Te=>Te.id),{deletedIds:ce,failedIds:fe}=await T(Ae);if(ce.length>0){const Te=fe.length>0?fe.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:fe.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:fe.length}):G.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:G.dateLabel}):void 0;ae.success(ce.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ce.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ce.length}),{description:di(Te)})}fe.length>0&&ae.error(fe.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:fe.length}),{description:di(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[k,T,t]);a.useEffect(()=>Ir.onDeleteRequest(G=>{if(!P&&(G.mode??"session")==="session"){K(G);return}L(G)}),[L,P,K]),a.useEffect(()=>Ir.onDirectoryRequest(()=>{n(!0)}),[]),a.useEffect(()=>{if(!i){u([]),d(!1),g(!1),b(!1),N(new Set);return}const G=i.sessions.map(fe=>{const Te=w(fe.id);return Te?{session:fe,metadata:Te}:null}).filter(fe=>!!fe);u(G),d(!1),b(!1),N(new Set);const Ae=new Map;if(i.worktree?.path&&Ae.set(hr(i.worktree.path),i.worktree),G.forEach(({metadata:fe})=>{fe.path&&Ae.set(hr(fe.path),fe)}),Ae.size===0){b(!0);return}let ce=!1;return(async()=>{const fe=new Map,Te=new Set;await Promise.all(Array.from(Ae.entries()).map(async([me,B])=>{try{const ye=await $h(B.path);fe.set(me,ye),ye?.isDirty&&Te.add(me)}catch{B.status&&(fe.set(me,B.status),B.status.isDirty&&Te.add(me))}})).catch(me=>{console.warn("Failed to inspect worktree status before deletion:",me)}),!ce&&(N(Te),b(!0),c(me=>{if(!me?.worktree?.path)return me;const B=hr(me.worktree.path),ye=fe.get(B);if(!ye)return me;const _e=me.worktree.status;return _e?.isDirty===ye.isDirty&&_e?.ahead===ye.ahead&&_e?.behind===ye.behind&&_e?.upstream===ye.upstream?me:{...me,worktree:{...me.worktree,status:ye}}}),u(me=>me.map(B=>{const ye=hr(B.metadata.path),_e=fe.get(ye);return _e?{session:B.session,metadata:{...B.metadata,status:_e}}:B})))})(),()=>{ce=!0}},[i,w]),a.useEffect(()=>{oe||d(!1)},[oe]);const he=a.useCallback(async(G,Ae)=>{const ce=m&&oe,fe=U(G),Te=hr(G.path),me=hr(fe.path);try{await zh(fe,G,{deleteRemoteBranch:ce,deleteLocalBranch:Ae});const B=hr(S?.directoryOverride);return S?.open&&Te&&B===Te&&me&&(j(null),v({projectId:fe.id,directoryOverride:me},{force:!0})),hr(M)===Te&&me&&tn.getState().setDirectory(me,{showOverlay:!1}),!0}catch(B){return ae.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:di(B instanceof Error?B.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[oe,M,m,U,S?.directoryOverride,S?.open,j,v,t]),de=a.useCallback(async()=>{if(i){p(!0);try{const G=je,Ae=G&&m,ce=G&&f;if(i.sessions.length===0&&pe&&i.worktree){if(!await he(i.worktree,ce)){$();return}const me=t(m&&oe?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");ae.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:di(me)}),$();return}if(i.sessions.length===1){const fe=i.sessions[0];if(!(pe?await A(fe.id):await k(fe.id,{archiveWorktree:!1,deleteRemoteBranch:Ae,deleteLocalBranch:ce}))){ae.error(t(pe?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),p(!1);return}const me=!pe&&G?t(Ae?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;ae.success(t(pe?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:di(me),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const fe=i.sessions.map(B=>B.id);let Te=[],me=[];if(pe){const B=await C(fe);Te=B.archivedIds,me=B.failedIds}else{const B=await T(fe);Te=B.deletedIds,me=B.failedIds}if(pe&&i.worktree&&me.length===0&&await he(i.worktree,ce),Te.length>0){const B=!pe&&G?t(Ae?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,_e=[me.length>0?pe?me.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:me.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:me.length}):me.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:me.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:me.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,B].filter(Boolean).join(" ");ae.success(pe?Te.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:Te.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:Te.length}):Te.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Te.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Te.length}),{description:di(_e||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(me.length>0&&(ae.error(pe?me.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:me.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:me.length}):me.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:me.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:me.length}),{description:di(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),Te.length===0)){p(!1);return}}pe&&i.sessions.length===1&&i.worktree&&await he(i.worktree,ce),$()}finally{p(!1)}}},[i,m,f,k,T,A,C,$,je,pe,oe,he,t]),we=i?.worktree??l[0]?.metadata??null,xe=i?i.mode==="worktree"?i.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):i.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:i.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:i.sessions.length}):i.sessions.length===1?i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:i.sessions.length,dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:i.sessions.length}):"",De=i?s.jsxs("div",{className:Pe(pe?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:Pe(pe?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[pe&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:Pe(pe?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(G=>s.jsxs("li",{className:Pe(pe?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:Pe(!pe&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:G.title||t("sessions.sidebar.session.untitled")})]},G.id)),i.sessions.length>5&&s.jsx("li",{className:Pe(pe?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:i.sessions.length-5})})]})]}),pe?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),we?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:we.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:we?Zo(we.path,H):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),ie&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,le=pe?oe?s.jsxs("button",{type:"button",onClick:()=>{Se||d(G=>!G)},disabled:Se,className:Pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",Se?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[m?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,Ce=pe?s.jsxs("button",{type:"button",onClick:()=>{re||g(G=>!G)},disabled:re,className:Pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",re?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ue=pe?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[Ce,le]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{variant:"ghost",onClick:$,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{variant:"destructive",onClick:de,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>E(!P),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!P,children:[P?s.jsx(I,{name:"checkbox-blank",className:"size-4"}):s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{variant:"ghost",onClick:$,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{variant:"destructive",onClick:de,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ve=pe?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[Z?s.jsx(xa,{open:!!i,onClose:()=>{x||$()},title:ve,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ue}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[xe&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:xe}),De]})}):s.jsx(Ks,{open:!!i,onOpenChange:G=>{if(!G){if(x)return;$()}},children:s.jsxs(Gs,{className:Pe(pe?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(Qs,{children:[s.jsxs(Ys,{className:Pe(pe&&"flex items-center gap-2"),children:[pe&&s.jsx(I,{name:"delete-bin",className:"h-5 w-5"}),ve]}),xe&&s.jsx(dn,{children:xe})]}),s.jsx("div",{className:Pe(pe&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:De}),s.jsx(sr,{className:"mt-2 gap-2 pt-1 pb-1",children:ue})]})}),s.jsx(Jp,{open:e,onOpenChange:n})]})},El=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),TS=(t,e)=>{const n=El(t),r=El(e);return`${n}-${r}`.substring(0,60)},ru=(t,e)=>`${t}/${e}`,ES=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},iu=(t,e)=>{const n=ES(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Jh(t.id,n),jt.getState().markSessionAsOpenChamberCreated(t.id),Zr.getState().upsertSession(o);try{Qh().ensureChild(n,{bootstrap:!1}).setState(c=>{const l=c.session.findIndex(m=>m.id===t.id);if(l>=0&&c.session[l]===o)return c;const u=l>=0?c.session.map((m,d)=>d===l?o:m):[...c.session,o].sort((m,d)=>m.id.localeCompare(d.id));return{session:u,sessionTotal:Math.max(c.sessionTotal,u.length),limit:Math.max(c.limit,u.length)}})}catch{}return o},RS=()=>{const t=Ms.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(o=>o.id===e);if(n?.path)return{id:n.id,path:n.path};const r=tn.getState().currentDirectory??null;if(r&&r.trim().length>0){const o=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${o}`,path:o}}return null},tl=Ni()(hu(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:o,files:i,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let l=0;l<r.length;l++){if(!r[l].prompt.trim())return t({error:`Group ${l+1}: prompt is required`}),null;if(r[l].models.length<1)return t({error:`Group ${l+1}: select at least 1 model`}),null;if(r[l].models.length>5)return t({error:`Group ${l+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const l=RS();if(!l)return t({error:"Select a project",isLoading:!1}),null;const u=l.path,d=await Uh(u)&&e.isolateRuns!==!1,f=El(n),g=d?await wa(u):void 0,x=d?await Hh(u):null,p=[],y=c?.filter(S=>S.trim().length>0)??[];for(let S=0;S<r.length;S++){const v=r[S],j=v.prompt,k=new Map;for(const T of v.models){const C=`${T.providerID}:${T.modelID}`;k.set(C,(k.get(C)||0)+1)}const A=new Map;for(const T of v.models){const C=`${T.providerID}:${T.modelID}`,P=k.get(C)||1,E=(A.get(C)||0)+1;A.set(C,E);const M=TS(T.providerID,T.modelID),H=r.length>1?`g${S+1}`:void 0,R=P>1?ru(f,`${M}/${E}`):ru(f,M),_=H?`${H}/${R}`:R,z=Yj({groupSlug:f,runGroup:H,providerID:T.providerID,modelID:T.modelID,index:P>1?E:void 0});try{if(!d){const Z=await Hn.withDirectory(u,()=>Hn.createSession({title:z}));iu(Z,u),p.push({sessionId:Z.id,worktreePath:u,providerID:T.providerID,modelID:T.modelID,variant:T.variant,prompt:j});continue}const V=await Gh(l,{preferredName:_,mode:"new",branchName:_,worktreeName:_,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:y},{resolvedRootTrackingRemote:x}),F={...V,createdFromBranch:g,kind:"standard"},te=await Hn.withDirectory(V.path,()=>Hn.createSession({title:z}));iu(te,V.path),jt.getState().setWorktreeMetadata(te.id,F),p.push({sessionId:te.id,worktreePath:V.path,providerID:T.providerID,modelID:T.modelID,variant:T.variant,prompt:j})}catch(V){console.warn("[MultiRun] Failed to create session:",V)}}}const b=c?.filter(S=>S.trim().length>0)??[];b.length>0&&Kh(l,b).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=p.map(S=>S.sessionId),N=p[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const w=i?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{const S=qh.getState().expandText;await Promise.allSettled(p.map(async v=>{try{const j=await S(v.prompt).catch(()=>v.prompt);await Yh({sessionId:v.sessionId,directory:v.worktreePath,content:j,providerID:v.providerID,modelID:v.modelID,variant:v.variant,agent:o,files:w})}catch(j){console.warn("[MultiRun] Failed to start run:",j)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:h,firstSessionId:N}}catch(l){return t({error:l instanceof Error?l.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),MS="oc:lastWorktreeSourceBranch";function qm(t){const e=pt.c(30),{git:n}=Gn(),r=Tu(t),o=Wl(t),i=Ul(t),c=Xh(t),l=_s(BS),u=_s(_S);let m,d;e[0]!==t||e[1]!==u||e[2]!==n||e[3]!==o||e[4]!==i?(m=()=>{!t||!n||o!==null||i||u(t,n,{silent:!0})},d=[t,n,u,o,i],e[0]=t,e[1]=u,e[2]=n,e[3]=o,e[4]=i,e[5]=m,e[6]=d):(m=e[5],d=e[6]),a.useEffect(m,d);let f;e[7]!==r?.all||e[8]!==t||e[9]!==l||e[10]!==n||e[11]!==o?(f=()=>{!t||!n||o===!0&&(r?.all||l(t,n))},e[7]=r?.all,e[8]=t,e[9]=l,e[10]=n,e[11]=o,e[12]=f):f=e[12];const g=r?.all;let x;e[13]!==t||e[14]!==l||e[15]!==n||e[16]!==o||e[17]!==g?(x=[t,n,o,g,l],e[13]=t,e[14]=l,e[15]=n,e[16]=o,e[17]=g,e[18]=x):x=e[18],a.useEffect(f,x);const p=i||o===!0&&c;let y;e:{if(!r?.all){let k;e[19]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[19]=k):k=e[19],y=k;break e}let j;e[20]!==r.all?(j=r.all.filter(OS).sort(),e[20]=r.all,e[21]=j):j=e[21],y=j}const b=y;let h;e:{if(!r?.all){let k;e[22]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[22]=k):k=e[22],h=k;break e}let j;e[23]!==r.all?(j=r.all.filter(LS).map(FS).sort(),e[23]=r.all,e[24]=j):j=e[24],h=j}const N=h;let w;e:{if(!t){w=null;break e}if(o!==null){w=o;break e}if(p){w=null;break e}w=r?.all?!0:null}const S=w;let v;return e[25]!==S||e[26]!==p||e[27]!==b||e[28]!==N?(v={localBranches:b,remoteBranches:N,isLoading:p,isGitRepository:S},e[25]=S,e[26]=p,e[27]=b,e[28]=N,e[29]=v):v=e[29],v}function FS(t){return t.replace(/^remotes\//,"")}function LS(t){return t.startsWith("remotes/")}function OS(t){return!t.startsWith("remotes/")}function _S(t){return t.fetchStatus}function BS(t){return t.fetchBranches}const VS=({directory:t,value:e,onChange:n,className:r,disabled:o,id:i})=>{const{t:c}=Tt(),{localBranches:l,remoteBranches:u,isLoading:m,isGitRepository:d}=qm(t),f=a.useMemo(()=>[...l,...u.map(x=>`remotes/${x}`)],[l,u]);a.useEffect(()=>{if(o||m||f.length===0||e&&f.includes(e))return;(async()=>{try{const p=t?await wa(t).catch(()=>null):null,y=localStorage.getItem(MS);y&&f.includes(y)?n(y):p&&f.includes(p)?n(p):f.includes("main")?n("main"):f.includes("master")?n("master"):f[0]&&n(f[0])}catch{}})()},[f,t,o,m,n,e]);const g=o||!d||m;return s.jsxs("div",{children:[s.jsxs(zn,{value:e,onValueChange:n,disabled:g,children:[s.jsx(Wn,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(En,{placeholder:c(m?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(Un,{className:"max-h-[280px] max-w-[320px]",children:m?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.loadingBranches")}):l.length===0&&u.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[l.length>0&&s.jsxs(ml,{children:[s.jsx(Ic,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),l.map(x=>s.jsx(qs,{value:x,className:"whitespace-normal break-all",children:x},x))]}),l.length>0&&u.length>0&&s.jsx(Zh,{}),u.length>0&&s.jsxs(ml,{children:[s.jsx(Ic,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),u.map(x=>s.jsx(qs,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),d===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},$S=10*1024*1024,sl=5,Ko=t=>{const e=pt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let o;return e[1]!==n?(o=s.jsxs(Ot,{children:[r,s.jsx(Bt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=o):o=e[2],o},fi=t=>{const e=pt.c(9),{htmlFor:n,required:r,children:o,info:i}=t;let c;e[0]!==r?(c=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=c):c=e[1];let l;e[2]!==o||e[3]!==n||e[4]!==c?(l=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,c]}),e[2]=o,e[3]=n,e[4]=c,e[5]=l):l=e[5];const u=i&&i;let m;return e[6]!==l||e[7]!==u?(m=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,u]}),e[6]=l,e[7]=u,e[8]=m):m=e[8],m},zS=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=Tt(),[i,c]=a.useState(""),[l,u]=a.useState(()=>[{id:co(),prompt:"",models:[]}]),[m,d]=a.useState(""),[f,g]=a.useState([]),[x,p]=a.useState(!1),[y,b]=a.useState([]),[h,N]=a.useState(!1),[w,S]=a.useState(!1),[v,j]=a.useState(!0),k=a.useRef(null),A=tn(B=>B.currentDirectory??null),T=tn(B=>B.homeDirectory??null),C=a.useMemo(()=>{if(typeof window>"u")return null;const B=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof B=="string"&&B.trim().length>0?B.trim():null},[]),P=Ms(B=>B.activeProjectId),E=Ms(B=>B.setActiveProjectIdOnly),M=Ms(B=>B.projects),[H,R]=a.useState(()=>P??null);a.useEffect(()=>{if(P){R(P);return}!H&&M.length>0&&R(M[0].id)},[P,M,H]);const _=a.useMemo(()=>H?M.find(B=>B.id===H)??null:null,[M,H]),z=_?.path??A,V=a.useCallback(B=>{R(B),B!==P&&E(B)},[P,E]),{currentTheme:F}=Tr(),te=a.useCallback(B=>{const ye=B.label?.trim()||Si(B.path,T),_e=B.icon?Jl[B.icon]:null,J=B.color?Sa[B.color]:void 0,Me=_e?s.jsx(I,{name:_e,className:"h-3.5 w-3.5 shrink-0",style:J?{color:J}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:J?{color:J}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[B.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:B.iconBackground?{backgroundColor:B.iconBackground}:void 0,children:s.jsx(Na,{project:{id:B.id,iconImage:B.iconImage??null},options:{themeVariant:F.metadata.variant,iconColor:F.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Me})}):Me,s.jsx("span",{className:"truncate",children:ye})]})},[T,F.metadata.variant,F.colors.surface.foreground]),Z=a.useMemo(()=>{if(_?.path)return{id:_.id,path:_.path};const B=A??C;return B?{id:`path:${B}`,path:B}:null},[_,A,C]),[ne]=a.useState(()=>typeof window<"u"?or():!1),U=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ie=Su(),oe=a.useMemo(()=>{if(typeof window>"u")return null;const B=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof B=="number"&&Number.isFinite(B)&&B>0)return B;if(typeof navigator>"u")return null;const ye=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ye)return null;const _e=Number.parseInt(ye[1],10),J=Number.parseInt(ye[2],10);return Number.isNaN(_e)?null:_e===10?J:_e},[]),pe=a.useMemo(()=>ne&&U||ie?"pl-[5.5rem]":"pl-3",[ne,U,ie]),je=a.useMemo(()=>!ne||!U||oe===null?"":oe>=26?"h-12":oe<=15?"h-14":"",[ne,U,oe]),Se=a.useCallback(async B=>{B.target.closest("button, a, input, select, textarea")||B.button===0&&ne&&await ep()},[ne]);a.useEffect(()=>{if(!n)return;const B=ye=>{ye.key==="Escape"&&(ye.preventDefault(),ye.stopPropagation(),n())};return window.addEventListener("keydown",B,!0),()=>window.removeEventListener("keydown",B,!0)},[n]);const[re,L]=a.useState(""),{isLoading:$,isGitRepository:K}=qm(z),he=a.useRef(!1),de=K===!0,we=de&&v;a.useEffect(()=>{if(K===!1){he.current=!0,j(!1);return}K===!0&&he.current&&(he.current=!1,j(!0))},[K]);const xe=tl(B=>B.createMultiRun),De=tl(B=>B.error),le=tl(B=>B.clearError);a.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&u(B=>{const ye=[...B];return ye.length>0&&!ye[0].prompt.trim()&&(ye[0]={...ye[0],prompt:t}),ye})},[t]),a.useEffect(()=>{if(!Z)return;let B=!1;return S(!0),(async()=>{try{const ye=await tp(Z);B||b(ye)}catch{}finally{B||S(!1)}})(),()=>{B=!0}},[Z]);const Ce=a.useCallback((B,ye)=>{u(_e=>_e.map(J=>J.id===B?{...J,...ye}:J))},[]),ue=a.useCallback(B=>{u(ye=>ye.filter(_e=>_e.id!==B))},[]),ve=a.useCallback(()=>{u(B=>[...B,{id:co(),prompt:"",models:[]}])},[]),G=async B=>{const ye=B.target.files;if(!ye)return;let _e=0;for(let J=0;J<ye.length;J++){const Me=ye[J];if(Me.size>$S){ae.error(o("multirun.launcher.toast.fileTooLarge",{fileName:Me.name}));continue}try{const Ee=await new Promise((Ne,Be)=>{const se=new FileReader;se.onload=()=>Ne(se.result),se.onerror=Be,se.readAsDataURL(Me)});g(Ne=>[...Ne,{id:co(),filename:Me.name,mimeType:Me.type||"application/octet-stream",size:Me.size,dataUrl:Ee}]),_e++}catch(Ee){console.error("File attach failed",Ee),ae.error(o("multirun.launcher.toast.attachFailed",{fileName:Me.name}))}}_e>0&&ae.success(_e===1?o("multirun.launcher.toast.attachedSingle",{count:_e}):o("multirun.launcher.toast.attachedPlural",{count:_e})),k.current&&(k.current.value="")},Ae=B=>{g(ye=>ye.filter(_e=>_e.id!==B))},ce=a.useMemo(()=>l.reduce((B,ye)=>B+ye.models.length,0),[l]),fe=async B=>{B.preventDefault();const ye=l.filter(_e=>_e.prompt.trim()&&_e.models.length>=1);if(ye.length!==0&&!(ce<1)){p(!0),le();try{H&&H!==P&&E(H);const _e=f.map(Be=>({mime:Be.mimeType,filename:Be.filename,url:Be.dataUrl})),J=y.filter(Be=>Be.trim().length>0),Me=ye.map(Be=>({prompt:Be.prompt.trim(),models:Be.models.map(se=>({providerID:se.providerID,modelID:se.modelID,displayName:se.displayName,variant:se.variant}))})),Ee={name:i.trim(),groups:Me,agent:m||void 0,worktreeBaseBranch:we?re:void 0,isolateRuns:we,files:_e.length>0?_e:void 0,setupCommands:J.length>0?J:void 0},Ne=await xe(Ee);Ne&&(Ne.firstSessionId&&jt.getState().setCurrentSession(Ne.firstSessionId),e?.())}finally{p(!1)}}},Te=!!(i.trim()&&l.some(B=>B.prompt.trim()&&B.models.length>=1)&&ce>=1&&z&&!$&&(K===!1||!we||re)),me=y.filter(B=>B.trim()).length;return s.jsxs("form",{onSubmit:fe,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:Se,className:Pe("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",pe,je),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:o("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":o("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})}),s.jsx(Bt,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(ba,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(fi,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),M.length>0?s.jsxs(zn,{value:H??void 0,onValueChange:V,children:[s.jsx(Wn,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:_?s.jsx(En,{children:te(_)}):s.jsx(En,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx(Un,{fitContent:!0,children:M.map(B=>s.jsx(qs,{value:B.id,className:"max-w-[24rem]",children:te(B)},B.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:o("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(fi,{htmlFor:"group-name",required:!0,info:s.jsx(Ko,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(kn,{id:"group-name",value:i,onChange:B=>c(B.target.value),placeholder:o("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(fi,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Ko,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(VS,{directory:z,value:re,onChange:L,disabled:!we,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(ji,{checked:v,onChange:j,disabled:!de,ariaLabel:o("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:o("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(fi,{htmlFor:"multirun-agent",info:s.jsx(Ko,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(zm,{value:m,onChange:d,id:"multirun-agent"})]})]}),s.jsxs(Vi,{open:h,onOpenChange:N,children:[s.jsxs(vo,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(I,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:o("multirun.launcher.setupCommands.label")}),me>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:me}),s.jsx(I,{name:"arrow-down-s",className:Pe("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx($i,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:w?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:o("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[y.map((B,ye)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(kn,{value:B,onChange:_e=>{const J=[...y];J[ye]=_e.target.value,b(J)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>b(y.filter((_e,J)=>J!==ye)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":o("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]},`${B}-${ye}`)),s.jsxs("button",{type:"button",onClick:()=>b([...y,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(I,{name:"add",className:"h-3 w-3"}),o("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(fi,{htmlFor:"prompt",required:!0,children:o("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:k,type:"file",multiple:!0,className:"hidden",onChange:G,accept:"*/*"}),s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>k.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(I,{name:"attachment-2",className:"h-3 w-3"}),o("multirun.launcher.attachments.attach")]})}),s.jsx(Bt,{children:o("multirun.launcher.attachments.tooltip")})]}),f.map(B=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[B.mimeType.startsWith("image/")?s.jsx(I,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(I,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:B.filename,children:B.filename}),s.jsx("button",{type:"button",onClick:()=>Ae(B.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(I,{name:"close",className:"h-3 w-3"})})]},B.id))]})]}),l.map((B,ye)=>s.jsx(WS,{group:B,groupIndex:ye,canRemove:l.length>1,onUpdate:Ce,onRemove:ue},B.id)),s.jsxs("button",{type:"button",onClick:ve,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),o("multirun.launcher.groups.addGroup")]}),De&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:De})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!we&&K!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(I,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:o("multirun.launcher.project.gitRequired")})]}):null,s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:n,children:o("multirun.launcher.actions.cancel")}),s.jsx(ze,{type:"submit",size:"sm",disabled:!Te||x,children:x?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:ce})})})]})})]})},WS=t=>{const e=pt.c(99),{group:n,groupIndex:r,canRemove:o,onUpdate:i,onRemove:c}=t,{t:l}=Tt(),[u,m]=a.useState(!1),[d,f]=a.useState(""),[g,x]=a.useState(!1),[p,y]=a.useState(""),[b,h]=a.useState(!1),[N,w]=a.useState(""),S=a.useRef(null),v=a.useRef(null),j=a.useRef(null),k=a.useRef(null);let A;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(A=J=>{n.models.length>=sl||i(n.id,{models:[...n.models,J]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=A):A=e[3];const T=A;let C;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(C=J=>{i(n.id,{models:n.models.filter((Me,Ee)=>Ee!==J)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=C):C=e[7];const P=C;let E;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(E=(J,Me)=>{i(n.id,{models:n.models.map((Ee,Ne)=>Ne===J?Me:Ee)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=E):E=e[11];const M=E;let H;e[12]===Symbol.for("react.memo_cache_sentinel")?(H=(J,Me)=>{if(J.startsWith("/")){const se=J.indexOf(" "),O=J.indexOf(`
206
+ `),D=Math.min(se===-1?J.length:se,O===-1?J.length:O);if(Me<=D&&se===-1){y(J.substring(1,D)),x(!0),m(!1),h(!1);return}}x(!1);const Ee=J.substring(0,Me),Ne=Ee.lastIndexOf("#");if(Ne!==-1){const se=Ne>0?Ee[Ne-1]:null,O=Ee.substring(Ne+1);if((!se||/\s/.test(se))&&!O.includes(" ")&&!O.includes(`
207
+ `)){w(O),h(!0),m(!1);return}}h(!1);const Be=Ee.lastIndexOf("@");if(Be!==-1){const se=Be>0?Ee[Be-1]:null,O=Ee.substring(Be+1);(!se||/\s/.test(se))&&!O.includes(" ")&&!O.includes(`
208
+ `)?(f(O),m(!0)):m(!1);return}m(!1)},e[12]=H):H=e[12];const R=H;let _;e[13]!==n.id||e[14]!==i?(_=J=>{i(n.id,{prompt:J})},e[13]=n.id,e[14]=i,e[15]=_):_=e[15];const z=_;let V;e[16]!==n.prompt||e[17]!==z?(V=J=>{const Me=n.prompt,Ne=S.current?.selectionStart??Me.length,se=Me.substring(0,Ne).lastIndexOf("@"),O=J.relativePath&&J.relativePath.trim().length>0?J.relativePath.trim():J.path||J.name,D=se!==-1?se:Ne,Y=`${Me.substring(0,D)}@${O} ${Me.substring(Ne)}`,be=D+O.length+2;z(Y),m(!1),f(""),requestAnimationFrame(()=>{const Oe=S.current;Oe&&(Oe.selectionStart=be,Oe.selectionEnd=be,Oe.focus()),R(Y,be)})},e[16]=n.prompt,e[17]=z,e[18]=V):V=e[18];const F=V;let te;e[19]!==n.prompt||e[20]!==z?(te=J=>{const Me=n.prompt,Ne=S.current?.selectionStart??Me.length,se=Me.substring(0,Ne).lastIndexOf("@"),O=se!==-1?se:Ne,D=`${Me.substring(0,O)}@${J} ${Me.substring(Ne)}`,Y=O+J.length+2;z(D),m(!1),f(""),requestAnimationFrame(()=>{const be=S.current;be&&(be.selectionStart=Y,be.selectionEnd=Y,be.focus()),R(D,Y)})},e[19]=n.prompt,e[20]=z,e[21]=te):te=e[21];const Z=te;let ne;e[22]!==z?(ne=J=>{const Me=`/${J.name} `;z(Me),x(!1),y(""),h(!1),requestAnimationFrame(()=>{const Ee=S.current;Ee&&(Ee.focus(),Ee.selectionStart=Ee.value.length,Ee.selectionEnd=Ee.value.length),R(Me,Me.length)})},e[22]=z,e[23]=ne):ne=e[23];const U=ne;let ie;e[24]!==n.prompt||e[25]!==z?(ie=(J,Me)=>{const Ee=n.prompt,Be=S.current?.selectionStart??Ee.length,O=Ee.substring(0,Be).lastIndexOf("#"),D=O!==-1?O:Be,Y=`${Ee.substring(0,D)}#${Me} ${Ee.substring(Be)}`,be=D+Me.length+2;z(Y),h(!1),w(""),requestAnimationFrame(()=>{const Oe=S.current;Oe&&(Oe.selectionStart=be,Oe.selectionEnd=be,Oe.focus()),R(Y,be)})},e[24]=n.prompt,e[25]=z,e[26]=ie):ie=e[26];const oe=ie;let pe;e[27]!==g||e[28]!==u||e[29]!==b?(pe=J=>{if(g&&j.current&&(J.key==="Enter"||J.key==="ArrowUp"||J.key==="ArrowDown"||J.key==="Escape"||J.key==="Tab")){J.preventDefault(),j.current.handleKeyDown(J.key);return}u&&v.current&&(J.key==="Enter"||J.key==="ArrowUp"||J.key==="ArrowDown"||J.key==="Escape"||J.key==="Tab")&&(J.preventDefault(),v.current.handleKeyDown(J.key)),b&&k.current&&(J.key==="Enter"||J.key==="ArrowUp"||J.key==="ArrowDown"||J.key==="Escape"||J.key==="Tab")&&(J.preventDefault(),k.current.handleKeyDown(J.key))},e[27]=g,e[28]=u,e[29]=b,e[30]=pe):pe=e[30];const je=pe,Se=r+1;let re;e[31]!==l||e[32]!==Se?(re=l("multirun.launcher.groups.groupLabel",{index:Se}),e[31]=l,e[32]=Se,e[33]=re):re=e[33];let L;e[34]!==re?(L=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:re}),e[34]=re,e[35]=L):L=e[35];let $;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==l?($=o&&s.jsx("button",{type:"button",onClick:()=>c(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":l("multirun.launcher.groups.removeGroup"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=o,e[37]=n.id,e[38]=c,e[39]=l,e[40]=$):$=e[40];let K;e[41]!==L||e[42]!==$?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[L,$]}),e[41]=L,e[42]=$,e[43]=K):K=e[43];let he;e[44]!==l?(he=l("multirun.launcher.groups.prompt.label"),e[44]=l,e[45]=he):he=e[45];let de;e[46]!==he?(de=s.jsx(fi,{required:!0,children:he}),e[46]=he,e[47]=de):de=e[47];const we=n.prompt;let xe;e[48]!==z?(xe=J=>{const Me=J.target.value;z(Me);const Ee=J.target.selectionStart??Me.length;R(Me,Ee)},e[48]=z,e[49]=xe):xe=e[49];let De;e[50]!==l?(De=l("multirun.launcher.groups.prompt.placeholder"),e[50]=l,e[51]=De):De=e[51];let le;e[52]!==n.prompt||e[53]!==je||e[54]!==xe||e[55]!==De?(le=s.jsx(gi,{ref:S,value:we,onChange:xe,onKeyDown:je,placeholder:De,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=je,e[54]=xe,e[55]=De,e[56]=le):le=e[56];let Ce;e[57]!==p||e[58]!==U||e[59]!==g?(Ce=g?s.jsx(Bu,{ref:j,searchQuery:p,onCommandSelect:U,onClose:()=>x(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=p,e[58]=U,e[59]=g,e[60]=Ce):Ce=e[60];let ue;e[61]!==Z||e[62]!==F||e[63]!==d||e[64]!==u?(ue=u?s.jsx(Vu,{ref:v,searchQuery:d,onFileSelect:F,onAgentSelect:Z,onClose:()=>m(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=Z,e[62]=F,e[63]=d,e[64]=u,e[65]=ue):ue=e[65];let ve;e[66]!==oe||e[67]!==b||e[68]!==N?(ve=b?s.jsx($u,{ref:k,searchQuery:N,onSnippetSelect:oe,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=oe,e[67]=b,e[68]=N,e[69]=ve):ve=e[69];let G;e[70]!==le||e[71]!==Ce||e[72]!==ue||e[73]!==ve?(G=s.jsxs("div",{className:"relative",children:[le,Ce,ue,ve]}),e[70]=le,e[71]=Ce,e[72]=ue,e[73]=ve,e[74]=G):G=e[74];let Ae;e[75]!==de||e[76]!==G?(Ae=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[de,G]}),e[75]=de,e[76]=G,e[77]=Ae):Ae=e[77];let ce;e[78]!==l?(ce=l("multirun.launcher.models.info",{max:sl}),e[78]=l,e[79]=ce):ce=e[79];let fe;e[80]!==ce?(fe=s.jsx(Ko,{children:ce}),e[80]=ce,e[81]=fe):fe=e[81];let Te;e[82]!==l?(Te=l("multirun.launcher.models.label"),e[82]=l,e[83]=Te):Te=e[83];let me;e[84]!==fe||e[85]!==Te?(me=s.jsx(fi,{required:!0,info:fe,children:Te}),e[84]=fe,e[85]=Te,e[86]=me):me=e[86];let B;e[87]!==n.models||e[88]!==T||e[89]!==P||e[90]!==M?(B=s.jsx(Um,{selectedModels:n.models,onAdd:T,onRemove:P,onUpdate:M,minModels:1,maxModels:sl}),e[87]=n.models,e[88]=T,e[89]=P,e[90]=M,e[91]=B):B=e[91];let ye;e[92]!==me||e[93]!==B?(ye=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[me,B]}),e[92]=me,e[93]=B,e[94]=ye):ye=e[94];let _e;return e[95]!==K||e[96]!==Ae||e[97]!==ye?(_e=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[K,Ae,ye]}),e[95]=K,e[96]=Ae,e[97]=ye,e[98]=_e):_e=e[98],_e},US=a.createContext(null),HS=t=>{const e=pt.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(US.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},ou=wo(()=>Ui(()=>import("./TerminalView-CePdcScA.js"),__vite__mapDeps([5,1,2,0,3,4,6,7,8])).then(t=>({default:t.TerminalView}))),GS=wo(()=>Ui(()=>import("./NewWorktreeDialog-C6394QE9.js").then(t=>t.a1),__vite__mapDeps([6,1,2,0,3,4,7])).then(t=>({default:t.SettingsView}))),KS=wo(()=>Ui(()=>import("./SettingsWindow-DXEjjH2f.js"),__vite__mapDeps([9,1,2,0,3,4,6,7])).then(t=>({default:t.SettingsWindow}))),qS=wo(()=>Ui(()=>import("./MultiRunWindow-DXXoYCBh.js"),__vite__mapDeps([10,1,2,0,3,4,6,7,8])).then(t=>({default:t.MultiRunWindow}))),YS=280,JS=500,QS=360,XS=860,ZS=()=>{const o=Fe(re=>re.isSidebarOpen),i=Fe(re=>re.isRightSidebarOpen),c=Fe(re=>re.isBottomTerminalOpen),l=Fe(re=>re.setRightSidebarOpen),u=Fe(re=>re.setBottomTerminalOpen),m=Fe(re=>re.activeMainTab),d=Fe(re=>re.setIsMobile),f=Fe(re=>re.isSessionSwitcherOpen),g=Fe(re=>re.isSettingsDialogOpen),x=Fe(re=>re.setSettingsDialogOpen),p=Fe(re=>re.isMultiRunLauncherOpen),y=Fe(re=>re.setMultiRunLauncherOpen),b=Fe(re=>re.multiRunLauncherPrefillPrompt),{isMobile:h,isTablet:N}=Pr(),w=Fe(re=>re.sidebarWidth),S=Fe(re=>re.rightSidebarWidth),v=a.useRef(!1),j=a.useRef(!1),k=a.useRef(!1),[A,T]=a.useState(!1),[C,P]=a.useState(!1),[E,M]=a.useState(!1),[H,R]=a.useState(!1),_=a.useCallback(re=>{T(re),Fe.getState().setSessionSwitcherOpen(re)},[]),z=a.useRef(!1),V=a.useRef(typeof window>"u"?0:window.innerWidth),F=hc(-V.current),te=et.useRef(0),Z=hc(V.current),ne=et.useRef(0);et.useEffect(()=>{h&&(te.current=window.innerWidth,ne.current=window.innerWidth)},[h]),et.useEffect(()=>{if(!h){M(!1);return}A&&M(!0),pc(F,A?0:-te.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[A,h,F]),et.useEffect(()=>{if(!h){R(!1);return}z.current=C,C&&R(!0),pc(Z,C?0:ne.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,C,Z]),et.useEffect(()=>{if(h)return F.on("change",re=>{const L=te.current||V.current,$=A||re>-L+.5;M(K=>K===$?K:$)})},[h,F,A]),et.useEffect(()=>{if(h)return Z.on("change",re=>{const L=ne.current||V.current,$=C||re<L-.5;R(K=>K===$?K:$)})},[h,C,Z]),et.useEffect(()=>{h&&!f&&A&&_(!1)},[f,h,A,_]),et.useEffect(()=>{if(!h){k.current=!1;return}k.current||(k.current=!0,_(!1),P(!1),Fe.getState().isRightSidebarOpen&&l(!1))},[h,_,l]),et.useEffect(()=>{if(!h||m!=="chat"||A||C||g)return;let re=!1,L;const $=K=>{L=window.setTimeout(()=>{if(re)return;const he=jt.getState(),de=Fe.getState();if(!(de.activeMainTab!=="chat"||de.isSettingsDialogOpen||he.currentSessionId||he.newSessionDraft?.open)){if(he.isLoading){$(250);return}he.openNewSessionDraft()}},K)};return $(500),()=>{re=!0,L!==void 0&&window.clearTimeout(L)}},[m,h,g,A,C]),et.useEffect(()=>{!h||!g||(_(!1),P(!1),i&&l(!1))},[h,g,i,_,l]);const U=Ti(re=>re.checkForUpdates);a.useEffect(()=>{let he=!1,de=null;const we=De=>{const le=Math.round(De*1e3);return Math.max(3e5,Math.min(864e5,le))},xe=De=>{he||(de=window.setTimeout(async()=>{const le=await U(),Ce=typeof le=="number"&&Number.isFinite(le)?we(le):36e5;xe(Ce)},De))};return xe(3e3),()=>{he=!0,de!==null&&window.clearTimeout(de)}},[U]),a.useEffect(()=>{Fe.getState().isMobile!==h&&d(h)},[h,d]),a.useEffect(()=>{if(typeof window>"u")return;let re;const L=()=>{re===void 0&&(re=window.requestAnimationFrame(()=>{re=void 0,Fe.getState().updateProportionalSidebarWidths()}))};return window.addEventListener("resize",L),()=>{window.removeEventListener("resize",L),re!==void 0&&window.cancelAnimationFrame(re)}},[]),a.useEffect(()=>{if(typeof window>"u")return;let re;const L=()=>{const K=Fe.getState(),he=window.innerWidth,de=window.innerHeight;if(!h&&!N){const we=he<1140,xe=he>=1220;we?K.isRightSidebarOpen&&(l(!1),v.current=!0):xe&&v.current&&(l(!0),v.current=!1);const De=de<640,le=de>=700;De?K.isBottomTerminalOpen&&(u(!1),j.current=!0):le&&j.current&&(u(!0),j.current=!1)}},$=()=>{re===void 0&&(re=window.requestAnimationFrame(()=>{re=void 0,L()}))};return L(),window.addEventListener("resize",$),()=>{window.removeEventListener("resize",$),re!==void 0&&window.cancelAnimationFrame(re)}},[h,N,u,l]),a.useEffect(()=>{if(typeof window>"u")return;const re=Fe.subscribe((L,$)=>{const K=window.innerWidth,he=window.innerHeight,de=K>=1220,we=he>=700;L.isRightSidebarOpen!==$.isRightSidebarOpen&&de&&(v.current=!1),L.isBottomTerminalOpen!==$.isBottomTerminalOpen&&we&&(j.current=!1)});return()=>{re()}},[h,N,u,l]);const ie=a.useCallback(()=>{A&&_(!1),P(!C)},[A,C,_]),oe=a.useMemo(()=>{switch(m){case"plan":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(jm,{})});case"git":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(Nl,{})});case"diff":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(xm,{})});case"terminal":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(ou,{})});case"files":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(vm,{})});case"context":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(fm,{})});default:return null}},[m]),pe=m==="chat",je=a.useMemo(()=>Math.min(JS,Math.max(YS,w||wl)),[w]),Se=a.useMemo(()=>Math.min(XS,Math.max(QS,S||vl)),[S]);return s.jsx(Qp,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:Pe("main-content-safe-area",h?"flex h-[100dvh] flex-col":"flex h-[100dvh]","bg-background"),children:[s.jsx(E1,{}),s.jsx(yv,{}),s.jsx(Sv,{}),s.jsx(PS,{}),h?s.jsxs(HS,{value:{leftDrawerOpen:A,rightDrawerOpen:C,toggleLeftDrawer:()=>{const re=!A;C&&P(!1),_(re)},toggleRightDrawer:ie,leftDrawerX:F,rightDrawerX:Z,leftDrawerWidth:te,rightDrawerWidth:ne,setMobileLeftDrawerOpen:_,setRightSidebarOpen:P},children:[!g&&s.jsx(qc,{onToggleLeftDrawer:()=>{const re=!A;C&&P(!1),_(re)},onToggleRightDrawer:()=>{ie()},leftDrawerOpen:A,rightDrawerOpen:C}),s.jsx("div",{"data-page-scroll-lock":"true",className:Pe("flex flex-1 overflow-hidden relative",g&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:Pe("absolute inset-0",!pe&&"invisible"),children:s.jsx(on,{children:s.jsx(gl,{})})}),oe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(on,{children:oe})}),p&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(on,{children:s.jsx(zS,{initialPrompt:b,onCreated:()=>y(!1),onCancel:()=>y(!1)})})}),E&&s.jsx(gc.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:F},"aria-hidden":!A,children:s.jsx(on,{children:s.jsx(nu,{mobileVariant:!0})})}),H&&s.jsx(gc.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:Z},"aria-hidden":!C,children:s.jsx(on,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(Nl,{})})})})]})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(on,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(GS,{onClose:()=>x(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[s.jsx(qc,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-sidebar","data-page-scroll-lock":"true",children:[s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute top-0 z-0 bg-sidebar transition-[left,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{left:`${o?je:0}px`,opacity:o?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-0 z-0 bg-sidebar transition-[left,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{left:`${o?je:0}px`,opacity:o?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute top-0 z-0 bg-sidebar transition-[right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{right:`${i?Se:0}px`,opacity:i?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-0 z-0 bg-sidebar transition-[right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{right:`${i?Se:0}px`,opacity:i?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}}),s.jsx(Xg,{isOpen:o,isMobile:h,className:"border-0",children:s.jsx(nu,{})}),s.jsxs("div",{className:Pe("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-background","border border-border/50 rounded-[10px]",!o&&"border-l-transparent",!i&&"border-r-transparent"),"data-page-scroll-lock":"true",children:[s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:Pe("absolute inset-0",!pe&&"invisible"),children:s.jsx(on,{children:s.jsx(gl,{})})}),oe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(on,{children:oe})})]}),s.jsx(T1,{})]})}),s.jsx(Kg,{isOpen:c,isMobile:h,children:c?s.jsx(on,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(ou,{})})}):null})]}),s.jsx(Zg,{isOpen:i,className:"border-0",children:s.jsx(on,{children:s.jsx(Ey,{})})})]})]}),s.jsx(a.Suspense,{fallback:null,children:s.jsx(KS,{open:g,onOpenChange:x})}),s.jsx(a.Suspense,{fallback:null,children:s.jsx(qS,{open:p,onOpenChange:y,initialPrompt:b})})]})]})})},e2=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},Zn=t=>{const e=pt.c(8),{label:n,value:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=o):o=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let c;e[3]!==r?(c=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=c):c=e[4];let l;return e[5]!==i||e[6]!==c?(l=s.jsxs("div",{className:"rounded-md p-2",style:o,children:[i,c]}),e[5]=i,e[6]=c,e[7]=l):l=e[7],l},au=t=>{const e=pt.c(43),{title:n,snapshot:r,emptyLabel:o}=t,{t:i}=Tt();let c;if(e[0]!==o||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const l=r.entries.slice(0,12);let u;e[8]!==r.entries?(u=r.entries.reduce(n2,0),e[8]=r.entries,e[9]=u):u=e[9];const m=u;let d;e[10]!==n?(d=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=d):d=e[11];let f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(f=r.startedAt?e2(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=f):f=e[15];let g;e[16]!==f?(g=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:f}),e[16]=f,e[17]=g):g=e[17];let x;e[18]!==d||e[19]!==g?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,g]}),e[18]=d,e[19]=g,e[20]=x):x=e[20];let p;e[21]!==i?(p=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=p):p=e[22];let y;e[23]!==r.entries.length||e[24]!==p?(y=s.jsx(Zn,{label:p,value:r.entries.length}),e[23]=r.entries.length,e[24]=p,e[25]=y):y=e[25];let b;e[26]!==i?(b=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=b):b=e[27];let h;e[28]!==b||e[29]!==m?(h=s.jsx(Zn,{label:b,value:m}),e[28]=b,e[29]=m,e[30]=h):h=e[30];let N;e[31]!==i?(N=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=N):N=e[32];let w;e[33]!==r.lastUpdatedAt||e[34]!==i?(w=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=w):w=e[35];let S;e[36]!==N||e[37]!==w?(S=s.jsx(Zn,{label:N,value:w}),e[36]=N,e[37]=w,e[38]=S):S=e[38];let v;e[39]!==h||e[40]!==S||e[41]!==y?(v=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[y,h,S]}),e[39]=h,e[40]=S,e[41]=y,e[42]=v):v=e[42],c=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,v,l.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:o}):s.jsx(_n,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:l.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=o,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=c}else c=e[7];return c},t2=t=>{const e=pt.c(101),{onClose:n}=t,{t:r}=Tt(),[o,i]=a.useState("memory"),[c,l]=a.useState("idle"),u=jt(r2),m=Wu(i2),d=Kl(),f=sp(o2),g=tr(a2),[x,p]=a.useState(l2),[y,b]=a.useState(c2);let h;e[0]!==x.entries?(h=new Map,x.entries.forEach(ce=>{h.set(ce.metric,ce.count)}),e[0]=x.entries,e[1]=h):h=e[1];let N;e[2]!==h?(N=h.get("ui.message_list.render")??0,e[2]=h,e[3]=N):N=e[3];let w;e[4]!==h?(w=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=w):w=e[5];let S;e[6]!==h?(S=h.get("ui.chat_message.render")??0,e[6]=h,e[7]=S):S=e[7];let v;e[8]!==h?(v=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=v):v=e[9];let j;e[10]!==h?(j=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=j):j=e[11];let k;e[12]!==h?(k=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=k):k=e[13];let A;e[14]!==N||e[15]!==w||e[16]!==S||e[17]!==v||e[18]!==j||e[19]!==k?(A={messageListRender:N,messageListRenderStreaming:w,chatMessageRender:S,chatMessageRenderStreaming:v,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:k},e[14]=N,e[15]=w,e[16]=S,e[17]=v,e[18]=j,e[19]=k,e[20]=A):A=e[20];const T=A;let C,P;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const ce=()=>{p(Oo()),b(_o())};ce();const fe=window.setInterval(ce,500);return()=>window.clearInterval(fe)},P=[],e[21]=C,e[22]=P):(C=e[21],P=e[22]),a.useEffect(C,P);let E,M;e[23]!==c?(E=()=>{if(c==="idle")return;const ce=window.setTimeout(()=>{l("idle")},1500);return()=>window.clearTimeout(ce)},M=[c],e[23]=c,e[24]=E,e[25]=M):(E=e[24],M=e[25]),a.useEffect(E,M);let H=0,R;if(e[26]!==f?(R=Object.keys(f),e[26]=f,e[27]=R):R=e[27],e[28]!==f||e[29]!==R||e[30]!==H){for(const ce of R)H=H+(f[ce]?.length??0);e[28]=f,e[29]=R,e[30]=H,e[31]=H}else H=e[31];const _=H;let z;if(e[32]!==u||e[33]!==f||e[34]!==m||e[35]!==d||e[36]!==r){let ce;e[38]!==u||e[39]!==f||e[40]!==m||e[41]!==r?(ce=fe=>{const Te=f[fe.id]?.length||0,me=m.get(fe.id);return{id:fe.id,title:fe.title||r("memoryDebugPanel.common.untitled"),messageCount:Te,isStreaming:me?.isStreaming||!1,isZombie:me?.isZombie||!1,backgroundCount:me?.backgroundMessageCount||0,lastAccessed:me?.lastAccessedAt||0,isCurrent:fe.id===u}},e[38]=u,e[39]=f,e[40]=m,e[41]=r,e[42]=ce):ce=e[42],z=d.map(ce).sort(d2),e[32]=u,e[33]=f,e[34]=m,e[35]=d,e[36]=r,e[37]=z}else z=e[37];const V=z;let F;e[43]!==f?(F=Object.keys(f),e[43]=f,e[44]=F):F=e[44];const te=F.length;let Z;e[45]===Symbol.for("react.memo_cache_sentinel")?(Z=async()=>{try{const ce={generatedAt:new Date().toISOString(),ui:Oo(),vscode:_o()};await navigator.clipboard.writeText(JSON.stringify(ce,null,2)),l("copied")}catch{l("error")}},e[45]=Z):Z=e[45];const ne=Z;let U;e[46]===Symbol.for("react.memo_cache_sentinel")?(U={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=U):U=e[46];let ie;e[47]!==o?(ie=o==="memory"?s.jsx(I,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(I,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=o,e[48]=ie):ie=e[48];let oe;e[49]!==r?(oe=r("memoryDebugPanel.title"),e[49]=r,e[50]=oe):oe=e[50];let pe;e[51]!==oe?(pe=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:oe}),e[51]=oe,e[52]=pe):pe=e[52];let je;e[53]!==ie||e[54]!==pe?(je=s.jsxs("div",{className:"flex items-center gap-2",children:[ie,pe]}),e[53]=ie,e[54]=pe,e[55]=je):je=e[55];let Se;e[56]!==o?(Se=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ze,{size:"xs",variant:"ghost",onClick:ne,children:s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ze,{size:"xs",variant:"ghost",onClick:()=>{rp(),p(Oo()),b(_o())},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=o,e[57]=Se):Se=e[57];let re;e[58]!==n?(re=n?s.jsx(ze,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=re):re=e[59];let L;e[60]!==Se||e[61]!==re?(L=s.jsxs("div",{className:"flex items-center gap-1",children:[Se,re]}),e[60]=Se,e[61]=re,e[62]=L):L=e[62];let $;e[63]!==je||e[64]!==L?($=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[je,L]}),e[63]=je,e[64]=L,e[65]=$):$=e[65];let K;e[66]===Symbol.for("react.memo_cache_sentinel")?(K={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=K):K=e[66];const he=o==="memory"?"secondary":"ghost";let de;e[67]===Symbol.for("react.memo_cache_sentinel")?(de=()=>i("memory"),e[67]=de):de=e[67];let we;e[68]!==r?(we=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=we):we=e[69];let xe;e[70]!==he||e[71]!==we?(xe=s.jsx(ze,{size:"sm",variant:he,className:"flex-1",onClick:de,children:we}),e[70]=he,e[71]=we,e[72]=xe):xe=e[72];const De=o==="streaming"?"secondary":"ghost";let le;e[73]===Symbol.for("react.memo_cache_sentinel")?(le=()=>i("streaming"),e[73]=le):le=e[73];let Ce;e[74]!==r?(Ce=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=Ce):Ce=e[75];let ue;e[76]!==De||e[77]!==Ce?(ue=s.jsx(ze,{size:"sm",variant:De,className:"flex-1",onClick:le,children:Ce}),e[76]=De,e[77]=Ce,e[78]=ue):ue=e[78];let ve;e[79]!==xe||e[80]!==ue?(ve=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:K,children:[xe,ue]}),e[79]=xe,e[80]=ue,e[81]=ve):ve=e[81];let G;e[82]!==o||e[83]!==te||e[84]!==c||e[85]!==u||e[86]!==f||e[87]!==m||e[88]!==V||e[89]!==d||e[90]!==T||e[91]!==x||e[92]!==r||e[93]!==g||e[94]!==_||e[95]!==y?(G=o==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(Zn,{label:r("memoryDebugPanel.metric.totalMessages"),value:_}),s.jsx(Zn,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${te} / ${Pc.MAX_SESSIONS}`})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:np()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:Pc.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:g})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(_n,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(ce=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:ce.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:ce.title}),ce.isStreaming?s.jsx(I,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,ce.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:ce.messageCount})}),ce.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",ce.backgroundCount]}):null]})]},ce.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Ot,{children:[s.jsx(_t,{asChild:!0,children:s.jsx(ze,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:d.map(u2),currentSessionId:u,cachedSessions:Object.keys(f),memoryStates:Object.fromEntries(m)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Bt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(c==="copied"?"memoryDebugPanel.streaming.copy.copied":c==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ze,{size:"xs",variant:"outline",onClick:ne,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(Zn,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(Zn,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:y.entries.length}),s.jsx(Zn,{label:r("memoryDebugPanel.metric.messageListRenders"),value:T.messageListRender}),s.jsx(Zn,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:T.messageListRenderStreaming}),s.jsx(Zn,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:T.chatMessageRender}),s.jsx(Zn,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:T.chatMessageRenderStreaming}),s.jsx(Zn,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:T.chatMessageRenderStaticDuringStream}),s.jsx(Zn,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:T.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(au,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),y.entries.length>0?s.jsx(au,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:y,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=o,e[83]=te,e[84]=c,e[85]=u,e[86]=f,e[87]=m,e[88]=V,e[89]=d,e[90]=T,e[91]=x,e[92]=r,e[93]=g,e[94]=_,e[95]=y,e[96]=G):G=e[96];let Ae;return e[97]!==$||e[98]!==ve||e[99]!==G?(Ae=s.jsxs(ip,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:U,children:[$,ve,G]}),e[97]=$,e[98]=ve,e[99]=G,e[100]=Ae):Ae=e[100],Ae},s2=t2;function n2(t,e){return t+e.count}function r2(t){return t.currentSessionId}function i2(t){return t.sessionMemoryState}function o2(t){return t.message}function a2(t){return t.totalRequestCount}function l2(){return Oo()}function c2(){return _o()}function d2(t,e){return e.lastAccessed-t.lastAccessed}function u2(t){return{id:t.id,title:t.title}}const m2=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},f2=async()=>{const t=m2()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},lu="openchamber:menu-action",nl="openchamber:check-for-updates",h2=t=>{const e=jt(k=>k.openNewSessionDraft),n=Fe(k=>k.toggleCommandPalette),r=Fe(k=>k.setCommandPaletteOpen),o=Fe(k=>k.toggleHelpDialog),i=Fe(k=>k.toggleSidebar),c=Fe(k=>k.setSessionSwitcherOpen),l=Fe(k=>k.setActiveMainTab),u=Fe(k=>k.setSettingsDialogOpen),m=Fe(k=>k.setAboutDialogOpen),d=Fe(k=>k.toggleRightSidebar),f=Fe(k=>k.setRightSidebarOpen),g=Fe(k=>k.setRightSidebarTab),x=Fe(k=>k.toggleBottomTerminal),p=Fe(k=>k.setBottomTerminalExpanded),y=Ti(k=>k.checkForUpdates),{setThemeMode:b}=Tr(),h=a.useRef(!1),N=a.useCallback(()=>{h.current||(h.current=!0,y().then(()=>{const{available:k,error:A}=Ti.getState();if(A){ae.error("Failed to check for updates",{description:A});return}k||ae.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[y]),w=a.useCallback(()=>{Ir.requestDirectoryDialog()},[]),S=a.useCallback(k=>{const A=op();if(A.length===0)return;const T=jt.getState().currentSessionId,C=A.findIndex(M=>M.id===T);let P=k>0?0:A.length-1;C>=0&&(P=(C+k+A.length)%A.length);const E=A[P];E&&(l("chat"),c(!1),jt.getState().setCurrentSession(E.id))},[l,c]),v=a.useCallback(k=>{const{activeProjectId:A,projects:T,setActiveProject:C}=Ms.getState();if(T.length===0)return;const P=T.findIndex(H=>H.id===A);let E=k>0?0:T.length-1;P>=0&&(E=(P+k+T.length)%T.length);const M=T[E];M&&C(M.id)},[]),j=a.useCallback(k=>{switch(k){case"about":m(!0);break;case"settings":u(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":l("chat"),c(!1),e();break;case"new-worktree-session":l("chat"),c(!1),_u();break;case"change-workspace":w();break;case"toggle-right-sidebar":d();break;case"open-right-sidebar-git":f(!0),g("git");break;case"open-right-sidebar-files":f(!0),g("files");break;case"toggle-terminal":x();break;case"toggle-terminal-expanded":p(!Fe.getState().isBottomTerminalExpanded);break;case"copy":{const A=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(A)||f2();break}case"theme-light":b("light");break;case"theme-dark":b("dark");break;case"theme-system":b("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"go-back":tn.getState().goBack();break;case"go-forward":tn.getState().goForward();break;case"previous-session":S(-1);break;case"next-session":S(1);break;case"previous-project":v(-1);break;case"next-project":v(1);break;case"help-dialog":o();break;case"download-logs":{ap().catch(()=>{ae.error("Failed to collect OpenCode status")});break}}},[w,v,S,t,e,m,l,c,r,u,p,f,g,b,x,n,o,d,i]);a.useEffect(()=>{const k=T=>{const C=T.detail;C&&j(C)},A=()=>{N()};return window.addEventListener(lu,k),window.addEventListener(nl,A),()=>{window.removeEventListener(lu,k),window.removeEventListener(nl,A)}},[j,N]),a.useEffect(()=>{if(typeof window>"u")return;const A=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof A!="function")return;let T=null,C=null;return A("openchamber:menu-action",P=>{const E=P?.payload;typeof E=="string"&&j(E)}).then(P=>{T=P}).catch(()=>{}),A("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(nl))}).then(P=>{C=P}).catch(()=>{}),()=>{(async()=>{try{const E=T?.();E instanceof Promise&&await E}catch{}try{const E=C?.();E instanceof Promise&&await E}catch{}})()}},[j])},p2="/api/notifications/stream",g2=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),x2=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},b2=t=>{const e=pt.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||or()||!Yl()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(Li().sse(p2));return i.onmessage=y2,()=>{i.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),a.useEffect(r,o)};function y2(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Fe.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&g2())return;const r=x2(e);if(!r)return;bo()?.notifications?.notifyAgentCompletion(r)}const w2=t=>!(t.dismissed==="true"||t.sessionShown==="true"||t.hasActiveToast),v2=t=>!(!t.version||t.seenVersions.has(t.version)||t.dismissedVersion!==null&&t.dismissedVersion===t.version),j2=t=>{if(t===null||typeof t!="object")return"";const e=t.version;return typeof e!="string"?"":e.trim()},S2=t=>!t||t.available!==!0||typeof t.latestVersion!="string"?"":t.latestVersion.trim(),cu="pwa-install-toast-shown",du="pwa-install-toast-dismissed",N2=()=>{const t=pt.c(6),{browserTab:e}=Xp(),{t:n}=Tt(),r=a.useRef(n);let o,i;t[0]!==n?(o=()=>{r.current=n},i=[n],t[0]=n,t[1]=o,t[2]=i):(o=t[1],i=t[2]),a.useEffect(o,i);let c,l;t[3]!==e?(c=()=>{if(typeof window>"u"||!Yl()||!e)return;let u=null,m=null;const d=()=>{m!==null&&(ae.dismiss(m),m=null)},f=async()=>{if(!u)return;const p=u;u=null,d(),await p.prompt();const{outcome:y}=await p.userChoice;y==="accepted"&&ae.success(r.current("pwa.installPrompt.started"))},g=p=>{const y=p;if(typeof y.prompt!="function")return;y.preventDefault(),u=y;const b=Dr(),h=yu();w2({dismissed:b.getItem(du),sessionShown:h.getItem(cu),hasActiveToast:m!==null})&&(h.setItem(cu,"true"),m=ae.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{f()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Dr().setItem(du,"true"),d()}}}))},x=()=>{u=null,d(),ae.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",g),window.addEventListener("appinstalled",x),()=>{d(),window.removeEventListener("beforeinstallprompt",g),window.removeEventListener("appinstalled",x)}},l=[e],t[3]=e,t[4]=c,t[5]=l):(c=t[4],l=t[5]),a.useEffect(c,l)},k2=()=>{const t=pt.c(3),[e,n]=a.useState(C2),{isUpdating:r}=e;let o,i;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>cp(n),i=[],t[0]=o,t[1]=i):(o=t[0],i=t[1]),a.useEffect(o,i),!r)return null;let c;return t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:s.jsx(ja,{width:80,height:80,isAnimated:!0})}),t[2]=c):c=t[2],c};function C2(){return lp()}const A2=({open:t,onOpenChange:e})=>{const{t:n}=Tt(),r=!1,[o,i]=a.useState(null),[c,l]=a.useState(null),[u,m]=a.useState(!1),[d,f]=a.useState(!1),[g,x]=a.useState(null),[p,y]=a.useState(!1);a.useCallback(async()=>{},[g,u,r,n]),a.useEffect(()=>{if(!t)return;(async()=>{try{const N=await Fs("/api/system/info");if(N.ok){const w=await N.json();if(typeof w.openchamberVersion=="string"&&w.openchamberVersion.trim()){i(w.openchamberVersion);return}}}catch{}i(await dp())})()},[t]),a.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const w=await Fs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!w.ok)return;const S=await w.json().catch(()=>null),v=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!h&&v&&l(v)}catch{}})(),()=>{h=!0}},[t]),a.useEffect(()=>{{x(null),y(!1);return}},[t,r]);const b=o;return s.jsx(Ks,{open:t,onOpenChange:e,children:s.jsx(Gs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(ja,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[b&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:b})}),c&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:c})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},rl=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},D2=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to OpenChamber and click Authorize again.":n},I2=()=>{const t=to(i=>i.completeAuth),[e,n]=a.useState("working"),[r,o]=a.useState("Completing MCP authorization...");return a.useEffect(()=>{if(typeof window>"u"){n("error"),o("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),c=rl(i,"code"),l=Zp(i),u=eg(i),m=rl(i,"error"),d=rl(i,"error_description");if(m){u&&Fs(`/api/mcp/auth/pending?state=${encodeURIComponent(u)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(d??m);return}(async()=>{try{if(!c)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let f=l;if(!f&&u){const g=await Fs(`/api/mcp/auth/pending?state=${encodeURIComponent(u)}`);if(g.ok){const x=await g.json().catch(()=>null);x?.name?.trim()&&(f={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!f?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(f.name,c,f.directory),u&&await Fs(`/api/mcp/auth/pending?state=${encodeURIComponent(u)}`,{method:"DELETE"}).catch(()=>{}),n("success"),o("Authorization completed. You can close this tab and return to OpenChamber.")}catch(f){u&&await Fs(`/api/mcp/auth/pending?state=${encodeURIComponent(u)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(D2(f,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(ze,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},eo="opencode-update-available",Fo="opencode-upgrade-progress",P2=5e3,T2=[1e4,6e4],uu="opencode-update-toast-dismissed-version",Ym=()=>{const{t}=Tt(),e=Fe(c=>c.showOpenCodeUpdateNotifications),n=et.useRef(new Set),r=et.useRef(!1);et.useEffect(()=>{e||ae.dismiss(eo)},[e]);const o=et.useCallback(()=>{ae.dismiss(Fo),up({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=et.useCallback(async()=>{if(!r.current){r.current=!0,ae.dismiss(eo),ae.message(t("opencodeUpdate.toast.upgrading.title"),{id:Fo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(I,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const c=await Fs("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),l=await c.json().catch(()=>null);if(!c.ok||l?.success===!1)throw new Error(l?.error||c.statusText||t("opencodeUpdate.toast.failed.description"));ae.success(t("opencodeUpdate.toast.updated.title"),{id:Fo,description:l?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:l.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(I,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:o}})}catch(c){ae.error(t("opencodeUpdate.toast.failed.title"),{id:Fo,description:c instanceof Error?c.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[o,t]);return et.useEffect(()=>{const c=f=>{if(!Fe.getState().showOpenCodeUpdateNotifications){ae.dismiss(eo);return}v2({version:f,dismissedVersion:Dr().getItem(uu),seenVersions:n.current})&&(n.current.add(f),ae.info(t("opencodeUpdate.toast.available.title"),{id:eo,description:t("opencodeUpdate.toast.available.description",{version:f}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:t("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{Dr().setItem(uu,f),ua({openCodeUpdateToastDismissedVersion:f}),ae.dismiss(eo)}}}))},l=f=>{const g=j2(f.detail);c(g)};let u=!1;const m=[],d=async f=>{try{const g=await Fs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!g.ok)throw new Error(g.statusText||"OpenCode upgrade status check failed");const x=await g.json().catch(()=>null),p=S2(x);!u&&p&&c(p)}catch{const g=T2[f];!u&&g!==void 0&&m.push(setTimeout(()=>{d(f+1)},g))}};return e&&m.push(setTimeout(()=>{d(0)},P2)),window.addEventListener("openchamber:opencode-update-available",l),()=>{u=!0;for(const f of m)clearTimeout(f);window.removeEventListener("openchamber:opencode-update-available",l)}},[i,e,t]),null},mu=wo(()=>Ui(()=>import("./OnboardingScreen-CLXmHHBW.js"),__vite__mapDeps([11,1,2,0,3,4])).then(t=>({default:t.OnboardingScreen}))),E2=()=>{const t=pt.c(3),e=Fe(_2),n=Fe(B2);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(A2,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},R2=t=>{const e=pt.c(21),{onRetry:n,isRetrying:r}=t,{t:o}=Tt();let i;e[0]!==o?(i=o("startup.initRecovery.title"),e[0]=o,e[1]=i):i=e[1];let c;e[2]!==i?(c=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let l;e[4]!==o?(l=o("startup.initRecovery.description"),e[4]=o,e[5]=l):l=e[5];let u;e[6]!==l?(u=s.jsx("p",{className:"typography-body text-muted-foreground",children:l}),e[6]=l,e[7]=u):u=e[7];let m;e[8]!==c||e[9]!==u?(m=s.jsxs("div",{className:"flex flex-col gap-2",children:[c,u]}),e[8]=c,e[9]=u,e[10]=m):m=e[10];let d;e[11]!==r||e[12]!==o?(d=o(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=o,e[13]=d):d=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==d?(f=s.jsx(ze,{type:"button",onClick:n,disabled:r,children:d}),e[14]=r,e[15]=n,e[16]=d,e[17]=f):f=e[17];let g;return e[18]!==m||e[19]!==f?(g=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[m,f]})}),e[18]=m,e[19]=f,e[20]=g):g=e[20],g},fu=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",M2=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),o=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:o,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},F2=()=>typeof window>"u"?!1:window.location.pathname===sg,L2=t=>{const e=pt.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,i=tn(V2),c=jt($2),l=jt(z2),u=Xl(),m=a.useRef(null);let d;e[0]!==n.directory?(d=fu(n.directory),e[0]=n.directory,e[1]=d):d=e[1];const f=d;let g;e[2]!==i?(g=fu(i),e[2]=i,e[3]=g):g=e[3];const x=g;let p,y;if(e[4]!==x||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==l||e[11]!==u?(p=()=>{if(r||f&&x!==f)return;const v=`${f}
209
+ ${n.sessionId}`;m.current===v&&c===n.sessionId||(m.current=v,l(n.sessionId,n.directory),u.ensureSessionRenderable(n.sessionId,!0))},y=[x,c,n.directory,n.sessionId,f,r,l,u],e[4]=x,e[5]=c,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=l,e[11]=u,e[12]=p,e[13]=y):(p=e[12],y=e[13]),a.useEffect(p,y),f&&x!==f)return null;let b;e[14]!==o?(b=s.jsx(Uu,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=b):b=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Ym,{}),e[16]=h):h=e[16];let N;e[17]!==n.readOnly?(N=s.jsx(gl,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=N):N=e[18];let w;e[19]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Hu,{}),e[19]=w):w=e[19];let S;return e[20]!==b||e[21]!==N?(S=s.jsxs(s.Fragment,{children:[b,h,N,w]}),e[20]=b,e[21]=N,e[22]=S):S=e[22],S};function O2({apis:t}){a.useEffect(()=>{mp("App:mounted"),fp()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=ls($=>$.initializeApp),n=ls($=>$.isInitialized),r=ls($=>$.isConnected),o=ls($=>$.providers.length),i=ls($=>$.agents.length),c=ls($=>$.loadProviders),l=ls($=>$.loadAgents),u=jt($=>$.error),m=jt($=>$.clearError),d=tn($=>$.currentDirectory),f=tn($=>$.setDirectory),g=tn($=>$.isSwitchingDirectory),[x,p]=a.useState(!1),y=vi($=>$.refreshStatus),[b,h]=a.useState(()=>t.runtime.isVSCode),[N,w]=a.useState(!0),[S,v]=a.useState(!1),[j,k]=a.useState(0),[A,T]=a.useState(0),[C,P]=a.useState(!1),E=Fe($=>$.wideChatLayoutEnabled),M=Fe($=>$.mobileKeyboardMode),H=a.useMemo(()=>or(),[]),R=Bl($=>$.setPlanModeEnabled),[_,z]=a.useState(()=>Tc()),[V,F]=a.useState(()=>{const $=Ec();return $!==null?Rc({isDesktopShell:!0,bootOutcome:$}):null}),te=a.useRef(!1),Z=a.useMemo(()=>M2(),[]),ne=!Z||N,U=a.useMemo(()=>F2(),[]);a.useEffect(()=>(Mc(x),()=>{Mc(!1)}),[x]),a.useEffect(()=>{hp(M)},[M]),a.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),a.useEffect(()=>bu($=>{jt.getState().prepareForRuntimeSwitch($.previousRuntimeKey),Fe.getState().prepareForRuntimeSwitch($.previousRuntimeKey),pf(),Hn.reconnectToRuntimeBaseUrl(),ls.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),Ms.getState().resetForRuntimeSwitch(),jt.getState().restoreForRuntimeSwitch($.runtimeKey),Fe.getState().restoreForRuntimeSwitch($.runtimeKey),pp(),T(K=>K+1),v(!1),k(K=>K+1)}),[]),a.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",E),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[E]),a.useEffect(()=>(Fc(t),()=>Fc(null)),[t]),a.useEffect(()=>{Z||y(t.github,{force:!0})},[t.github,Z,y]),gp();const ie=_==="valid",oe=V?.screen==="main";a.useEffect(()=>{if(!xp({isDesktopShell:H,isInitialized:n,bootOutcomeKnown:ie,bootViewIsMain:oe}))return;const $=setTimeout(()=>{const K=document.getElementById("initial-loading");K&&(K.classList.add("fade-out"),setTimeout(()=>{K.remove()},300))},150);return()=>clearTimeout($)},[H,n,ie,oe]),a.useEffect(()=>{if(!H||_!=="malformed")return;const $=document.getElementById("initial-loading");$&&($.textContent="Desktop startup failed — please restart the app.")},[H,_]),a.useEffect(()=>{if(H)return;const $=setTimeout(()=>{const K=document.getElementById("initial-loading");K&&!n&&(K.classList.add("fade-out"),setTimeout(()=>{K.remove()},300))},5e3);return()=>clearTimeout($)},[H,n]),a.useEffect(()=>{let $=!1;return(async()=>{const he=await Fs("/health",{method:"GET"}).catch(()=>null);if(!he||!he.ok||$)return;const de=await he.json().catch(()=>null);if(!de||$)return;const we=de.planModeExperimentalEnabled;R(we===!0||we===1||we==="1"||we==="true")})(),()=>{$=!0}},[R]),a.useEffect(()=>{b||e()},[e,b]),a.useEffect(()=>{if(b||n)return;let $=!0,K,he=0;const de=10,we=1e3,xe=async()=>{if(!$)return;if(he>=de){v(!0);return}const De=ls.getState();if(De.isInitialized){v(!1);return}he+=1,await De.initializeApp();const le=ls.getState();if(!$)return;if(le.isInitialized){v(!1);return}if(he>=de){v(!0);return}const Ce=Math.min(we*Math.pow(2,he-1),16e3);K=setTimeout(xe,Ce)};return K=setTimeout(xe,we),()=>{$=!1,K&&clearTimeout(K)}},[j,n,b]),a.useEffect(()=>{n&&v(!1)},[n]),a.useEffect(()=>{if(!S)return;const $=document.getElementById("initial-loading");$&&($.classList.add("fade-out"),setTimeout(()=>{$.remove()},300))},[S]),a.useEffect(()=>{if(b||!r||o>0&&i>0)return;let $=!0,K=0;const he=15,de=async()=>{const xe=ls.getState();if(!(xe.providers.length>0&&xe.agents.length>0))try{xe.providers.length===0&&await c({source:"startupRecovery"}),ls.getState().agents.length===0&&await l({source:"startupRecovery"})}catch{}};de();const we=setInterval(()=>{if($){if(++K>=he){clearInterval(we);return}de()}},2e3);return()=>{$=!1,clearInterval(we)}},[r,b,l,c,o,i]),a.useEffect(()=>{g||b||r&&Hn.setDirectory(d)},[d,g,r,b]),a.useEffect(()=>{if(!Z||typeof window>"u")return;const $=de=>{const we=de?.visible===!0;w(we)},K=de=>{if(de.origin!==window.location.origin)return;const we=de.data;we?.type==="openchamber:embedded-visibility"&&$(we.payload)},he=window;return he.__openchamberSetEmbeddedVisibility=$,window.addEventListener("message",K),()=>{window.removeEventListener("message",K),he.__openchamberSetEmbeddedVisibility===$&&delete he.__openchamberSetEmbeddedVisibility}},[Z]),a.useEffect(()=>{!Z?.directory||b||d!==Z.directory&&f(Z.directory,{showOverlay:!1})},[d,Z,b,f]),a.useEffect(()=>{if(!Z||typeof window>"u")return;const $=K=>{K.storageArea===window.localStorage&&K.key==="ui-store"&&Fe.persist.rehydrate()};return window.addEventListener("storage",$),()=>{window.removeEventListener("storage",$)}},[Z]),a.useEffect(()=>{if(typeof window>"u")return;const $=K=>{const he=K.detail,de=typeof he?.sessionId=="string"?he.sessionId.trim():"";if(!de)return;const we=typeof he?.directory=="string"&&he.directory.trim().length>0?he.directory.trim():null;Fe.getState().setActiveMainTab("chat"),jt.getState().setCurrentSession(de,we)};return window.addEventListener("openchamber:open-session",$),()=>window.removeEventListener("openchamber:open-session",$)},[]),a.useEffect(()=>{if(typeof window>"u")return;const $=K=>{const he=K.detail,de=typeof he?.directory=="string"&&he.directory.trim().length>0?he.directory.trim():null,we=typeof he?.projectId=="string"&&he.projectId.trim().length>0?he.projectId.trim():null;Fe.getState().setActiveMainTab("chat"),Fe.getState().setSessionSwitcherOpen(!1),jt.getState().openNewSessionDraft({selectedProjectId:we,directoryOverride:de,preserveDirectoryOverride:!!de})};return window.addEventListener("openchamber:open-draft-session",$),()=>window.removeEventListener("openchamber:open-draft-session",$)},[]),a.useEffect(()=>{if(typeof window>"u")return;const $=K=>{const he=K.detail,de=typeof he?.projectPath=="string"?he.projectPath.trim():"";if(!de)return;const we=Ms.getState(),xe=we.projects.find(De=>De.path===de);xe?we.setActiveProject(xe.id):we.addProject(de)};return window.addEventListener("openchamber:open-project",$),()=>window.removeEventListener("openchamber:open-project",$)},[]),a.useEffect(()=>{typeof window>"u"||!n||g||te.current||(te.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,g]),bp({enabled:ne}),b2({enabled:ne}),N2(),yp(),tg();const pe=a.useCallback(()=>{p($=>!$)},[]);h2(pe),a.useEffect(()=>{if(Z)return;const $=K=>{$l(K)&&K.shiftKey&&!K.altKey&&(K.code==="KeyD"||K.key.toLowerCase()==="d")&&(K.preventDefault(),p(de=>!de))};return window.addEventListener("keydown",$,!0),()=>window.removeEventListener("keydown",$,!0)},[Z]),a.useEffect(()=>{Z||u&&setTimeout(()=>m(),5e3)},[m,Z,u]),a.useEffect(()=>{if(!H||_!=="not-injected")return;let $=!1,K=0;const he=200,de=2e3,we=50,xe=()=>{if($)return;K++;const De=Tc();if(De!=="not-injected"){if($=!0,z(De),De==="valid"){const Ce=Ec();Ce&&F(Rc({isDesktopShell:!0,bootOutcome:Ce}))}return}const le=Math.min(he*Math.pow(1.1,K),de);if(K>=we){const Ce=document.getElementById("initial-loading");Ce&&!Ce.textContent?.includes("taking longer")&&(Ce.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(xe,le)};return window.setTimeout(xe,he),()=>{$=!0}},[H,_]);const je=a.useCallback(async()=>{if(wp({isDesktopShell:or(),isDesktopLocalOriginActive:uo()})){await vp();return}window.location.reload()},[]),Se=a.useCallback(async()=>{if(!C){v(!1),P(!0);try{await ls.getState().initializeApp()}finally{P(!1)}ls.getState().isInitialized||k($=>$+1)}},[C]),re=$=>{if($.screen==="recovery")return $.variant};if(H&&V&&V.screen!=="main"){if(V.screen==="chooser")return s.jsx(on,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(a.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(mu,{mode:"first-launch",onCliAvailable:je,onChooseRemote:()=>{}})})})});const $=re(V),K=V.screen==="recovery"&&"url"in V?V.url:void 0;return s.jsx(on,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(a.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(mu,{mode:"recovery",recoveryVariant:$,recoveryHostUrl:K,recoveryHostLabel:void 0,onCliAvailable:je})})})})}if(Z)return s.jsx(on,{children:s.jsx(Lc,{sdk:Hn.getSdkClient(),directory:d||"",children:s.jsx(Oc,{apis:t,children:s.jsx(_c,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(L2,{embeddedSessionChat:Z,isVSCodeRuntime:b,embeddedBackgroundWorkEnabled:ne})})})})},A)});if(U)return s.jsx(on,{children:s.jsx(I2,{})});if(S&&!n&&!b&&!Z)return s.jsx(on,{children:s.jsx(R2,{onRetry:()=>{Se()},isRetrying:C})});const L=!n&&!H;return s.jsx(on,{children:s.jsx(Lc,{sdk:Hn.getSdkClient(),directory:d||"",children:s.jsx(Oc,{apis:t,children:s.jsx(jx,{children:s.jsx(jp,{children:s.jsx(_c,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:H?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(Uu,{embeddedBackgroundWorkEnabled:ne}),s.jsx(Ym,{}),s.jsx(ZS,{}),s.jsx(Hu,{}),!L&&s.jsxs(s.Fragment,{children:[s.jsx(k2,{}),s.jsx(E2,{}),x&&s.jsx(s2,{onClose:()=>p(!1)})]})]})})})})})},A)})}function _2(t){return t.isAboutDialogOpen}function B2(t){return t.setAboutDialogOpen}function V2(t){return t.currentDirectory}function $2(t){return t.currentSessionId}function z2(t){return t.setCurrentSession}const W2=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Sp();Np().then(()=>{Promise.all([kp(),Cp()]).catch(t=>{console.error("[main] settings init failed:",t)}),Ap(),Dp(),Ip()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Jm=document.getElementById("root");if(!Jm)throw new Error("Root element not found");uf.createRoot(Jm).render(s.jsx(et.StrictMode,{children:s.jsx(Pp,{children:s.jsx(Tp,{children:s.jsx(Ep,{children:s.jsx(Rp,{children:s.jsx(O2,{apis:W2})})})})})}));const Z2=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{zS as M,Z2 as m,Hs as u};