@openchamber/web 1.13.1 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{DiagramView-la2P5DUr.js → DiagramView-l49NCoWI.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-BspFAgXe.js +7 -0
- package/dist/assets/{MultiRunWindow-B9NPliTC.js → MultiRunWindow-BP1L8slG.js} +1 -1
- package/dist/assets/{NewWorktreeDialog-BnK_0_OO.js → NewWorktreeDialog-B2o615D_.js} +1 -1
- package/dist/assets/OnboardingScreen-DNQQWFmn.js +1 -0
- package/dist/assets/{SessionSwitcherDropdown-CuRsG7FM.js → SessionSwitcherDropdown-Bz03hrU9.js} +1 -1
- package/dist/assets/{SettingsWindow-Cs3xbqtf.js → SettingsWindow-L-jJDG3k.js} +1 -1
- package/dist/assets/{TerminalView-CLKpaKdm.js → TerminalView-CZYwjWYc.js} +1 -1
- package/dist/assets/index-Di3CDurc.css +1 -0
- package/dist/assets/index-DkRLSXEX.js +3 -0
- package/dist/assets/{main-B2rXVG8L.js → main-DmS7A2g8.js} +2 -2
- package/dist/assets/main-gqEqIL1b.js +214 -0
- package/dist/assets/miniChat-DZORfsku.js +2 -0
- package/dist/assets/mobile-DkitItmP.js +2 -0
- package/dist/assets/{renderElectronMiniChatApp-BLM-RCP0.js → renderElectronMiniChatApp-S7GCIhbH.js} +2 -2
- package/dist/assets/{renderMobileApp-BXScr4up.js → renderMobileApp-CxEnmaQL.js} +3 -3
- package/dist/assets/{useAppFontEffects-ByW8wOJM.js → useAppFontEffects-DkrfZHQv.js} +114 -114
- package/dist/assets/vendor--Dwc_TRgJ.css +1 -0
- package/dist/assets/{vendor-.bun-d5B0wgQr.js → vendor-.bun-CIlawBoH.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +1 -1
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/MarkdownRendererImpl-CkGSBGo5.js +0 -8
- package/dist/assets/OnboardingScreen-laLzQZgy.js +0 -1
- package/dist/assets/index-68ujKCUc.js +0 -3
- package/dist/assets/index-C-aQ_xRH.css +0 -1
- package/dist/assets/main-CuEzPtRt.js +0 -214
- package/dist/assets/miniChat-DVXSR0vu.js +0 -2
- package/dist/assets/mobile-BgYrNCOf.js +0 -2
- package/dist/assets/vendor--V65Sl9C2.css +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalView-CZYwjWYc.js","assets/vendor-.bun-CIlawBoH.js","assets/vendor--Dwc_TRgJ.css","assets/useAppFontEffects-DkrfZHQv.js","assets/index-DkRLSXEX.js","assets/index-Di3CDurc.css","assets/NewWorktreeDialog-B2o615D_.js","assets/mobileLayoutPreference-Dio-WWkI.js","assets/SessionSwitcherDropdown-Bz03hrU9.js","assets/DiagramView-l49NCoWI.js","assets/SettingsWindow-L-jJDG3k.js","assets/MultiRunWindow-BP1L8slG.js","assets/OnboardingScreen-DNQQWFmn.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as s,e as gt,a as io,R as i,d as jf,p as rc,b as Sf,H as Ze,I as Nf,u as ga,l as yo,n as xa,D as ba,q as ya,S as Fl,v as Ll,w as ic,C as oc,L as Ol,N as Ah,O as Dh,T as Ih,W as Ph,X as ti,Y as Th,$ as Rh,F as Eh,a0 as Mh,a1 as Fh,a2 as Lh,a3 as kf,a4 as Oh,a5 as Bh,a6 as Bl,a7 as Vh,s as _h,m as $h,a8 as nd,a9 as rd,aa as id,ab as zh,ac as Uh,ad as Wh,ae as Hh,af as Gh,ag as Kh,_ as oo,ah as od,ai as ad,aj as ld,G as qh}from"./vendor-.bun-CIlawBoH.js";import{f as ac,h as cr,j as Xi,k as cd,l as Yh,m as wa,n as Cf,p as Qh,e as Cs,q as Lo,b as Re,t as Jh,v as Fa,w as Wr,a as $r,x as zr,y as Vl,z as Xh,A as Zh,R as dd,B as ud,u as qs,C as ep,D as ki,E as Af,F as Df,G as lc,o as Bn,H as tp,g as Ai,I as sp,r as cc,J as np,K as dc,L as If,M as rp,N as ip,O as na,P as ra,Q as op,S as ap,T as lp,U as fd,V as md,W as hd,X as pd,Y as cp,Z as dp,d as gd,_ as up,$ as fp,a0 as mp,i as hp,s as pp}from"./index-DkRLSXEX.js";import{u as At,m as De,ap as xs,I,p as dr,t as de,aq as en,ar as Tr,as as tn,at as sn,a as Qn,au as Rr,av as Pi,aw as xd,ax as Mt,ay as Ft,az as Lt,aA as gp,ad as Do,aB as va,aC as si,ae as Io,af as Pf,a6 as uc,aD as Tf,aE as xp,Q as es,z as dt,aF as bp,a8 as Rf,y as xr,x as fc,D as ys,R as Ti,aG as Ef,aH as Mf,aI as ja,aJ as Ff,aK as Lf,a5 as Of,aL as Bf,aM as Vf,aN as yp,aO as wp,T as mc,aP as La,aQ as ni,aR as hc,aS as ia,X as Zs,aT as vp,aU as _f,aV as jp,aW as $f,aX as zf,aY as Us,aZ as $s,B as $e,a_ as Fs,a$ as Ls,b0 as ai,b1 as Sp,b2 as Np,b3 as zo,b4 as Rn,b5 as Uf,b6 as Wf,a2 as pc,b7 as kp,b8 as bd,b9 as yd,ba as Ci,n as bn,bb as Ri,bc as Zi,bd as Cp,be as Ap,bf as Dp,bg as Ip,bh as Oa,bi as Ba,bj as Va,bk as _a,bl as ri,bm as oi,bn as Pp,bo as Tp,bp as an,bq as Rp,br as Ep,bs as Mp,bt as Fp,bu as Lp,k as Di,bv as gc,bw as Op,bx as Bp,by as Vp,bz as _p,bA as $p,bB as zp,bC as Up,bD as Vn,bE as _n,bF as $n,bG as Nn,bH as zn,bI as Is,bJ as Wp,w as Po,M as $a,S as za,bK as Hp,bL as sr,bM as Gp,b as li,d as xc,c as Ua,bN as Kp,bO as Hf,bP as qp,bQ as Yp,e as bc,bR as Qp,f as xn,bS as Wa,a3 as Ir,j as Jp,bT as Xp,bU as nl,bV as Zp,bW as eg,F as Ur,bX as yc,bY as Ha,bZ as gn,b_ as Ei,l as eo,b$ as Gf,c0 as tg,c1 as sg,c2 as ng,c3 as wd,c4 as rg,q as Hr,r as vd,v as jd,c5 as Sd,c6 as Kf,c7 as Nd,c8 as kd,c9 as qf,ca as ig,cb as Yf,o as Cd,J as og,cc as rl,cd as wc,ce as ag,cf as lg,cg,ch as Oo,ci as dg,cj as vc,ck as ug,cl as jc,cm as Qf,cn as Uo,co as fg,cp as Pr,cq as mg,cr as Jf,cs as hg,ct as pg,cu as Ad,cv as Xf,cw as Zf,cx as em,E as Sc,P as Ga,G as Ka,L as Sa,cy as Na,cz as Fn,H as gg,K as xg,cA as bg,cB as _l,cC as yg,cD as wg,cE as vg,cF as Dd,cG as jg,cH as Sg,cI as Ng,cJ as Nc,cK as tm,cL as kg,cM as Cg,cN as Ag,cO as Dg,cP as Id,cQ as Pd,cR as Ig,cS as Pg,cT as Tg,cU as Rg,cV as Eg,cW as Mg,N as Fg,cX as Td,cY as Lg,cZ as sm,O as Og,c_ as Bg,A as Vg,C as _g,c$ as $g,d0 as zg,d1 as Ug,d2 as Wg,d3 as Hg,d4 as Gg,d5 as Kg,d6 as ka,d7 as qg,d8 as Rd,d9 as Yg,da as Qg,db as Jg,dc as ao,dd as Xg,de as Ed,df as Zg,dg as ex,dh as tx,di as sx,dj as nm,dk as rm,dl as nx,dm as rx,dn as ix,dp as oa,aa as ox,dq as ax,dr as lx,U as cx,V as dx,W as ux,Y as Md,Z as Fd,_ as Ld,ds as fx,$ as im,a0 as om,dt as mx,ak as hx,al as px,am as gx,an as xx,ao as bx,ag as yx,ah as wx,ai as vx,aj as jx}from"./useAppFontEffects-DkrfZHQv.js";import{I as Od,o as Sx,p as Bd,q as Nx,r as Vd,t as Yr,s as kx,v as il,w as To,U as Ca,x as Aa,y as to,z as Bo,B as so,k as am,M as lm,i as dn,j as Cx,E as Ax,F as Dx,G as Ix,l as $l,H as cm,P as dm,J as Px,K as Tx,C as Rx,a as Ex,L as kc,Q as um,R as Cc,T as Ac,V as Dc,W as fm,X as mm,Y as zl,Z as hm,_ as Ul,$ as aa,a0 as Mx,a1 as Fx,e as wo,N as Lx,D as Ox,u as Bx,n as Vx,m as Wl,a2 as _x,a3 as $x,g as zx,a4 as Ux,a5 as Wx,c as Hx,O as pm,d as Gx,a6 as Kx}from"./NewWorktreeDialog-B2o615D_.js";import{S as qx,C as Yx,W as Qx,g as Ic,r as Jx,n as as,i as Ro,d as no,c as Ki,a as _d,b as Xx,e as vo,f as gm,h as Zx,j as eb,u as ol}from"./SessionSwitcherDropdown-Bz03hrU9.js";function xm(t){const{drafts:e,editingDraftId:n,commentText:r,onTextChange:o,selection:a,isDragging:c,fileLabel:l,newWidgetId:d,mapDraftToRange:u,onSave:m,onCancel:f,onEdit:g,onDelete:y}=t,p=[];for(const x of e){const b=u(x);if(x.id===n){p.push({afterLine:b.end,id:`edit-${x.id}`,content:s.jsx(Od,{initialText:r,onTextChange:o,fileLabel:l,lineRange:b,isEditing:!0,onSave:m,onCancel:f},`edit-${x.id}`)});continue}p.push({afterLine:b.end,id:`card-${x.id}`,content:s.jsx(Sx,{draft:x,onEdit:()=>g(x),onDelete:()=>y(x)},`card-${x.id}`)})}if(a&&!n&&!c){const x={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};p.push({afterLine:x.end,id:d,content:s.jsx(Od,{initialText:r,onTextChange:o,fileLabel:l,lineRange:x,isEditing:!1,onSave:m,onCancel:f},d)})}return p}function $d(t){const e=gt.c(14);let n,r,o,a;e[0]!==t?({size:o,className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);const c=typeof o=="number"?`${o}px`:o,l=typeof o=="number"?`${o}px`:o;let d;e[5]!==a||e[6]!==c||e[7]!==l?(d={width:c,height:l,...a},e[5]=a,e[6]=c,e[7]=l,e[8]=d):d=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=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]=u):u=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:u}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const ii=[{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"}],Hl="finder",Gl=new Set(["finder","terminal"]),Pc=t=>typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32"&&t.id==="finder"?{...t,label:"Explorer",appName:"File Explorer"}:t,Kl=t=>{if(!t)return null;const e=ii.find(n=>n.id===t)??null;return e?Pc(e):null},al=()=>ii.filter(t=>Gl.has(t.id)).map(t=>({...Pc(t)})),tb=()=>{if(typeof window>"u")return Hl;const t=window.localStorage.getItem("openInAppId");return t&&Kl(t)?t:Hl};let ll=!1,_i=!1,Qr=!1,Jr=0,jo=null;const zd=()=>{jo&&(clearTimeout(jo),jo=null)},pr=io()((t,e)=>({selectedAppId:tb(),availableApps:al(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(ll||typeof window>"u")return;ll=!0;const n=(d,u=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:al(),hasLoadedApps:u});return}const m=new Set(d.map(p=>p.name)),f=new Map(d.map(p=>[p.name,p.iconDataUrl??void 0])),y=ii.filter(p=>m.has(p.appName)||Gl.has(p.id)).map(p=>({...Pc(p),iconDataUrl:f.get(p.appName)}));t({availableApps:y,hasLoadedApps:!0})},r=async d=>{if(!cr()||!Xi()||_i||e().hasLoadedApps&&!d)return;const m=ii.map(f=>f.appName);zd(),_i=!0,Qr=!1,t({isScanning:!0});try{const{apps:f,success:g,hasCache:y,isCacheStale:p}=await cd(m,d),x=g&&!y&&f.length===0&&Jr<3;if(t({isCacheStale:y?p:!1}),n(f,g?!x:!1),g){if(x){const h=[800,1600,3200][Jr]??3200;Jr+=1,Qr=!0,jo=setTimeout(()=>{r()},h);return}Jr=0,Qr=!1;return}if(Jr<3){const h=[1e3,3e3,7e3][Jr]??7e3;Jr+=1,Qr=!0,jo=setTimeout(()=>{r()},h)}}finally{_i=!1,Qr||t({isScanning:!1})}};r();const o=d=>{const u=d.detail,m=u&&typeof u.openInAppId=="string"&&u.openInAppId.length>0&&Kl(u.openInAppId)?u.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},a=()=>{r()},c=d=>{const u=d.detail;Array.isArray(u)&&(Jr=3,Qr=!1,t({isScanning:!1,isCacheStale:!1}),n(u))};window.addEventListener("openchamber:settings-synced",o),window.addEventListener("openchamber:app-ready",a),window.addEventListener("openchamber:installed-apps-updated",c),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(ll||e().initialize(),!cr()||!Xi()||_i||e().hasLoadedApps&&!n)return;const o=ii.map(a=>a.appName);zd(),n&&t({hasLoadedApps:!1}),_i=!0,Qr=!1,t({isScanning:!0});try{const{apps:a,hasCache:c,isCacheStale:l}=await cd(o,n),d=new Set(a.map(g=>g.name)),u=new Map(a.map(g=>[g.name,g.iconDataUrl??void 0])),f=ii.filter(g=>d.has(g.appName)||Gl.has(g.id)).map(g=>({...g,iconDataUrl:u.get(g.appName)}));t({availableApps:f.length>0?f:al(),hasLoadedApps:f.length>0,isCacheStale:c?l:!1})}finally{_i=!1,Qr||t({isScanning:!1})}},selectApp:async n=>{Kl(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ac({openInAppId:n}))}})),sb="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",nb="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",cl=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__!=="win32"?sb:t.id==="terminal"?nb:void 0}),Ud=t=>{const e=gt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[a,c]=i.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const d=l,u=r||o;if(u&&!a){let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=()=>c(!0),e[2]=g):g=e[2];let y;return e[3]!==u?(y=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:g}),e[3]=u,e[4]=y):y=e[4],y}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=De("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let f;return e[6]!==d?(f=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=f):f=e[7],f},rb=t=>{const e=gt.c(75),{directory:n,className:r}=t,{t:o}=At(),a=pr(ib),c=pr(ob),l=pr(ab),d=pr(lb),u=pr(cb),m=pr(db),f=pr(ub);let g,y;e[0]!==u?(g=()=>{u()},y=[u],e[0]=u,e[1]=g,e[2]=y):(g=e[1],y=e[2]),i.useEffect(g,y);const p=cr()&&Xi();let x;e:{let Ne;e[3]!==c||e[4]!==a?(Ne=c.find(q=>q.id===a)??c.find(fb)??c[0]??ii[0],e[3]=c,e[4]=a,e[5]=Ne):Ne=e[5];const Y=Ne;if(Y){let q;e[6]!==Y?(q=cl(Y),e[6]=Y,e[7]=q):q=e[7],x=q;break e}let G;e[8]===Symbol.for("react.memo_cache_sentinel")?(G=cl(ii[0]),e[8]=G):G=e[8],x=G}const b=x;if(!p||!n||c.length===0)return null;let h;e[9]!==n?(h=async Ne=>{await Yh(n,Ne.id,Ne.appName)||await wa(n,Ne.appName)},e[9]=n,e[10]=h):h=e[10];const N=h;let w;e[11]!==N||e[12]!==f?(w=async Ne=>{await f(Ne.id),await N(Ne)},e[11]=N,e[12]=f,e[13]=w):w=e[13];const S=w;let j;e[14]!==n||e[15]!==o?(j=async()=>{(await dr(n)).ok&&de.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=j):j=e[16];const k=j;let v;e[17]!==r?(v=De("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]=v):v=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 A=d&&"animate-pulse";let C;e[22]!==A?(C=De("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",A),e[22]=A,e[23]=C):C=e[23];let O;e[24]!==b.label||e[25]!==o?(O=o("openInApp.actions.openInAria",{app:b.label}),e[24]=b.label,e[25]=o,e[26]=O):O=e[26];let T;e[27]!==b.fallbackIconDataUrl||e[28]!==b.iconDataUrl||e[29]!==b.label?(T=s.jsx(Ud,{label:b.label,iconDataUrl:b.iconDataUrl,fallbackIconDataUrl:b.fallbackIconDataUrl}),e[27]=b.fallbackIconDataUrl,e[28]=b.iconDataUrl,e[29]=b.label,e[30]=T):T=e[30];let E;e[31]!==C||e[32]!==O||e[33]!==T||e[34]!==D?(E=s.jsx("button",{type:"button",onClick:D,className:C,"aria-label":O,children:T}),e[31]=C,e[32]=O,e[33]=T,e[34]=D,e[35]=E):E=e[35];let F;e[36]===Symbol.for("react.memo_cache_sentinel")?(F=De("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]=F):F=e[36];let R;e[37]!==o?(R=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=R):R=e[38];let L;e[39]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=L):L=e[39];let B;e[40]!==R?(B=s.jsx(en,{asChild:!0,children:s.jsx("button",{type:"button",className:F,"aria-label":R,children:L})}),e[40]=R,e[41]=B):B=e[41];let V;e[42]!==k?(V=()=>{k()},e[42]=k,e[43]=V):V=e[43];let M;e[44]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(I,{name:"file-copy",className:"h-4 w-4"}),e[44]=M):M=e[44];let ee;e[45]!==o?(ee=o("openInApp.actions.copyPath"),e[45]=o,e[46]=ee):ee=e[46];let se;e[47]!==ee?(se=s.jsx("span",{className:"typography-ui-label text-foreground",children:ee}),e[47]=ee,e[48]=se):se=e[48];let J;e[49]!==V||e[50]!==se?(J=s.jsxs(xs,{className:"flex items-center gap-2",onClick:V,children:[M,se]}),e[49]=V,e[50]=se,e[51]=J):J=e[51];let K;e[52]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(Tr,{}),e[52]=K):K=e[52];let Z;if(e[53]!==c||e[54]!==S||e[55]!==b.id){let Ne;e[57]!==S||e[58]!==b.id?(Ne=Y=>{const G=cl(Y);return s.jsxs(xs,{className:"flex items-center gap-2",onClick:()=>{S(Y)},children:[s.jsx(Ud,{label:Y.label,iconDataUrl:Y.iconDataUrl,fallbackIconDataUrl:G.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Y.label}),b.id===Y.id?s.jsx(I,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},Y.id)},e[57]=S,e[58]=b.id,e[59]=Ne):Ne=e[59],Z=c.map(Ne),e[53]=c,e[54]=S,e[55]=b.id,e[56]=Z}else Z=e[56];let re;e[60]!==l||e[61]!==m||e[62]!==o?(re=l?s.jsxs(xs,{className:"flex items-center gap-2",onClick:()=>{m(!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]=m,e[62]=o,e[63]=re):re=e[63];let pe;e[64]!==J||e[65]!==Z||e[66]!==re?(pe=s.jsxs(tn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[J,K,Z,re]}),e[64]=J,e[65]=Z,e[66]=re,e[67]=pe):pe=e[67];let Se;e[68]!==B||e[69]!==pe?(Se=s.jsxs(sn,{children:[B,pe]}),e[68]=B,e[69]=pe,e[70]=Se):Se=e[70];let te;return e[71]!==E||e[72]!==Se||e[73]!==v?(te=s.jsxs("div",{className:v,children:[E,Se]}),e[71]=E,e[72]=Se,e[73]=v,e[74]=te):te=e[74],te};function ib(t){return t.selectedAppId}function ob(t){return t.availableApps}function ab(t){return t.isCacheStale}function lb(t){return t.isScanning}function cb(t){return t.initialize}function db(t){return t.loadInstalledApps}function ub(t){return t.selectApp}function fb(t){return t.id===Hl}const mb=1e6,hb="terminal-store";let Wd=!1;const dl=t=>typeof t=="object"&&t!==null,pb=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 ul=(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}),fl=t=>({tabs:[t],activeTabId:t.id}),mr=(t,e)=>t.tabs.findIndex(n=>n.id===e),Ms=io()(jf(rc((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 a=new Map(o.sessions),c=`tab-${o.nextTabId}`,l=ul(c,"Terminal");return a.set(r,fl(l)),{sessions:a,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 a=o.activeTabId;return a?o.tabs.find(c=>c.id===a)??o.tabs[0]:o.tabs[0]},createTab:n=>{const r=In(n);if(!r)return"tab-invalid";const o=`tab-${e().nextTabId}`;return t(a=>{const c=new Map(a.sessions),l=c.get(r),d=a.nextTabId+1,m=`Terminal ${(l?.tabs.length??0)+1}`,f=ul(o,m);return l?c.set(r,{...l,tabs:[...l.tabs,f]}):c.set(r,fl(f)),{sessions:c,nextTabId:d}}),o},setActiveTab:(n,r)=>{const o=In(n);t(a=>{const c=new Map(a.sessions),l=c.get(o);return!l||l.activeTabId===r||mr(l,r)<0?a:(c.set(o,{...l,activeTabId:r}),{sessions:c})})},setTabLabel:(n,r,o)=>{const a=In(n),c=o.trim();c&&t(l=>{const d=new Map(l.sessions),u=d.get(a);if(!u)return l;const m=mr(u,r);if(m<0||u.tabs[m]?.label===c)return l;const f=[...u.tabs];return f[m]={...f[m],label:c},d.set(a,{...u,tabs:f}),{sessions:d}})},setTabIconKey:(n,r,o)=>{const a=In(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const u=mr(d,r);if(u<0)return c;const m=o?.trim()||null;if(d.tabs[u]?.iconKey===m)return c;const f=[...d.tabs];return f[u]={...f[u],iconKey:m},l.set(a,{...d,tabs:f}),{sessions:l}})},closeTab:async(n,r)=>{const o=In(n),l=e().sessions.get(o)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(l)try{await Qh(l)}catch{}t(d=>{const u=new Map(d.sessions),m=u.get(o);if(!m)return d;const f=mr(m,r);if(f<0)return d;const g=m.tabs.filter(b=>b.id!==r),y=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,b])=>!(b.directory===o&&b.tabId===r))),p=Object.keys(y).length!==Object.keys(d.projectActionRuns).length;if(g.length===0){const b=`tab-${d.nextTabId}`,h=ul(b,"Terminal");return u.set(o,fl(h)),{sessions:u,nextTabId:d.nextTabId+1,...p?{projectActionRuns:y}:{}}}let x=m.activeTabId;return m.activeTabId===r&&(x=g[Math.min(f,g.length-1)]?.id??g[0]?.id??null),u.set(o,{...m,tabs:g,activeTabId:x}),{sessions:u,...p?{projectActionRuns:y}:{}}})},setTabSessionId:(n,r,o)=>{const a=In(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const u=mr(d,r);if(u<0)return c;const m=d.tabs[u],f=o!==null&&m.terminalSessionId!==o,g=o?"running":m.terminalSessionId?"exited":m.lifecycle,y={...m,terminalSessionId:o,lifecycle:g,isConnecting:!1,...f?{bufferChunks:[],bufferLength:0}:{}},p=[...d.tabs];return p[u]=y,l.set(a,{...d,tabs:p}),{sessions:l}})},setTabLifecycle:(n,r,o)=>{const a=In(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const u=mr(d,r);if(u<0)return c;const m=[...d.tabs];return m[u]={...m[u],lifecycle:o,isConnecting:!1},l.set(a,{...d,tabs:m}),{sessions:l}})},setConnecting:(n,r,o)=>{const a=In(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const u=mr(d,r);if(u<0)return c;const m=[...d.tabs];return m[u]={...m[u],isConnecting:o},l.set(a,{...d,tabs:m}),{sessions:l}})},appendToBuffer:(n,r,o)=>{if(!o)return;const a=In(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const u=mr(d,r);if(u<0)return c;const m=d.tabs[u],f=c.nextChunkId,g={id:f,data:o},y=[...m.bufferChunks,g];let p=m.bufferLength+o.length;for(;p>mb&&y.length>1;){const b=y.shift();if(!b)break;p-=b.data.length}const x=[...d.tabs];return x[u]={...m,bufferChunks:y,bufferLength:p},l.set(a,{...d,tabs:x}),{sessions:l,nextChunkId:f+1}})},setTabPreviewUrl:(n,r,o,a={})=>{const c=In(n);t(l=>{const d=new Map(l.sessions),u=d.get(c);if(!u)return l;const m=mr(u,r);if(m<0)return l;const f=u.tabs[m],g=a.autoOpened??f.previewAutoOpened,y=a.locked??f.previewUrlLocked;if(f.previewUrl===o&&f.previewAutoOpened===g&&f.previewUrlLocked===y)return l;const p=[...u.tabs];return p[m]={...f,previewUrl:o,previewAutoOpened:g,previewUrlLocked:y},d.set(c,{...u,tabs:p}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const o=In(n);t(a=>{const c=new Map(a.sessions),l=c.get(o);if(!l)return a;const d=mr(l,r);if(d<0)return a;const u=l.tabs[d];if(!u.previewUrl||u.previewAutoOpened)return a;const m=[...l.tabs];return m[d]={...u,previewAutoOpened:!0},c.set(o,{...l,tabs:m}),{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 a=o.projectActionRuns[n];return!a||a.status===r?o:{projectActionRuns:{...o.projectActionRuns,[n]:{...a,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(a=>{const c=new Map(a.sessions),l=c.get(o);if(!l)return a;const d=mr(l,r);if(d<0)return a;const u=[...l.tabs];return u[d]={...u[d],bufferChunks:[],bufferLength:0},c.set(o,{...l,tabs:u}),{sessions:c}})},removeDirectory:n=>{const r=In(n);t(o=>{const a=new Map(o.sessions);a.delete(r);const c=Object.fromEntries(Object.entries(o.projectActionRuns).filter(([,l])=>l.directory!==r));return{sessions:a,projectActionRuns:c}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:hb,storage:Sf(()=>Cf()),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(!dl(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[d,u]=l;if(typeof d!="string"||!dl(u))continue;const m=Array.isArray(u.tabs)?u.tabs:[],f=[];for(const p of m){if(!dl(p))continue;const x=typeof p.id=="string"?p.id:null;if(!x)continue;const b=pb(x);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:x,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 u.activeTabId=="string"?u.activeTabId:null,y=g?f.some(p=>p.id===g):!1;r.set(d,{tabs:f,activeTabId:y?g:f[0].id})}const a=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,c=Math.max(e.nextTabId,a,o+1);return{...e,sessions:r,nextChunkId:1,nextTabId:c,hasHydrated:!0}}})));if(typeof window<"u"&&!Wd){Wd=!0;const t=Ms.persist,e=()=>{Ms.getState().hasHydrated||Ms.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const gb=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],xb=["dev","start","preview","serve"];async function bb(t,e,n){if(!t)return null;const r=vb(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const o=jb(n);if(o){const a=await Sb(t);return{command:`${a==="npm"?"npm run":a==="yarn"?"yarn":a==="pnpm"?"pnpm":a==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await yb(t)){const o=await wb(),a=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${a}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${a}/`}}return null}async function yb(t){const e=`${t}/index.html`,n=await Da(e,t);return typeof n=="string"&&n.trim().length>0}async function wb(){try{const t=await Cs("/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 vb(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(xb.some(o=>n.includes(o)))return e}return null}function jb(t){for(const{pattern:e}of gb)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Sb(t){const e=await Da(`${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 a=await Da(`${t}/${r}`,t);if(typeof a=="string"&&a.trim().length>0)return o}return"npm"}async function Da(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await Cs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=Lo()?.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 Cs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Nb(t){try{const e=await Da(`${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 kb=t=>new Promise(e=>{window.setTimeout(e,t)}),Cb="\x1B",Ab=new RegExp(`${Cb}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Db=/https?:\/\/[^\s<>'"`]+/gi,Zn="__openchamber_auto_discover_preview__",Ib=15e3,Pb=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},Tb=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}},Rb=t=>{const n=t.replace(Ab,"").match(Db);if(!n||n.length===0)return null;const r=n.map(a=>a.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const a of r)try{const c=new URL(a);c.port&&c.port.length>0&&o.push({raw:a,parsed:c})}catch{}if(o.length>0){const a=c=>{const{parsed:l}=c,d=l.hostname.toLowerCase(),u=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=l.pathname||"/",f=m.split("/").filter(Boolean).length,g=m==="/"||m==="",y=!!(l.search||l.hash);let p=0;return u&&(p+=50),g&&(p+=30),p-=Math.min(f*5,20),y&&(p-=10),p};return o.sort((c,l)=>a(l)-a(c)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},bm=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:a}=At(),{terminal:c,runtime:l}=Qn(),{isMobile:d}=Rr(),u=i.useMemo(()=>cr(),[]),m=Bd(_=>_.instances),f=Bd(_=>_.load),g=Re(_=>_.setBottomTerminalOpen),y=Re(_=>_.setActiveMainTab),p=Re(_=>_.setSettingsPage),x=Re(_=>_.setSettingsDialogOpen),b=Re(_=>_.setSettingsProjectsSelectedId),h=Re(_=>_.openContextPreview),N=Ms(_=>_.sessions),w=Ms(_=>_.ensureDirectory),S=Ms(_=>_.setTabLabel),j=Ms(_=>_.setTabIconKey),k=Ms(_=>_.setActiveTab),v=Ms(_=>_.setConnecting),D=Ms(_=>_.setTabSessionId),A=Ms(_=>_.setTabPreviewUrl),C=Ms(_=>_.projectActionRuns),O=Ms(_=>_.setProjectActionRun),T=Ms(_=>_.updateProjectActionRunStatus),E=Ms(_=>_.removeProjectActionRun),[F,R]=i.useState([]),[L,B]=i.useState(null),[V,M]=i.useState(!1),ee=i.useRef({}),se=i.useRef({}),J=i.useRef({}),K=i.useRef({}),Z=i.useRef(0),re=t?.id??null,pe=t?.path??"",Se=i.useMemo(()=>re?{id:re,path:pe}:null,[re,pe]);i.useEffect(()=>{u&&f().catch(()=>{})},[u,f]);const te=i.useCallback(async _=>{await Pi(_)},[]),Ne=i.useCallback(async()=>{if(!Se)return;const _=Z.current+1;Z.current=_,M(!0);try{const ye=await xd(Se);if(Z.current!==_)return;const $=ye.actions;R($),B(Ie=>Ie===Zn||Ie&&$.some(je=>je.id===Ie)?Ie:null)}catch{if(Z.current!==_)return}finally{Z.current===_&&M(!1)}},[Se]),Y=i.useMemo(()=>Nx(e||Se?.path||""),[e,Se?.path]),G=i.useMemo(()=>L?F.find(_=>_.id===L)??null:null,[F,L]),q=i.useMemo(()=>({id:Zn,name:a("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[a]),oe=!d,le=i.useMemo(()=>oe?[q,...F]:F,[F,q,oe]);i.useEffect(()=>{Ne()},[Ne]),i.useEffect(()=>{if(typeof window>"u")return;const _=ye=>{const $=ye.detail;re&&($?.projectId&&$.projectId!==re||Ne())};return window.addEventListener(Vd,_),()=>{window.removeEventListener(Vd,_)}},[Ne,re]),i.useEffect(()=>{L&&(L===Zn&&oe||F.some(_=>_.id===L)||B(null))},[F,oe,L]),i.useEffect(()=>{for(const[_,ye]of Object.entries(C)){const Ie=N.get(ye.directory)?.tabs.find(je=>je.id===ye.tabId);(!Ie||Ie.terminalSessionId!==ye.sessionId)&&E(_)}},[C,E,N]),i.useEffect(()=>{for(const[_,ye]of Object.entries(C)){const $=se.current[_]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};se.current[_]=$;const Ie=le.find(Be=>Be.id===ye.actionId);if(!Ie)continue;const Fe=N.get(ye.directory)?.tabs.find(Be=>Be.id===ye.tabId);if(!Fe||!Array.isArray(Fe.bufferChunks)||Fe.bufferChunks.length===0)continue;const Ae=Fe.bufferChunks.filter(Be=>$.lastSeenChunkId===null?!0:Be.id>$.lastSeenChunkId);if(Ae.length===0)continue;const ne=Ae.map(Be=>Be.data).join(""),P=`${$.tail}${ne}`,me=!$.openedUrl&&Ie.autoOpenUrl===!0?Rb(P):null,ae=Ae[Ae.length-1]?.id??$.lastSeenChunkId;if($.lastSeenChunkId=ae,$.tail=P.slice(-512),me)if($.openedUrl=!0,$.openInPreview){const Be=C[_];Be&&(A(Be.directory,Be.tabId,me,{locked:!1,autoOpened:!1}),Be.status==="waiting-for-preview"&&T(_,"running"),window.clearTimeout(K.current[_]),delete K.current[_],h(Be.directory,me))}else te(me),de.success(a("projectActions.toast.openedUrlFromOutput"));se.current[_]=$}for(const _ of Object.keys(se.current))C[_]||(delete se.current[_],window.clearTimeout(K.current[_]),delete K.current[_])},[le,h,te,C,A,a,N,T]);const ve=i.useCallback(async(_,ye={})=>{if(!Y)throw new Error(a("projectActions.error.noActiveDirectory"));const $=Yr(Y,_.id);w(Y);const Ie=Ms.getState(),je=Ie.getDirectoryState(Y);let Fe=ee.current[$]||null;const Ae=Fe?!!je?.tabs.some(me=>me.id===Fe):!1;(!Fe||!Ae)&&(Fe=Ie.createTab(Y),ee.current[$]=Fe),S(Y,Fe,`Action: ${_.name}`),j(Y,Fe,_.icon||"play"),ye.revealTerminal!==!1&&(k(Y,Fe),g(!0),y("terminal"));const P=Ms.getState().getDirectoryState(Y)?.tabs.find(me=>me.id===Fe);return{key:$,tabId:Fe,sessionId:P?.terminalSessionId??null}},[w,Y,y,k,g,j,S,a]),Ee=i.useCallback(async _=>{if(l.isVSCode||!o&&d)return;if(!Y){de.error(a("projectActions.error.noActiveDirectoryForAction"));return}const ye=Yr(Y,_.id),$=C[ye];if(!($&&$.status==="running"))try{const Ie=_.id===Zn?await(async()=>{const[Qe,st]=await Promise.all([xd({id:Se?.id??"",path:Y}),Nb(Y)]),ut=await bb(Y,Qe.actions,st);if(!ut)throw new Error(a("contextPanel.preview.noDevServer"));return{id:Zn,name:a("projectActions.actions.autoDiscover"),command:ut.command,icon:"search",autoOpenUrl:!0,openUrl:ut.previewUrlHint||""}})():_,je=Ie.autoOpenUrl===!0&&(Ie.openUrl||"").trim().length>0,{key:Fe,tabId:Ae,sessionId:ne}=await ve(Ie,{revealTerminal:!je&&_.id!==Zn});let P=ne,me=!1;if(!P){v(Y,Ae,!0);try{P=(await c.createSession({cwd:Y})).sessionId,me=!0,D(Y,Ae,P)}finally{v(Y,Ae,!1)}}if(!P)throw new Error(a("projectActions.error.failedToCreateTerminalSession"));me&&await kb(350),Ie.id===Zn&&(J.current[Fe]?.(),v(Y,Ae,!0),J.current[Fe]=Jh(P,Qe=>{Qe.type==="data"&&typeof Qe.data=="string"&&Qe.data.length>0&&Ms.getState().appendToBuffer(Y,Ae,Qe.data),Qe.type==="exit"&&(Ms.getState().setTabLifecycle(Y,Ae,"exited"),Ms.getState().setConnecting(Y,Ae,!1),Ms.getState().removeProjectActionRun(Fe),delete se.current[Fe],J.current[Fe]?.(),delete J.current[Fe],window.clearTimeout(K.current[Fe]),delete K.current[Fe])},()=>{Ms.getState().setConnecting(Y,Ae,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const ae=Ie.autoOpenUrl===!0&&u&&(Ie.desktopOpenSshForward||"").trim().length>0,Be=Ie.autoOpenUrl?Tb(Ie.openUrl):null,Ge=Ie.autoOpenUrl&&u?kx(Ie.desktopOpenSshForward,m):null;O({key:Fe,directory:Y,actionId:Ie.id,tabId:Ae,sessionId:P,status:Ie.id===Zn&&!Be?"waiting-for-preview":"running"}),window.clearTimeout(K.current[Fe]),delete K.current[Fe],Ie.id===Zn&&!Be&&(K.current[Fe]=window.setTimeout(()=>{Ms.getState().updateProjectActionRunStatus(Fe,"running"),delete K.current[Fe]},Ib)),Ge?(A(Y,Ae,null,{locked:!0}),te(Ge),de.success(a("projectActions.toast.openedForwardedUrl"))):Be?(A(Y,Ae,Be,{locked:!0,autoOpened:!0}),h(Y,Be),de.success(a("projectActions.toast.openedActionUrl"))):je?(A(Y,Ae,null,{locked:!0}),de.error(a("projectActions.error.invalidCustomUrlFormat"))):ae?(A(Y,Ae,null,{locked:!0}),de.error(a("projectActions.error.selectedDesktopSshForwardUnavailable"))):A(Y,Ae,null,{locked:!1,autoOpened:!1}),se.current[Fe]={lastSeenChunkId:null,openedUrl:!!Ge||!!Be||je,tail:"",openInPreview:Ie.id===Zn};const Ke=Pb(Ie.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
+
`));await c.sendInput(P,`${Ke}\r`)}catch(Ie){E(ye),delete se.current[ye],J.current[ye]?.(),delete J.current[ye],window.clearTimeout(K.current[ye]),delete K.current[ye],de.error(Ie instanceof Error?Ie.message:a("projectActions.error.failedToRunAction"))}},[m,ve,o,d,u,Y,te,h,C,l.isVSCode,E,v,O,A,D,Se?.id,a,c]),_e=i.useCallback(async _=>{const ye=Yr(Y,_.id),$=C[ye];if(!$)return;T(ye,"stopping");try{await c.sendInput($.sessionId,"")}catch{}if(await new Promise(Fe=>{window.setTimeout(Fe,1e3)}),Ms.getState().getDirectoryState($.directory)?.tabs.find(Fe=>Fe.id===$.tabId)?.terminalSessionId===$.sessionId){if(typeof c.forceKill=="function")try{await c.forceKill({sessionId:$.sessionId})}catch{}else try{await c.close($.sessionId)}catch{}D($.directory,$.tabId,null)}E(ye),delete se.current[ye],J.current[ye]?.(),delete J.current[ye],window.clearTimeout(K.current[ye]),delete K.current[ye]},[Y,C,E,D,c,T]),Oe=i.useCallback(()=>{const _=G??le[0];if(!_)return;const ye=Yr(Y,_.id),$=C[ye];if($?.status!=="stopping"){if($){_e(_);return}Ee(_)}},[le,Y,Ee,C,G,_e]),Me=i.useCallback((_,ye=!1)=>{if(B(_.id),!ye){Ee(_);return}const $=Yr(Y,_.id),Ie=C[$];if(Ie?.status!=="stopping"){if(Ie){_e(_);return}Ee(_)}},[Y,Ee,C,_e]),he=i.useCallback(()=>{Se?.id&&(b(Se.id),p("projects"),x(!0))},[x,p,b,Se?.id]);if(l.isVSCode||!o&&d||!Se||!Y)return null;const Ce=G??le[0]??null;if(!Ce)return null;const xe=Ce.icon||"play",ue=Ce.id===Zn?"search":il[xe]||"play",H=Yr(Y,Ce.id),ce=C[H],fe=ce?.status==="stopping",U=ce?.status==="waiting-for-preview",z=ce?N.get(ce.directory)?.tabs.find(_=>_.id===ce.tabId)?.previewUrl??null:null,be=!!(ce&&z),ge=()=>{!ce||!z||h(ce.directory,z)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:V||fe,className:De("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:Oe,"aria-label":ce?a("projectActions.actions.stopNamedAria",{name:Ce.name}):a("projectActions.actions.runNamedAria",{name:Ce.name}),children:fe||U?s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):ce?s.jsx(I,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(I,{name:ue,className:"h-5 w-5"})}),be?s.jsxs(Mt,{children:[s.jsx(Ft,{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":a("projectActions.actions.openPreview"),onClick:ge,children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(Lt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(sn,{children:[s.jsx(en,{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":a("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(tn,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(xs,{className:"flex items-center gap-2",onClick:he,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx(Tr,{}),le.map(_=>{const ye=_.icon||"play",$=_.id===Zn?"search":il[ye]||"play",Ie=Yr(Y,_.id),je=C[Ie],Fe=!!je,Ae=je?.status==="stopping";return s.jsxs(xs,{className:"flex items-center gap-2",onClick:()=>{Me(_,!0)},children:[s.jsx(I,{name:$,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:_.name}),Ae||je?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):Fe?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},_.id)})]})]})]}):s.jsxs("div",{className:De("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:Oe,disabled:V||fe,className:De("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":ce?a("projectActions.actions.stopNamedAria",{name:Ce.name}):a("projectActions.actions.runNamedAria",{name:Ce.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:fe||U?s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):ce?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(I,{name:ue,className:"h-4 w-4"})})}),be?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ge,className:De(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":a("projectActions.actions.openPreview"),children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(Lt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(sn,{children:[s.jsx(en,{asChild:!0,children:s.jsx("button",{type:"button",className:De(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":a("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(tn,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(xs,{className:"flex items-center gap-2",onClick:he,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx(Tr,{}),le.map(_=>{const ye=_.icon||"play",$=_.id===Zn?"search":il[ye]||"play",Ie=Yr(Y,_.id),je=C[Ie],Fe=!!je,Ae=je?.status==="stopping";return s.jsxs(xs,{className:"flex items-center gap-2",onClick:()=>{Me(_,!0)},children:[s.jsx(I,{name:$,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:_.name}),Ae||je?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):Fe?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},_.id)})]})]})]})},qa="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",Eb="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",Wo=i.memo(function(e){const n=gt.c(17),{visible:r,title:o,ariaLabel:a,onClick:c,className:l,Icon:d,iconClassName:u,pressed:m}=e,f=r===void 0?!0:r,g=m===void 0?!1:m;if(!f)return null;const y=l??qa,p=g&&"bg-interactive-selection text-interactive-selection-foreground";let x;n[0]!==y||n[1]!==p?(x=De(y,p),n[0]=y,n[1]=p,n[2]=x):x=n[2];const b=u??"h-[18px] w-[18px]";let h;n[3]!==d||n[4]!==b?(h=s.jsx(I,{name:d,className:b}),n[3]=d,n[4]=b,n[5]=h):h=n[5];let N;n[6]!==a||n[7]!==c||n[8]!==g||n[9]!==x||n[10]!==h?(N=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":a,"aria-pressed":g,className:x,children:h})}),n[6]=a,n[7]=c,n[8]=g,n[9]=x,n[10]=h,n[11]=N):N=n[11];let w;n[12]!==o?(w=s.jsx(Lt,{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(Mt,{children:[N,w]}),n[14]=N,n[15]=w,n[16]=S):S=n[16],S}),Mb=i.memo(function(e){const n=gt.c(42),{isMobile:r,githubAuthStatus:o,githubAccounts:a,githubAvatarUrl:c,githubLogin:l,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:u}=e,{t:m}=At();if(!o?.connected||r)return null;if(a.length>1){let p;n[0]===Symbol.for("react.memo_cache_sentinel")?(p=De(qa,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=p):p=n[0];let x;n[1]!==l||n[2]!==m?(x=l?m("header.github.connectedWithLogin",{login:l}):m("header.github.connected"),n[1]=l,n[2]=m,n[3]=x):x=n[3];let b;n[4]!==c||n[5]!==l||n[6]!==m?(b=c?s.jsx("img",{src:c,alt:l?m("header.github.avatarWithLogin",{login:l}):m("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]=m,n[7]=b):b=n[7];let h;n[8]!==d||n[9]!==x||n[10]!==b?(h=s.jsx(en,{asChild:!0,children:s.jsx("button",{type:"button",className:p,title:x,disabled:d,children:b})}),n[8]=d,n[9]=x,n[10]=b,n[11]=h):h=n[11];let N;n[12]!==m?(N=m("header.github.accountsTitle"),n[12]=m,n[13]=N):N=n[13];let w;n[14]!==N?(w=s.jsx(xp,{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(Tr,{}),n[16]=S):S=n[16];let j;if(n[17]!==a||n[18]!==u||n[19]!==d||n[20]!==m){let D;n[22]!==u||n[23]!==d||n[24]!==m?(D=A=>{const C=A.user,O=!!A.current,T=A.source==="gh-cli"?m("header.github.accountSource.cli"):m("header.github.accountSource.oauth");return s.jsxs(xs,{className:"gap-2",disabled:d,onSelect:()=>{O||u(A.id)},children:[C?.avatarUrl?s.jsx("img",{src:C.avatarUrl,alt:C.login?m("header.github.avatarWithLogin",{login:C.login}):m("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.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:C.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:T})]}):null]}),O?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},A.id)},n[22]=u,n[23]=d,n[24]=m,n[25]=D):D=n[25],j=a.map(D),n[17]=a,n[18]=u,n[19]=d,n[20]=m,n[21]=j}else j=n[21];let k;n[26]!==w||n[27]!==j?(k=s.jsxs(tn,{align:"end",className:"w-64",children:[w,S,j]}),n[26]=w,n[27]=j,n[28]=k):k=n[28];let v;return n[29]!==h||n[30]!==k?(v=s.jsxs(sn,{children:[h,k]}),n[29]=h,n[30]=k,n[31]=v):v=n[31],v}let f;n[32]!==l||n[33]!==m?(f=l?m("header.github.connectedWithLogin",{login:l}):m("header.github.connected"),n[32]=l,n[33]=m,n[34]=f):f=n[34];let g;n[35]!==c||n[36]!==l||n[37]!==m?(g=c?s.jsx("img",{src:c,alt:l?m("header.github.avatarWithLogin",{login:l}):m("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]=m,n[38]=g):g=n[38];let y;return n[39]!==f||n[40]!==g?(y=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]=y):y=n[41],y}),Fb=i.memo(function(e){const n=gt.c(84),{isDesktopApp:r,currentInstanceLabel:o,compactCurrentInstanceLabel:a,currentInstanceIsLocal:c,isDesktopServicesOpen:l,setIsDesktopServicesOpen:d,refreshCurrentInstanceLabel:u,desktopServicesTab:m,setDesktopServicesTab:f,quotaResultsLength:g,fetchAllQuotas:y,servicesTabItems:p,quotaLastUpdated:x,quotaDisplayMode:b,quotaDisplayTabItems:h,handleDisplayModeChange:N,handleUsageRefresh:w,isQuotaLoading:S,isUsageRefreshSpinning:j,hasRateLimits:k,rateLimitGroups:v,expandedFamilies:D,toggleFamilyExpanded:A,shortcutLabel:C,showDevShutdown:O,isDevShutdownInFlight:T,onDevShutdown:E,remoteUpdateInfo:F,remoteUpdateChecking:R,remoteUpdateError:L,onOpenRemoteUpdate:B,showPredValues:V,timeFormatPreference:M}=e,{t:ee}=At();let se;n[0]!==m||n[1]!==y||n[2]!==g||n[3]!==u||n[4]!==d?(se=Me=>{d(Me),Me&&(u(),m==="usage"&&g===0&&y())},n[0]=m,n[1]=y,n[2]=g,n[3]=u,n[4]=d,n[5]=se):se=n[5];let J;n[6]!==o||n[7]!==r||n[8]!==ee?(J=r?ee("header.services.openWithCurrent",{current:o}):ee("header.services.open"),n[6]=o,n[7]=r,n[8]=ee,n[9]=J):J=n[9];const K=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let Z;n[10]!==K?(Z=De(qa,K),n[10]=K,n[11]=Z):Z=n[11];let re;n[12]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(I,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=re):re=n[12];let pe;n[13]!==a||n[14]!==r?(pe=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:a}):null,n[13]=a,n[14]=r,n[15]=pe):pe=n[15];let Se;n[16]!==J||n[17]!==Z||n[18]!==pe?(Se=s.jsx(Ft,{asChild:!0,children:s.jsx(en,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":J,className:Z,children:[re,pe]})})}),n[16]=J,n[17]=Z,n[18]=pe,n[19]=Se):Se=n[19];let te;n[20]!==o||n[21]!==r||n[22]!==C||n[23]!==ee?(te=r?ee("header.services.tooltip.currentInstanceWithShortcuts",{current:o,toggle:C("toggle_services_menu"),nextTab:C("cycle_services_tab")}):ee("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]=ee,n[24]=te):te=n[24];let Ne;n[25]!==te?(Ne=s.jsx(Lt,{children:s.jsx("p",{children:te})}),n[25]=te,n[26]=Ne):Ne=n[26];let Y;n[27]!==Se||n[28]!==Ne?(Y=s.jsxs(Mt,{children:[Se,Ne]}),n[27]=Se,n[28]=Ne,n[29]=Y):Y=n[29];let G;n[30]!==y||n[31]!==g||n[32]!==f?(G=Me=>{const he=Me;f(he),he==="usage"&&g===0&&y()},n[30]=y,n[31]=g,n[32]=f,n[33]=G):G=n[33];let q;n[34]!==m||n[35]!==p||n[36]!==G?(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(To,{items:p,activeId:m,onSelect:G,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=m,n[35]=p,n[36]=G,n[37]=q):q=n[37];let oe;n[38]!==c||n[39]!==m||n[40]!==r||n[41]!==l||n[42]!==B||n[43]!==R||n[44]!==L||n[45]!==F||n[46]!==d||n[47]!==ee?(oe=r&&m==="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:ee("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:F?.available?ee("header.services.remoteUpdate.available",{version:F.version||""}):R?ee("header.services.remoteUpdate.checking"):L||ee("header.services.remoteUpdate.upToDate")})]}),F?.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:B,children:ee("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(gp,{embedded:!0,open:l&&m==="instance",onOpenChange:Bb,onHostSwitched:()=>d(!1)})]}):null,n[38]=c,n[39]=m,n[40]=r,n[41]=l,n[42]=B,n[43]=R,n[44]=L,n[45]=F,n[46]=d,n[47]=ee,n[48]=oe):oe=n[48];let le;n[49]!==m||n[50]!==l?(le=m==="mcp"?s.jsx(lm,{active:l&&m==="mcp"}):null,n[49]=m,n[50]=l,n[51]=le):le=n[51];let ve;n[52]!==m||n[53]!==D||n[54]!==N||n[55]!==w||n[56]!==k||n[57]!==S||n[58]!==j||n[59]!==b||n[60]!==h||n[61]!==x||n[62]!==v||n[63]!==V||n[64]!==ee||n[65]!==M||n[66]!==A?(ve=m==="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:ee("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:ym(x,M)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(To,{items:h,activeId:b,onSelect:Me=>{N(Me)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:De("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||j,"aria-label":ee("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:De("h-4 w-4",j&&"animate-spin")})})]})]}),k?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:ee("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:v.map((Me,he)=>{const Ce=D[Me.providerId]??[];return s.jsxs(i.Fragment,{children:[he>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(Do,{providerId:Me.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Me.providerName})]}),Me.entries.length===0&&(!Me.modelFamilies||Me.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Me.error??ee("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Me.entries.map(xe=>{const[ue,H]=xe,ce=b==="remaining"?H.remainingPercent:H.usedPercent,fe=va(H.usedPercent,H.resetAt,H.windowSeconds,ue),U=fe?.dailyAllocationPercent!=null?b==="remaining"?100-si(fe.elapsedRatio):si(fe.elapsedRatio):null,z=Io(H.valueLabel,ce),be=Pf(H.resetAt,H.resetAfterFormatted??H.resetAtFormatted,M);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:uc(ue)}),be?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:be}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:z==="-"?"":z})]}),s.jsx(Ca,{percent:ce,tonePercent:H.usedPercent,className:"h-1.5",expectedMarkerPercent:U}),fe&&V?s.jsx(Aa,{paceInfo:fe,compact:!0}):null]},`${Me.providerId}-${ue}`)}),Me.modelFamilies&&Me.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:Me.modelFamilies.map(xe=>{const ue=xe.familyId??"other",H=Ce.includes(ue);return s.jsxs(to,{open:H,onOpenChange:()=>A(Me.providerId,ue),children:[s.jsxs(Bo,{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:xe.familyLabel}),H?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(so,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:xe.models.map(ce=>{const[fe,U]=ce,z=b==="remaining"?U.remainingPercent:U.usedPercent,be=va(U.usedPercent,U.resetAt,U.windowSeconds),ge=be?.dailyAllocationPercent!=null?b==="remaining"?100-si(be.elapsedRatio):si(be.elapsedRatio):null,_=Io(U.valueLabel,z);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:am(fe)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:_==="-"?"":_})]}),s.jsx(Ca,{percent:z,tonePercent:U.usedPercent,className:"h-1.5",expectedMarkerPercent:ge}),be&&V?s.jsx(Aa,{paceInfo:be,compact:!0}):null]},`${Me.providerId}-${fe}`)})})})]},ue)})}):null]})]},Me.providerId)})})]}):null,n[52]=m,n[53]=D,n[54]=N,n[55]=w,n[56]=k,n[57]=S,n[58]=j,n[59]=b,n[60]=h,n[61]=x,n[62]=v,n[63]=V,n[64]=ee,n[65]=M,n[66]=A,n[67]=ve):ve=n[67];let Ee;n[68]!==T||n[69]!==E||n[70]!==O||n[71]!==ee?(Ee=O?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(xs,{disabled:T,onSelect:()=>{E()},children:ee("header.services.shutdownDev")})})]}):null,n[68]=T,n[69]=E,n[70]=O,n[71]=ee,n[72]=Ee):Ee=n[72];let _e;n[73]!==q||n[74]!==oe||n[75]!==le||n[76]!==ve||n[77]!==Ee?(_e=s.jsxs(tn,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[q,oe,le,ve,Ee]}),n[73]=q,n[74]=oe,n[75]=le,n[76]=ve,n[77]=Ee,n[78]=_e):_e=n[78];let Oe;return n[79]!==l||n[80]!==se||n[81]!==Y||n[82]!==_e?(Oe=s.jsxs(sn,{open:l,onOpenChange:se,children:[Y,_e]}),n[79]=l,n[80]=se,n[81]=Y,n[82]=_e,n[83]=Oe):Oe=n[83],Oe}),Lb=(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??""),Ob=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),a=`${r} ${o}`.trim();return n.length>2||a.length<e.length?`${a}...`:a}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},ym=(t,e)=>{if(!t)return"-";try{return Tf(t,e,{fallback:"-"})}catch{return"-"}},Pn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Xr=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,Hd=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{const{t:o}=At(),a=Re(X=>X.setSessionSwitcherOpen),c=Re(X=>X.toggleSidebar),l=Re(X=>X.isSidebarOpen),d=Re(X=>X.toggleBottomTerminal),u=Re(X=>X.toggleRightSidebar),m=Re(X=>X.openContextOverview),f=Re(X=>X.openContextPlan),g=Re(X=>X.openContextBrowser),y=Re(X=>X.openContextPanelTab),p=Re(X=>X.closeContextPanel),x=Re(X=>X.contextPanelByDirectory),b=Re(X=>X.activeMainTab),h=Re(X=>X.setActiveMainTab),N=Re(X=>X.shortcutOverrides),w=Re(X=>X.timeFormatPreference),S=es(X=>X.getCurrentModel),j=Qn(),[k,v]=i.useState(!1),D=dt(X=>X.getContextUsage),A=dt(X=>!!X.newSessionDraft?.open),C=dt(X=>X.currentSessionId),O=bp(C??""),T=Rf(C??null),E=xr(X=>X.activeSessions),F=fc(),R=ys(X=>X.activeProjectId?X.projects.find(et=>et.id===X.activeProjectId)??null:null),L=i.useMemo(()=>{if(!R)return null;const X=R.label?.trim();if(X)return X;const et=R.path.split(/[\\/]/).filter(Boolean);return et[et.length-1]??null},[R]),B=dn(X=>X.results),V=dn(X=>X.fetchAllQuotas),M=dn(X=>X.isLoading),ee=dn(X=>X.lastUpdated),se=dn(X=>X.displayMode),J=dn(X=>X.showPredValues),K=dn(X=>X.dropdownProviderIds),Z=dn(X=>X.loadSettings),re=dn(X=>X.setDisplayMode),{isMobile:pe}=Rr(),Se=Ti(X=>X.status),te=Ti(X=>X.setStatus),Ne=i.useRef(null),[Y,G]=i.useState(()=>typeof window>"u"?!1:cr()),q=i.useMemo(()=>Fa(),[]),oe=Ef(),[le,ve]=i.useState(!1),Ee=i.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),_e=i.useMemo(()=>typeof window>"u"?!1:!!window.__OPENCHAMBER_ELECTRON__&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),Oe=i.useMemo(()=>{if(typeof window>"u")return null;const X=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof X=="number"&&Number.isFinite(X)&&X>0)return X;if(typeof navigator>"u")return null;const et=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!et)return null;const ht=Number.parseInt(et[1],10),Tt=Number.parseInt(et[2],10);return Number.isNaN(ht)?null:ht===10?Tt:ht},[]);Ze.useEffect(()=>{typeof window>"u"||G(cr())},[]);const Me=S(),he=Me&&typeof Me.limit=="object"&&Me.limit!==null?Me.limit:null,Ce=he&&typeof he.context=="number"?he.context:0,xe=he&&typeof he.output=="number"?he.output:0,ue=D(Ce,xe),[H,ce]=i.useState(null),fe=!C||O;Ze.useEffect(()=>{if(!C){ce(X=>X===null?X:null);return}if(ue&&ue.totalTokens>0){ce(X=>Lb(X,ue)?X:ue);return}fe&&ce(X=>X===null?X:null)},[ue,C,fe]);const U=Re(X=>X.isSessionSwitcherOpen),z=Se?.connected?Se.user?.avatarUrl??null:null,be=Se?.connected?Se.user?.login??null:null,ge=Se?.accounts??[],[_,ye]=i.useState(!1),[$,Ie]=i.useState(!1),[je,Fe]=i.useState(!1),[Ae,ne]=i.useState(!1),[P,me]=i.useState("Local"),[ae,Be]=i.useState(!0),[Ge,Ke]=i.useState(!1),[Qe,st]=i.useState(null),[ut,vt]=i.useState(!1),[Ve,tt]=i.useState(null),nt=i.useMemo(()=>Ob(P),[P]),[xt,Rt]=i.useState(Y?"instance":"usage"),[bt,ot]=i.useState("usage");Ze.useEffect(()=>{!Y&&xt==="instance"&&Rt("usage")},[xt,Y]);const at=i.useMemo(()=>Wr(),[]),Ut=!at&&b==="chat"&&!!H&&H.totalTokens>0,Nt=H&&H.contextLimit>0?Math.min(999,H.totalTokens/H.contextLimit*100):0,_t=i.useCallback(async()=>{if(!(typeof window>"u"||!Y))try{if(Xi()){me("Local"),Be(!0);return}Be(!1);const X=await Mf(),et=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,ht=$r();if(ht&&ja(ht,et)){me("Local"),Be(!0);return}const Tt=X.hosts.find(is=>ht?ja(ht,Ff(is)):!1);if(Tt?.label?.trim()){me(Lf(Tt.label.trim()));return}me("Instance")}catch{me("Local"),Be(!0)}},[Y]);Ze.useEffect(()=>{_t()},[_t]);const Le=i.useCallback(async()=>{if(ae){st(null),tt(null);return}vt(!0),tt(null);try{const X=new URLSearchParams({appType:"web",instanceMode:"remote"}),et=await Cs(`/api/openchamber/update-check?${X.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!et.ok)throw new Error(`Server responded with ${et.status}`);const ht=await et.json();st({available:ht.available??!1,version:ht.version,currentVersion:ht.currentVersion??"unknown",body:ht.body,nextSuggestedCheckInSec:typeof ht.nextSuggestedCheckInSec=="number"?ht.nextSuggestedCheckInSec:void 0,packageManager:ht.packageManager,updateCommand:ht.updateCommand})}catch(X){st(null),tt(X instanceof Error?X.message:o("header.services.remoteUpdate.error"))}finally{vt(!1)}},[ae,o]);i.useEffect(()=>{st(null),tt(null),Ke(!1)},[ae,P]),i.useEffect(()=>{if(!Y||ae)return;const X=3e3,et=3600*1e3;let ht=!1,Tt=null;const is=os=>{Tt=window.setTimeout(()=>{if(ht||typeof document<"u"&&document.visibilityState!=="visible"){is(et);return}Le().finally(()=>{ht||is(et)})},os)};return is(X),()=>{ht=!0,Tt!==null&&window.clearTimeout(Tt)}},[Le,ae,P,Y]);const Dt=i.useCallback(()=>{if(Qe?.available){Ke(!0);return}Le()},[Le,Qe?.available]);Cx();const Ot=dn(X=>X.selectedModels),mt=dn(X=>X.expandedFamilies),Et=dn(X=>X.toggleFamilyExpanded),qt=i.useMemo(()=>{const X=[];for(const et of Of){if(!K.includes(et.id))continue;const ht=B.find(Rs=>Rs.providerId===et.id),Tt=ht?.usage?.windows??{},is=ht?.usage?.models,os=Object.entries(Tt),ds={providerId:et.id,providerName:et.name,entries:os,error:ht&&!ht.ok&&ht.configured?ht.error:void 0};if(is&&Object.keys(is).length>0){const Rs=Ot[et.id]??[],Hs=Rs.length>0,kn=Ax(is,et.id),jr=Dx(et.id),Sr=Ix(jr);ds.modelFamilies=[];for(const ln of Sr){const En=kn.get(ln.id)??[];if(En.length===0)continue;const Cn=Hs?En.filter(An=>Rs.includes(An)):En;if(Cn.length===0)continue;const jn=[];for(const An of Cn){const rr=is[An];if(rr?.windows){const cn=Object.entries(rr.windows);cn.length>0&&jn.push([An,cn[0][1]])}}jn.length>0&&ds.modelFamilies.push({familyId:ln.id,familyLabel:ln.label,models:jn})}const Vs=kn.get(null)??[],Lr=Hs?Vs.filter(ln=>Rs.includes(ln)):Vs;if(Lr.length>0){const ln=[];for(const En of Lr){const Cn=is[En];if(Cn?.windows){const jn=Object.entries(Cn.windows);jn.length>0&&ln.push([En,jn[0][1]])}}ln.length>0&&ds.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:ln})}}(os.length>0||ds.modelFamilies&&ds.modelFamilies.length>0||ds.error)&&X.push(ds)}return X},[K,B,Ot,o]),Vt=qt.length>0;i.useEffect(()=>{Z()},[Z]);const Wt=i.useCallback(async X=>{re(X);try{await ac({usageDisplayMode:X})}catch(et){console.warn("Failed to update usage display mode:",et)}},[re]),Yt=i.useCallback(()=>{if(Ae)return;ne(!0);const X=new Promise(et=>setTimeout(et,500));Promise.all([V(),X]).finally(()=>{ne(!1)})},[V,Ae]),Bt=i.useMemo(()=>C?F.find(X=>X.id===C)??E.find(X=>X.id===C)??T??Bf().find(X=>X.id===C)??null:null,[C,T,E,F]),Ht=i.useRef(null),[Jt,rs]=i.useState(0);i.useEffect(()=>{if(!C){Ht.current&&(Ht.current=null,rs(Tt=>Tt+1));return}if(Bt){Ht.current={sessionId:C,session:Bt,expiresAt:Date.now()+2e3};return}const X=Ht.current;if(!X||X.sessionId!==C)return;const et=X.expiresAt-Date.now();if(et<=0){Ht.current=null,rs(Tt=>Tt+1);return}const ht=window.setTimeout(()=>{Ht.current?.sessionId===C&&(Ht.current=null),rs(Tt=>Tt+1)},et);return()=>{window.clearTimeout(ht)}},[C,Bt]);const Qt=(()=>{if(Bt)return Bt;if(!C)return null;const X=Ht.current;return X&&X.sessionId===C&&X.expiresAt>Date.now()?X.session:null})(),Xt=dt(X=>C?X.worktreeMetadata.get(C)?.path??"":""),bs=dt(X=>C?X.worktreeMetadata.get(C)?.branch?.trim()??null:null),yt=Vf(X=>C?X.getAttachment(C):void 0),Ue=i.useMemo(()=>yt?yp(yt,{pending:o("gitView.empty.worktreeSetupInProgress")}):null,[o,yt]),Ye=i.useMemo(()=>yt?yt.legacy?"legacy":yt.degraded?"degraded":yt.worktreeStatus==="pending"?"pending":yt.worktreeStatus==="missing"?"missing":yt.worktreeStatus==="invalid"?"invalid":yt.attentionReason?"attention":null:null,[yt]),Ct=i.useMemo(()=>Pn(Xt||""),[Xt]),kt=i.useMemo(()=>{const X=typeof Qt?.directory=="string"?Qt.directory:"";return Pn(X||"")},[Qt?.directory]),It=dt(X=>X.newSessionDraft?.open?Pn(X.newSessionDraft.bootstrapPendingDirectory??X.newSessionDraft.directoryOverride??""):""),rt=i.useMemo(()=>Ct||kt||It,[It,kt,Ct]),ts=dt(X=>{const et=Pn(Ct||kt||"");if(!et)return null;for(const ht of X.availableWorktreesByProject.values()){const is=ht.find(os=>Pn(os.path)===et)?.branch?.trim();if(is)return is}return null}),Gt=wp(rt||null)||bs||ts,nn=i.useMemo(()=>{if(!C)return L??"OpenChamber";const X=Qt?.title?.trim();return X&&X.length>0?X:"Untitled Session"},[L,Qt?.title,C]),js=i.useMemo(()=>Pn(rt||R?.path||""),[R?.path,rt]),ss=i.useMemo(()=>R?{id:R.id,path:R.path}:null,[R]),Os=i.useRef(null);i.useEffect(()=>{!ss||!js||(Os.current={projectRef:ss,directory:js})},[js,ss]);const Ps=i.useMemo(()=>ss&&js?{projectRef:ss,directory:js}:Os.current,[js,ss]),As=mc(X=>X.planModeEnabled),yn=dt(X=>X.isSessionPlanAvailable),Ys=As&&C?yn(C):!1,un=Ys,wn=i.useRef("");i.useEffect(()=>{if(!As){Re.getState().activeMainTab==="plan"&&Re.getState().setActiveMainTab("chat");return}if(!C)return;const X=`${C||"none"}:${kt||"none"}:${Qt?.time?.created||0}:${Qt?.slug||"none"}`;wn.current!==X&&(wn.current=X),!Ys&&Re.getState().activeMainTab==="plan"&&Re.getState().setActiveMainTab("chat")},[As,Ys,Qt?.slug,Qt?.time?.created,C,kt]);const zs=i.useCallback(async X=>{if(!(!X||_)){ye(!0);try{const et=j.github?await j.github.authActivate(X):await(async()=>{const ht=await Cs("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:X})}),Tt=await ht.json().catch(()=>null);if(!ht.ok||!Tt)throw new Error(Tt?.error||ht.statusText);return Tt})();te(et)}catch(et){console.error("Failed to switch GitHub account:",et)}finally{ye(!1)}}},[_,j.github,te]),we=i.useCallback(()=>{if(typeof document>"u")return;const X=document.activeElement;if(!X)return;const et=X.tagName;(et==="INPUT"||et==="TEXTAREA"||et==="SELECT"||X.isContentEditable)&&X.blur()},[]),Je=i.useCallback(()=>{if(pe){we(),a(!U);return}c()},[we,pe,U,a,c]),wt=i.useCallback(()=>{zr("desktop_open_draft_mini_chat_window",{directory:Pn(rt||R?.path||""),projectId:R?.id??null,apiBaseUrl:$r(),clientToken:Vl()}).catch(X=>{console.warn("[header] failed to open draft mini chat window",X)})},[R?.id,R?.path,rt]),Pt=i.useCallback(()=>{if(A){wt();return}C&&zr("desktop_open_session_mini_chat_window",{sessionId:C,directory:Pn(rt||R?.path||""),apiBaseUrl:$r(),clientToken:Vl()}).catch(X=>{console.warn("[header] failed to open session mini chat window",X)})},[R?.path,C,wt,A,rt]),$t=i.useCallback(()=>{const X=Pn(rt||"");if(!X)return;const et=x[X];if(Xr(et)==="context"){p(X);return}m(X)},[p,x,m,rt]),ft=i.useMemo(()=>{const X=Pn(rt||"");if(!X)return!1;const et=x[X];return Xr(et)==="context"},[x,rt]),ls=i.useCallback(()=>{const X=Pn(rt||"");if(!X)return;const et=x[X];if(Xr(et)==="plan"){p(X);return}f(X)},[p,x,f,rt]),cs=i.useCallback(()=>{const X=Pn(rt||"");if(!X)return;const et=x[X];if(Xr(et)==="diff"){p(X);return}y(X,{mode:"diff",stagedDiff:!1})},[p,x,y,rt]),Ns=i.useCallback(()=>{const X=Pn(rt||"");if(!X)return;const et=x[X];if(Xr(et)==="browser"){p(X);return}g(X)},[p,x,g,rt]),ms=i.useMemo(()=>{const X=Pn(rt||"");if(!X)return!1;const et=x[X];return Xr(et)==="plan"},[x,rt]),Qs=i.useMemo(()=>{const X=Pn(rt||"");if(!X)return!1;const et=x[X];return Xr(et)==="diff"},[x,rt]),He=i.useMemo(()=>{const X=Pn(rt||"");if(!X)return!1;const et=x[X];return Xr(et)==="browser"},[x,rt]),ns=qa,ws=Eb,vs=i.useMemo(()=>$?"services":n?"sessions":r?"git":b,[b,$,n,r]),Ws=i.useCallback(()=>{Ie(!1),n&&t&&t(),r&&e&&e(),!t&&U&&a(!1)},[U,n,t,e,r,a]),Ss=i.useCallback(()=>{n||Ie(!1),t?.()},[n,t]),Bs=i.useCallback(()=>{r||Ie(!1),e?.()},[e,r]),fs=i.useMemo(()=>Y&&Ee&&!le?"5.5rem":oe?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!Y||_e)&&!at?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[Y,le,Ee,oe,at,_e]);Ze.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",fs)},[fs]);const ci=l?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",br=l?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";Ze.useEffect(()=>{if(!Y||!Ee){ve(!1);return}let X=!1;const et=async()=>{try{const Tt=await zr("desktop_is_window_fullscreen");X||ve(Tt===!0)}catch{X||ve(!1)}},ht=()=>{et()};return et(),window.addEventListener("openchamber:window-resized",ht),()=>{X=!0,window.removeEventListener("openchamber:window-resized",ht)}},[Y,Ee]);const yr=i.useMemo(()=>!Y||!Ee||Oe===null?"":Oe>=26?"h-12":Oe<=15?"h-14":"",[Y,Ee,Oe]),wr=i.useMemo(()=>{if(!(Y&&!_e||at))return{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))"}},[Y,at,_e]),Jn=i.useCallback(()=>{if(typeof document>"u")return;const X=Ne.current?.getBoundingClientRect().height;X&&document.documentElement.style.setProperty("--oc-header-height",`${X}px`)},[]);Ze.useEffect(()=>{if(typeof window>"u")return;Jn();const X=Ne.current;if(!X||typeof ResizeObserver>"u")return()=>{};let et=0;const ht=()=>{et||(et=requestAnimationFrame(()=>{et=0,Jn()}))},Tt=new ResizeObserver(ht);return Tt.observe(X),window.addEventListener("resize",ht),window.addEventListener("orientationchange",ht),()=>{et&&cancelAnimationFrame(et),Tt.disconnect(),window.removeEventListener("resize",ht),window.removeEventListener("orientationchange",ht)}},[Jn]),Ze.useEffect(()=>{Jn()},[Jn,pe,yr]);const vr=i.useCallback(async X=>{const et=X.target;et.closest(".app-region-no-drag")||et.closest("button, a, input, select, textarea")||X.button===0&&Y&&await Xh()},[Y]),Xn=i.useMemo(()=>{if(pe){const X=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return un&&X.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),X.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"},{id:"diagram",label:o("layout.mainTab.diagram"),icon:"file"}),X}return[]},[pe,un,o]),ur=i.useCallback(X=>La(ni(X,N)),[N]);Ze.useEffect(()=>{!pe&&(b==="git"||b==="terminal"||b==="diff"||b==="files"||b==="context")&&h("chat")},[b,pe,h]);const Un=i.useMemo(()=>{const X=[];return Y&&X.push({value:"instance",label:o("layout.services.instance"),icon:s.jsx(I,{name:"server",className:"h-3.5 w-3.5"})}),X.push({value:"usage",label:o("layout.services.usage"),icon:s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"})},{value:"mcp",label:"MCP",icon:s.jsx($l,{className:"h-3.5 w-3.5"})}),X},[Y,o]),ps=i.useMemo(()=>Un.map(X=>({id:X.value,label:X.label,icon:X.icon})),[Un]),Ds=i.useMemo(()=>{if(typeof window>"u"||Y||at)return!1;const X=window.location.hostname;return X==="localhost"||X==="127.0.0.1"||X==="::1"},[Y,at]),Er=i.useCallback(async()=>{if(k)return;v(!0),Fe(!1);const X=[];let et=!1;try{try{for(const[,ht]of Ms.getState().sessions.entries())for(const Tt of ht.tabs)Tt.previewUrl&&X.push(Tt.previewUrl)}catch{}try{await Zh({})}catch{}try{(await Cs("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:X})})).ok?et=!0:et=(await Cs("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{et||v(!1)}},[k,Fe]),vn=i.useMemo(()=>[{value:"usage",label:o("header.services.used")},{value:"remaining",label:o("header.services.remaining")}],[o]),rn=i.useMemo(()=>vn.map(X=>({id:X.value,label:X.label})),[vn]),nr=i.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($l,{className:"h-3.5 w-3.5"})}],[o]);Ze.useEffect(()=>{const X=et=>{if(hc(et)&&!et.shiftKey&&!et.altKey){const ht=parseInt(et.key,10);ht>=1&&ht<=Xn.length&&(et.preventDefault(),pe&&(we(),Ws()),h(Xn[ht-1].id))}};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[we,Ws,pe,h,Xn]),Ze.useEffect(()=>{const X=et=>{const ht=ni("toggle_services_menu",N);if(ia(et,ht)){et.preventDefault(),je?Fe(!1):(Fe(!0),_t(),xt==="usage"&&B.length===0&&V());return}const Tt=ni("cycle_services_tab",N);if(ia(et,Tt)){et.preventDefault();const os=Un.map(kn=>kn.value);if(os.length===0)return;const ds=os.indexOf(xt),Rs=ds===-1?0:(ds+1)%os.length,Hs=os[Rs];Rt(Hs),Fe(!0),_t(),Hs==="usage"&&B.length===0&&V();return}const is=ni("toggle_context_plan",N);ia(et,is)&&(et.preventDefault(),ls())};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[N,je,xt,Un,B.length,V,_t,ls]);const Mr=X=>{const et=b===X.id,ht=X.icon==="diff",Tt=ht?null:X.icon,is=X.id==="chat",os=Rs=>ht?s.jsx($d,{size:Rs}):Tt?s.jsx(I,{name:Tt,className:`h-${Rs/4} w-${Rs/4}`}):null,ds=s.jsxs("button",{type:"button",onClick:()=>h(X.id),className:De("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",et?"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",is&&!pe&&"min-w-[100px] justify-center"),"aria-label":X.label,"aria-selected":et,role:"tab",children:[pe?os(20):s.jsxs(s.Fragment,{children:[os(16),s.jsx("span",{className:"header-tab-label",children:X.label})]}),X.badge!==void 0&&X.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:X.badge})]});return s.jsx(i.Fragment,{children:ds},X.id)},Gr=at?null:s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.actions.toggleChangesPanelAria"),"aria-pressed":Qs,onClick:cs,className:ns,children:s.jsxs("span",{className:"relative h-5 w-5 overflow-hidden rounded-[2px]",children:[s.jsx("span",{className:"absolute left-[4px] top-[4px] h-3 w-[5px] bg-[var(--status-error)]/25"}),s.jsx("span",{className:"absolute right-[4px] top-[4px] h-3 w-[5px] bg-[var(--status-success)]/25"}),s.jsx(I,{name:"layout-column",className:"absolute inset-0 h-5 w-5"})]})})}),s.jsx(Lt,{children:s.jsx("p",{children:o("header.actions.toggleChangesPanel")})})]}),Fr=s.jsxs(s.Fragment,{children:[un&&s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.actions.openPlanAria"),onClick:ls,className:De(ns,ms&&"bg-[var(--interactive-hover)]"),children:s.jsx(I,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Lt,{children:s.jsx("p",{children:o("header.actions.planWithShortcut",{shortcut:ur("toggle_context_plan")})})})]}),s.jsx(rb,{directory:js,className:"mr-1"}),s.jsx(Fb,{isDesktopApp:Y,currentInstanceLabel:P,compactCurrentInstanceLabel:nt,currentInstanceIsLocal:ae,isDesktopServicesOpen:je,setIsDesktopServicesOpen:Fe,refreshCurrentInstanceLabel:_t,desktopServicesTab:xt,setDesktopServicesTab:Rt,quotaResultsLength:B.length,fetchAllQuotas:V,servicesTabItems:ps,quotaLastUpdated:ee,quotaDisplayMode:se,showPredValues:J,quotaDisplayTabItems:rn,handleDisplayModeChange:Wt,handleUsageRefresh:Yt,isQuotaLoading:M,isUsageRefreshSpinning:Ae,hasRateLimits:Vt,rateLimitGroups:qt,expandedFamilies:mt,toggleFamilyExpanded:Et,shortcutLabel:ur,showDevShutdown:Ds,isDevShutdownInFlight:k,onDevShutdown:Er,remoteUpdateInfo:Qe,remoteUpdateChecking:ut,remoteUpdateError:Ve,onOpenRemoteUpdate:Dt,timeFormatPreference:w}),s.jsx(Wo,{title:o("header.actions.terminalPanelWithShortcut",{shortcut:ur("toggle_terminal")}),ariaLabel:o("header.actions.toggleTerminalPanelAria"),onClick:d,Icon:"terminal-box"}),pe?null:s.jsx(Wo,{title:o("contextPanel.browser.open"),ariaLabel:o("contextPanel.browser.open"),onClick:Ns,pressed:He,Icon:"global"}),s.jsx(Wo,{title:o("header.actions.rightSidebarWithShortcut",{shortcut:ur("toggle_right_sidebar")}),ariaLabel:o("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx(Mb,{isMobile:pe,githubAuthStatus:Se,githubAccounts:ge,githubAvatarUrl:z,githubLogin:be,isSwitchingGitHubAccount:_,handleGitHubAccountSwitch:zs})]}),gs=q&&(A||!!C),Ts=()=>s.jsxs("div",{onMouseDown:vr,className:De("app-region-drag relative flex h-12 select-none items-center pr-3",yr),style:wr,role:"tablist","aria-label":o("header.navigation.mainAria"),children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:ci}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:br}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[s.jsx(qx,{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:A?o("sessions.switcher.draftTitle"):nn}),L||Gt||!A&&Ye?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:[L?s.jsx("span",{className:"truncate",children:L}):null,Gt?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:Gt})]}):null,!A&&Ye?s.jsxs("span",{className:De("inline-flex min-w-0 items-center gap-0.5",Ye==="attention"||Ye==="invalid"||Ye==="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:Ue})]}):null]}):null]})}),Xn.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Xn.map(X=>Mr(X))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ut&&H?s.jsx(Yx,{totalTokens:H.totalTokens,percentage:Nt,colorPercentage:H.percentage,contextLimit:H.contextLimit,outputLimit:H.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:$t,pressed:ft,className:gs?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,Gr,s.jsx(Wo,{visible:gs,title:o(A?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(A?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Pt,className:De(ns,"mr-1"),Icon:"picture-in-picture-2"}),Fr,s.jsx(Qx,{visible:_e})]})]})]}),Wn=()=>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:Ss,className:De(ws,vs==="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"})}):U?s.jsx("button",{type:"button",onClick:()=>a(!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:Je,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&&U&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!U||!!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:Xn.map(X=>{const et=b===X.id,ht=X.icon==="diff",Tt=ht?null:X.icon;return s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{pe&&(we(),Ws()),h(X.id)},"aria-label":X.label,"aria-selected":et,role:"tab",className:De(ws,"relative rounded-lg",vs===X.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[ht?s.jsx($d,{className:"h-5 w-5"}):Tt?s.jsx(I,{name:Tt,className:"h-5 w-5"}):null,X.badge!==void 0&&X.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:X.badge}),X.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(Lt,{children:s.jsx("p",{children:X.label})})]},X.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Ps&&s.jsx(bm,{projectRef:Ps.projectRef,directory:Ps.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(sn,{open:$,onOpenChange:X=>{X&&(n&&t&&t(),r&&e&&e()),Ie(X),X&&B.length===0&&V()},children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx(en,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:De(ws,vs==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(I,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Lt,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(tn,{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(To,{items:nr,activeId:bt,onSelect:X=>{const et=X;ot(et),et==="usage"&&B.length===0&&V()},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:()=>Ie(!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(lm,{active:$&&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:ym(ee,w)})]}),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:()=>Wt("usage"),className:De("typography-ui-label px-1 pb-0.5 transition-colors",se==="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:()=>Wt("remaining"),className:De("typography-ui-label px-1 pb-0.5 transition-colors",se==="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:De("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:Yt,disabled:M||Ae,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:De("h-4 w-4",Ae&&"animate-spin")})})]})]})}),!Vt&&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:qt.map((X,et)=>s.jsxs(i.Fragment,{children:[et>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(Do,{providerId:X.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:X.providerName})]}),X.entries.length===0&&(!X.modelFamilies||X.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:X.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[X.entries.map(([ht,Tt])=>{const is=se==="remaining"?Tt.remainingPercent:Tt.usedPercent,os=va(Tt.usedPercent,Tt.resetAt,Tt.windowSeconds,ht),ds=os?.dailyAllocationPercent!=null?se==="remaining"?100-si(os.elapsedRatio):si(os.elapsedRatio):null,Rs=Io(Tt.valueLabel,is),Hs=Pf(Tt.resetAt,Tt.resetAfterFormatted??Tt.resetAtFormatted,w);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:uc(ht)}),Hs?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Hs}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Rs==="-"?"":Rs})]}),s.jsx(Ca,{percent:is,tonePercent:Tt.usedPercent,className:"h-1.5",expectedMarkerPercent:ds}),os&&J?s.jsx(Aa,{paceInfo:os,compact:!0}):null]},`${X.providerId}-${ht}`)}),X.modelFamilies&&X.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:X.modelFamilies.map(ht=>{const is=(mt[X.providerId]??[]).includes(ht.familyId??"other");return s.jsxs(to,{open:is,onOpenChange:()=>Et(X.providerId,ht.familyId??"other"),children:[s.jsxs(Bo,{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:ht.familyLabel}),is?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(so,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ht.models.map(([os,ds])=>{const Rs=se==="remaining"?ds.remainingPercent:ds.usedPercent,Hs=va(ds.usedPercent,ds.resetAt,ds.windowSeconds),kn=Hs?.dailyAllocationPercent!=null?se==="remaining"?100-si(Hs.elapsedRatio):si(Hs.elapsedRatio):null,jr=Io(ds.valueLabel,Rs);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:am(os)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:jr==="-"?"":jr})]}),s.jsx(Ca,{percent:Rs,tonePercent:ds.usedPercent,className:"h-1.5",expectedMarkerPercent:kn}),Hs&&J?s.jsx(Aa,{paceInfo:Hs,compact:!0}):null]},`${X.providerId}-${os}`)})})})]},ht.familyId??"other")})})]})]},X.providerId))})]})]})})]}),e?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Bs,className:De(ws,"relative",vs==="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(Lt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),fn=De("header-safe-area relative z-10 bg-background",pe&&"border-b border-border/50");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:Ne,className:fn,style:{"--padding-scale":"1"},children:pe?Wn():Ts()}),s.jsx(cm,{open:Ge,onOpenChange:Ke,info:Qe,downloading:!1,downloaded:!1,progress:null,error:Ve,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function Bb(){}const Gd=180,Kd=640,Vb=110,_b=t=>{const e=gt.c(44),{isOpen:n,isMobile:r,children:o}=t,{t:a}=At(),c=Re($b),l=Re(zb),d=Re(Ub),u=Re(Wb),[m,f]=i.useState(null),[g,y]=i.useState(!1),p=i.useRef(null),x=i.useRef(0),b=i.useRef(c||300),h=Math.min(Kd,Math.max(Gd,c||300));let N,w;e[0]!==n?(N=()=>{n||(f(null),y(!1))},w=[n],e[0]=n,e[1]=N,e[2]=w):(N=e[1],w=e[2]),i.useEffect(N,w);let S,j;e[3]!==l||e[4]!==r||e[5]!==n?(S=()=>{if(r||!n||!l)return;const Z=()=>{const Se=p.current?.parentElement?.getBoundingClientRect().height;if(!Se||Se<=0)return;const te=Math.max(0,Math.round(Se));f(Ne=>Ne===te?Ne:te)};Z();const re=p.current?.parentElement;if(!re)return;const pe=new ResizeObserver(Z);return pe.observe(re),()=>{pe.disconnect()}},j=[l,r,n],e[3]=l,e[4]=r,e[5]=n,e[6]=S,e[7]=j):(S=e[6],j=e[7]),i.useEffect(S,j);let k,v;if(e[8]!==l||e[9]!==r||e[10]!==g||e[11]!==d||e[12]!==u?(k=()=>{if(r||!g||l)return;const Z=pe=>{const Se=x.current-pe.clientY,te=Math.min(Kd,Math.max(Gd,b.current+Se));d(te)},re=()=>{y(!1),Re.getState().bottomTerminalHeight<=Vb&&u(!1)};return window.addEventListener("pointermove",Z),window.addEventListener("pointerup",re,{once:!0}),()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",re)}},v=[l,r,g,d,u],e[8]=l,e[9]=r,e[10]=g,e[11]=d,e[12]=u,e[13]=k,e[14]=v):(k=e[13],v=e[14]),i.useEffect(k,v),r)return null;const D=n?l?Math.max(0,m??h):h:0,A=n&&l;let C;e[15]!==D||e[16]!==l||e[17]!==n?(C=Z=>{!n||l||(y(!0),x.current=Z.clientY,b.current=D,Z.preventDefault())},e[15]=D,e[16]=l,e[17]=n,e[18]=C):C=e[18];const O=C,T=A?"absolute inset-x-0 bottom-0 z-40":"relative",E=g?"transition-none":"transition-[height] duration-300 ease-in-out",F=(!n||A)&&"border-t-0";let R;e[19]!==F||e[20]!==T||e[21]!==E?(R=De("flex overflow-hidden border-t border-border bg-sidebar",T,E,F),e[19]=F,e[20]=T,e[21]=E,e[22]=R):R=e[22];let L;e[23]!==D||e[24]!==A?(L=A?{top:0}:{height:`${D}px`,minHeight:`${D}px`,maxHeight:`${D}px`},e[23]=D,e[24]=A,e[25]=L):L=e[25];const B=!n||!l&&D===0;let V;e[26]!==O||e[27]!==l||e[28]!==n||e[29]!==g||e[30]!==a?(V=n&&!l&&s.jsx("div",{className:De("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:O,role:"separator","aria-orientation":"horizontal","aria-label":a("terminalView.bottomDock.resizeAria")}),e[26]=O,e[27]=l,e[28]=n,e[29]=g,e[30]=a,e[31]=V):V=e[31];const M=!n&&"pointer-events-none select-none opacity-0";let ee;e[32]!==M?(ee=De("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",M),e[32]=M,e[33]=ee):ee=e[33];const se=!n;let J;e[34]!==o||e[35]!==ee||e[36]!==se?(J=s.jsx("div",{className:ee,"aria-hidden":se,children:o}),e[34]=o,e[35]=ee,e[36]=se,e[37]=J):J=e[37];let K;return e[38]!==R||e[39]!==L||e[40]!==B||e[41]!==V||e[42]!==J?(K=s.jsxs("section",{ref:p,className:R,style:L,"aria-hidden":B,children:[V,J]}),e[38]=R,e[39]=L,e[40]=B,e[41]=V,e[42]=J,e[43]=K):K=e[43],K};function $b(t){return t.bottomTerminalHeight}function zb(t){return t.isBottomTerminalExpanded}function Ub(t){return t.setBottomTerminalHeight}function Wb(t){return t.setBottomTerminalOpen}const qd=280,Yd=280,Qd=500,Hb=({isOpen:t,isMobile:e,children:n,className:r,topBar:o})=>{const{t:a}=At(),c=Re(v=>v.sidebarWidth),l=Re(v=>v.setSidebarWidth),[d,u]=i.useState(!1),m=i.useRef(0),f=i.useRef(c||qd),g=i.useRef(null),y=i.useRef(null),p=i.useRef(null),x=i.useCallback(v=>Math.min(Qd,Math.max(Yd,v)),[]),b=i.useCallback(v=>{const D=p.current;D&&(D.style.width=`${v}px`,D.style.minWidth=`${v}px`,D.style.maxWidth=`${v}px`,D.style.setProperty("--oc-left-sidebar-width",`${v}px`))},[]);if(i.useEffect(()=>{e&&d&&u(!1)},[e,d]),i.useEffect(()=>{d||(g.current=null,y.current=null)},[d]),e)return null;const h=Math.min(Qd,Math.max(Yd,c||qd)),N=t?h:0,w=v=>{if(t){try{v.currentTarget.setPointerCapture(v.pointerId)}catch{}y.current=v.pointerId,u(!0),m.current=v.clientX,f.current=N,g.current=N,b(N),v.preventDefault()}},S=v=>{if(e||!d||y.current!==v.pointerId)return;const D=v.clientX-m.current,A=x(f.current+D);g.current!==A&&(g.current=A,b(A))},j=v=>{if(y.current!==v.pointerId||e)return;try{v.currentTarget.releasePointerCapture(v.pointerId)}catch{}const D=x(g.current??N);y.current=null,g.current=null,u(!1),l(D)},k=d?g.current??N:N;return s.jsxs("aside",{ref:p,className:De("relative flex h-full overflow-hidden border-r border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar oc-vibrancy-surface",!t&&"border-r-0",r),style:{width:`${k}px`,minWidth:`${k}px`,maxWidth:`${k}px`,"--oc-left-sidebar-width":`${d?k:h}px`,overflowX:"clip",transitionProperty:d?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||N===0,children:[t&&s.jsx("div",{className:De("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",d&&"bg-[var(--interactive-border)]"),onPointerDown:w,onPointerMove:S,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:De("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",d&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[o,s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx(Zs,{children:n})})]})]})},Gb=()=>{const t=gt.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={height:"var(--oc-header-height, 3rem)"},t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("div",{className:"app-region-drag shrink-0",style:{width:"var(--oc-titlebar-left-inset, 0.75rem)"}}),t[1]=n):n=t[1];let r;return t[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs("div",{"aria-hidden":!0,className:"flex shrink-0",style:e,children:[n,s.jsx("div",{className:"app-region-no-drag shrink-0",style:{width:"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)"}}),s.jsx("div",{className:"app-region-drag flex-1"})]}),t[2]=r):r=t[2],r},Ho=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function Kb(){const t=ys(f=>f.activeProjectId?f.projects.find(g=>g.id===f.activeProjectId)??null:null),e=dt(f=>f.currentSessionId),n=Rf(e??null),r=dt(f=>e?f.worktreeMetadata.get(e)?.path??"":""),o=dt(f=>f.newSessionDraft?.open?Ho(f.newSessionDraft.bootstrapPendingDirectory??f.newSessionDraft.directoryOverride??""):""),a=i.useMemo(()=>Ho(r||""),[r]),c=i.useMemo(()=>{const f=typeof n?.directory=="string"?n.directory:"";return Ho(f||"")},[n?.directory]),l=a||c||o,d=i.useMemo(()=>Ho(l||t?.path||""),[t?.path,l]),u=i.useMemo(()=>t?{id:t.id,path:t.path}:null,[t]),m=i.useRef(null);return i.useEffect(()=>{u&&d&&(m.current={projectRef:u,directory:d})},[d,u]),i.useMemo(()=>u&&d?{projectRef:u,directory:d}:m.current,[u,d])}const Jd="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 hover:bg-interactive-hover transition-colors",qb=()=>{const t=gt.c(31),{t:e}=At(),n=Re(Yb),r=Re(Qb),o=Re(Jb),a=Kb(),c=i.useRef(null),l=La(ni("toggle_sidebar",o));let d;e:{if(typeof window>"u"){d=!1;break e}d=!!window.__OPENCHAMBER_ELECTRON__&&window.__OPENCHAMBER_PLATFORM__==="win32"}const u=d,m=Zb;let f,g;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{if(typeof document>"u")return;const F=c.current;if(!F)return;const R=()=>{const B=F.getBoundingClientRect().width;document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(B)}px`)};if(R(),typeof ResizeObserver>"u")return;const L=new ResizeObserver(R);return L.observe(F),()=>{L.disconnect()}},g=[],t[0]=f,t[1]=g):(f=t[0],g=t[1]),i.useEffect(f,g);const y="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let p;t[2]===Symbol.for("react.memo_cache_sentinel")?(p={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=p):p=t[2];const x="flex items-center gap-2";let b;t[3]!==e?(b=u?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,"aria-label":e("header.actions.openAppMenuAria"),className:De(Jd,"shrink-0"),children:s.jsx(I,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(Lt,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[3]=e,t[4]=b):b=t[4];const h=Mt;let N;t[5]!==e?(N=e("header.actions.openSessionsAria"),t[5]=e,t[6]=N):N=t[6];let w,S;t[7]===Symbol.for("react.memo_cache_sentinel")?(w=De(Jd,"shrink-0"),S=s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[7]=w,t[8]=S):(w=t[7],S=t[8]);let j;t[9]!==N||t[10]!==n?(j=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":N,className:w,children:S})}),t[9]=N,t[10]=n,t[11]=j):j=t[11];const k=Lt,v=e("header.actions.openSessionsWithShortcut",{shortcut:l});let D;t[12]!==v?(D=s.jsx("p",{children:v}),t[12]=v,t[13]=D):D=t[13];let A;t[14]!==k||t[15]!==D?(A=s.jsx(k,{children:D}),t[14]=k,t[15]=D,t[16]=A):A=t[16];let C;t[17]!==h||t[18]!==j||t[19]!==A?(C=s.jsxs(h,{children:[j,A]}),t[17]=h,t[18]=j,t[19]=A,t[20]=C):C=t[20];let O;t[21]!==r||t[22]!==a?(O=a?s.jsx(bm,{projectRef:a.projectRef,directory:a.directory,className:r?"oc-vibrancy-pill":void 0}):null,t[21]=r,t[22]=a,t[23]=O):O=t[23];let T;t[24]!==C||t[25]!==O||t[26]!==b?(T=s.jsxs("div",{ref:c,className:x,children:[b,C,O]}),t[24]=C,t[25]=O,t[26]=b,t[27]=T):T=t[27];let E;return t[28]!==T||t[29]!==p?(E=s.jsx("div",{className:y,style:p,children:T}),t[28]=T,t[29]=p,t[30]=E):E=t[30],E};function Yb(t){return t.toggleSidebar}function Qb(t){return t.isSidebarOpen}function Jb(t){return t.shortcutOverrides}function Xb(t){console.warn("[titlebar] failed to open app menu",t)}function Zb(t){const e=t.currentTarget.getBoundingClientRect();zr("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(Xb)}const Xd=420,ey=({isOpen:t,children:e,className:n})=>{const{t:r}=At(),o=Re(j=>j.rightSidebarWidth),a=Re(j=>j.setRightSidebarWidth),[c,l]=i.useState(!1),d=i.useRef(0),u=i.useRef(o||Xd),m=i.useRef(null),f=i.useRef(null),g=i.useRef(null),y=i.useCallback(j=>Math.min(dd,Math.max(ud,j)),[]),p=i.useCallback(j=>{const k=g.current;k&&(k.style.width=`${j}px`,k.style.minWidth=`${j}px`,k.style.maxWidth=`${j}px`,k.style.setProperty("--oc-right-sidebar-width",`${j}px`))},[]),x=Math.min(dd,Math.max(ud,o||Xd)),b=t?x:0,h=j=>{if(t){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}f.current=j.pointerId,l(!0),d.current=j.clientX,u.current=b,m.current=b,p(b),j.preventDefault()}},N=j=>{if(!c||f.current!==j.pointerId)return;const k=d.current-j.clientX,v=y(u.current+k);m.current!==v&&(m.current=v,p(v))},w=j=>{if(f.current!==j.pointerId)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const k=y(m.current??b);f.current=null,m.current=null,l(!1),a(k)},S=c?m.current??b:b;return s.jsxs("aside",{ref:g,className:De("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`,"--oc-right-sidebar-width":`${c?S:x}px`,overflowX:"clip",transitionProperty:c?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||b===0,children:[t&&s.jsx("div",{className:De("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:De("relative z-10 flex h-full min-h-0 shrink-0 flex-col pt-2 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})]})},Zd=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent});function wm(t){const e=gt.c(120),{t:n}=At(),{open:r,onOpenChange:o,target:a,projectDirectory:c,submitting:l,onConfirm:d}=t,u=l===void 0?!1:l,m=es(dy),f=es(cy),g=vp(ly),y=es(ay),p=es(oy),x=es(iy),b=es(ry),h=es(ny);let N;e[0]!==h||e[1]!==x||e[2]!==p||e[3]!==b?(N=()=>Zd({providerID:p,modelID:x,variant:b,agent:h}),e[0]=h,e[1]=x,e[2]=p,e[3]=b,e[4]=N):N=e[4];const[w,S]=i.useState(N);let j,k;e[5]!==g||e[6]!==f||e[7]!==m||e[8]!==r||e[9]!==c?(j=()=>{r&&(m({directory:c,source:"todoSendDialog"}),f({directory:c}),g())},k=[r,m,f,g,c],e[5]=g,e[6]=f,e[7]=m,e[8]=r,e[9]=c,e[10]=j,e[11]=k):(j=e[10],k=e[11]),i.useEffect(j,k);let v,D;e[12]!==h||e[13]!==x||e[14]!==p||e[15]!==b||e[16]!==r?(v=()=>{r&&S(Zd({providerID:p,modelID:x,variant:b,agent:h}))},D=[r,p,x,b,h],e[12]=h,e[13]=x,e[14]=p,e[15]=b,e[16]=r,e[17]=v,e[18]=D):(v=e[17],D=e[18]),i.useEffect(v,D);let A,C;e[19]!==w.modelID||e[20]!==w.providerID||e[21]!==r||e[22]!==y?(A=()=>{if(!r||y.length===0)return;const je=y.find(P=>P.id===w.providerID)??y[0],Fe=Array.isArray(je?.models)?je.models:[],Ae=Fe.some(P=>P.id===w.modelID),ne=Fe[0]?.id??"";je?.id===w.providerID&&Ae||S(P=>({...P,providerID:je?.id??"",modelID:Ae?P.modelID:ne,variant:""}))},C=[r,y,w.providerID,w.modelID],e[19]=w.modelID,e[20]=w.providerID,e[21]=r,e[22]=y,e[23]=A,e[24]=C):(A=e[23],C=e[24]),i.useEffect(A,C);const O=sy;let T;if(e[25]!==w.modelID||e[26]!==w.providerID||e[27]!==y){let je;e[29]!==w.providerID?(je=Ae=>Ae.id===w.providerID,e[29]=w.providerID,e[30]=je):je=e[30],T=y.find(je)?.models?.find(Ae=>Ae.id===w.modelID),e[25]=w.modelID,e[26]=w.providerID,e[27]=y,e[28]=T}else T=e[28];const E=T;let F;e[31]!==E?(F=E?.variants?Object.keys(E.variants):[],e[31]=E,e[32]=F):F=e[32];const R=F,L=R.length>0;let B,V;e[33]!==w.variant||e[34]!==L?(B=()=>{L||!w.variant||S(ty)},V=[L,w.variant],e[33]=w.variant,e[34]=L,e[35]=B,e[36]=V):(B=e[35],V=e[36]),i.useEffect(B,V);let M;e[37]!==w.modelID||e[38]!==w.providerID?(M=w.providerID.trim().length>0&&w.modelID.trim().length>0,e[37]=w.modelID,e[38]=w.providerID,e[39]=M):M=e[39];const ee=M;let se;e[40]!==ee||e[41]!==w||e[42]!==d||e[43]!==u?(se=()=>{!ee||u||d(w)},e[40]=ee,e[41]=w,e[42]=d,e[43]=u,e[44]=se):se=e[44];const J=se;let K,Z;e[45]!==J||e[46]!==r?(K=()=>{if(!r)return;const je=Fe=>{(Fe.metaKey||Fe.ctrlKey)&&Fe.key==="Enter"&&(Fe.preventDefault(),J())};return window.addEventListener("keydown",je),()=>window.removeEventListener("keydown",je)},Z=[r,J],e[45]=J,e[46]=r,e[47]=K,e[48]=Z):(K=e[47],Z=e[48]),i.useEffect(K,Z);let re;e[49]!==n||e[50]!==a?(re=n(a==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=a,e[51]=re):re=e[51];const pe=re;let Se;e[52]!==o||e[53]!==u?(Se=je=>{u||o(je)},e[52]=o,e[53]=u,e[54]=Se):Se=e[54];let te;e[55]!==pe?(te=s.jsx(Us,{children:s.jsx($s,{children:pe})}),e[55]=pe,e[56]=te):te=e[56];let Ne;e[57]!==n?(Ne=n("chat.modelControls.model"),e[57]=n,e[58]=Ne):Ne=e[58];let Y;e[59]!==Ne?(Y=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:Ne}),e[59]=Ne,e[60]=Y):Y=e[60];let G;e[61]===Symbol.for("react.memo_cache_sentinel")?(G=(je,Fe)=>{S(Ae=>({...Ae,providerID:je,modelID:Fe,variant:""}))},e[61]=G):G=e[61];let q;e[62]!==w.modelID||e[63]!==w.providerID?(q=s.jsx(_f,{providerId:w.providerID,modelId:w.modelID,className:"max-w-[320px] justify-between",dropdownPortalToBody:!0,onChange:G}),e[62]=w.modelID,e[63]=w.providerID,e[64]=q):q=e[64];let oe;e[65]!==Y||e[66]!==q?(oe=s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[Y,q]}),e[65]=Y,e[66]=q,e[67]=oe):oe=e[67];let le;e[68]!==n?(le=n("sessions.scheduledTasks.editor.thinkingLevel.label"),e[68]=n,e[69]=le):le=e[69];let ve;e[70]!==le?(ve=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:le}),e[70]=le,e[71]=ve):ve=e[71];const Ee=!L;let _e;e[72]===Symbol.for("react.memo_cache_sentinel")?(_e=je=>S(Fe=>({...Fe,variant:je})),e[72]=_e):_e=e[72];let Oe;e[73]!==w.variant||e[74]!==Ee||e[75]!==R?(Oe=s.jsx(jp,{value:w.variant,options:R,disabled:Ee,onChange:_e}),e[73]=w.variant,e[74]=Ee,e[75]=R,e[76]=Oe):Oe=e[76];let Me;e[77]!==ve||e[78]!==Oe?(Me=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ve,Oe]}),e[77]=ve,e[78]=Oe,e[79]=Me):Me=e[79];let he;e[80]!==n?(he=n("sessions.scheduledTasks.editor.agent.label"),e[80]=n,e[81]=he):he=e[81];let Ce;e[82]!==he?(Ce=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:he}),e[82]=he,e[83]=Ce):Ce=e[83];let xe;e[84]===Symbol.for("react.memo_cache_sentinel")?(xe=je=>S(Fe=>({...Fe,agent:je})),e[84]=xe):xe=e[84];let ue;e[85]!==w.agent?(ue=s.jsx($f,{agentName:w.agent,filter:O,dropdownPortalToBody:!0,onChange:xe}),e[85]=w.agent,e[86]=ue):ue=e[86];let H;e[87]!==Ce||e[88]!==ue?(H=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[Ce,ue]}),e[87]=Ce,e[88]=ue,e[89]=H):H=e[89];let ce;e[90]!==oe||e[91]!==Me||e[92]!==H?(ce=s.jsxs("div",{className:"flex flex-col gap-4",children:[oe,Me,H]}),e[90]=oe,e[91]=Me,e[92]=H,e[93]=ce):ce=e[93];let fe;e[94]!==o?(fe=()=>o(!1),e[94]=o,e[95]=fe):fe=e[95];let U;e[96]!==n?(U=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[96]=n,e[97]=U):U=e[97];let z;e[98]!==u||e[99]!==fe||e[100]!==U?(z=s.jsx($e,{variant:"ghost",size:"sm",onClick:fe,disabled:u,children:U}),e[98]=u,e[99]=fe,e[100]=U,e[101]=z):z=e[101];const be=!ee||u;let ge;e[102]!==u||e[103]!==n?(ge=n(u?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[102]=u,e[103]=n,e[104]=ge):ge=e[104];let _;e[105]!==J||e[106]!==be||e[107]!==ge?(_=s.jsx($e,{size:"sm",onClick:J,disabled:be,children:ge}),e[105]=J,e[106]=be,e[107]=ge,e[108]=_):_=e[108];let ye;e[109]!==z||e[110]!==_?(ye=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[z,_]}),e[109]=z,e[110]=_,e[111]=ye):ye=e[111];let $;e[112]!==te||e[113]!==ce||e[114]!==ye?($=s.jsxs(Fs,{className:"max-w-md overflow-visible",children:[te,ce,ye]}),e[112]=te,e[113]=ce,e[114]=ye,e[115]=$):$=e[115];let Ie;return e[116]!==r||e[117]!==Se||e[118]!==$?(Ie=s.jsx(Ls,{open:r,onOpenChange:Se,children:$}),e[116]=r,e[117]=Se,e[118]=$,e[119]=Ie):Ie=e[119],Ie}function ty(t){return{...t,variant:""}}function sy(t){return zf(t.mode)}function ny(t){return t.currentAgentName||""}function ry(t){return t.currentVariant||""}function iy(t){return t.currentModelId}function oy(t){return t.currentProviderId}function ay(t){return t.providers}function ly(t){return t.loadAgents}function cy(t){return t.loadAgents}function dy(t){return t.loadProviders}const ql=5,vm=15,Go=new Map,la=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},uy=(t,e)=>{const n=la(e);return Math.max(n*ql,Math.min(n*vm,n*t))},fy=async(t,e)=>{const n=await Cp(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},my=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,eu=t=>[...t.filter(e=>!e.completed),...t.filter(e=>e.completed)],tu=(t,e)=>{const n=t.findIndex(r=>r.completed);return n===-1?[...t,e]:[...t.slice(0,n),e,...t.slice(n)]},hy=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:a,listeners:c,setNodeRef:l,setActivatorNodeRef:d,transform:u,transition:m,isDragging:f}=ic(o);let g;e[2]!==u?(g=oc.Transform.toString(u),e[2]=u,e[3]=g):g=e[3];let y;e[4]!==g||e[5]!==m?(y={transform:g,transition:m},e[4]=g,e[5]=m,e[6]=y):y=e[6];const p=f&&"opacity-60";let x;e[7]!==p?(x=De(p),e[7]=p,e[8]=x):x=e[8];let b;e[9]!==a||e[10]!==r||e[11]!==f||e[12]!==c||e[13]!==d?(b=r({attributes:a,listeners:c,setActivatorNodeRef:d,isDragging:f}),e[9]=a,e[10]=r,e[11]=f,e[12]=c,e[13]=d,e[14]=b):b=e[14];let h;return e[15]!==l||e[16]!==y||e[17]!==x||e[18]!==b?(h=s.jsx("li",{ref:l,style:y,className:x,children:b}),e[15]=l,e[16]=y,e[17]=x,e[18]=b,e[19]=h):h=e[19],h},py=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:o})=>{const{t:a}=At(),[c,l]=i.useState(!1),[d,u]=i.useState(""),[m,f]=i.useState([]),[g,y]=i.useState(""),[p,x]=i.useState(null),[b,h]=i.useState(()=>new Set),[N,w]=i.useState([]),[S,j]=i.useState(null),[k,v]=i.useState(!1),[D,A]=i.useState(0),C=i.useRef(!1),O=i.useRef(""),T=i.useRef(null),E=Re(P=>P.todoPanelHeight),F=Re(P=>P.setTodoPanelHeight),R=Re(P=>P.notesPanelHeight),L=Re(P=>P.setNotesPanelHeight),[B,V]=i.useState(!1),M=i.useRef(0),ee=i.useRef(E),se=dt(P=>P.currentSessionId),J=dt(P=>P.createSession),K=dt(P=>P.initializeNewOpenChamberSession),Z=dt(P=>P.sendMessage),re=dt(P=>P.setCurrentSession),pe=ai(P=>P.setPendingInputText),Se=qs(P=>P.currentDirectory),te=Re(P=>P.openContextPanelTab),Ne=Re(P=>P.setActiveMainTab),Y=Re(P=>P.setSessionSwitcherOpen),G=Re(P=>P.padding),q=i.useCallback(async(P,me)=>{if(!t)return!1;const ae=t.id,Ge=(Go.get(ae)??Promise.resolve()).catch(()=>{}).then(()=>Sp(t,{notes:P,todos:me}));Go.set(ae,Ge);try{const Ke=await Ge;return Ke||de.error(a("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),Ke}finally{Go.get(ae)===Ge&&Go.delete(ae)}},[t,a]);i.useEffect(()=>{if(!t){u(""),f([]),w([]),y(""),h(new Set);return}let P=!1;return l(!0),(async()=>{try{const me=await Np(t),ae=await Promise.all(me.plans.map(Be=>fy(Be,a("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(P)return;u(me.notes),f(eu(me.todos)),w(ae),O.current=me.notes,C.current=!0,y(""),h(new Set)}catch{P||(de.error(a("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),u(""),f([]),w([]),O.current="",C.current=!0)}finally{P||l(!1)}})(),()=>{P=!0}},[D,t,a]),i.useEffect(()=>{if(!t)return;const P=me=>{const ae=me.detail;ae?.projectId&&ae.projectId!==t.id||A(Be=>Be+1)};return window.addEventListener("openchamber:project-plan-saved",P),window.addEventListener("openchamber:project-notes-updated",P),()=>{window.removeEventListener("openchamber:project-plan-saved",P),window.removeEventListener("openchamber:project-notes-updated",P)}},[t]),i.useEffect(()=>{if(m.length<7)return;const P=uy(m.length,G),me=la(G)*ql;E!==P&&(E<me||E>P)&&F(P)},[m.length,G,E,F]),i.useEffect(()=>{if(!B)return;const P=ae=>{const Be=ae.clientY-M.current,Ge=Math.min(la(G)*vm,Math.max(la(G)*ql,ee.current+Be));F(Ge)},me=()=>{V(!1)};return window.addEventListener("pointermove",P),window.addEventListener("pointerup",me,{once:!0}),window.addEventListener("pointercancel",me,{once:!0}),()=>{window.removeEventListener("pointermove",P),window.removeEventListener("pointerup",me),window.removeEventListener("pointercancel",me)}},[B,G,F]);const oe=i.useCallback(P=>{V(!0),M.current=P.clientY,ee.current=E,P.preventDefault()},[E]),le=i.useCallback(()=>{T.current!==null&&(window.clearTimeout(T.current),T.current=null)},[]),ve=i.useCallback(()=>{le(),O.current=d,q(d,m)},[le,d,q,m]);i.useEffect(()=>{if(!(!t||!C.current)&&d!==O.current)return T.current=window.setTimeout(()=>{T.current=null,O.current=d,q(d,m)},400),()=>{le()}},[le,d,q,t,m]),i.useEffect(()=>()=>le(),[le]);const Ee=i.useCallback(()=>{const P=g.trim();if(!P)return;const me=tu(m,{id:my(),text:P.slice(0,zo),completed:!1,createdAt:Date.now()});f(me),y(""),q(d,me)},[g,d,q,m]),_e=i.useCallback(P=>{h(me=>{const ae=new Set(me);return ae.has(P)?ae.delete(P):ae.add(P),ae})},[]),Oe=i.useCallback((P,me)=>{const ae=m.find(Qe=>Qe.id===P);if(!ae||ae.completed===me)return;const Be=m.filter(Qe=>Qe.id!==P),Ge={...ae,completed:me},Ke=me?[...Be,Ge]:tu(Be,Ge);f(Ke),q(d,Ke)},[d,q,m]),Me=i.useCallback(P=>{const me=m.filter(ae=>ae.id!==P);f(me),q(d,me)},[d,q,m]),he=i.useCallback(()=>{const P=m.filter(me=>!me.completed);P.length!==m.length&&(f(P),q(d,P))},[d,q,m]),Ce=i.useCallback(P=>{const{active:me,over:ae}=P;if(!ae||me.id===ae.id)return;const Be=m.findIndex(Qe=>Qe.id===me.id),Ge=m.findIndex(Qe=>Qe.id===ae.id);if(Be===-1||Ge===-1)return;const Ke=eu(Nf(m,Be,Ge));f(Ke),q(d,Ke)},[d,q,m]),xe=ga(yo(xa,{activationConstraint:{distance:8}})),ue=g.slice(0,zo),H=m.reduce((P,me)=>P+(me.completed?1:0),0),ce=i.useCallback(()=>{Ne("chat"),Y(!1)},[Ne,Y]),fe=i.useCallback((P,me)=>{!t||p||j({kind:"session",todoId:P,todoText:me})},[t,p]),U=i.useCallback(P=>{if(!se){de.error(a("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}ce();const me=`\`\`\`md
|
|
4
|
+
${P}
|
|
5
|
+
\`\`\``;pe(me,"append"),de.success(a("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[se,r,ce,pe,a]),z=i.useCallback((P,me)=>{if(!(!t||p)){if(!n){de.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}j({kind:"worktree",todoId:P,todoText:me})}},[n,t,p,a]),be=i.useCallback(async P=>{if(!t||!S)return;const me=await Rn("plan.todo.visible",{todo_text:S.todoText}),Be=[{synthetic:!0,text:await Rn("plan.todo.instructions",{todo_text:S.todoText})}];v(!0),x(S.todoId);try{ce();let Ge=null,Ke=t.path;if(S.kind==="worktree"){if(!n){de.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const st=await Uf(t.path,Wf());if(!st?.id)return;Ge=st.id,Ke=st.path}else{const st=await J(void 0,t.path,null);if(!st?.id){de.error(a("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Ge=st.id,Ke=st.directory??t.path,K(st.id,es.getState().agents??[])}if(!Ge)return;const Qe=pc.getState();Qe.saveSessionModelSelection(Ge,P.providerID,P.modelID),P.agent.trim()&&(Qe.saveSessionAgentSelection(Ge,P.agent),Qe.saveAgentModelForSession(Ge,P.agent,P.providerID,P.modelID),Qe.saveAgentModelVariantForSession(Ge,P.agent,P.providerID,P.modelID,P.variant||void 0)),re(Ge,Ke),await Z(me,P.providerID,P.modelID,P.agent.trim()||void 0,void 0,void 0,Be,P.variant||void 0),de.success(S.kind==="worktree"?a("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):a("rightSidebar.contextNotesTodo.toast.sentToNewSession")),j(null),r?.()}catch(Ge){const Ke=Ge instanceof Error?Ge.message:void 0;de.error(a("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Ke?{description:Ke}:void 0)}finally{v(!1),x(null)}},[n,J,K,r,S,t,ce,Z,re,a]),ge=i.useRef(null),[_,ye]=i.useState(!1),[$,Ie]=i.useState(null),je=i.useCallback(async P=>{if(!(!t||$)){Ie(P);try{if(!await kp(t,P)){de.error(a("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}w(ae=>ae.filter(Be=>Be.id!==P)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Ie(null)}}},[$,t,a]),Fe=i.useCallback(async()=>{if(!t||_)return;const P=await ep({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(P.success&&P.path){ye(!0);try{const me=new URLSearchParams({path:P.path,allowOutsideWorkspace:"true"});P.outsideFileGrant&&me.set("outsideFileGrant",P.outsideFileGrant);const ae=await Cs(`/api/fs/read?${me.toString()}`,{cache:"no-store"});if(!ae.ok){de.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Be=await ae.text();if(!Be.trim()){de.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Ge=P.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await bd(t,Be,Ge)){de.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),de.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(me){const ae=me instanceof Error?me.message:void 0;de.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),ae?{description:ae}:void 0)}finally{ye(!1)}}else P.error==="Native file picker not available"&&ge.current?.click()},[_,t,a]),Ae=i.useCallback(async P=>{if(!(!t||!P)){ye(!0);try{const me=await P.text();if(!me.trim()){de.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const ae=P.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await bd(t,me,ae)){de.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),de.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(me){const ae=me instanceof Error?me.message:void 0;de.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),ae?{description:ae}:void 0)}finally{ye(!1)}}},[t,a]),ne=i.useCallback(P=>{const me=t?.path?.trim(),ae=Se?.trim()||me;ae&&te(ae,{mode:"plan",targetPath:P.path,dedupeKey:P.path,label:P.title})},[Se,te,t]);return t?s.jsxs("div",{className:De("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:a("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:[d.length,"/",yd]})]}),s.jsx(Ci,{value:d,onChange:P=>u(P.target.value.slice(0,yd)),onBlur:ve,placeholder:a("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:R,onResizeHeightChange:L,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:a("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?a("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):a("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:he,disabled:c||H===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:a("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[ue.length,"/",zo]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(bn,{value:ue,onChange:P=>y(P.target.value.slice(0,zo)),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),Ee())},placeholder:a("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:c,className:"h-8"}),s.jsx("button",{type:"button",onClick:Ee,disabled:c||ue.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":a("rightSidebar.contextNotesTodo.todo.addAria"),title:a("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:De("overflow-y-auto rounded-lg border border-border/60 bg-background/40",B&&"transition-none"),style:m.length<7?void 0:{height:`${E}px`,maxHeight:`${E}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(ba,{sensors:xe,collisionDetection:ya,onDragEnd:Ce,children:s.jsx(Fl,{items:m.map(P=>P.id),strategy:Ll,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(P=>{const me=b.has(P.id);return s.jsx(hy,{id:P.id,children:ae=>s.jsxs("div",{className:De("flex gap-1.5 px-2.5 py-1.5",me?"items-start":"items-center"),children:[s.jsx("button",{type:"button",ref:ae.setActivatorNodeRef,...ae.attributes,...ae.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":a("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:P.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:P.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(Ri,{checked:P.completed,onChange:Be=>Oe(P.id,Be),ariaLabel:a("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:P.text})})}),s.jsx("button",{type:"button",onClick:()=>_e(P.id),className:De("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-normal text-foreground",me?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",P.completed&&"text-muted-foreground line-through"),title:me?void 0:P.text,"aria-label":me?a("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:P.text}):a("rightSidebar.contextNotesTodo.todo.actions.expand",{text:P.text}),children:P.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>Me(P.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":a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:P.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:P.text}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(sn,{children:[s.jsx(en,{asChild:!0,children:s.jsx("button",{type:"button",disabled:p===P.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":a("rightSidebar.contextNotesTodo.todo.actions.send",{text:P.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.send",{text:P.text}),children:s.jsx(I,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(tn,{align:"end",className:"w-56",children:[s.jsx(xs,{onClick:()=>U(P.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(xs,{onClick:()=>fe(P.id,P.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(xs,{onClick:()=>{z(P.id,P.text)},disabled:!n,children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},P.id)})})})})}),m.length>=7&&s.jsx("div",{className:De("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",B&&"bg-[var(--interactive-border)]"),onPointerDown:oe,role:"separator","aria-orientation":"horizontal","aria-label":a("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:a("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:N.length===1?a("rightSidebar.contextNotesTodo.plans.filesSingle",{count:N.length}):a("rightSidebar.contextNotesTodo.plans.filesPlural",{count:N.length})})]}),s.jsx("input",{ref:ge,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:P=>{const me=P.target.files?.[0]??null;Ae(me),P.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Fe,disabled:!t||_,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":a("rightSidebar.contextNotesTodo.plans.importFromFile"),title:a("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:a("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:N.map(P=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>ne(P),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:P.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(P.createdAt).toLocaleDateString(Zi())})]}),s.jsx("button",{type:"button",onClick:()=>{je(P.id)},disabled:$===P.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:a("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":a("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:P.title}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},P.id))})})]}),s.jsx(wm,{open:S!==null,onOpenChange:P=>{!P&&!k&&j(null)},target:S?.kind??"session",projectDirectory:t?.path??null,submitting:k,onConfirm:be})]}):s.jsx("div",{className:De("w-full min-w-0 p-3",o),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.empty.selectProject")})})},jm=12,gy=[{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"}],xy=t=>{const e=gt.c(18),{isActive:n,burstKey:r,className:o,durationMs:a,bursts:c,onComplete:l}=t,d=r===void 0?0:r,u=a===void 0?900:a,m=c===void 0?gy:c,f=Ze.useRef(!1);let g,y;e[0]!==n||e[1]!==l?(g=()=>{!n&&f.current&&l?.(),n&&(f.current=!0)},y=[n,l],e[0]=n,e[1]=l,e[2]=g,e[3]=y):(g=e[2],y=e[3]),Ze.useEffect(g,y);let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=Array.from({length:jm},by),e[4]=p):p=e[4];const x=p;if(!n)return null;let b;e[5]!==o?(b=De("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=b):b=e[6];let h;if(e[7]!==d||e[8]!==m||e[9]!==u){let w;e[11]!==d||e[12]!==u?(w=S=>{const j={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${u}ms`};return s.jsx("div",{className:"firework-burst",style:j,children:x.map((k,v)=>{const D=k.x*S.radius,A=k.y*S.radius,C={"--translate-x":`${D}px`,"--translate-y":`${A}px`,"--particle-delay":`${k.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:C},`${S.id}-${v}-${d}`)})},`${S.id}-${d}`)},e[11]=d,e[12]=u,e[13]=w):w=e[13],h=m.map(w),e[7]=d,e[8]=m,e[9]=u,e[10]=h}else h=e[10];let N;return e[14]!==d||e[15]!==b||e[16]!==h?(N=s.jsx("div",{className:b,"aria-hidden":"true","data-burst-key":d,children:h}),e[14]=d,e[15]=b,e[16]=h,e[17]=N):N=e[17],N};function by(t,e){const n=Math.PI*2*e/jm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const yy=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 a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={isActive:!1,cycle:0},e[2]=a):a=e[2];const[c,l]=Ze.useState(a),d=Ze.useRef(null);let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=u):u=e[3];const m=u;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{m(),l(wy)},e[4]=f):f=e[4];const g=f;let y;e[5]!==o?(y=()=>{m(),l(vy),d.current=window.setTimeout(()=>{l(jy),d.current=null},o)},e[5]=o,e[6]=y):y=e[6];const p=y;let x,b;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=()=>()=>m(),b=[m],e[7]=x,e[8]=b):(x=e[7],b=e[8]),Ze.useEffect(x,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 wy(t){return t.isActive?{...t,isActive:!1}:t}function vy(t){return{isActive:!0,cycle:t.cycle+1}}function jy(t){return t.isActive?{...t,isActive:!1}:t}const Sm=i.createContext(void 0),Sy=t=>{const e=gt.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:a,dismissFireworks:c}=yy();let l;e[0]!==c||e[1]!==a?(l={triggerFireworks:a,dismissFireworks:c},e[0]=c,e[1]=a,e[2]=l):l=e[2];const d=l;let u;e[3]!==o||e[4]!==r?(u=s.jsx(xy,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=u):u=e[5];let m;return e[6]!==n||e[7]!==u||e[8]!==d?(m=s.jsxs(Sm.Provider,{value:d,children:[n,u]}),e[6]=n,e[7]=u,e[8]=d,e[9]=m):m=e[9],m},Ny=()=>{const t=i.useContext(Sm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Nm="gitmojiCache",ky=1e3*60*60*24*7,km="1",Cy="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Cm=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},ml=()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem(Nm);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==km||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Cm),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Ay=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:km};window.localStorage.setItem(Nm,JSON.stringify(e))}catch{return}},su=t=>Date.now()-t.fetchedAt<ky;let Ko=null;const So=new Set,nu=async()=>{if(Ko)return Ko;const t=(async()=>{try{const e=await fetch(Cy);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(Cm):[];return Ay(r),So.forEach(o=>o(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return So.forEach(r=>r(n)),n}finally{Ko=null}})();return Ko=t,t},Dy=t=>{const[e,n]=i.useState(()=>t?ml()?.gitmojis??[]:[]),[r,o]=i.useState(!1),a=i.useRef(t);a.current=t,i.useEffect(()=>{if(!t){So.delete(n),n([]),o(!1);return}const l=ml();if(l&&(n(l.gitmojis),su(l)))return;So.add(n),o(!0);let d=!1;return nu().finally(()=>{!d&&a.current&&o(!1)}),()=>{d=!0,So.delete(n)}},[t]);const c=i.useCallback(async()=>{if(!a.current)return[];if(e.length>0)return e;const l=ml();return l&&su(l)?l.gitmojis:nu()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:c}},ru=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function Iy(t,e,n){const r=gt.c(5),[o,a]=i.useState();let c,l;return r[0]!==n||r[1]!==t||r[2]!==e?(c=()=>{if(e){a(void 0);return}if(!t){a(void 0);return}a(void 0);let d=!1;return(async()=>{const[u,m]=await Promise.all([Ap(t),Dp(t)]).catch(Py);if(d)return;const f=ru(u),g=ru(m);if(!f||!g||g===f)return;const y=n||"",p=g.split("/").filter(Boolean).pop()||g;a({source:"sdk",path:g,projectDirectory:f,branch:y,label:y||p,name:p,worktreeRoot:g,worktreeStatus:"ready",headState:y?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!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]),i.useEffect(c,l),e??o}function Py(){return["",""]}const lo=async(t,e)=>{const n=await Cs(`/api/git/integrate/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function ho(t){return lo("plan",t)}async function Ty(t){return lo("conflict-details",{tempWorktreePath:t})}async function Ry(t){return(await lo("cherry-pick-status",{tempWorktreePath:t})).inProgress}async function Ey(t){return lo("run",{plan:t})}async function My(t){await lo("abort",{state:t})}async function Fy(t){return lo("continue",{state:t})}const Ly=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:o,refreshKey:a,onRefresh:c})=>{const{t:l}=At(),d=dt(M=>M.currentSessionId),u=Re(M=>M.setActiveMainTab),[m,f]=Ze.useState(!1),g=Ze.useRef(null),[y,p]=Ze.useState(o);Ze.useEffect(()=>{p(o)},[o]),Ze.useEffect(()=>{if(m){const M=setTimeout(()=>{g.current?.focus()},0);return()=>clearTimeout(M)}},[m]);const x=!!(t&&e&&y&&y!=="HEAD"&&e!==y),[b,h]=Ze.useState({kind:"idle"}),[N,w]=Ze.useState(!1),[S,j]=Ze.useState([]),k=Ze.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);Ze.useEffect(()=>{if(!k||typeof window>"u")return;const M=window.localStorage.getItem(k);if(!M)return;let ee=!1;try{const se=JSON.parse(M);if(!se?.tempWorktreePath||se.repoRoot!==t){window.localStorage.removeItem(k);return}(async()=>{const J=await Ry(se.tempWorktreePath).catch(()=>!1);if(ee)return;if(!J){window.localStorage.removeItem(k);return}const K=await Ty(se.tempWorktreePath).catch(()=>null);ee||K&&h({kind:"conflict",state:se,details:K})})()}catch{window.localStorage.removeItem(k)}return()=>{ee=!0}},[k,t]),Ze.useEffect(()=>{if(!x){h({kind:"idle"});return}let M=!1;return h({kind:"loading"}),(async()=>{try{const ee=await ho({repoRoot:t,sourceBranch:e,targetBranch:y});if(M)return;if(h({kind:"ready",plan:ee}),ee.commits.length>0){const J=ee.commits.slice(-50).reverse(),K=await Ip(t,J);M||(j(K),w(!1))}else M||(j([]),w(!1))}catch{M||h({kind:"idle"})}})(),()=>{M=!0}},[x,t,e,y,a]);const v=Ze.useCallback(M=>{d&&dt.getState().setWorktreeMetadata(d,{...n,createdFromBranch:M})},[d,n]),D=dt(M=>M.openNewSessionDraft),A=Ze.useCallback(async M=>{const ee=await Rn("git.integrate.cherrypick.resolve.visible",{current_commit:M.state.currentCommit,target_branch:M.state.targetBranch}),se=await Rn("git.integrate.cherrypick.resolve.instructions",{repo_root:M.state.repoRoot,temp_worktree_path:M.state.tempWorktreePath,source_branch:M.state.sourceBranch,target_branch:M.state.targetBranch,current_commit:M.state.currentCommit}),J=`Cherry-pick conflict context (JSON)
|
|
6
|
+
${JSON.stringify({repoRoot:M.state.repoRoot,tempWorktreePath:M.state.tempWorktreePath,sourceBranch:M.state.sourceBranch,targetBranch:M.state.targetBranch,currentCommit:M.state.currentCommit,remainingCommits:M.state.remainingCommits,statusPorcelain:M.details.statusPorcelain,unmergedFiles:M.details.unmergedFiles,currentPatchMeta:M.details.currentPatchMeta,currentPatch:M.details.currentPatch,diff:M.details.diff},null,2)}`;return{visibleText:ee,instructionsText:se,payloadText:J}},[]),C=ai(M=>M.setPendingInputText),O=ai(M=>M.setPendingSyntheticParts),T=Ze.useCallback(async(M,ee)=>{const se=await A(M);if(ee){D({directoryOverride:M.state.tempWorktreePath,initialPrompt:se.visibleText,syntheticParts:[{text:se.instructionsText,synthetic:!0},{text:se.payloadText,synthetic:!0}]}),u("chat");return}if(!d){de.error(l("gitView.integrate.noActiveSession"),{description:l("gitView.integrate.noActiveSessionDescription")});return}C(se.visibleText,"replace"),O([{text:se.instructionsText,synthetic:!0},{text:se.payloadText,synthetic:!0}]),u("chat")},[d,u,A,D,C,O,l]),E=Ze.useCallback(async()=>{if(b.kind==="ready"){if(b.plan.commits.length===0){de.message(l("gitView.integrate.noCommitsToMoveToast"));return}h({kind:"running",plan:b.plan});try{const M=await Ey(b.plan);if(M.kind==="success"){de.success(l("gitView.integrate.commitsMovedToast"),{description:M.moved===1?l("gitView.integrate.commitsMovedDescriptionSingle",{count:M.moved,branch:b.plan.targetBranch}):l("gitView.integrate.commitsMovedDescriptionPlural",{count:M.moved,branch:b.plan.targetBranch})});const ee=await ho(b.plan);h({kind:"ready",plan:ee}),c?.();return}M.kind==="conflict"&&(de.error(l("gitView.integrate.cherryPickConflictToast"),{description:l("gitView.integrate.cherryPickConflictDescription")}),h({kind:"conflict",state:M.state,details:M.details}),k&&typeof window<"u"&&window.localStorage.setItem(k,JSON.stringify(M.state)))}catch(M){const ee=M instanceof Error?M.message:String(M);de.error(l("gitView.integrate.failedToMoveToast"),{description:ee});const se=await ho({repoRoot:t,sourceBranch:e,targetBranch:y}).catch(()=>null);h(se?{kind:"ready",plan:se}:{kind:"idle"})}}},[b,c,t,e,y,k,l]),F=Ze.useCallback(async()=>{if(b.kind==="conflict")try{await My(b.state),de.message(l("gitView.integrate.cherryPickAbortedToast")),k&&typeof window<"u"&&window.localStorage.removeItem(k)}finally{const M=await ho({repoRoot:t,sourceBranch:e,targetBranch:y}).catch(()=>null);h(M?{kind:"ready",plan:M}:{kind:"idle"})}},[b,t,e,y,k,l]),R=Ze.useCallback(async()=>{if(b.kind==="conflict")try{const M=await Fy(b.state);if(M.kind==="success"){de.success(l("gitView.integrate.cherryPickFinishedToast"));const ee=await ho({repoRoot:t,sourceBranch:e,targetBranch:y}).catch(()=>null);h(ee?{kind:"ready",plan:ee}:{kind:"idle"}),k&&typeof window<"u"&&window.localStorage.removeItem(k),c?.();return}M.kind==="conflict"&&(h({kind:"conflict",state:M.state,details:M.details}),k&&typeof window<"u"&&window.localStorage.setItem(k,JSON.stringify(M.state)))}catch(M){const ee=M instanceof Error?M.message:String(M);de.error(l("gitView.integrate.cherryPickContinueFailedToast"),{description:ee})}},[b,t,e,y,c,k,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," → ",y]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(sn,{open:m,onOpenChange:f,children:[s.jsx(en,{asChild:!0,children:s.jsxs($e,{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:y}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(tn,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(Oa,{className:"h-full min-h-0",children:[s.jsx(Ba,{ref:g,placeholder:l("gitView.branch.searchPlaceholder"),onKeyDown:M=>M.stopPropagation()}),s.jsxs(Va,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(_a,{children:l("gitView.branch.empty")}),s.jsx(ri,{heading:l("gitView.branch.localBranches"),children:r.map(M=>s.jsx(oi,{value:M,onSelect:()=>{p(M),v(M),f(!1)},children:M},M))})]})]})})]}),b.kind==="ready"?s.jsx($e,{size:"sm",onClick:()=>{E()},disabled:!x||b.plan.commits.length===0,children:l("gitView.integrate.move")}):b.kind==="loading"?s.jsx($e,{size:"sm",variant:"outline",disabled:!0,children:l("gitView.integrate.checking")}):b.kind==="running"?s.jsx($e,{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(M=>!M),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(M=>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:M.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:M.subject||M.sha})]},M.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(M=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:M},M)),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($e,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{F()},children:l("gitView.operation.abort")}),s.jsxs($e,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{T({state:b.state,details:b.details},!1)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),l("gitView.integrate.currentSession")]}),s.jsxs($e,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{T({state:b.state,details:b.details},!0)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),l("gitView.integrate.newSession")]}),s.jsx($e,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:l("gitView.operation.continue")})]})]})]})]})},Oy=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:o=!1,uncommittedFileCount:a,onChanged:c})=>{const{t:l}=At(),[d,u]=i.useState([]),[m,f]=i.useState(!1),[g,y]=i.useState(""),[p,x]=i.useState(""),[b,h]=i.useState(null),[N,w]=i.useState({}),S=i.useCallback(async()=>{if(n){f(!0);try{const C=await Pp(n);u(C.stashes),w({})}catch(C){de.error(C instanceof Error?C.message:l("gitView.stashes.toast.loadFailed"))}finally{f(!1)}}},[n,l]);i.useEffect(()=>{t&&S()},[S,t]),i.useEffect(()=>{if(!t||!n||d.length===0)return;let C=!1;const O=d.map(T=>T.ref);return Tp(n,O).then(T=>{C||w(T.counts)}).catch(()=>{}),()=>{C=!0}},[n,t,d]);const j=i.useMemo(()=>{const C=g.trim().toLowerCase();return C?d.filter(O=>`${O.ref} ${O.message} ${O.relativeTime}`.toLowerCase().includes(C)):d},[g,d]),k=i.useCallback(async C=>{await S(),await c?.(C)},[S,c]),v=async()=>{if(!(!n||b)){h("create");try{const C=await Rp(n,{message:p.trim()||void 0});C.created?(de.success(l("gitView.stashes.toast.created")),x("")):de.info(l("gitView.stashes.toast.noChanges")),await k({affectsIndex:!!(C.created&&o)})}catch(C){de.error(C instanceof Error?C.message:l("gitView.stashes.toast.createFailed"))}finally{h(null)}}},D=async(C,O)=>{if(!(!n||b)&&!(O==="drop"&&!window.confirm(l("gitView.stashes.confirm.drop",{ref:C.ref})))){h(`${O}:${C.ref}`);try{O==="apply"&&await Ep(n,{ref:C.ref}),O==="pop"&&await Mp(n,{ref:C.ref}),O==="drop"&&await Fp(n,{ref:C.ref});const T=O==="apply"?"gitView.stashes.toast.applySuccess":O==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";de.success(l(T)),await k({affectsIndex:O!=="drop"})}catch(T){const E=O==="apply"?"gitView.stashes.toast.applyFailed":O==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";de.error(T instanceof Error?T.message:l(E)),await k({affectsIndex:O!=="drop"})}finally{h(null)}}},A=b!==null;return s.jsx(Ls,{open:t,onOpenChange:e,children:s.jsxs(Fs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(Us,{children:[s.jsxs($s,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"archive-stack",className:"h-5 w-5"}),l("gitView.stashes.title")]}),s.jsx(an,{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(bn,{value:p,onChange:C=>x(C.target.value),placeholder:l("gitView.stashes.messagePlaceholder"),disabled:A||!r,className:"flex-1"}),s.jsxs($e,{onClick:v,disabled:!r||A||!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:a})]})]}),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(bn,{value:g,onChange:C=>y(C.target.value),placeholder:l("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:m?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"})}):j.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:l(g?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):j.map((C,O)=>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(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{children:O===0&&!g.trim()?l("gitView.stashes.latestLabel"):l("gitView.stashes.itemNumber",{number:O+1})})}),s.jsx(Lt,{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(hl,{label:l("gitView.stashes.actions.apply"),loading:b===`apply:${C.ref}`,onClick:()=>D(C,"apply"),disabled:A,children:s.jsx(I,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(hl,{label:l("gitView.stashes.actions.pop"),loading:b===`pop:${C.ref}`,onClick:()=>D(C,"pop"),disabled:A,children:s.jsx(I,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(hl,{label:l("gitView.stashes.actions.drop"),loading:b===`drop:${C.ref}`,onClick:()=>D(C,"drop"),disabled:A,destructive:!0,children:s.jsx(I,{name:"delete-bin",className:"size-4"})})]})]},C.ref))})]})})},hl=t=>{const e=gt.c(17),{label:n,loading:r,disabled:o,destructive:a,onClick:c,children:l}=t,d=r||void 0,u=a?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==u?(m=De("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",u),e[0]=u,e[1]=m):m=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]!==d||e[9]!==m||e[10]!==f?(g=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:c,disabled:o,children:f})}),e[5]=o,e[6]=n,e[7]=c,e[8]=d,e[9]=m,e[10]=f,e[11]=g):g=e[11];let y;e[12]!==n?(y=s.jsx(Lt,{sideOffset:6,children:n}),e[12]=n,e[13]=y):y=e[13];let p;return e[14]!==g||e[15]!==y?(p=s.jsxs(Mt,{children:[g,y]}),e[14]=g,e[15]=y,e[16]=p):p=e[16],p},By=t=>{const e=gt.c(16),{onOpenStashes:n}=t,{t:r}=At();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 a;e[1]!==r?(a=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=a):a=e[2];let c;e[3]!==a?(c=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:a}),e[3]=a,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 d;e[7]!==l?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:l}),e[7]=l,e[8]=d):d=e[8];let u;e[9]!==n||e[10]!==r?(u=n?s.jsxs($e,{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]=u):u=e[11];let m;return e[12]!==c||e[13]!==d||e[14]!==u?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[o,c,d,u]}),e[12]=c,e[13]=d,e[14]=u,e[15]=m):m=e[15],m},Zr=8,Vy=t=>{const e=gt.c(18),{laned:n,totalLanes:r,isExpanded:o}=t,{lane:a,color:c,connectors:l}=n,u=Math.max(r,a+1)*Zr+Zr/2,m=i.useRef(null),f=i.useRef(null);let g;e[0]!==c||e[1]!==l||e[2]!==a||e[3]!==u?(g=()=>{const h=m.current,N=f.current;if(!h||!N)return;const w=h.offsetHeight;if(w===0)return;const S=window.devicePixelRatio||1;N.width=u*S,N.height=w*S;const j=N.getContext("2d");if(!j)return;j.scale(S,S),j.clearRect(0,0,u,w);const k=w/2,v=a*Zr+Zr/2,D=getComputedStyle(N),A=D.getPropertyValue("--surface-muted-foreground").trim()||D.color,C=E=>{if(!E.startsWith("var("))return E;const F=E.slice(4,-1).trim();return D.getPropertyValue(F).trim()||A},O=[...l].sort($y);for(const E of O){const F=E.fromLane*Zr+Zr/2,R=E.toLane*Zr+Zr/2,L=E.type==="passing"?.72:E.type==="branch-out"||E.type==="merge-in"?.95:1;j.beginPath(),j.strokeStyle=C(E.color),j.globalAlpha=L,j.lineWidth=1.25,j.lineCap="round";e:switch(E.type){case"passing":case"commit-lane":{j.moveTo(F,0),j.lineTo(F,w);break e}case"top-stub":{j.moveTo(F,0),j.lineTo(F,k);break e}case"bottom-stub":{j.moveTo(F,k),j.lineTo(F,w);break e}case"branch-out":{const B=(k+w)/2;j.moveTo(v,k),j.bezierCurveTo(v,B,R,B,R,w);break e}case"merge-in":{const B=k/2;j.moveTo(F,0),j.bezierCurveTo(F,B,v,B,v,k);break e}default:continue}j.stroke(),j.globalAlpha=1}const T=D.getPropertyValue("--background").trim()||D.getPropertyValue("--surface-background").trim();j.beginPath(),j.arc(v,k,4,0,Math.PI*2),j.fillStyle=C(c),j.fill(),j.beginPath(),j.arc(v,k,5,0,Math.PI*2),j.strokeStyle=T||A,j.lineWidth=2,j.stroke()},e[0]=c,e[1]=l,e[2]=a,e[3]=u,e[4]=g):g=e[4];let y;e[5]!==c||e[6]!==l||e[7]!==o||e[8]!==a||e[9]!==n||e[10]!==r||e[11]!==u?(y=[n,a,c,l,r,o,u],e[5]=c,e[6]=l,e[7]=o,e[8]=a,e[9]=n,e[10]=r,e[11]=u,e[12]=y):y=e[12],i.useLayoutEffect(g,y);let p;e[13]!==u?(p={width:u,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=u,e[14]=p):p=e[14];let x;e[15]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx("canvas",{ref:f,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=x):x=e[15];let b;return e[16]!==p?(b=s.jsx("div",{ref:m,style:p,children:x}),e[16]=p,e[17]=b):b=e[17],b};function _y(t){return t==="branch-out"||t==="merge-in"}function $y(t,e){const n=_y;return(n(t.type)?1:0)-(n(e.type)?1:0)}const iu=15e3,ou=500,au=12,lu=8*1024*1024,cu=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),du=t=>{if(t.size<=au){let o=0;for(const a of t.values())o+=cu(a);if(o<=lu)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[o,a]of e){if(n.size>=au)continue;const c=cu(a);r+c>lu&&n.size>0||(n.set(o,a),r+=c)}return new Map(Array.from(n.entries()).reverse())};function uu(t,e){const n=new Date(t);return Number.isNaN(n.getTime())?t:gc(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function zy(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 Uy(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 Wy=i.memo(({entry:t,mode:e="history",laned:n,totalLanes:r,isExpanded:o,onToggle:a,files:c,isLoadingFiles:l,onCopyHash:d,directory:u,onConflict:m,onActionSuccess:f})=>{const{t:g}=At(),y=Re(K=>K.timeFormatPreference),p=e==="graph",[x,b]=i.useState(null),[h,N]=i.useState(!1),[w,S]=i.useState(""),[j,k]=i.useState(null),[v,D]=i.useState(new Set),[A,C]=i.useState(new Map),[O,T]=i.useState(new Set),E=async()=>{if(u){b("checkout");try{await Up(u,t.hash),de.success(g("gitView.history.actions.detachedHead")),f?.()}catch(K){de.error(String(K.message))}finally{b(null)}}},F=async()=>{if(!(!u||!w.trim())){b("createBranch");try{await Op(u,w.trim(),t.hash),N(!1),S(""),f?.()}catch(K){de.error(String(K.message))}finally{b(null)}}},R=async()=>{if(u){b("cherryPick");try{const K=await zp(u,t.hash);K.conflict?m?.({conflict:!0,conflictFiles:K.conflictFiles,operation:"cherry-pick"}):f?.()}catch(K){de.error(String(K.message))}finally{b(null)}}},L=async()=>{if(u){b("revert");try{const K=await $p(u,t.hash);K.conflict?m?.({conflict:!0,conflictFiles:K.conflictFiles,operation:"revert"}):f?.()}catch(K){de.error(String(K.message))}finally{b(null)}}},B=async(K,Z=!1)=>{if(!(!u||x!==null)){b("reset");try{await Bp(u,t.hash,K,Z),f?.()}catch(re){de.error(String(re.message))}finally{b(null)}}},V=async()=>{if(!j)return;const K=j;switch(k(null),K){case"checkout":return E();case"cherryPick":return R();case"revert":return L();case"merge":return M();case"rebase":return ee();case"resetSoft":return B("soft");case"resetMixed":return B("mixed");case"resetHard":return B("hard",!0)}},M=async()=>{if(u){b("merge");try{const K=await _p(u,{branch:t.hash});K.conflict?m?.({conflict:!0,conflictFiles:K.conflictFiles,operation:"merge"}):f?.()}catch(K){de.error(String(K.message))}finally{b(null)}}},ee=async()=>{if(u){b("rebase");try{const K=await Vp(u,{onto:t.hash});K.conflict?m?.({conflict:!0,conflictFiles:K.conflictFiles,operation:"rebase"}):f?.()}catch(K){de.error(String(K.message))}finally{b(null)}}},se=i.useCallback(async K=>{const Z=K.path;if(!u){C(re=>new Map(re).set(Z,"error"));return}C(re=>du(new Map(re).set(Z,"loading")));try{const re=Lp(u,t.hash,K.path,!1),pe=new Promise((te,Ne)=>{setTimeout(()=>Ne(new Error(`Timed out after ${iu}ms`)),iu)}),Se=await Promise.race([re,pe]);C(te=>du(new Map(te).set(Z,Se)))}catch{C(re=>new Map(re).set(Z,"error"))}},[u,t.hash]),J=i.useCallback(async K=>{const Z=K.path;if(K.changeType==="R"||K.isBinary){D(te=>{const Ne=new Set(te);return Ne.has(Z)?Ne.delete(Z):Ne.add(Z),Ne});return}const re=A.get(Z);if(v.has(Z)&&re&&re!=="error"){D(te=>{const Ne=new Set(te);return Ne.delete(Z),Ne});return}D(te=>{const Ne=new Set(te);return Ne.add(Z),Ne}),!(re&&re!=="error"||K.insertions+K.deletions>ou&&!O.has(Z))&&await se(K)},[A,O,se,v]);return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:a,className:De("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(Vy,{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 K=Uy(t.refs);return K.length>0?s.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:K.map(Z=>s.jsx("span",{className:De("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",Z.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":Z.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:Z.label},Z.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:uu(t.date,y),children:uu(t.date,y)})]}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("code",{className:"shrink-0 font-mono",children:t.hash.slice(0,8)}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:K=>{K.stopPropagation(),d(t.hash)},children:s.jsx(I,{name:"file-copy",className:"size-3"})})}),s.jsx(Lt,{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&&j?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.${j}Confirm`)}),s.jsxs($e,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:x!==null,onClick:K=>{K.stopPropagation(),V()},children:[x!==null?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.confirmButton")]}),s.jsx($e,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:x!==null,onClick:K=>{K.stopPropagation(),k(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($e,{variant:"outline",size:"xs",className:"h-6",disabled:x!==null,onClick:K=>{K.stopPropagation(),k("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:K=>S(K.target.value),onKeyDown:K=>{K.key==="Enter"&&F(),K.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($e,{variant:"outline",size:"xs",className:"h-6",disabled:!w.trim()||x!==null,onClick:K=>{K.stopPropagation(),F()},children:[x==="createBranch"?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.createBranchConfirm")]})]}):s.jsx($e,{variant:"outline",size:"xs",className:"h-6",onClick:K=>{K.stopPropagation(),N(!0)},children:g("gitView.history.actions.createBranch")}),s.jsx($e,{variant:"outline",size:"xs",className:"h-6",disabled:x!==null,onClick:K=>{K.stopPropagation(),k("cherryPick")},children:g("gitView.history.actions.cherryPick")}),s.jsx($e,{variant:"outline",size:"xs",className:"h-6",disabled:x!==null,onClick:K=>{K.stopPropagation(),k("revert")},children:g("gitView.history.actions.revert")}),s.jsxs(sn,{children:[s.jsx(en,{asChild:!0,children:s.jsxs($e,{variant:"outline",size:"xs",className:"h-6",disabled:x!==null,onClick:K=>K.stopPropagation(),children:[x==="reset"?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,g("gitView.history.actions.reset")]})}),s.jsx(tn,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(K=>s.jsx(xs,{disabled:x!==null,onSelect:Z=>{Z.stopPropagation(),k(`reset${K.charAt(0).toUpperCase()+K.slice(1)}`)},children:g(`gitView.history.actions.reset${K.charAt(0).toUpperCase()+K.slice(1)}`)},K))})]}),s.jsx($e,{variant:"outline",size:"xs",className:"h-6",disabled:x!==null,onClick:K=>{K.stopPropagation(),k("merge")},children:g("gitView.history.actions.merge")}),s.jsx($e,{variant:"outline",size:"xs",className:"h-6",disabled:x!==null,onClick:K=>{K.stopPropagation(),k("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(K=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>J(K),className:De("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",v.has(K.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:De("font-semibold w-3 text-center shrink-0",zy(K.changeType)),children:K.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:K.path,children:K.path}),!K.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",K.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",K.deletions]})]}),K.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:g("gitView.history.binary")}),s.jsx(I,{name:v.has(K.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),v.has(K.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:K.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.renamedNoDiff")}):K.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.binaryNoDiff")}):(()=>{const Z=K.insertions+K.deletions;if(!O.has(K.path)&&Z>ou)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:Z})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:g("gitView.history.largeDiffDescription")}),s.jsx($e,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{T(pe=>new Set(pe).add(K.path)),se(K)},children:g("gitView.history.renderDiffAnyway")})]});const re=A.get(K.path);return re==="loading"||re===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:g("gitView.history.loadingDiff")}):re==="error"?s.jsx("button",{type:"button",onClick:()=>J(K),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(dm,{original:re.original,modified:re.modified,language:Di(K.path)||"",fileName:K.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},K.path))})]})]})}),fu=["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 qo(t){return fu[t%fu.length]}function Hy(t){if(t.length===0)return[];const e=[],n=[];for(let r=0;r<t.length;r++){const o=t[r],a=[];for(let y=0;y<e.length;y++)e[y]===o.hash&&a.push(y);let c=a.length>0?a[0]:-1;if(c===-1){const y=e.indexOf(null);y!==-1?c=y:(c=e.length,e.push(null))}const l=a.slice(1),d=qo(c),u=e[c]===o.hash,m=o.parents.length>0;m?e[c]=o.parents[0]:e[c]=null;const f=[];for(let y=1;y<o.parents.length;y++){const p=o.parents[y],x=e.indexOf(p);if(x!==-1)f.push(x);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=[];u&&m?g.push({fromLane:c,toLane:c,color:d,type:"commit-lane"}):u&&!m?g.push({fromLane:c,toLane:c,color:d,type:"top-stub"}):!u&&m&&g.push({fromLane:c,toLane:c,color:d,type:"bottom-stub"});for(const y of l)g.push({fromLane:y,toLane:c,color:qo(y),type:"merge-in"}),e[y]=null;for(const y of f)g.push({fromLane:c,toLane:y,color:qo(y),type:"branch-out"});for(let y=0;y<e.length;y++)e[y]!==null&&y!==c&&(f.includes(y)||g.push({fromLane:y,toLane:y,color:qo(y),type:"passing"}));n.push({commit:o,lane:c,color:d,connectors:g})}return n}const Gy=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Ky=t=>{const e=gt.c(84),{mode:n,log:r,isLogLoading:o,logMaxCount:a,onLogMaxCountChange:c,expandedCommitHashes:l,onToggleCommit:d,commitFilesMap:u,loadingCommitHashes:m,onCopyHash:f,directory:g,showHeader:y,contentMaxHeightClassName:p,branchDivider:x,onConflict:b,onActionSuccess:h}=t,N=n===void 0?"history":n,w=y===void 0?!0:y,S=p===void 0?"max-h-[50vh]":p,j=x===void 0?null:x,{t:k}=At(),[v,D]=i.useState(!0),A=N==="graph";let C;e[0]!==A||e[1]!==r?(C=A&&r?Hy(r.all):[],e[0]=A,e[1]=r,e[2]=C):C=e[2];const O=C;let T;e[3]!==O?(T=Math.max(1,...O.map(qy)),e[3]=O,e[4]=T):T=e[4];const E=T;let F;e[5]!==O?(F=new Map(O.map(Yy)),e[5]=O,e[6]=F):F=e[6];const R=F;if(!r)return null;const L=j!==null&&j.insertBeforeIndex>0&&j.insertBeforeIndex<r.all.length,B=j!==null&&j.insertBeforeIndex===r.all.length,V=L||B;let M;e[7]!==j||e[8]!==L||e[9]!==B||e[10]!==r.all?(M=L?r.all.slice(0,j.insertBeforeIndex):B?r.all:[],e[7]=j,e[8]=L,e[9]=B,e[10]=r.all,e[11]=M):M=e[11];const ee=M;let se;if(e[12]!==j||e[13]!==u||e[14]!==S||e[15]!==g||e[16]!==l||e[17]!==L||e[18]!==V||e[19]!==A||e[20]!==o||e[21]!==R||e[22]!==m||e[23]!==r.all||e[24]!==a||e[25]!==E||e[26]!==N||e[27]!==h||e[28]!==b||e[29]!==f||e[30]!==c||e[31]!==d||e[32]!==k||e[33]!==ee){const G=L?r.all.slice(j.insertBeforeIndex):[];let q;e[35]!==j?.direction?(q=j?.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]=j?.direction,e[36]=q):q=e[36];const oe=q;let le;e[37]!==u||e[38]!==g||e[39]!==l||e[40]!==A||e[41]!==R||e[42]!==m||e[43]!==E||e[44]!==N||e[45]!==h||e[46]!==b||e[47]!==f||e[48]!==d?(le=Oe=>s.jsx("ul",{className:"divide-y divide-border/60",children:Oe.map(Me=>s.jsx(Wy,{entry:Me,mode:N,laned:A?R.get(Me.hash):void 0,totalLanes:A?E:void 0,isExpanded:l.has(Me.hash),onToggle:()=>d(Me.hash),files:u.get(Me.hash)??[],isLoadingFiles:m.has(Me.hash),onCopyHash:f,directory:g,onConflict:b,onActionSuccess:h},Me.hash))}),e[37]=u,e[38]=g,e[39]=l,e[40]=A,e[41]=R,e[42]=m,e[43]=E,e[44]=N,e[45]=h,e[46]=b,e[47]=f,e[48]=d,e[49]=le):le=e[49];const ve=le;let Ee;e[50]!==o||e[51]!==r.all.length||e[52]!==a||e[53]!==c||e[54]!==k?(Ee=r.all.length>=a?s.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:s.jsx($e,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(a+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"}),k("gitView.history.loadingMore")]}):k("gitView.history.loadMore")})}):null,e[50]=o,e[51]=r.all.length,e[52]=a,e[53]=c,e[54]=k,e[55]=Ee):Ee=e[55];const _e=Ee;se=s.jsx(Vn,{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:k("gitView.history.noCommits")})}):V&&j?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-0",children:[ee.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ve(ee)}):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:j.branchName,children:j.branchName}),oe]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),G.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ve(G)}):null]}),_e]}):s.jsxs(s.Fragment,{children:[ve(r.all),_e]})}),e[12]=j,e[13]=u,e[14]=S,e[15]=g,e[16]=l,e[17]=L,e[18]=V,e[19]=A,e[20]=o,e[21]=R,e[22]=m,e[23]=r.all,e[24]=a,e[25]=E,e[26]=N,e[27]=h,e[28]=b,e[29]=f,e[30]=c,e[31]=d,e[32]=k,e[33]=ee,e[34]=se}else se=e[34];const J=se;if(!w){if(V){let q;return e[56]!==J?(q=s.jsx("section",{className:"h-full min-h-0",children:J}),e[56]=J,e[57]=q):q=e[57],q}let G;return e[58]!==J?(G=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:J}),e[58]=J,e[59]=G):G=e[59],G}let K;e[60]!==k?(K=k("gitView.history.title"),e[60]=k,e[61]=K):K=e[61];let Z;e[62]!==K?(Z=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:K}),e[62]=K,e[63]=Z):Z=e[63];let re;e[64]!==o||e[65]!==v||e[66]!==a||e[67]!==c||e[68]!==k?(re=v&&s.jsx("div",{onClick:Qy,onPointerDown:Jy,children:s.jsxs(_n,{value:String(a),onValueChange:G=>c(Number(G)),disabled:o,children:[s.jsx($n,{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(Nn,{placeholder:k("gitView.history.commitsPlaceholder")})}),s.jsx(zn,{children:Gy.map(G=>s.jsx(Is,{value:String(G.value),children:k(G.labelKey)},G.value))})]})}),e[64]=o,e[65]=v,e[66]=a,e[67]=c,e[68]=k,e[69]=re):re=e[69];let pe;e[70]!==v?(pe=v?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]=v,e[71]=pe):pe=e[71];let Se;e[72]!==re||e[73]!==pe?(Se=s.jsxs("div",{className:"flex items-center gap-2",children:[re,pe]}),e[72]=re,e[73]=pe,e[74]=Se):Se=e[74];let te;e[75]!==Z||e[76]!==Se?(te=s.jsxs(Bo,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[Z,Se]}),e[75]=Z,e[76]=Se,e[77]=te):te=e[77];let Ne;e[78]!==J?(Ne=s.jsx(so,{children:J}),e[78]=J,e[79]=Ne):Ne=e[79];let Y;return e[80]!==v||e[81]!==te||e[82]!==Ne?(Y=s.jsxs(to,{open:v,onOpenChange:D,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[te,Ne]}),e[80]=v,e[81]=te,e[82]=Ne,e[83]=Y):Y=e[83],Y};function qy(t){return t.lane+1}function Yy(t){return[t.commit.hash,t]}function Qy(t){return t.stopPropagation()}function Jy(t){return t.stopPropagation()}const Am=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 a=0;const c=async()=>{for(;;){const l=a;if(a+=1,l>=t.length)return;o[l]=await n(t[l])}};return await Promise.all(Array.from({length:r},()=>c())),o},Xy=9e4,Zy=15e3,ew=5*6e4,tw=[2e3,5e3],sw=6e4,nw=2*6e4,rw=5*6e4,iw=4,ow=720*6e4,aw="openchamber.github-pr-status",lw=t=>t==="closed"||t==="merged",cw=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},No=(t,e,n)=>`${t}::${e}`,Yo=new Map,Qo=new Map,po=new Set,mu=new Map,bo=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),Ia=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=Ia(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},Dm=(t,e)=>Object.entries(t).filter(([,n])=>Tc(n)===e).map(([n])=>n),dw=(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}}},Jo=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},uw=(t,e,n)=>{const r=Dm(t,e),o=r.map(d=>Jo(t[d])).filter(d=>!!d);if(o.length===0)return null;const a=Jo(t[n]);if(a&&Tc(t[n])===e)return a;const c=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&Jo(d)));if(c)return Jo(c);const l=o.find(d=>!!d.remoteName);return l||(o[0]??null)},fw=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:Ia(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),mw=t=>({...bo(),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=io()(rc((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:bo()}})},setParams:(n,r)=>{t(o=>{const a=o.entries[n]??bo();return{entries:{...o.entries,[n]:dw(a,r)}}})},startWatching:n=>{if(t(a=>{const c=a.entries[n]??bo();return{entries:{...a.entries,[n]:{...c,watchers:c.watchers+1}}}}),Yo.has(n))return;const r=a=>{const c=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},a),l=Qo.get(n)??[];l.push(c),Qo.set(n,l)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),tw.forEach(a=>r(a));const o=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const a=e().entries[n];if(!a||a.watchers<=0)return;if(!!!a.status?.pr){const u=Date.now();if(u-a.lastDiscoveryPollAt<ew)return;t(m=>{const f=m.entries[n];return f?{entries:{...m.entries,[n]:{...f,lastDiscoveryPollAt:u}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(lw(a.status?.pr?.state))return;const l=Date.now()-a.lastRefreshAt,d=cw(a.status)?sw:a.status?.checks&&a.status.checks.state!=="pending"?rw:nw;l<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},Zy);Yo.set(n,o)},stopWatching:n=>{t(c=>{const l=c.entries[n];if(!l)return c;const d=Math.max(0,l.watchers-1);return{entries:{...c.entries,[n]:{...l,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const o=Yo.get(n);typeof o=="number"&&window.clearInterval(o),Yo.delete(n);const a=Qo.get(n);a&&a.length>0&&a.forEach(c=>{window.clearTimeout(c)}),Qo.delete(n)},refresh:async(n,r)=>{const o=e(),a=o.entries[n],c=Tc(a);if(!a||!c)return;const l=Dm(o.entries,c),d=l.some(f=>!!o.entries[f]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const u=mu.get(c)??0;if(!r?.force&&Date.now()-u<Xy||po.has(c))return;const m=uw(o.entries,c,n);if(m){if(po.add(c),mu.set(c,Date.now()),t(f=>{const g={...f.entries};return l.forEach(y=>{const p=g[y];p&&(g[y]={...p,lastRefreshAt:Date.now(),isLoading:r?.silent?p.isLoading:!0,error:null})}),{entries:g}}),m.githubAuthChecked&&m.githubConnected===!1){t(f=>{const g={...f.entries};return l.forEach(y=>{const p=g[y];p&&(g[y]={...p,status:{connected:!1},error:null,isLoading:r?.silent?p.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?p.isInitialStatusResolved:!0})}),{entries:g}}),po.delete(c);return}if(!m.github?.prStatus){t(f=>{const g={...f.entries};return l.forEach(y=>{const p=g[y];p&&(g[y]={...p,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?p.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?p.isInitialStatusResolved:!0})}),{entries:g}}),po.delete(c);return}try{t(g=>({...g,activeRequestCount:g.activeRequestCount+1,totalRequestCount:g.totalRequestCount+1}));const f=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(g=>{const y={...g.entries};return l.forEach(p=>{const x=y[p];if(!x)return;const b=x.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??x.resolvedRemoteName??m.remoteName??null,j=Ia(x)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};y[p]={...x,status:w,error:null,isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...j,remoteName:S??j.remoteName??null}}}),{entries:y}})}catch(f){const g=f instanceof Error?f.message:String(f);t(y=>{const p={...y.entries};return l.forEach(x=>{const b=p[x];b&&(p[x]={...b,error:g||"Failed to load PR status",isLoading:r?.silent?b.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?b.isInitialStatusResolved:!0})}),{entries:p}})}finally{po.delete(c),t(f=>({...f,activeRequestCount:Math.max(0,f.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const o=Array.from(new Set(n.map(a=>{const c=a.directory.trim(),l=a.branch.trim();return!c||!l?null:No(c,l,a.remoteName??null)}).filter(a=>!!a)));await Am(o,iw,a=>e().refresh(a,r))},updateStatus:(n,r)=>{t(o=>{const a=o.entries[n]??bo();return{entries:{...o.entries,[n]:{...a,status:r(a.status)}}}})}}),{name:aw,storage:Sf(()=>ki()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=Ia(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<ow}).map(([e,n])=>[e,fw(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([o,a])=>[o,mw(a)]))}}})),hw=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"},pw=t=>{const e=hw(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}},gw=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 pl=new Map,hu=new Map;const xw=t=>{const e=gt.c(2);let n;return e[0]!==t?(n=r=>{const o=new Map,a=new Map;for(const c of t){const l=r.entries[c];if(!l)continue;const d=pw(l);if(!d)continue;const u=gw(d);o.set(c,u),a.set(c,d)}if(o.size===pl.size){let c=!0;for(const[l,d]of o)if(pl.get(l)!==d){c=!1;break}if(c)return hu}return pl=o,hu=a,a},e[0]=t,e[1]=n):n=e[1],tr(n)},bw=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"}},yw=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"},ww=[2e3,5e3],pu=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),ei=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):""},vw=(t,e)=>{const n=ei(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},jw=(t,e)=>`${t}::${e}`,Rc=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},gl=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const a=t.find(c=>c.name===n);if(a)return a}const r=Rc(e.trackingBranch);if(r){const a=r==="origin"?t.find(l=>l.name==="upstream"):null;if(a)return a;const c=t.find(l=>l.name===r);if(c)return c}const o=t.find(a=>a.name==="origin");return o||(t[0]??null)},Sw=t=>t.startsWith("pr-"),Nw=(t,e)=>{const n=Rc(e),r=new Map(t.map(c=>[c.name,c])),o=[],a=c=>{c&&(o.some(l=>l.name===c.name)||o.push(c))};return n&&a(r.get(n)),a(r.get("upstream")),a(r.get("origin")),t.filter(c=>!Sw(c.name)).forEach(c=>a(c)),t.forEach(c=>a(c)),o},xl=new Map,bl=Pi;function kw(t,e){const[n,r]=i.useState(null),[o,a]=i.useState([]),c=i.useRef(null);return i.useEffect(()=>{r(null),a([])},[t]),i.useEffect(()=>{if(!t||!e?.repoUpstream||c.current===t)return;c.current=t;let l=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(l||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const u=await e.repoBranches(d.upstream.owner,d.upstream.repo);l||a(u)}catch{}}catch{}})(),()=>{l=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:o}}const Cw=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:a=[],onGeneratedDescription:c})=>{const{t:l}=At(),d=Re(we=>we.timeFormatPreference),{github:u}=Qn(),m=Ti(we=>we.status),f=Ti(we=>we.hasChecked),g=Re(we=>we.setSettingsDialogOpen),y=Re(we=>we.setSettingsPage),p=Re(we=>we.setActiveMainTab),x=dt(we=>we.currentSessionId),{isMobile:b,hasTouchInput:h}=Rr(),N=i.useCallback(()=>{y("github"),g(!0)},[g,y]),w=i.useMemo(()=>jw(t,e),[t,e]),S=i.useMemo(()=>xl.get(w)??null,[w]),j=tr(we=>we.ensureEntry),k=tr(we=>we.setParams),v=tr(we=>we.startWatching),D=tr(we=>we.stopWatching),A=tr(we=>we.refresh),C=tr(we=>we.updateStatus),[O,T]=i.useState(()=>S?.title??pu(e)),[E,F]=i.useState(()=>S?.body??""),[R,L]=i.useState(()=>S?.draft??!1),[B,V]=i.useState(()=>S?.additionalContext??""),[M,ee]=i.useState(()=>{const we=typeof S?.targetBaseBranch=="string"?ei(S.targetBaseBranch):"";return we||ei(n)}),[se,J]=i.useState("squash"),[K,Z]=i.useState(!1),[re,pe]=i.useState(!1),[Se,te]=i.useState(!1),[Ne,Y]=i.useState(!1),[G,q]=i.useState(!1),[oe,le]=i.useState(!1),[ve,Ee]=i.useState(null),[_e,Oe]=i.useState(""),[Me,he]=i.useState(""),[Ce,xe]=i.useState(!1),[ue,H]=i.useState(!1),[ce,fe]=i.useState(()=>gl(o,{selectedRemoteName:S?.selectedRemoteName,trackingBranch:r})),[U,z]=i.useState(!1),{detectedUpstream:be,upstreamBranches:ge}=kw(t,u);i.useEffect(()=>{z(!1)},[t]);const _=o.some(we=>we.name==="upstream"),$=!!(t&&e&&n&&(e!==n||(_||be!==null))),Ie=i.useMemo(()=>No(t,e),[t,e]),je=tr(we=>we.entries[Ie]),Fe=je?.isLoading??!1,Ae=je?.status??null,ne=je?.error??null,P=je?.isInitialStatusResolved??!1,me=i.useMemo(()=>{const we=U?null:ce?.name?.trim()||null,Je=new Set;for(const $t of a){const ft=vw($t,we);!ft||ft==="HEAD"||Je.add(ft)}if(U)for(const $t of ge)$t&&$t!=="HEAD"&&Je.add($t);const wt=ei(n);wt&&wt!=="HEAD"&&Je.add(wt);const Pt=ei(M);return Pt&&Pt!=="HEAD"&&Je.add(Pt),Array.from(Je).sort(($t,ft)=>$t.localeCompare(ft))},[n,a,ce?.name,M,ge,U]);i.useEffect(()=>{if(o.length===0){ce&&fe(null);return}(!ce||!o.some(we=>we.name===ce.name))&&fe(gl(o,{selectedRemoteName:S?.selectedRemoteName,trackingBranch:r}))},[S?.selectedRemoteName,o,ce,r]),i.useEffect(()=>{const we=ei(n);if(!M&&we){ee(we);return}if(me.length!==0&&!me.includes(M)){const Je=me.includes(we)?we:me[0];Je&&ee(Je)}},[me,n,M]);const[ae,Be]=i.useState(!1),[Ge,Ke]=i.useState(null),[Qe,st]=i.useState(!1),[ut,vt]=i.useState(new Set),[Ve,tt]=i.useState(!1),[nt,xt]=i.useState(null),[Rt,bt]=i.useState(!1),ot=i.useRef(new Set),at=i.useRef(null),Ut=i.useRef(!1),Nt=i.useRef(new Set),_t=i.useRef([]);i.useEffect(()=>{be&&!_&&z(!0)},[be,_]),i.useEffect(()=>{U&&be?.defaultBranch&&ee(be.defaultBranch)},[U,be?.defaultBranch]);const Le=Ae?.pr??null,Dt=Le?`${t}#${Le.number}`:null,Ot=!!(Dt&&ve===Dt);i.useEffect(()=>{if(!u?.prContext||!Le||typeof Le.body=="string"&&Le.body.length>0)return;const we=`${t}#${Le.number}`;if(ot.current.has(we))return;ot.current.add(we),Ee(we);let Je=!1;return u.prContext(t,Le.number,{includeDiff:!1,includeCheckDetails:!1}).then(wt=>{if(Je)return;const Pt=wt?.pr;Pt&&C(Ie,$t=>!$t?.pr||$t.pr.number!==Le.number?$t:{...$t,pr:{...$t.pr,body:Pt.body||""}})}).catch(()=>{}).finally(()=>{Je||Ee(wt=>wt===we?null:wt)}),()=>{Je=!0}},[t,u,Le,Ie,C]),i.useEffect(()=>{if(!Le){le(!1),Oe(""),he(""),at.current=null;return}const we=at.current!==null&&at.current!==Le.number;we&&le(!1),(!oe||we)&&(Oe(Le.title||""),he(Le.body||"")),at.current=Le.number},[oe,Le]);const mt=i.useCallback(async()=>{if(!u?.prContext){de.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(Le){Be(!0),vt(new Set),st(!0);try{const we=await u.prContext(t,Le.number,{includeDiff:!1,includeCheckDetails:!0});Ke(we)}catch(we){const Je=we instanceof Error?we.message:String(we);de.error(l("gitView.pr.toast.loadCheckDetailsFailed"),{description:Je})}finally{st(!1)}}},[t,u,Le,l]),Et=i.useCallback(async()=>{if(!u?.prContext){de.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(Le){tt(!0),bt(!0);try{const we=await u.prContext(t,Le.number,{includeDiff:!1,includeCheckDetails:!1});xt(we)}catch(we){const Je=we instanceof Error?we.message:String(we);de.error(l("gitView.pr.toast.loadCommentsFailed"),{description:Je})}finally{bt(!1)}}},[t,u,Le,l]),qt=i.useCallback(we=>{if(!we)return"";const Je=Date.parse(we);return Number.isFinite(Je)?gc(Je,d,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):we},[d]),Vt=i.useMemo(()=>{const we=m?.user?.login;return typeof we=="string"?we.trim():""},[m]),Wt=i.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)]",[]),Yt=i.useCallback(we=>{const Je=Vt.toLowerCase(),wt=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return we.replace(wt,(Pt,$t,ft)=>{const ls=`@${ft}`,cs=ft.toLowerCase();return`${$t}[${ls}](https://github.com/${cs}${Je&&cs===Je?"?oc-self-mention=1":""})`})},[Vt]),Bt=i.useMemo(()=>{const we=(nt?.issueComments??[]).map(Pt=>({id:`issue-${Pt.id}`,body:Pt.body||"",authorName:Pt.author?.name||Pt.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:Pt.author?.login||null,avatarUrl:Pt.author?.avatarUrl||null,createdAt:Pt.createdAt,context:l("gitView.pr.comments.generalContext"),path:null,line:null})),Je=(nt?.reviewComments??[]).map(Pt=>({id:`review-${Pt.id}`,body:Pt.body||"",authorName:Pt.author?.name||Pt.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:Pt.author?.login||null,avatarUrl:Pt.author?.avatarUrl||null,createdAt:Pt.createdAt,context:l("gitView.pr.comments.reviewContext"),path:Pt.path||null,line:Pt.line??null})),wt=[...we,...Je];return wt.sort((Pt,$t)=>{const ft=Pt.createdAt?Date.parse(Pt.createdAt):0,ls=$t.createdAt?Date.parse($t.createdAt):0,cs=Number.isFinite(ft)?ft:0,Ns=Number.isFinite(ls)?ls:0;return cs-Ns}),wt},[nt,l]),Ht=i.useCallback(()=>{if(!x)return de.error(l("gitView.pr.toast.noActiveSession"),{description:l("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:we,currentModelId:Je,currentAgentName:wt,currentVariant:Pt}=es.getState(),$t=pc.getState().lastUsedProvider,ft=we||$t?.providerID,ls=Je||$t?.modelID;return!ft||!ls?(de.error(l("gitView.pr.toast.noModelSelected")),null):{sessionId:x,providerID:ft,modelID:ls,currentAgentName:wt??null,currentVariant:Pt??null}},[x,l]),Jt=i.useCallback((we,Je,wt,Pt)=>{dt.getState().sendMessage(Je,we.providerID,we.modelID,we.currentAgentName??void 0,void 0,void 0,[{text:wt,synthetic:!0},{text:Pt,synthetic:!0}],we.currentVariant??void 0).catch($t=>{const ft=$t instanceof Error?$t.message:String($t);de.error(l("gitView.pr.toast.sendMessageFailed"),{description:ft})})},[l]),rs=i.useCallback(we=>{const Je=we.status||"unknown",wt=we.conclusion??void 0,Pt=wt?`${Je} / ${wt}`:Je,$t=we.app?.name||we.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:we.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:$t?`${$t} · ${Pt}`:Pt})]}),we.detailsUrl?s.jsx($e,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:we.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),we.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:we.output.title}):null,we.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:we.output.summary}):null,we.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:we.output.text}):null,Array.isArray(we.annotations)&&we.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",we.annotations.length>20?` (showing 20/${we.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:we.annotations.slice(0,20).map((ft,ls)=>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:[ft.title||ft.level||"Issue",ft.path?` · ${ft.path}`:"",typeof ft.startLine=="number"?`:${ft.startLine}`:"",typeof ft.endLine=="number"&&ft.endLine!==ft.startLine?`-${ft.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:ft.message}),ft.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:ft.rawDetails}):null]},`${ft.path||"file"}:${ft.startLine||ls}:${ls}`))})]}):null,we.job?.steps&&we.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:we.job.steps.map((ft,ls)=>{const cs=(ft.conclusion||"").toLowerCase(),Ns=cs&&!["success","neutral","skipped"].includes(cs),ms=`${we.id??"run"}:${we.job?.jobId??"job"}:${ft.number??ls}:${ft.name}`,Qs=ut.has(ms);return Ns?s.jsxs(to,{open:Qs,children:[s.jsxs("button",{type:"button",onClick:()=>{vt(He=>{const ns=new Set(He);return ns.has(ms)?ns.delete(ms):ns.add(ms),ns})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Ns?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Qs?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:ft.name}),ft.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:ft.conclusion}):null]}),s.jsx(so,{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 ft.number=="number"?s.jsxs("div",{children:[l("gitView.pr.checks.stepLabel"),": ",ft.number]}):null,ft.status?s.jsxs("div",{children:[l("gitView.pr.checks.statusLabel"),": ",ft.status]}):null,ft.conclusion?s.jsxs("div",{children:[l("gitView.pr.checks.conclusionLabel"),": ",ft.conclusion]}):null,ft.startedAt?s.jsxs("div",{children:[l("gitView.pr.checks.startedLabel"),": ",qt(ft.startedAt)]}):null,ft.completedAt?s.jsxs("div",{children:[l("gitView.pr.checks.completedLabel"),": ",qt(ft.completedAt)]}):null]})})]},ms):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:ft.name}),ft.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:ft.conclusion}):null]},ms)})})]}):null]})},[ut,qt,l]),Qt=i.useCallback(async()=>{if(p("chat"),!u?.prContext){de.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Le)return;const we=Ht();if(we)try{const Je=await u.prContext(t,Le.number,{includeDiff:!1,includeCheckDetails:!0}),Pt=(Je.checkRuns??[]).filter(Ns=>{const ms=typeof Ns.conclusion=="string"?Ns.conclusion.toLowerCase():"";return ms?!["success","neutral","skipped"].includes(ms):!1});if(Pt.length===0){de.message(l("gitView.pr.toast.noFailedChecks"));return}const $t=await Rn("github.pr.checks.review.visible"),ft=await Rn("github.pr.checks.review.instructions"),ls=Pt.flatMap(Ns=>(Array.isArray(Ns.annotations)?Ns.annotations:[]).map(Qs=>({run:Ns.name,level:Qs.level,title:Qs.title,path:Qs.path,startLine:Qs.startLine,endLine:Qs.endLine,message:Qs.message,rawDetails:Qs.rawDetails}))),cs=`GitHub PR failed checks (JSON)
|
|
7
|
+
${JSON.stringify({repo:Je.repo??null,pr:Je.pr??null,failedChecks:Pt,failedAnnotations:ls},null,2)}`;Jt(we,$t,ft,cs)}catch(Je){const wt=Je instanceof Error?Je.message:String(Je);de.error(l("gitView.pr.toast.loadChecksFailed"),{description:wt})}},[t,Jt,u,Le,Ht,p,l]),Xt=i.useCallback(async()=>{if(p("chat"),!u?.prContext){de.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Le)return;const we=Ht();if(we)try{const Je=await u.prContext(t,Le.number,{includeDiff:!1,includeCheckDetails:!1}),wt=Je.issueComments??[],Pt=Je.reviewComments??[];if(wt.length+Pt.length===0){de.message(l("gitView.pr.toast.noPrComments"));return}const ft=await Rn("github.pr.comments.review.visible"),ls=await Rn("github.pr.comments.review.instructions"),cs=`GitHub PR comments (JSON)
|
|
8
|
+
${JSON.stringify({repo:Je.repo??null,pr:Je.pr??null,issueComments:wt,reviewComments:Pt},null,2)}`;Jt(we,ft,ls,cs)}catch(Je){const wt=Je instanceof Error?Je.message:String(Je);de.error(l("gitView.pr.toast.loadPrCommentsFailed"),{description:wt})}},[t,Jt,u,Le,Ht,p,l]),bs=i.useCallback(async we=>{tt(!1),p("chat");const Je=Ht();if(!Je)return;const wt=await Rn("github.pr.comment.single.visible"),Pt=await Rn("github.pr.comment.single.instructions"),$t=`GitHub PR comment (JSON)
|
|
9
|
+
${JSON.stringify({repo:nt?.repo??null,pr:nt?.pr??Le??null,comment:we},null,2)}`;Jt(Je,wt,Pt,$t)},[nt,Jt,Le,Ht,p]),yt=i.useCallback(async we=>{await A(Ie,we)},[Ie,A]),Ue=i.useCallback(()=>{_t.current.forEach(we=>{window.clearTimeout(we)}),_t.current=ww.map(we=>window.setTimeout(()=>{yt({force:!0,silent:!0,markInitialResolved:!0})},we))},[yt]);i.useEffect(()=>{if(!u?.prStatus||!$||o.length<=1||Ut.current||Ae?.pr)return;const we=`${w}::${ce?.name??""}`;if(Nt.current.has(we))return;Nt.current.add(we);const Je=Nw(o,r).filter($t=>$t.name!==ce?.name);if(Je.length===0)return;let wt=!1;return(async()=>{for(const $t of Je){if(wt)return;try{if(!(await u.prStatus(t,e,$t.name))?.pr)continue;if(wt)return;fe(ls=>ls?.name===$t.name?ls:$t);return}catch{}}})(),()=>{wt=!0}},[e,$,t,u,o,ce?.name,w,Ae?.pr,r]),i.useEffect(()=>{j(Ie),k(Ie,{directory:t,branch:e,remoteName:ce?.name??null,canShow:$,github:u,githubAuthChecked:f,githubConnected:m?.connected??null})},[e,$,t,j,u,f,m?.connected,Ie,ce?.name,k]),i.useEffect(()=>(v(Ie),()=>{D(Ie)}),[Ie,v,D]),i.useEffect(()=>{const we=xl.get(w)??null;T(we?.title??pu(e)),F(we?.body??""),L(we?.draft??!1),ee(we?.targetBaseBranch?ei(we.targetBaseBranch):ei(n));const Je=gl(o,{selectedRemoteName:we?.selectedRemoteName,trackingBranch:r});fe(wt=>wt?.name===Je?.name?wt:Je)},[n,e,o,w,r]),i.useEffect(()=>{yt({markInitialResolved:!0})},[Ie,yt]),i.useEffect(()=>{!$||!ce?.name||yt({force:!0,silent:!0,markInitialResolved:!0})},[$,yt,ce?.name]),i.useEffect(()=>{const we=Ae?.resolvedRemoteName?.trim();if(!we||Ut.current)return;const Je=o.find(wt=>wt.name===we);Je&&fe(wt=>wt?.name===Je.name?wt:Je)},[o,Ae?.resolvedRemoteName]),i.useEffect(()=>{const we=Ae?.pr?.state==="closed"||Ae?.pr?.state==="merged",Je=je?.lastRefreshAt??0,wt=Date.now()-Je>6e4,Pt=!we&&wt,$t=()=>{Pt&&yt({force:!0,silent:!0})},ft=()=>{document.visibilityState==="visible"&&Pt&&yt({force:!0,silent:!0})};return window.addEventListener("focus",$t),document.addEventListener("visibilitychange",ft),()=>{window.removeEventListener("focus",$t),document.removeEventListener("visibilitychange",ft)}},[yt,Ae?.pr?.state,je?.lastRefreshAt]),i.useEffect(()=>{f&&m?.connected===!1&&yt({force:!0,silent:!0,markInitialResolved:!0})},[f,m,yt]),i.useEffect(()=>{!t||!e||xl.set(w,{title:O,body:E,draft:R,additionalContext:B,targetBaseBranch:M,selectedRemoteName:ce?.name})},[w,O,E,R,B,M,ce?.name,t,e]),i.useEffect(()=>{const we=_t.current;return()=>{we.forEach(Je=>{window.clearTimeout(Je)}),_t.current=[]}},[]);const Ye=i.useCallback(async()=>{if(!K&&t){Z(!0);try{const Je={base:U&&be?.defaultBranchSha?be.defaultBranchSha:M,head:e};B&&(Je.context=B);const wt=await Wp(t,Je);wt.title?.trim()&&T(wt.title.trim()),wt.body?.trim()&&F(wt.body.trim()),c?.()}catch(we){const Je=we instanceof Error?we.message:String(we);de.error(l("gitView.pr.toast.generateDescriptionFailed"),{description:Je})}finally{Z(!1)}}},[B,e,be?.defaultBranchSha,t,K,c,M,l,U]),Ct=i.useCallback(async()=>{if(!u?.prCreate){de.error(l("gitView.pr.toast.githubApiUnavailable"));return}const we=O.trim();if(!we){de.error(l("gitView.pr.toast.titleRequired"));return}const Je=M.trim();if(!Je){de.error(l("gitView.pr.toast.baseBranchRequired"));return}if(!U&&Je===e){de.error(l("gitView.pr.toast.baseMustDifferFromHead"));return}pe(!0);try{const wt=Rc(r),Pt=U&&be,$t=await u.prCreate({directory:t,title:we,head:e,base:Je,...E.trim()?{body:E}:{},draft:R,...Pt?{targetRepo:{owner:be.owner,repo:be.repo},headRemote:"origin"}:{...ce?{remote:ce.name}:{},...wt&&wt!==ce?.name?{headRemote:wt}:{}}});de.success(l("gitView.pr.toast.prCreated")),C(Ie,ft=>ft&&{...ft,pr:$t}),await yt({force:!0}),Ue()}catch(wt){const Pt=wt instanceof Error?wt.message:String(wt);de.error(l("gitView.pr.toast.createPrFailed"),{description:Pt})}finally{pe(!1)}},[E,e,be,t,R,u,Ie,yt,Ue,ce,M,O,r,C,U,l]),kt=i.useCallback(async we=>{if(!u?.prMerge){de.error(l("gitView.pr.toast.githubApiUnavailable"));return}Y(!0);try{const Je=await u.prMerge({directory:t,number:we.number,method:se});Je.merged?de.success(l("gitView.pr.toast.prMerged")):de.message(l("gitView.pr.toast.prNotMerged"),{description:Je.message||l("gitView.pr.notMergeable")}),await yt({force:!0}),Ue()}catch(Je){const wt=Je instanceof Error?Je.message:String(Je);de.error(l("gitView.pr.toast.mergeFailed"),{description:wt}),we.url&&bl(we.url)}finally{Y(!1)}},[t,u,se,yt,Ue,l]),It=i.useCallback(async we=>{if(!u?.prReady){de.error(l("gitView.pr.toast.githubApiUnavailable"));return}q(!0);try{await u.prReady({directory:t,number:we.number}),de.success(l("gitView.pr.toast.markedReady")),await yt({force:!0}),Ue()}catch(Je){const wt=Je instanceof Error?Je.message:String(Je);de.error(l("gitView.pr.toast.markReadyFailed"),{description:wt}),we.url&&bl(we.url)}finally{q(!1)}},[t,u,yt,Ue,l]),rt=i.useCallback(async we=>{if(!u?.prUpdate){de.error(l("gitView.pr.toast.githubApiUnavailable"));return}const Je=_e.trim();if(!Je){de.error(l("gitView.pr.toast.titleRequired"));return}te(!0);try{const wt=await u.prUpdate({directory:t,number:we.number,title:Je,body:Me});C(Ie,Pt=>Pt&&{...Pt,pr:{...Pt.pr??we,...wt}}),le(!1),de.success(l("gitView.pr.toast.prUpdated")),await yt({force:!0}),Ue()}catch(wt){const Pt=wt instanceof Error?wt.message:String(wt);de.error(l("gitView.pr.toast.updatePrFailed"),{description:Pt})}finally{te(!1)}},[t,Me,_e,u,Ie,yt,Ue,C,l]);if(!$)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 ts=Ae?.repo?.url||null,hs=U&&be?.url?be.url:ts,Gt=Ae?.checks??null,nn=!!Ae?.canMerge,js=!!Ae?.connected,ss=f&&Ae?.connected===!1,Os=yw(Ae),Ps=Os?`var(--pr-${Os})`:"var(--status-info)",As=Os==="draft"?"git-pr-draft":Os==="merged"?"git-merge":Os==="closed"?"git-close-pull-request":"git-pull-request",yn=Le?[`${Le.state}${Le.draft?" (draft)":""}`,Le.mergeable===!1?l("gitView.pr.notMergeable"):null,Le.state==="open"&&typeof Le.mergeableState=="string"&&Le.mergeableState&&Le.mergeableState!=="unknown"?Le.mergeableState:null].filter(Boolean).join(" · "):"",Ys=Gt?Gt.total>0?`${Gt.success}/${Gt.total} ${l("gitView.pr.checks.label")}`:`${Gt.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:[Le?s.jsxs(Mt,{children:[s.jsx(Ft,{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:()=>{bl(Le.url)},"aria-label":l("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(I,{name:As,className:"size-4 shrink-0",style:{color:Ps}})})}),s.jsx(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(I,{name:As,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")}),Le?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",Le.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Fe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(Mt,{children:[s.jsx(Ft,{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:Fe,onClick:()=>{yt({force:!0})},"aria-label":l("gitView.pr.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.refresh")})})]})]})]}),Le?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:Ps},children:yn}),Gt?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${bw(Gt.state)}`}),Ys]}):null,r&&ce&&r.split("/")[0]!==ce.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",ce.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[ss?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.githubNotConnected")}),s.jsx($e,{variant:"outline",size:"sm",onClick:N,className:"w-fit",children:l("gitView.pr.actions.openSettings")})]}):null,ne?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:ne}),hs?s.jsx($e,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:hs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!Le&&!P&&!ne&&!ss?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")]}):Le?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:[oe?s.jsxs("div",{className:"space-y-2",children:[s.jsx(bn,{value:_e,onChange:we=>Oe(we.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h}),s.jsx(Ci,{value:Me,onChange:we=>he(we.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:Le.title}),Le.body?.trim()?s.jsx(Po,{content:Le.body,className:"typography-markdown-body text-muted-foreground break-words mt-1",enableFileReferences:!1}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:l(Ot?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),nn&&Le.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.draftMustBeReady")}):null,nn?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:[Le.state==="open"?oe?s.jsxs(s.Fragment,{children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{le(!1),Oe(Le.title||""),he(Le.body||"")},disabled:Se,"aria-label":l("gitView.pr.actions.cancelEditingAria"),children:s.jsx(I,{name:"close",className:"size-4"})})}),s.jsx(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>rt(Le),disabled:Se||!_e.trim(),"aria-label":l("gitView.pr.actions.savePrAria"),children:Se?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})})}),s.jsx(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>le(!0),"aria-label":l("gitView.pr.actions.editPrAria"),children:s.jsx(I,{name:"edit",className:"size-4"})})}),s.jsx(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.editPr")})})]}):null,Gt?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:mt,disabled:Qe,"aria-label":l("gitView.pr.actions.openChecksAria"),children:Qe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"information",className:"size-4"})})}),s.jsx(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.openChecks")})})]}):null,Gt?.failure?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{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(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{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(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.openComments")})})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{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:Xt,"aria-label":l("gitView.pr.actions.shareCommentsAria"),children:s.jsx(I,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.shareComments")})})]}),nn&&Le.draft&&Le.state==="open"?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>It(Le),disabled:G||Ne||Se||oe,"aria-label":l("gitView.pr.actions.markReadyAria"),children:G?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:nn?s.jsxs(s.Fragment,{children:[s.jsxs(_n,{value:se,onValueChange:we=>J(we),disabled:Ne||Le.state!=="open",children:[s.jsx($n,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(Nn,{})}),s.jsxs(zn,{children:[s.jsx(Is,{value:"squash",children:l("gitView.pr.mergeMethod.squash")}),s.jsx(Is,{value:"merge",children:l("gitView.pr.mergeMethod.merge")}),s.jsx(Is,{value:"rebase",children:l("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>kt(Le),disabled:Ne||G||Le.state!=="open"||Le.draft||Se||oe,"aria-label":l("gitView.pr.actions.mergePrAria"),children:Ne?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"})})}),s.jsx(Lt,{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)"})," → ",M," ",s.jsxs("span",{className:"opacity-60",children:["(",U&&be?"upstream":"remote",")"]})]})]}),hs?s.jsx($e,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:hs,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(bn,{value:O,onChange:we=>T(we.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")}),me.length>0?s.jsxs(_n,{value:M,onValueChange:ee,children:[s.jsx($n,{className:"h-9",children:s.jsx(Nn,{placeholder:l("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(zn,{children:me.map(we=>s.jsx(Is,{value:we,children:we},we))})]}):s.jsx(bn,{value:M,onChange:we=>ee(we.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(Ci,{value:E,onChange:we=>F(we.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:()=>L(we=>!we),onKeyDown:we=>{(we.key===" "||we.key==="Enter")&&(we.preventDefault(),L(Je=>!Je))},children:[s.jsx(Ri,{size:"sm",checked:R,onChange:we=>L(we),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($e,{variant:"outline",size:"sm",onClick:()=>H(!0),children:B.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),B.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(to,{open:Ce,onOpenChange:xe,children:[s.jsxs(Bo,{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:Ce?l("gitView.pr.actions.hide"):B.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),s.jsx(so,{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(Ci,{value:B,onChange:we=>V(we.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($a,{open:ue,onClose:()=>H(!1),title:l("gitView.pr.additionalContext.title"),footer:s.jsx($e,{size:"sm",onClick:()=>H(!1),className:"w-full",children:l("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ci,{value:B,onChange:we=>V(we.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($e,{variant:"outline",size:"sm",onClick:Ye,disabled:K||re,children:[K?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($e,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Ct,disabled:re||!js||!M.trim()||!U&&M.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:re?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(Ls,{open:ae,onOpenChange:Be,children:s.jsxs(Fs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(Us,{children:[s.jsxs($s,{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(an,{children:Le?l("gitView.pr.numberLabel",{number:Le.number}):l("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[Qe?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,Qe?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(Ge?.checkRuns)&&Ge?.checkRuns.length>0?Ge.checkRuns.map((we,Je)=>{const wt=`${we.id??"run"}:${we.job?.jobId??"job"}:${we.name}:${Je}`;return s.jsx("div",{className:"p-1",children:rs(we)},wt)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:l("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(Ls,{open:Ve,onOpenChange:tt,children:s.jsxs(Fs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(Us,{children:s.jsxs($s,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),l("gitView.pr.comments.title"),Le?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.numberLabel",{number:Le.number})}):null]})}),s.jsxs(za,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[Rt?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,Rt?null:s.jsx("div",{className:"space-y-4",children:Bt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Bt.map((we,Je)=>{const wt=(we.authorName||"?").charAt(0).toUpperCase(),Pt=Je===Bt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Pt?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:we.avatarUrl?s.jsx("img",{src:we.avatarUrl,alt:we.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:wt})}),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:[we.authorName,we.authorLogin&&we.authorLogin!==we.authorName?` · @${we.authorLogin}`:""]}),we.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:qt(we.createdAt)}):null,s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsxs($e,{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:()=>{bs(we)},"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(Lt,{children:s.jsx("p",{children:l("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[we.context,we.path?` · ${we.path}`:"",we.line?`:${we.line}`:""]}),s.jsx(Po,{content:Yt(we.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Wt].filter(Boolean).join(" "),enableFileReferences:!1})]})]},we.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:l("gitView.pr.comments.empty")})})]})]})})]})},Aw=t=>{const e=gt.c(150),{open:n,onOpenChange:r,conflictFiles:o,directory:a,operation:c,onAbort:l,onClearState:d}=t;let u;e[0]!==o?(u=o===void 0?[]:o,e[0]=o,e[1]=u):u=e[1];const m=u,{t:f}=At(),g=dt(Dw),y=dt(Iw),p=ai(Pw),x=ai(Tw),b=Re(Rw),[h,N]=i.useState(!1),[w,S]=i.useState(null),[j,k]=i.useState(null);let v,D;e[2]!==a||e[3]!==n||e[4]!==f?(v=()=>{!n||!a||(N(!0),k(null),S(null),Hp(a).then(U=>{S(U)}).catch(U=>{const z=U instanceof Error?U.message:f("gitView.conflict.loadFailed");k(z)}).finally(()=>{N(!1)}))},D=[n,a,f],e[2]=a,e[3]=n,e[4]=f,e[5]=v,e[6]=D):(v=e[5],D=e[6]),i.useEffect(v,D);let A;e[7]!==w||e[8]!==a||e[9]!==c?(A=async()=>{if(!w)return null;const U=c==="merge"?"merge":"rebase",z=w.headInfo||(c==="merge"?"MERGE_HEAD":"REBASE_HEAD"),be=c==="merge"?"git commit --no-edit":"git rebase --continue",ge=await Rn("git.conflict.resolve.visible",{operation_label:U,head_ref:z}),_=await Rn("git.conflict.resolve.instructions",{operation_label:U,directory:a,operation:c,head_info:w.headInfo||"N/A",continue_cmd:be}),ye=`${U} conflict context (JSON)
|
|
10
|
+
${JSON.stringify({directory:a,operation:w.operation,headInfo:w.headInfo,statusPorcelain:w.statusPorcelain,unmergedFiles:w.unmergedFiles,diff:w.diff},null,2)}`;return{visibleText:ge,instructionsText:_,payloadText:ye}},e[7]=w,e[8]=a,e[9]=c,e[10]=A):A=e[10];const C=A;let O;e[11]!==l||e[12]!==r?(O=()=>{l(),r(!1)},e[11]=l,e[12]=r,e[13]=O):O=e[13];const T=O;let E;e[14]!==d||e[15]!==r?(E=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=E):E=e[16];const F=E;let R;e[17]!==C||e[18]!==y||e[19]!==d||e[20]!==r||e[21]!==b||e[22]!==p||e[23]!==x||e[24]!==f?(R=async()=>{const U=await C();if(!U){de.error(f("gitView.conflict.noDetailsAvailable"));return}if(!y){de.error(f("gitView.conflict.noActiveSession"),{description:f("gitView.conflict.noActiveSessionDescription")});return}p(U.visibleText,"replace"),x([{text:U.instructionsText,synthetic:!0},{text:U.payloadText,synthetic:!0}]),b("chat"),d?.(),r(!1)},e[17]=C,e[18]=y,e[19]=d,e[20]=r,e[21]=b,e[22]=p,e[23]=x,e[24]=f,e[25]=R):R=e[25];const L=R;let B;e[26]!==C||e[27]!==a||e[28]!==d||e[29]!==r||e[30]!==g||e[31]!==b||e[32]!==f?(B=async()=>{const U=await C();if(!U){de.error(f("gitView.conflict.noDetailsAvailable"));return}g({directoryOverride:a,initialPrompt:U.visibleText,syntheticParts:[{text:U.instructionsText,synthetic:!0},{text:U.payloadText,synthetic:!0}]}),b("chat"),d?.(),r(!1)},e[26]=C,e[27]=a,e[28]=d,e[29]=r,e[30]=g,e[31]=b,e[32]=f,e[33]=B):B=e[33];const V=B;let M,ee,se,J,K,Z,re,pe,Se,te,Ne,Y,G,q,oe,le,ve,Ee,_e,Oe,Me,he;if(e[34]!==w||e[35]!==m||e[36]!==y||e[37]!==T||e[38]!==F||e[39]!==L||e[40]!==V||e[41]!==h||e[42]!==j||e[43]!==r||e[44]!==n||e[45]!==c||e[46]!==f){const U=f(c==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),z=w?.unmergedFiles||m;se=Ls,Me=n,he=r,ee=Fs,Oe="max-w-md w-[calc(100vw-2rem)]",q="flex flex-col gap-4 overflow-hidden";let be;e[69]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx(I,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=be):be=e[69];const ge=s.jsxs("div",{className:"flex items-center gap-2",children:[be,s.jsx($s,{children:f("gitView.conflict.detectedTitle",{operation:U})})]});let _;e[70]!==c||e[71]!==f?(_=f("gitView.conflict.detectedDescription",{operation:c}),e[70]=c,e[71]=f,e[72]=_):_=e[72];let ye;e[73]!==_?(ye=s.jsx(an,{children:_}),e[73]=_,e[74]=ye):ye=e[74],e[75]!==ge||e[76]!==ye?(oe=s.jsxs(Us,{children:[ge,ye]}),e[75]=ge,e[76]=ye,e[77]=oe):oe=e[77],e[78]!==h||e[79]!==f?(le=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]=le):le=e[80],e[81]!==j||e[82]!==f?(ve=j&&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:j})}),e[81]=j,e[82]=f,e[83]=ve):ve=e[83],e[84]!==z||e[85]!==f?(Ee=z.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:z.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:z.map(Ew)})})]}),e[84]=z,e[85]=f,e[86]=Ee):Ee=e[86],e[87]!==w||e[88]!==f?(_e=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]=_e):_e=e[89],Ne="flex flex-col gap-2 pt-2";let $;e[90]!==V?($=()=>{V()},e[90]=V,e[91]=$):$=e[91];const Ie=h||!w;let je;e[92]!==h?(je=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]=je):je=e[93];let Fe;e[94]!==f?(Fe=f("gitView.conflict.resolveNewSession"),e[94]=f,e[95]=Fe):Fe=e[95],e[96]!==$||e[97]!==Ie||e[98]!==je||e[99]!==Fe?(Y=s.jsxs($e,{variant:"default",onClick:$,disabled:Ie,className:"w-full gap-2",children:[je,Fe]}),e[96]=$,e[97]=Ie,e[98]=je,e[99]=Fe,e[100]=Y):Y=e[100];let Ae;e[101]!==L?(Ae=()=>{L()},e[101]=L,e[102]=Ae):Ae=e[102];const ne=h||!w||!y;let P;e[103]!==h?(P=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]=P):P=e[104];let me;e[105]!==f?(me=f("gitView.conflict.resolveCurrentSession"),e[105]=f,e[106]=me):me=e[106],e[107]!==Ae||e[108]!==ne||e[109]!==P||e[110]!==me?(G=s.jsxs($e,{variant:"outline",onClick:Ae,disabled:ne,className:"w-full gap-2",children:[P,me]}),e[107]=Ae,e[108]=ne,e[109]=P,e[110]=me,e[111]=G):G=e[111],Se="flex gap-2 pt-1";let ae;e[112]!==f?(ae=f("gitView.conflict.continueLater"),e[112]=f,e[113]=ae):ae=e[113],e[114]!==F||e[115]!==ae?(te=s.jsx($e,{variant:"ghost",size:"sm",onClick:F,className:"flex-1",children:ae}),e[114]=F,e[115]=ae,e[116]=te):te=e[116],M=$e,J="destructive",K="sm",Z=T,re="flex-1",pe=f("gitView.conflict.abortOperation",{operation:U}),e[34]=w,e[35]=m,e[36]=y,e[37]=T,e[38]=F,e[39]=L,e[40]=V,e[41]=h,e[42]=j,e[43]=r,e[44]=n,e[45]=c,e[46]=f,e[47]=M,e[48]=ee,e[49]=se,e[50]=J,e[51]=K,e[52]=Z,e[53]=re,e[54]=pe,e[55]=Se,e[56]=te,e[57]=Ne,e[58]=Y,e[59]=G,e[60]=q,e[61]=oe,e[62]=le,e[63]=ve,e[64]=Ee,e[65]=_e,e[66]=Oe,e[67]=Me,e[68]=he}else M=e[47],ee=e[48],se=e[49],J=e[50],K=e[51],Z=e[52],re=e[53],pe=e[54],Se=e[55],te=e[56],Ne=e[57],Y=e[58],G=e[59],q=e[60],oe=e[61],le=e[62],ve=e[63],Ee=e[64],_e=e[65],Oe=e[66],Me=e[67],he=e[68];let Ce;e[117]!==M||e[118]!==J||e[119]!==K||e[120]!==Z||e[121]!==re||e[122]!==pe?(Ce=s.jsx(M,{variant:J,size:K,onClick:Z,className:re,children:pe}),e[117]=M,e[118]=J,e[119]=K,e[120]=Z,e[121]=re,e[122]=pe,e[123]=Ce):Ce=e[123];let xe;e[124]!==Se||e[125]!==te||e[126]!==Ce?(xe=s.jsxs("div",{className:Se,children:[te,Ce]}),e[124]=Se,e[125]=te,e[126]=Ce,e[127]=xe):xe=e[127];let ue;e[128]!==Ne||e[129]!==Y||e[130]!==G||e[131]!==xe?(ue=s.jsxs("div",{className:Ne,children:[Y,G,xe]}),e[128]=Ne,e[129]=Y,e[130]=G,e[131]=xe,e[132]=ue):ue=e[132];let H;e[133]!==q||e[134]!==oe||e[135]!==le||e[136]!==ve||e[137]!==Ee||e[138]!==_e||e[139]!==ue?(H=s.jsxs("div",{className:q,children:[oe,le,ve,Ee,_e,ue]}),e[133]=q,e[134]=oe,e[135]=le,e[136]=ve,e[137]=Ee,e[138]=_e,e[139]=ue,e[140]=H):H=e[140];let ce;e[141]!==ee||e[142]!==Oe||e[143]!==H?(ce=s.jsx(ee,{className:Oe,children:H}),e[141]=ee,e[142]=Oe,e[143]=H,e[144]=ce):ce=e[144];let fe;return e[145]!==se||e[146]!==Me||e[147]!==he||e[148]!==ce?(fe=s.jsx(se,{open:Me,onOpenChange:he,children:ce}),e[145]=se,e[146]=Me,e[147]=he,e[148]=ce,e[149]=fe):fe=e[149],fe};function Dw(t){return t.openNewSessionDraft}function Iw(t){return t.currentSessionId}function Pw(t){return t.setPendingInputText}function Tw(t){return t.setPendingSyntheticParts}function Rw(t){return t.setActiveMainTab}function Ew(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const Mw=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:o})=>{const{t:a}=At(),[c,l]=i.useState(!0),[d,u]=i.useState(!1),m=a(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),f=async()=>{u(!0);try{await o(c),e(!1)}catch(y){const p=y instanceof Error?y.message:`Failed to ${n}`;de.error(p)}finally{u(!1)}},g=()=>{d||e(!1)};return s.jsx(Ls,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(Fs,{className:"max-w-md",children:[s.jsxs(Us,{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($s,{children:a("gitView.stash.title")})]}),s.jsx(an,{children:a("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:a("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:a("gitView.stash.stepStash")}),s.jsxs("li",{children:[a(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",a(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),c&&s.jsx("li",{children:a("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(Ri,{checked:c,onChange:l,disabled:d,ariaLabel:a("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&l(!c),children:a("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(sr,{className:"gap-2",children:[s.jsx($e,{variant:"ghost",size:"sm",onClick:g,disabled:d,children:a("gitView.common.cancel")}),s.jsx($e,{variant:"default",size:"sm",onClick:f,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.common.processing")]}):a("gitView.stash.confirmButton",{operation:m})})]})]})})},Fw=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:o,hasUnresolvedConflicts:a=!1,isLoading:c=!1})=>{const{t:l}=At(),[d,u]=i.useState(null),m=t&&t.head,f=e&&(e.headName||e.onto),g=m?"merge":f?"rebase":null;if(!g)return null;const y=async()=>{u("continue");try{await n()}finally{u(null)}},p=async()=>{u("abort");try{await r()}finally{u(null)}},x=d!==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:[a&&o&&s.jsxs($e,{variant:"outline",size:"sm",onClick:o,disabled:x||c,className:"gap-1.5",children:[s.jsx(I,{name:"sparkling",className:"size-4"}),l("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs($e,{variant:"ghost",size:"sm",onClick:p,disabled:x||c,className:"gap-1.5",children:[d==="abort"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"close",className:"size-4"}),l("gitView.operation.abort")]}),!a&&s.jsxs($e,{variant:"default",size:"sm",onClick:y,disabled:x||c,className:"gap-1.5",children:[d==="continue"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"}),l("gitView.operation.continue")]})]}),a&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:l("gitView.operation.resolveConflictsHint")})]})})},Lw=t=>{const e=gt.c(104),{currentBranch:n,localBranches:r,remoteBranches:o,onMerge:a,onRebase:c,disabled:l,isOperating:d,operationLogs:u,onOperationComplete:m,mode:f,defaultTargetBranch:g}=t,y=l===void 0?!1:l,p=d===void 0?!1:d,x=u===void 0?[]:u,b=f===void 0?"dialog":f,{t:h}=At(),[N,w]=i.useState(!1),[S,j]=i.useState("merge"),[k,v]=i.useState(null),[D,A]=i.useState(!1),[C,O]=i.useState(""),T=i.useRef(null),E=i.useRef(null),F=y||p,R=n||h("gitView.branch.currentBranchFallback"),L=x.length>0&&x.every(Ow),B=x.some(Bw);let V;e[0]===Symbol.for("react.memo_cache_sentinel")?(V=()=>{E.current&&(E.current.scrollTop=E.current.scrollHeight)},e[0]=V):V=e[0],i.useEffect(V,[x]);let M;if(e[1]!==C||e[2]!==n||e[3]!==r||e[4]!==o){e:{const Ae=C.toLowerCase();let ne;e[6]!==o?(ne=new Set(o.map(Vw).filter(Boolean)),e[6]=o,e[7]=ne):ne=e[7];const P=ne;let me;e[8]!==n||e[9]!==P?(me=Be=>Be!==n&&!P.has(Be),e[8]=n,e[9]=P,e[10]=me):me=e[10];const ae=r.filter(me);if(!Ae){M=ae;break e}M=ae.filter(Be=>Be.toLowerCase().includes(Ae))}e[1]=C,e[2]=n,e[3]=r,e[4]=o,e[5]=M}else M=e[5];const ee=M;let se;if(e[11]!==C||e[12]!==o){e:{const Ae=C.toLowerCase();if(!Ae){se=o;break e}se=o.filter(ne=>ne.toLowerCase().includes(Ae))}e[11]=C,e[12]=o,e[13]=se}else se=e[13];const J=se;let K;e[14]!==g||e[15]!==r||e[16]!==o?(K=()=>g&&(o.includes(g)||r.includes(g))?g:null,e[14]=g,e[15]=r,e[16]=o,e[17]=K):K=e[17];const Z=K;let re;e[18]!==Z||e[19]!==w?(re=()=>{w(!0),v(Z()),j("merge"),O("")},e[18]=Z,e[19]=w,e[20]=re):re=e[20];const pe=re;let Se;e[21]===Symbol.for("react.memo_cache_sentinel")?(Se=Ae=>{v(Ae),A(!1),O("")},e[21]=Se):Se=e[21];const te=Se;let Ne;e[22]!==a||e[23]!==c||e[24]!==S||e[25]!==k?(Ne=()=>{k&&(S==="merge"?a(k):c(k))},e[22]=a,e[23]=c,e[24]=S,e[25]=k,e[26]=Ne):Ne=e[26];const Y=Ne;let G;e[27]!==p||e[28]!==w?(G=()=>{p||(v(null),j("merge"),O(""),w(!1))},e[27]=p,e[28]=w,e[29]=G):G=e[29];const q=G,oe=()=>{p&&!L||(L&&m?.(),v(null),j("merge"),O(""),w(!1))};let le,ve;e[30]!==D?(le=()=>{D||O("")},ve=[D],e[30]=D,e[31]=le,e[32]=ve):(le=e[31],ve=e[32]),i.useEffect(le,ve);let Ee,_e;e[33]!==b||e[34]!==Z||e[35]!==k?(Ee=()=>{b!=="inline"||k||v(Z())},_e=[b,Z,k],e[33]=b,e[34]=Z,e[35]=k,e[36]=Ee,e[37]=_e):(Ee=e[36],_e=e[37]),i.useEffect(Ee,_e);const he=p?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:E,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:x.map(_w)})}),L?b==="dialog"?s.jsx(sr,{children:s.jsx($e,{variant:"default",size:"sm",onClick:oe,children:h(B?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx($e,{variant:"default",size:"sm",onClick:oe,children:h(B?"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:()=>j("merge"),className:De("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:De("size-4",S==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:De("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:()=>j("rebase"),className:De("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:De("size-4",S==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:De("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(sn,{open:D,onOpenChange:A,modal:!1,children:[s.jsx(en,{asChild:!0,children:s.jsxs($e,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:De("truncate",!k&&"text-muted-foreground"),children:k||h("gitView.branch.selectBranch")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(tn,{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(Oa,{className:"h-full min-h-0",children:[s.jsx(Ba,{ref:T,placeholder:h("gitView.branch.searchPlaceholder"),value:C,onValueChange:O,onKeyDown:$w}),s.jsxs(Va,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(_a,{children:h("gitView.branch.empty")}),ee.length>0&&s.jsx(ri,{heading:h("gitView.branch.localBranches"),children:ee.map(Ae=>s.jsx(oi,{onSelect:()=>te(Ae),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Ae})},`local-${Ae}`))}),ee.length>0&&J.length>0?s.jsx(Gp,{}):null,J.length>0&&s.jsx(ri,{heading:h("gitView.branch.remoteBranches"),children:J.map(Ae=>s.jsx(oi,{onSelect:()=>te(Ae),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Ae})},`remote-${Ae}`))})]})]})})]})]}),k?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:k})," ",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:k})]})})}):null,b==="dialog"?s.jsxs(sr,{className:"gap-2 pt-1",children:[s.jsx($e,{variant:"ghost",size:"sm",onClick:q,children:h("gitView.common.cancel")}),s.jsx($e,{variant:"default",size:"sm",onClick:Y,disabled:!k,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($e,{variant:"destructive",size:"sm",onClick:q,disabled:F,children:h("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx($e,{variant:"default",size:"sm",onClick:Y,disabled:F||!k,children:h(S==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(b==="inline"){let Ae;e[38]!==h?(Ae=h("gitView.branch.updateTitle"),e[38]=h,e[39]=Ae):Ae=e[39];let ne;e[40]!==Ae?(ne=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:Ae}),e[40]=Ae,e[41]=ne):ne=e[41];let P;e[42]!==h?(P=h("gitView.branch.updateDescriptionPrefix"),e[42]=h,e[43]=P):P=e[43];let me;e[44]!==R?(me=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=me):me=e[45];let ae;e[46]!==P||e[47]!==me?(ae=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[P," ",me,"."]}),e[46]=P,e[47]=me,e[48]=ae):ae=e[48];let Be;e[49]!==ne||e[50]!==ae?(Be=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[ne,ae]})}),e[49]=ne,e[50]=ae,e[51]=Be):Be=e[51];let Ge;e[52]!==he?(Ge=s.jsx("div",{className:"pt-3",children:he}),e[52]=he,e[53]=Ge):Ge=e[53];let Ke;return e[54]!==Be||e[55]!==Ge?(Ke=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Be,Ge]}),e[54]=Be,e[55]=Ge,e[56]=Ke):Ke=e[56],Ke}let Ce;e[57]!==p?(Ce=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]=Ce):Ce=e[58];let xe;e[59]!==h?(xe=h("gitView.branch.mergeRebase"),e[59]=h,e[60]=xe):xe=e[60];let ue;e[61]!==xe?(ue=s.jsx("span",{children:xe}),e[61]=xe,e[62]=ue):ue=e[62];let H;e[63]!==pe||e[64]!==F||e[65]!==Ce||e[66]!==ue?(H=s.jsx(Ft,{asChild:!0,children:s.jsxs($e,{variant:"outline",size:"sm",className:"gap-1.5",onClick:pe,disabled:F,children:[Ce,ue]})}),e[63]=pe,e[64]=F,e[65]=Ce,e[66]=ue,e[67]=H):H=e[67];let ce;e[68]!==h?(ce=h("gitView.branch.mergeRebaseTooltip"),e[68]=h,e[69]=ce):ce=e[69];let fe;e[70]!==ce?(fe=s.jsx(Lt,{sideOffset:8,children:ce}),e[70]=ce,e[71]=fe):fe=e[71];let U;e[72]!==H||e[73]!==fe?(U=s.jsxs(Mt,{children:[H,fe]}),e[72]=H,e[73]=fe,e[74]=U):U=e[74];let z;e[75]!==oe||e[76]!==w?(z=Ae=>{Ae?w(!0):oe()},e[75]=oe,e[76]=w,e[77]=z):z=e[77];let be;e[78]!==h?(be=h("gitView.branch.updateTitle"),e[78]=h,e[79]=be):be=e[79];let ge;e[80]!==be?(ge=s.jsx($s,{children:be}),e[80]=be,e[81]=ge):ge=e[81];let _;e[82]!==B||e[83]!==p||e[84]!==S||e[85]!==L||e[86]!==h||e[87]!==R?(_=p?h(L?B?"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]=B,e[83]=p,e[84]=S,e[85]=L,e[86]=h,e[87]=R,e[88]=_):_=e[88];let ye;e[89]!==_?(ye=s.jsx(an,{children:_}),e[89]=_,e[90]=ye):ye=e[90];let $;e[91]!==ge||e[92]!==ye?($=s.jsxs(Us,{children:[ge,ye]}),e[91]=ge,e[92]=ye,e[93]=$):$=e[93];let Ie;e[94]!==he||e[95]!==$?(Ie=s.jsxs(Fs,{className:"max-w-md",children:[$,he]}),e[94]=he,e[95]=$,e[96]=Ie):Ie=e[96];let je;e[97]!==N||e[98]!==z||e[99]!==Ie?(je=s.jsx(Ls,{open:N,onOpenChange:z,children:Ie}),e[97]=N,e[98]=z,e[99]=Ie,e[100]=je):je=e[100];let Fe;return e[101]!==U||e[102]!==je?(Fe=s.jsxs(s.Fragment,{children:[U,je]}),e[101]=U,e[102]=je,e[103]=Fe):Fe=e[103],Fe};function Ow(t){return t.status==="done"||t.status==="error"}function Bw(t){return t.status==="error"}function Vw(t){return t.slice(t.indexOf("/")+1)}function _w(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:De("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 $w(t){return t.stopPropagation()}const zw=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:o})=>{const a=[];let c=!1;return{enqueue:d=>{const u=a[a.length-1];if(u?.directory===d.directory&&u.direction===d.direction){d.paths.forEach(m=>u.paths.add(m));return}a.push(d)},flush:()=>{if(c)return;const d=a.shift();if(!d)return;c=!0;const u={directory:d.directory,direction:d.direction,paths:Array.from(d.paths),rollback:d.rollback};(async()=>{try{await t(u),e(u)}catch(m){n(u,m)}finally{r(u.paths),c=!1,a.length>0&&o()}})()},clear:()=>{a.length=0},size:()=>a.length,isRunning:()=>c}},gu="oc.git.actionTab",Uw=15e3,Ww=t=>t==="commit"||t==="branch"||t==="pr",Hw=40,Gw=20,xu={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:"},Kw=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,o=n.match(r);if(o){const l=o[1],d=xu[l];if(d)return e.find(u=>u.code===d)||null}const a=n.split(" ")[0],c=xu[a];return c&&e.find(l=>l.code===c)||null},qw=20,Ui=new Map,Yw=(t,e)=>{if(Ui.delete(t),Ui.set(t,e),Ui.size>qw){const n=Ui.keys().next().value;n!==void 0&&Ui.delete(n)}},Vr=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),bu=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Qw=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},Yl=({isActive:t})=>{const{t:e}=At(),{git:n}=Qn(),r=li(),[o,a]=i.useState(null),[c,l]=i.useState(!1),d=dt(Q=>Q.currentSessionId),u=dt(Q=>Q.newSessionDraft),m=dt(Q=>Q.setDraftBootstrapPendingDirectory),f=dt(Q=>Q.worktreeMetadata),g=dt(Q=>Q.availableWorktrees),y=Vr(r),p=i.useMemo(()=>{if(!y)return;const Q=g.find(ke=>Vr(ke.path)===y);if(Q)return Q;for(const ke of f.values())if(Vr(ke.path)===y)return ke},[g,y,f]),x=i.useMemo(()=>{if(d)return f.get(d)??p;if(u?.open)return p},[d,p,u?.open,f]),{profiles:b,globalIdentity:h,defaultGitIdentityId:N,loadProfiles:w,loadGlobalIdentity:S,loadDefaultGitIdentityId:j}=Px(Ol(Q=>({profiles:Q.profiles,globalIdentity:Q.globalIdentity,defaultGitIdentityId:Q.defaultGitIdentityId,loadProfiles:Q.loadProfiles,loadGlobalIdentity:Q.loadGlobalIdentity,loadDefaultGitIdentityId:Q.loadDefaultGitIdentityId}))),k=xc(r??null),v=Ua(r??null),D=Vf(Q=>d?Q.getAttachment(d):void 0),A=D?Kp(D):[],C=D&&!D.degraded&&!D.legacy?D.worktreeRoot??void 0:void 0,O=Iy(r,x,v?.current??void 0),T=Hf(r??null),E=qp(r??null),F=Yp(r??null),R=bc(r??null),L=Qp(r??null),{setActiveDirectory:B,fetchAll:V,ensureAll:M,fetchStatus:ee,fetchBranches:se,fetchLog:J,setLogMaxCount:K,fetchIdentity:Z,prefetchDiffs:re,moveStatusPathsOptimistically:pe,restoreStatus:Se,bumpIndexRevision:te}=xn(Ol(Q=>({setActiveDirectory:Q.setActiveDirectory,fetchAll:Q.fetchAll,ensureAll:Q.ensureAll,fetchStatus:Q.fetchStatus,fetchBranches:Q.fetchBranches,fetchLog:Q.fetchLog,setLogMaxCount:Q.setLogMaxCount,fetchIdentity:Q.fetchIdentity,prefetchDiffs:Q.prefetchDiffs,moveStatusPathsOptimistically:Q.moveStatusPathsOptimistically,restoreStatus:Q.restoreStatus,bumpIndexRevision:Q.bumpIndexRevision}))),Ne=Re(Q=>Q.isMobile),Y=Re(Q=>Q.openContextDiff),G=Re(Q=>Q.navigateToDiff),q=Re(Q=>Q.setRightSidebarOpen),oe=i.useRef(null),le=i.useRef(null),ve=i.useRef(null),Ee=i.useRef(null),_e=i.useRef(!0);i.useEffect(()=>()=>{_e.current=!1},[]);const Oe=i.useCallback(()=>{le.current!==null&&(window.clearTimeout(le.current),le.current=null)},[]),Me=i.useCallback(Q=>{Oe(),le.current=window.setTimeout(()=>{le.current=null,Vr(Q)===Vr(r)&&ee(Q,n,{silent:!0})},Uw)},[Oe,r,ee,n]);i.useEffect(()=>Oe,[Oe]);const he=i.useCallback(()=>{ve.current!==null&&(window.clearTimeout(ve.current),ve.current=null)},[]),Ce=i.useCallback(()=>{ve.current===null&&(ve.current=window.setTimeout(()=>{ve.current=null,Ee.current?.()},0))},[]),xe=i.useCallback(async(Q,ke,Pe)=>{if(ke==="stage"){if(n.stageGitFiles){await n.stageGitFiles(Q,Pe);return}await Promise.all(Pe.map(ze=>n.stageGitFile(Q,ze)));return}if(n.unstageGitFiles){await n.unstageGitFiles(Q,Pe);return}await Promise.all(Pe.map(ze=>n.unstageGitFile(Q,ze)))},[n]),ue=i.useMemo(()=>zw({runMutation:({directory:Q,direction:ke,paths:Pe})=>xe(Q,ke,Pe),onMutationComplete:({directory:Q})=>{te(Q),Me(Q)},onMutationError:({directory:Q,direction:ke,rollback:Pe},ze)=>{Pe?.(),te(Q),Me(Q);const pt=e(ke==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");de.error(ze instanceof Error?ze.message:pt)},onPathsComplete:Q=>{Nt(ke=>{const Pe=new Set(ke);return Q.forEach(ze=>Pe.delete(ze)),Pe})},scheduleFlush:Ce}),[te,xe,Ce,Me,e]);i.useEffect(()=>(Ee.current=ue.flush,()=>{Ee.current=null}),[ue]),i.useEffect(()=>()=>ue.clear(),[ue]),i.useEffect(()=>he,[he]),i.useEffect(()=>{if(!t)return;if(!r){a(null),l(!1);return}let Q=!1,ke=null;const Pe=async()=>{try{const ze=await Xp(r);if(Q)return;a(ze.status),ze.status==="pending"&&(ke=window.setTimeout(()=>{Pe()},500))}catch{Q||a(null)}};return Pe(),()=>{Q=!0,ke!==null&&window.clearTimeout(ke)}},[t,r]),i.useEffect(()=>{const Q=oe.current;oe.current=o,!(!r||!n)&&(Q==="pending"&&o==="ready"&&(l(!0),V(r,n).finally(()=>{window.setTimeout(()=>{l(!1)},1200)})),o==="failed"&&(m(null),l(!1)))},[r,V,n,m,o]);const H=Vr(u?.bootstrapPendingDirectory??null),ce=!!(r&&H&&H===Vr(r)),U=!!(r&&(o==="pending"||ce))||c,z=i.useMemo(()=>r?Ui.get(r)??null:null,[r]),be=es(Q=>Q.settingsGitmojiEnabled),[ge,_]=i.useState(null),{gitmojis:ye}=Dy(be);i.useEffect(()=>{const Q=C||O?.projectDirectory;if(!Q){_(null);return}let ke=!1;return Wa(Q).then(Pe=>{if(ke)return;const ze=Pe.trim();_(ze&&ze!=="HEAD"?ze:null)}).catch(()=>{ke||_(null)}),()=>{ke=!0}},[C,O?.projectDirectory]);const[$,Ie]=i.useState(z?.commitMessage??""),[je,Fe]=i.useState([]),[Ae,ne]=i.useState(!1),P=i.useRef(null),[me,ae]=i.useState(null),[Be,Ge]=i.useState(!1),[Ke,Qe]=i.useState(null),[st,ut]=i.useState(25),[vt,Ve]=i.useState(!1),{triggerFireworks:tt}=Ny(),nt=i.useRef(new Map),xt=i.useRef(0),Rt=i.useCallback(()=>{xt.current+=1,_e.current&&Ve(!0)},[]),bt=i.useCallback(()=>{xt.current=Math.max(0,xt.current-1),_e.current&&xt.current===0&&Ve(!1)},[]),[ot,at]=i.useState(new Set),[Ut,Nt]=i.useState(new Set),[_t,Le]=i.useState(!1),[Dt,Ot]=i.useState(0),[mt,Et]=i.useState(!1),[qt,Vt]=i.useState(z?.generatedHighlights??[]),Wt=Ut.size>0||ue.size()>0||ue.isRunning(),Yt=i.useCallback(()=>{const Q=P.current;Q&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q.scrollTo({top:Q.scrollHeight,behavior:"smooth"})})})},[]),Bt=C||O?.projectDirectory||null,Ht=v?.current||null,Jt=i.useMemo(()=>{const Q=v?.tracking;return Q?Q.startsWith("origin/"):!0},[v?.tracking]),rs=i.useMemo(()=>{const Q=O?.createdFromBranch,ke=typeof Q=="string"?Q.trim():"",Pe=typeof v?.current=="string"?v.current.trim():"",ze=typeof ge=="string"?ge.trim():"";return ke?ke===Pe&&ke.startsWith("opencode/")&&ze.length>0&&ze!==ke?ze:ke:ze||Pe||"HEAD"},[O?.createdFromBranch,v,ge]),Qt=i.useCallback(()=>{Vt([])},[]),[Xt,bs]=i.useState(new Set),[yt,Ue]=i.useState(new Map),[Ye,Ct]=i.useState(new Set),kt=i.useRef(yt),It=i.useRef(Ye),[rt,ts]=i.useState(null),[hs,Gt]=i.useState(null),[nn,js]=i.useState(""),[ss,Os]=i.useState(null),Ps=i.useMemo(()=>[{id:"commit",label:e("gitView.tabs.commit"),icon:s.jsx(I,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:e("gitView.tabs.update"),icon:s.jsx(I,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:e("gitView.tabs.pr"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[e]),[As,yn]=i.useState(()=>{if(typeof window>"u")return"commit";const Q=window.localStorage.getItem(gu);return Q==="worktree"?"branch":Ww(Q)?Q:"commit"}),[Ys,un]=i.useState([]),[wn,zs]=i.useState(null),[we,Je]=i.useState(null),[wt,Pt]=i.useState([]),[$t,ft]=i.useState(!1),[ls,cs]=i.useState([]),[Ns,ms]=i.useState("merge"),[Qs,He]=i.useState(null),[ns,ws]=i.useState(!1),[vs,Ws]=i.useState(100),Ss=i.useMemo(()=>d?`openchamber.conflict:${d}`:null,[d]),Bs=i.useCallback((Q,ke,Pe)=>{if(!Ss||typeof window>"u")return;const ze={directory:Q,conflictFiles:ke,operation:Pe};window.localStorage.setItem(Ss,JSON.stringify(ze))},[Ss]),fs=i.useCallback(()=>{!Ss||typeof window>"u"||window.localStorage.removeItem(Ss)},[Ss]);i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(gu,As)},[As]),i.useEffect(()=>{if(!Ss||typeof window>"u"||!r)return;const Q=window.localStorage.getItem(Ss);if(Q)try{const ke=JSON.parse(Q);if(ke.directory!==r){window.localStorage.removeItem(Ss);return}cs(ke.conflictFiles??[]),ms(ke.operation??"merge"),ft(!0)}catch{window.localStorage.removeItem(Ss)}},[Ss,r]);const[ci,br]=i.useState(!1),[yr,wr]=i.useState("merge"),[Jn,vr]=i.useState(""),Xn=i.useCallback(Q=>{dr(Q).then(ke=>{if(ke.ok){de.success(e("gitView.toast.commitHashCopied"));return}de.error(e("gitView.toast.copyFailed"))})},[e]),ur=i.useCallback(Q=>{bs(ke=>{const Pe=new Set(ke);return Pe.has(Q)?Pe.delete(Q):Pe.add(Q),Pe})},[]);i.useEffect(()=>{kt.current=yt},[yt]),i.useEffect(()=>{It.current=Ye},[Ye]),i.useEffect(()=>{if(!r||!n)return;const Q=Array.from(Xt).filter(Pe=>!kt.current.has(Pe)&&!It.current.has(Pe));if(Q.length===0)return;let ke=!1;return Ct(Pe=>{const ze=new Set(Pe);for(const pt of Q)ze.add(pt);return It.current=ze,ze}),Promise.all(Q.map(Pe=>n.getCommitFiles(r,Pe).then(ze=>({hash:Pe,files:ze.files})).catch(ze=>(console.error("Failed to fetch commit files:",ze),{hash:Pe,files:[]})))).then(Pe=>{ke||(Ue(ze=>{const pt=new Map(ze);for(const{hash:jt,files:us}of Pe)pt.set(jt,us);return kt.current=pt,pt}),Ct(ze=>{const pt=new Set(ze);for(const{hash:jt}of Pe)pt.delete(jt);return It.current=pt,pt}))}),()=>{ke=!0,Ct(Pe=>{let ze=!1;const pt=new Set(Pe);for(const jt of Q)pt.delete(jt)&&(ze=!0);return ze?(It.current=pt,pt):Pe})}},[Xt,r,n]),i.useEffect(()=>{r&&Yw(r,{directory:r,commitMessage:$,generatedHighlights:qt})},[$,r,qt]),i.useEffect(()=>{t&&(w(),S(),j())},[t,w,S,j]),i.useEffect(()=>{if(!t)return;if(!r||!n?.getRemoteUrl){Gt(null);return}let Q=!1;return n.getRemoteUrl(r).then(ke=>{Q||Gt(ke)}).catch(()=>{Q||Gt(null)}),()=>{Q=!0}},[t,r,n]);const Un=i.useCallback(async()=>{if(!r||!n?.getRemotes){un([]);return}try{const Q=await n.getRemotes(r);_e.current&&un(Q)}catch{_e.current&&un([])}},[r,n]);i.useEffect(()=>{t&&Un()},[t,Un]),i.useEffect(()=>{t&&r&&(B(r),M(r,n))},[t,r,B,M,n]),i.useEffect(()=>{if(t&&r)return Ir.onGitRefreshHint(Q=>{Vr(Q.directory)===Vr(r)&&ee(r,n)})},[t,r,ee,n]);const ps=i.useCallback(async(Q=!0)=>{if(r)try{await Promise.all([ee(r,n),se(r,n)])}catch(ke){if(Q){const Pe=ke instanceof Error?ke.message:e("gitView.toast.refreshRepositoryFailed");de.error(Pe)}}},[r,n,ee,se,e]),Ds=i.useCallback(async()=>{r&&await J(r,n,st)},[r,n,J,st]),Er=i.useCallback(async()=>{r&&await Z(r,n)},[r,n,Z]);i.useEffect(()=>{if(!t||!r||!n?.hasLocalIdentity||k!==!0)return;const Q=typeof N=="string"?N.trim():"";if(!Q||Q==="global"||nt.current.get(r)===Q)return;let Pe=!1;return(async()=>{try{const pt=await n.hasLocalIdentity?.(r);if(Pe||pt===!0)return;Rt(),await n.setGitIdentity(r,Q),nt.current.set(r,Q),await Er()}catch(pt){console.warn("Failed to auto-apply default git identity:",pt)}finally{Pe||bt()}})(),()=>{Pe=!0}},[t,Rt,r,N,bt,n,k,Er]);const vn=i.useMemo(()=>v?[...v.files??[]].sort((ke,Pe)=>ke.path.localeCompare(Pe.path)):[],[v]),rn=i.useMemo(()=>vn.filter(bu),[vn]),nr=i.useMemo(()=>vn.filter(Qw),[vn]);i.useEffect(()=>{if(!r||vn.length===0)return;const Q=[],ke=new Set,Pe=pt=>{!pt||ke.has(pt)||(ke.add(pt),Q.push(pt))};if(rn.forEach(pt=>Pe(pt.path)),je.forEach(Pe),vn.slice(0,Gw).forEach(pt=>Pe(pt.path)),Q.length===0)return;const ze=window.setTimeout(()=>{re(r,n,Q,{maxFiles:Hw})},120);return()=>{window.clearTimeout(ze)}},[vn,r,n,re,rn,je]);const Mr=Q=>Q?.pushed[0]?.remote||v?.tracking?.split("/")[0]||os.find(ke=>ke.name==="origin")?.name||os[0]?.name||"origin",Gr=async(Q,ke)=>{if(r){ae(Q);try{const Pe=ze=>{const pt=`${ze.name}/`,jt=v?.tracking?.startsWith(pt)?v.tracking.slice(pt.length):void 0;return{remote:ze.name,branch:jt,rebase:!0}};if(Q==="fetch"){if(!ke)throw new Error("No remote available for fetch");await n.gitFetch(r,{remote:ke.name}),de.success(e("gitView.toast.fetchedFromRemote",{name:ke.name}))}else if(Q==="pull"){if(!ke)throw new Error("No remote available for pull");const ze=await n.gitPull(r,Pe(ke));de.success(ze.files.length===1?e("gitView.toast.pulledFilesSingle",{count:ze.files.length,name:ke.name}):e("gitView.toast.pulledFilesPlural",{count:ze.files.length,name:ke.name}))}else if(Q==="push"){const ze=await n.gitPush(r);de.success(e("gitView.toast.pushedToUpstream",{name:Mr(ze)}))}else if(Q==="sync"){if(!ke)throw new Error("No remote available for sync");let ze=0,pt=!1;await n.gitFetch(r,{remote:ke.name});const jt=await n.getGitStatus(r);if((jt.behind??0)>0){if((jt.files?.length??0)>0){de.error(e("gitView.toast.commitOrStashBeforeSync"));return}ze=(await n.gitPull(r,Pe(ke))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),pt=!0),ze>0&&pt?de.success(ze===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:ze,name:ke.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:ze,name:ke.name})):ze>0?de.success(ze===1?e("gitView.toast.pulledFilesSingle",{count:ze,name:ke.name}):e("gitView.toast.pulledFilesPlural",{count:ze,name:ke.name})):pt?de.success(e("gitView.toast.pushedToUpstream",{name:ke.name})):de.success(e("gitView.toast.alreadyUpToDate"))}await ps(!1),await Ds()}catch(Pe){const ze=Pe instanceof Error?Pe.message:e("gitView.toast.syncActionFailed",{action:Q==="sync"?e("gitView.sync.syncChanges"):Q==="pull"?e("gitView.sync.pull"):Q});de.error(ze)}finally{ae(null)}}},Fr=i.useCallback(async Q=>{if(!r)return;const ke=Q.name.trim();if(!ke){de.error(e("gitView.toast.remoteNameRequired"));return}if(ke==="origin"){de.error(e("gitView.toast.cannotRemoveOriginRemote"));return}zs(ke);try{await n.removeRemote(r,{remote:ke}),de.success(e("gitView.toast.removedRemote",{name:ke})),await Promise.all([ps(!1),Un()])}catch(Pe){const ze=Pe instanceof Error?Pe.message:`Failed to remove ${ke}`;de.error(ze)}finally{zs(null)}},[r,n,Un,ps,e]),gs=async(Q={})=>{if(!r)return;if(!$.trim()){de.error(e("gitView.toast.enterCommitMessage"));return}const ke=rn.map(ze=>ze.path).sort();if(ke.length===0){de.error(e("gitView.toast.stageFileToCommit"));return}const Pe=Q.pushAfter?"commitAndPush":"commit";Qe(Pe);try{if(await n.createGitCommit(r,$.trim(),{files:ke,stageFiles:[]}),te(r),de.success(e("gitView.toast.commitCreated")),Ie(""),Qt(),await ps(),Q.pushAfter){const ze=await n.gitPush(r);de.success(e("gitView.toast.pushedToUpstream",{name:Mr(ze)})),tt(),await ps(!1)}else await ps(!1);await Ds(),Ot(ze=>ze+1)}catch(ze){const pt=ze instanceof Error?ze.message:e("gitView.toast.createCommitFailed");de.error(pt)}finally{Qe(null),Q.pushAfter&&ae(null)}},Ts=i.useCallback(async()=>{if(!r)return;const Q=rn.map(ke=>ke.path).sort();if(Q.length===0){de.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:Q.length}),Et(!0);try{const{message:ke}=await Jp(r,Q),Pe=ke.subject?.trim()??"",ze=Array.isArray(ke.highlights)?ke.highlights:[];if(Pe){let pt=Pe;if(be&&ye.length>0){const jt=Kw(Pe,ye);if(jt){const{code:us,emoji:Kt}=jt;!Pe.startsWith(us)&&!Pe.startsWith(Kt)&&(pt=`${us} ${Pe}`)}}Ie(pt)}Vt(ze),Yt()}catch(ke){console.error("[git-generation][browser] GitView generate handler failed",{message:ke instanceof Error?ke.message:String(ke),error:ke});const Pe=ke instanceof Error?ke.message:e("gitView.toast.generateCommitMessageFailed");de.error(Pe)}finally{Et(!1)}},[r,rn,be,ye,Yt,e]),Wn=Q=>Q.reason==="attention"?`${Q.attentionReason} in progress`:Q.reason==="missing"?"worktree is missing":"worktree is invalid",fn=async(Q,ke)=>{if(!r||!v)return;const Pe=nl(D);if(Pe.length>0){de.error(e("gitView.toast.cannotCreateBranch",{reason:Wn(Pe[0])}));return}const ze=v.current??null,pt=ke?.name??"origin";try{await n.createBranch(r,Q,ze??"HEAD"),de.success(e("gitView.toast.createdBranch",{name:Q})),await n.checkoutBranch(r,Q);let jt=!1;try{await n.gitPush(r,{remote:pt,branch:Q,options:["--set-upstream"]}),jt=!0}catch(us){const Kt=us instanceof Error?us.message:`Unable to push new branch to ${pt}.`;de.warning(e("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Kt]})})}await ps(),await Ds(),jt&&de.success(e("gitView.toast.upstreamSet",{branch:Q,remote:pt}))}catch(jt){const us=jt instanceof Error?jt.message:e("gitView.toast.createBranchFailed");throw de.error(us),jt}},X=async(Q,ke)=>{if(!r)return;const Pe=nl(D);if(Pe.length>0){de.error(e("gitView.toast.cannotRenameBranch",{reason:Wn(Pe[0])}));return}try{await n.renameBranch(r,Q,ke),de.success(e("gitView.toast.renamedBranch",{oldName:Q,newName:ke})),await ps(),await Ds()}catch(ze){const pt=ze instanceof Error?ze.message:e("gitView.toast.renameBranchFailed",{oldName:Q,newName:ke});de.error(pt)}},et=async Q=>{if(!r)return;const ke=nl(D);if(ke.length>0){de.error(e("gitView.toast.cannotCheckout",{reason:Wn(ke[0])}));return}const Pe=Q.replace(/^remotes\//,"");if(v?.current!==Pe)try{await n.checkoutBranch(r,Pe),de.success(e("gitView.toast.checkedOut",{name:Pe})),await ps(),await Ds()}catch(ze){const pt=ze instanceof Error?ze.message:e("gitView.toast.checkoutFailed",{name:Pe});de.error(pt)}},ht=async Q=>{if(r){Rt();try{await n.setGitIdentity(r,Q.id),de.success(e("gitView.toast.appliedIdentity",{name:Q.name})),await Er()}catch(ke){const Pe=ke instanceof Error?ke.message:e("gitView.toast.applyIdentityFailed");de.error(Pe)}finally{bt()}}},Tt=i.useMemo(()=>T?.all?T.all.filter(Q=>!Q.startsWith("remotes/")).sort():[],[T]),is=i.useMemo(()=>T?.all?T.all.filter(Q=>Q.startsWith("remotes/")).map(Q=>Q.replace(/^remotes\//,"")).sort():[],[T]),os=i.useMemo(()=>{if(Ys.length>0)return Ys;const Q=new Set,ke=v?.tracking?.trim();ke&&ke.includes("/")&&Q.add(ke.split("/")[0]);for(const Pe of is){const ze=Pe.indexOf("/");ze>0&&Q.add(Pe.slice(0,ze))}return Q.size===0&&hs&&Q.add("origin"),Array.from(Q).map(Pe=>({name:Pe,fetchUrl:hs??"",pushUrl:hs??""}))},[Ys,is,hs,v?.tracking]),ds=i.useMemo(()=>{const Q=new Set(os.map(pt=>pt.name)),ke=pt=>{if(!pt)return"";let jt=pt.trim();if(!jt||jt==="HEAD")return"";if(Tt.includes(jt))return jt;jt.startsWith("refs/heads/")&&(jt=jt.slice(11)),jt.startsWith("heads/")&&(jt=jt.slice(6)),jt.startsWith("remotes/")&&(jt=jt.slice(8));const us=jt.indexOf("/");if(us>0){const Kt=jt.slice(0,us);if(Q.has(Kt)){const on=jt.slice(us+1).trim();on&&(jt=on)}}return jt},Pe=ke(typeof O?.createdFromBranch=="string"?O.createdFromBranch:"");if(Pe)return Pe;const ze=ke(typeof ge=="string"?ge:"");return ze||(Tt.includes("main")?"main":Tt.includes("master")?"master":Tt.includes("develop")?"develop":"main")},[os,Tt,ge,O?.createdFromBranch]),Rs=i.useMemo(()=>os.map(Pe=>Pe.name).map(Pe=>`${Pe}/${ds}`).find(Pe=>is.includes(Pe))??ds,[ds,os,is]),Hs=i.useMemo(()=>{const Q=new Map;h&&Q.set(h.id,h);let ke=null;if(hs)try{let Pe=hs.trim();Pe.startsWith("git@")&&(Pe=`https://${Pe.slice(4).replace(":","/")}`),Pe.endsWith(".git")&&(Pe=Pe.slice(0,-4));const ze=new URL(Pe);ke=ze.hostname+ze.pathname}catch{}for(const Pe of b){if(Pe.authType!=="token"){Q.set(Pe.id,Pe);continue}const ze=Pe.host;if(!ze){Q.set(Pe.id,Pe);continue}if(!ze.includes("/")){Q.set(Pe.id,Pe);continue}ke&&ke===ze&&Q.set(Pe.id,Pe)}return Array.from(Q.values())},[b,h,hs]),kn=i.useMemo(()=>{if(F?.userName&&F?.userEmail){const Q=b.find(ke=>ke.userName===F.userName&&ke.userEmail===F.userEmail);return Q||(h&&h.userName===F.userName&&h.userEmail===F.userEmail?h:{id:"local-config",name:F.userName,userName:F.userName,userEmail:F.userEmail,sshKey:F.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return h??null},[F,b,h]),jr=rn.length,Sr=R||me!==null||Ke!==null,Vs=v?.current??null,Lr=!!(O&&Bt&&Ht&&Jt),ln=!!(r&&Vs),En=!!Vs,Cn=Lr&&Bt&&Ht&&O?{repoRoot:Bt,sourceBranch:Ht,worktreeMetadata:O}:null,jn=i.useMemo(()=>!ln||!r||!Vs?null:{directory:r,branch:Vs},[ln,Vs,r]);i.useEffect(()=>{if(!r||!n||!E?.all?.length||!Vs||!ds||Vs===ds){ts(null);return}let Q=!1;return(async()=>{try{const Pe=await n.getGitLog(r,{from:ds,to:"HEAD",maxCount:st});if(Q)return;const ze=new Set((Pe?.all??[]).map(jt=>jt.hash).filter(jt=>typeof jt=="string"&&jt.length>0));if(ze.size===0){ts(null);return}const pt=E.all.findIndex(jt=>!ze.has(jt.hash));if(pt===0){ts(null);return}if(pt===-1){ts({insertBeforeIndex:E.all.length,branchName:Vs,direction:"up"});return}ts({insertBeforeIndex:pt,branchName:Vs,direction:"up"})}catch{Q||ts(null)}})(),()=>{Q=!0}},[ds,Vs,r,n,E,st]),i.useEffect(()=>{He(null)},[r]),i.useEffect(()=>{if(ss!=="graph"||!r){ss!=="graph"&&He(null);return}let Q=!1;return ws(!0),n.getGitLog(r,{maxCount:vs,all:!0}).then(ke=>{Q||He(ke)}).catch(ke=>{console.error("Failed to fetch graph log:",ke)}).finally(()=>{Q||ws(!1)}),()=>{Q=!0}},[ss,r,vs,n]);const An=i.useCallback((Q,ke)=>{if(!r||Q.length===0)return;const Pe=Array.from(new Set(Q));Nt(pt=>{const jt=new Set(pt);return Pe.forEach(us=>jt.add(us)),jt});const ze=pe(r,Pe,ke);ue.enqueue({directory:r,direction:ke,paths:new Set(Pe),rollback:()=>Se(r,ze)}),Ce()},[r,ue,pe,Se,Ce]),rr=i.useCallback(async Q=>{if(r){at(ke=>{const Pe=new Set(ke);return Pe.add(Q),Pe});try{await n.revertGitFile(r,Q,{scope:"working"}),de.success(e("gitView.toast.revertedFile",{path:Q})),await ps(!1)}catch(ke){const Pe=ke instanceof Error?ke.message:e("gitView.toast.revertFailed");de.error(Pe)}finally{at(ke=>{const Pe=new Set(ke);return Pe.delete(Q),Pe})}}},[r,ps,n,e]),cn=i.useCallback(async(Q,ke,Pe="all")=>{if(!r||Q.length===0)return;const ze=Array.from(new Set(Q));if(_t||ze.some(Kt=>ot.has(Kt)))return;const pt=new Set(rn.map(Kt=>Kt.path)),jt=Pe==="all"&&ze.some(Kt=>pt.has(Kt));ke&&Le(!0),at(Kt=>{const on=new Set(Kt);return ze.forEach(ar=>on.add(ar)),on});const us=[];try{if(await Promise.all(ze.map(async Kt=>{try{await n.revertGitFile(r,Kt,{scope:Pe})}catch(on){us.push({path:Kt,message:on instanceof Error?on.message:e("gitView.toast.revertFailed")})}})),jt&&us.length<ze.length&&te(r),await ps(!1),us.length===0)de.success(ze.length===1?e("gitView.toast.revertedFilesSingle",{count:ze.length}):e("gitView.toast.revertedFilesPlural",{count:ze.length}));else if(us.length===ze.length)de.error(us[0]?.message||e("gitView.toast.revertFailed"));else{const Kt=ze.length-us.length;de.warning(Kt===1?e("gitView.toast.revertedSomeSingle",{success:Kt,failed:us.length}):e("gitView.toast.revertedSomePlural",{success:Kt,failed:us.length}))}}finally{at(Kt=>{const on=new Set(Kt);return ze.forEach(ar=>on.delete(ar)),on}),ke&&Le(!1)}},[te,r,n,_t,ps,ot,rn,e]),di=i.useCallback(async Q=>{await cn(Q,!0)},[cn]),Or=i.useCallback(async Q=>{await cn(Q,!1,"working")},[cn]),Nr=i.useCallback((Q,ke)=>{if(r&&!Ne){Y(r,Q,ke);return}G(Q,ke),Ne&&q(!1)},[r,Ne,G,Y,q]),Mi=i.useCallback(()=>Ge(!0),[]),ui=i.useMemo(()=>{const Q=[];return rn.length>0&&Q.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:rn,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:ke=>e("gitView.changes.unstageFileAria",{path:ke}),onActionFile:ke=>{An([ke],"unstage")},onActionAll:ke=>{An(ke,"unstage")},onViewDiff:ke=>Nr(ke,!0),onRevertFile:rr,showRevertActions:!1,accent:!0}),nr.length>0&&Q.push({id:"unstaged",title:e("gitView.changes.title"),entries:nr,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:ke=>e("gitView.changes.stageFileAria",{path:ke}),onActionFile:ke=>{An([ke],"stage")},onActionAll:ke=>{An(ke,"stage")},onViewDiff:ke=>Nr(ke,!1),onRevertFile:rr}),Q},[rr,Nr,An,rn,e,nr]),Dn=i.useCallback(Q=>{if(Q.length===0)return;const ke=Q.map(Pe=>Pe.trim()).filter(Boolean);if(ke.length===0){Qt();return}Ie(Pe=>{const ze=Pe.trim(),pt=ze.length>0?`
|
|
11
|
+
|
|
12
|
+
`:"";return`${ze}${pt}${ke.join(`
|
|
13
|
+
`)}`.trim()}),Qt()},[Qt]),ir=i.useCallback((Q,ke)=>{const Pe=ke||Q;Ie(ze=>{const pt=ze.trimStart();return pt.startsWith(Q)||ke&&pt.startsWith(ke)?ze:`${Pe.endsWith(" ")?Pe:`${Pe} `}${ze}`.trimStart()}),js(""),ne(!1)},[]),Sn=i.useCallback(Q=>{const ke=Q instanceof Error?Q.message.toLowerCase():"";return ke.includes("uncommitted changes")||ke.includes("local changes")||ke.includes("your local changes would be overwritten")||ke.includes("please commit your changes or stash them")||ke.includes("cannot rebase: you have unstaged changes")||ke.includes("error: cannot pull with rebase")},[]),Hn=i.useCallback((Q,ke)=>{Pt(Pe=>[...Pe,{message:Q,status:ke,timestamp:Date.now()}])},[]),mn=i.useCallback((Q,ke)=>{Pt(Pe=>{if(Pe.length===0)return Pe;const ze=[...Pe];return ze[ze.length-1]={...ze[ze.length-1],status:Q,...ke?{message:ke}:{}},ze})},[]),fi=i.useCallback(()=>{Pt([])},[]),Fi=i.useCallback(()=>{Pt([]),Je(null)},[]),Mn=i.useCallback(Q=>{const ke=Q.trim(),Pe=new Set(os.map(pt=>pt.name)),ze=ke.indexOf("/");if(ze>0){const pt=ke.slice(0,ze),jt=ke.slice(ze+1);if(Pe.has(pt)&&jt)return{branch:ke,remote:pt,remoteBranch:jt}}for(const pt of os){const jt=`${pt.name}/${ke}`;if(is.includes(jt))return{branch:jt,remote:pt.name,remoteBranch:ke}}return{branch:ke,remote:null,remoteBranch:null}},[os,is]),mi=i.useCallback(async Q=>{if(!r)return;Je("merge"),fi();const ke=v?.current,Pe=Mn(Q);try{Pe.remote&&Pe.remoteBranch&&(Hn(`Fetching ${Pe.remote}/${Pe.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:Pe.remote,branch:Pe.remoteBranch}),mn("done",`Fetched ${Pe.remote}/${Pe.remoteBranch}`)),Hn(`Merging ${Pe.branch} into ${ke}...`,"running");const ze=await n.merge(r,{branch:Pe.branch});ze.conflict?(mn("error","Merge conflicts detected"),cs(ze.conflictFiles??[]),ms("merge"),ft(!0),Bs(r,ze.conflictFiles??[],"merge")):(mn("done",`Merged ${Pe.branch} into ${ke}`),fs(),Hn("Refreshing repository status...","running"),await ps(),await Ds(),mn("done","Repository status updated"))}catch(ze){if(Sn(ze))mn("error","Uncommitted changes detected"),wr("merge"),vr(Pe.branch),br(!0);else{const pt=ze instanceof Error?ze.message:`Failed to merge ${Pe.branch}`;mn("error",pt)}}},[r,n,v,Mn,ps,Ds,Sn,Bs,fs,Hn,mn,fi]),Js=i.useCallback(async Q=>{if(!r)return;Je("rebase"),fi();const ke=v?.current,Pe=Mn(Q);try{Pe.remote&&Pe.remoteBranch&&(Hn(`Fetching ${Pe.remote}/${Pe.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:Pe.remote,branch:Pe.remoteBranch}),mn("done",`Fetched ${Pe.remote}/${Pe.remoteBranch}`)),Hn(`Rebasing ${ke} onto ${Pe.branch}...`,"running");const ze=await n.rebase(r,{onto:Pe.branch});ze.conflict?(mn("error","Rebase conflicts detected"),cs(ze.conflictFiles??[]),ms("rebase"),ft(!0),Bs(r,ze.conflictFiles??[],"rebase")):(mn("done",`Rebased ${ke} onto ${Pe.branch}`),fs(),Hn("Refreshing repository status...","running"),await ps(),await Ds(),mn("done","Repository status updated"))}catch(ze){if(Sn(ze))mn("error","Uncommitted changes detected"),wr("rebase"),vr(Pe.branch),br(!0);else{const pt=ze instanceof Error?ze.message:`Failed to rebase onto ${Pe.branch}`;mn("error",pt)}}},[r,n,v,Mn,ps,Ds,Sn,Bs,fs,Hn,mn,fi]),or=i.useCallback(async()=>{if(r)try{Ns==="merge"?(await n.abortMerge(r),de.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),de.success(e("gitView.toast.rebaseAborted"))),fs(),await ps(),await Ds()}catch(Q){const ke=Q instanceof Error?Q.message:`Failed to abort ${Ns}`;de.error(ke)}},[r,n,Ns,ps,Ds,fs,e]),hi=i.useMemo(()=>v?.files?v.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,[v?.files]),Li=i.useCallback(async()=>{if(r)try{const Q=!!v?.mergeInProgress?.head,ke=!!(v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto);if(Q){const Pe=await n.continueMerge(r);Pe.conflict?(cs(Pe.conflictFiles??[]),ms("merge"),ft(!0),Bs(r,Pe.conflictFiles??[],"merge"),de.error(e("gitView.toast.mergeConflictsDetected"))):(fs(),de.success(e("gitView.toast.mergeCompleted")),await ps(),await Ds())}else if(ke){const Pe=await n.continueRebase(r);Pe.conflict?(cs(Pe.conflictFiles??[]),ms("rebase"),ft(!0),Bs(r,Pe.conflictFiles??[],"rebase"),de.error(e("gitView.toast.rebaseConflictsDetected"))):(fs(),de.success(e("gitView.toast.rebaseStepCompleted")),await ps(),await Ds())}}catch(Q){const ke=Q instanceof Error?Q.message:e("gitView.toast.continueOperationFailed");de.error(ke)}},[r,n,v,ps,Ds,Bs,fs,e]),Kr=i.useCallback(async()=>{if(r)try{!!v?.mergeInProgress?.head?(await n.abortMerge(r),de.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),de.success(e("gitView.toast.rebaseAborted"))),fs(),await ps(),await Ds()}catch(Q){const ke=Q instanceof Error?Q.message:e("gitView.toast.abortOperationFailed");de.error(ke)}},[r,n,v,ps,Ds,fs,e]),pi=i.useCallback(()=>{if(!r)return;const ke=!!v?.mergeInProgress?.head?"merge":"rebase",Pe=v?.files?.filter(ze=>ze.index==="U"||ze.working_dir==="U").map(ze=>ze.path)??[];Pe.length>0&&cs(Pe),ms(ke),ft(!0)},[r,v]),Xs=i.useCallback(async Q=>{if(!r)return;const ke=v?.current,Pe=yr,ze=Jn,pt=(v?.files??[]).some(bu);try{await n.stash(r,{message:`Auto-stash before ${Pe} with ${ze}`,includeUntracked:!0}),pt&&te(r)}catch(Kt){const on=Kt instanceof Error?Kt.message:"Failed to stash changes";de.error(on);return}let jt=!1,us=!1;try{if(Pe==="merge"){const Kt=await n.merge(r,{branch:ze});Kt.conflict?(us=!0,cs(Kt.conflictFiles??[]),ms("merge"),ft(!0)):(jt=!0,de.success(e("gitView.toast.mergedIntoBranch",{branch:ze,currentBranch:ke||""})))}else{const Kt=await n.rebase(r,{onto:ze});Kt.conflict?(us=!0,cs(Kt.conflictFiles??[]),ms("rebase"),ft(!0)):(jt=!0,de.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:ke||"",branch:ze})))}if(Q&&jt)try{await n.stashPop(r),te(r),de.success(e("gitView.toast.stashedRestored"))}catch(Kt){const on=Kt instanceof Error?Kt.message:e("gitView.toast.restoreStashFailed");de.error(on)}else Q&&us&&de.info(e("gitView.toast.restoreStashManually"));await ps(),await Ds()}catch(Kt){if(Q)try{await n.stashPop(r),te(r)}catch{}throw Kt}},[te,r,n,v,yr,Jn,ps,Ds,e]),Oi=i.useCallback(Q=>{ut(Q),r&&(K(r,Q),J(r,n,Q))},[r,J,n,K]),uo=i.useCallback(Q=>{Ws(Q)},[]),fo=i.useCallback(()=>{Os(null),r&&(ee(r,n),se(r,n),J(r,n,st))},[r,ee,se,J,st,n]),Bi=i.useCallback(Q=>{if(Q.conflict){if(Q.operation==="cherry-pick"||Q.operation==="revert"){de.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:Q.conflictFiles?.join(", ")??"unknown files"})}),r&&(ee(r,n),se(r,n),J(r,n,st));return}cs(Q.conflictFiles??[]),ms(Q.operation),ft(!0),r&&Bs(r,Q.conflictFiles??[],Q.operation)}},[e,cs,ms,ft,Bs,r,ee,se,J,st,n]);return r?k===null||k===!0&&!v?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:e("gitView.loading.checkingRepository")})]})}):k===!1?U?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:e("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("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:e("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.notGitRepositoryDescription")}),A.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:De("flex h-full flex-col overflow-hidden"),children:[s.jsx(Tx,{status:v,localBranches:Tt,remoteBranches:is,branchInfo:T?.branches,syncAction:me,remotes:os,onFetch:Q=>Gr("fetch",Q),onSync:Q=>Gr("sync",Q),onRemoveRemote:Fr,removingRemoteName:wn,onCheckoutBranch:et,onCreateBranch:fn,onRenameBranch:X,activeIdentityProfile:kn,availableIdentities:Hs,onSelectIdentity:ht,isApplyingIdentity:vt,isWorktreeMode:!!O,onOpenHistory:()=>Os("history"),onOpenGraph:()=>Os("graph"),onOpenStashes:Mi,actionTabItems:Ps,activeActionTab:As,onSelectActionTab:Q=>yn(Q)}),r&&(v?.mergeInProgress?.head||v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto)&&s.jsx(Fw,{mergeInProgress:v?.mergeInProgress,rebaseInProgress:v?.rebaseInProgress,onContinue:Li,onAbort:Kr,onResolveWithAI:pi,hasUnresolvedConflicts:hi,isLoading:R}),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:De("min-w-0 min-h-0 h-full flex flex-col"),children:s.jsxs(Vn,{as:za,ref:P,outerClassName:"flex-1 min-h-0",className:De("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[As==="commit"?s.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(vn?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(Rx,{groups:ui,diffStats:v?.diffStats,revertingPaths:ot,isRevertingAll:_t,onVisiblePathsChange:Fe,onRevertAll:di,onRevertDirectory:Or,headerBackgroundClassName:"bg-background"})}),s.jsx(Ex,{stagedCount:jr,commitMessage:$,onCommitMessageChange:Ie,generatedHighlights:qt,onInsertHighlights:Dn,onGenerateMessage:Ts,isGeneratingMessage:mt,onCommit:()=>gs({pushAfter:!1}),onCommitAndPush:()=>gs({pushAfter:!0}),commitAction:Ke,hasPendingIndexMutation:Wt,gitmojiEnabled:be,onOpenGitmojiPicker:()=>ne(!0)})]}):s.jsx(By,{onOpenStashes:()=>Ge(!0)})}):null,As==="branch"?s.jsx("div",{className:"space-y-4",children:En?s.jsxs(s.Fragment,{children:[s.jsx(Lw,{mode:"inline",currentBranch:v?.current,localBranches:Tt,remoteBranches:is,defaultTargetBranch:Rs,onMerge:mi,onRebase:Js,disabled:Sr,isOperating:we!==null,operationLogs:wt,onOperationComplete:Fi}),Cn?s.jsx(Ly,{repoRoot:Cn.repoRoot,sourceBranch:Cn.sourceBranch,worktreeMetadata:Cn.worktreeMetadata,localBranches:Tt,defaultTargetBranch:rs,refreshKey:Dt,onRefresh:()=>{r&&(ee(r,n),se(r,n),J(r,n,st))}},Cn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})}):null,As==="pr"?s.jsx("div",{className:"space-y-4",children:jn?s.jsx(Cw,{directory:jn.directory,branch:jn.branch,baseBranch:ds,trackingBranch:v?.tracking??void 0,remotes:Ys,remoteBranches:is,onGeneratedDescription:Yt}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:e("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:e("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(Ls,{open:ss!==null,onOpenChange:Q=>{Q||Os(null)},children:s.jsxs(Fs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Us,{children:[s.jsx($s,{children:e(ss==="graph"?"gitView.graph.title":"gitView.history.title")}),s.jsx(an,{children:e("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(Ky,{mode:ss==="graph"?"graph":"history",log:ss==="graph"?Qs??E:E,isLogLoading:ss==="graph"&&ns||L,logMaxCount:ss==="graph"?vs:st,onLogMaxCountChange:ss==="graph"?uo:Oi,expandedCommitHashes:Xt,onToggleCommit:ur,commitFilesMap:yt,loadingCommitHashes:Ye,onCopyHash:Xn,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ss==="graph"?null:rt,onConflict:ss==="graph"?Bi:void 0,onActionSuccess:ss==="graph"?fo:void 0})})]})}),s.jsx(Oy,{open:Be,onOpenChange:Ge,directory:r,hasUncommittedChanges:(v?.files?.length??0)>0,hasStagedChanges:rn.length>0,uncommittedFileCount:v?.files?.length??0,onChanged:async Q=>{r&&Q?.affectsIndex&&te(r),await ps(!1),await Ds()}}),s.jsx(Ls,{open:Ae,onOpenChange:ne,children:s.jsxs(Fs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Us,{className:"px-4 pt-4",children:s.jsx($s,{children:e("gitView.gitmoji.title")})}),s.jsxs(Oa,{className:"h-[420px]",children:[s.jsx(Ba,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:nn,onValueChange:js}),s.jsxs(Va,{children:[s.jsx(_a,{children:e("gitView.gitmoji.empty")}),s.jsx(ri,{children:(ye.length===0?[]:ye.filter(Q=>{const ke=nn.trim().toLowerCase();return ke?Q.emoji.includes(ke)||Q.code.toLowerCase().includes(ke)||Q.description.toLowerCase().includes(ke):!0})).map(Q=>s.jsxs(oi,{onSelect:()=>ir(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))})]})]})]})}),r&&s.jsx(Aw,{open:$t,onOpenChange:ft,conflictFiles:ls,directory:r,operation:Ns,onAbort:or,onClearState:fs}),s.jsx(Mw,{open:ci,onOpenChange:br,operation:yr,targetBranch:Jn,onConfirm:Xs})]}):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:e("gitView.empty.selectSessionOrDirectory")})})},Ql=5e3,Jw=(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},yl=(t,e)=>Zp(eg.getState().dictionary,t,e),Xw=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"},Zw=async(t,e)=>{if(t.readFile)return(await t.readFile(e,{optional:!0})).content??"";const n=new URLSearchParams({path:e,optional:"true"}),r=await Cs(`/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()},Ec=async(t,e)=>{try{const n=await Zw(t,e);return Jw(n,Ql)>Ql?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:Xw(n)}}},Mc=t=>{if(t==="too-large"){const e=Ql.toLocaleString(Zi());return yl("contextFileOpen.failure.tooLarge",{count:e})}return yl(t==="missing"?"contextFileOpen.failure.missing":"contextFileOpen.failure.unreadable")},ev=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,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Im=(t,e)=>{const n=Tn(e),r=Tn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},tv=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),sv=new Set(["node_modules"]),nv=t=>sv.has(t),rv=t=>{const e=Tn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},iv=8,Dr=new Map,ov=t=>{const e=Dr.get(t);return e?(e.touchedAt=Date.now(),Dr.delete(t),Dr.set(t,e),e):null},wl=t=>{const e=Dr.get(t);if(e)return e.touchedAt=Date.now(),e;if(Dr.size>=iv){const r=Dr.keys().next().value;r!==void 0&&Dr.delete(r)}const n={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return Dr.set(t,n),n},av=t=>{Dr.delete(t)},Pm=(t,e)=>s.jsx(Ur,{filePath:t,extension:e}),lv=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 a;return e[1]!==o?(a=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=a):a=e[2],a},cv=t=>{const e=gt.c(73),{node:n,root:r,isExpanded:o,isActive:a,status:c,badge:l,permissions:d,downloadFile:u,onSelect:m,onToggle:f,onRevealPath:g,onOpenDialog:y}=t,{t:p}=At(),x=n.type==="directory",{canRename:b,canCreateFile:h,canCreateFolder:N,canDelete:w,canReveal:S}=d,[j,k]=i.useState(!1),[v,D]=i.useState(!1);let A;e[0]!==h||e[1]!==N||e[2]!==w||e[3]!==b||e[4]!==S?(A=G=>{!b&&!h&&!N&&!w&&!S||(G?.preventDefault(),D(!0))},e[0]=h,e[1]=N,e[2]=w,e[3]=b,e[4]=S,e[5]=A):A=e[5];const C=A;let O;e[6]!==x||e[7]!==n||e[8]!==m||e[9]!==f?(O=()=>{x?f(n.path):m(n)},e[6]=x,e[7]=n,e[8]=m,e[9]=f,e[10]=O):O=e[10];const T=O;let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=G=>{G.stopPropagation(),D(!1),k(!0)},e[11]=E):E=e[11];const F=E;let R;e[12]!==h||e[13]!==N||e[14]!==w||e[15]!==b||e[16]!==S||e[17]!==u||e[18]!==x||e[19]!==n||e[20]!==y||e[21]!==g||e[22]!==p?(R=G=>{const{Item:q,Separator:oe}=G;return s.jsxs(s.Fragment,{children:[b&&s.jsxs(q,{onClick:le=>{le.stopPropagation(),y("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.rename")]}),s.jsxs(q,{onClick:le=>{le.stopPropagation(),dr(n.path).then(ve=>{if(ve.ok){de.success(p("sidebarFilesTree.toast.pathCopied"));return}de.error(p("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.copyPath")]}),!x&&u&&s.jsxs(q,{onClick:le=>{le.stopPropagation(),u(n.path).catch(ve=>{console.error("Download failed:",ve),de.error(p("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.save")]}),S&&s.jsxs(q,{onClick:le=>{le.stopPropagation(),g(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",p(yc())]}),x&&(h||N)&&s.jsxs(s.Fragment,{children:[s.jsx(oe,{}),h&&s.jsxs(q,{onClick:le=>{le.stopPropagation(),y("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.newFile")]}),N&&s.jsxs(q,{onClick:le=>{le.stopPropagation(),y("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.newFolder")]})]}),w&&s.jsxs(s.Fragment,{children:[s.jsx(oe,{}),s.jsxs(q,{onClick:le=>{le.stopPropagation(),y("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.delete")]})]})]})},e[12]=h,e[13]=N,e[14]=w,e[15]=b,e[16]=S,e[17]=u,e[18]=x,e[19]=n,e[20]=y,e[21]=g,e[22]=p,e[23]=R):R=e[23];const L=R;let B;e[24]!==n.path||e[25]!==r?(B=G=>{const q=Im(r,n.path);!q||q==="."||(G.dataTransfer.setData("application/x-openchamber-file-path",q),G.dataTransfer.effectAllowed="copy")},e[24]=n.path,e[25]=r,e[26]=B):B=e[26];const V=B;let M;e[27]!==C?(M=s.jsx("div",{className:"group relative flex items-center",onContextMenu:C}),e[27]=C,e[28]=M):M=e[28];const ee=a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let se;e[29]!==ee?(se=De("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",ee,"cursor-grab active:cursor-grabbing"),e[29]=ee,e[30]=se):se=e[30];let J;e[31]!==x||e[32]!==o||e[33]!==n.extension||e[34]!==n.path?(J=x?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"}):Pm(n.path,n.extension),e[31]=x,e[32]=o,e[33]=n.extension,e[34]=n.path,e[35]=J):J=e[35];let K;e[36]!==n.name||e[37]!==n.path?(K=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[36]=n.name,e[37]=n.path,e[38]=K):K=e[38];let Z;e[39]!==x||e[40]!==c?(Z=!x&&c&&s.jsx(lv,{status:c}),e[39]=x,e[40]=c,e[41]=Z):Z=e[41];let re;e[42]!==l||e[43]!==x?(re=x&&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[42]=l,e[43]=x,e[44]=re):re=e[44];let pe;e[45]!==C||e[46]!==V||e[47]!==T||e[48]!==K||e[49]!==Z||e[50]!==re||e[51]!==se||e[52]!==J?(pe=s.jsxs("button",{type:"button",onClick:T,onContextMenu:C,draggable:!0,onDragStart:V,className:se,children:[J,K,Z,re]}),e[45]=C,e[46]=V,e[47]=T,e[48]=K,e[49]=Z,e[50]=re,e[51]=se,e[52]=J,e[53]=pe):pe=e[53];let Se;e[54]!==h||e[55]!==N||e[56]!==w||e[57]!==b||e[58]!==S||e[59]!==j||e[60]!==L||e[61]!==p?(Se=(b||h||N||w||S)&&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(sn,{open:j,onOpenChange:k,children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(en,{asChild:!0,children:s.jsx($e,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:F,title:p("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":p("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:p("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(tn,{align:"end",side:"bottom",onCloseAutoFocus:()=>k(!1),children:L({Item:xs,Separator:Tr})})]})}),e[54]=h,e[55]=N,e[56]=w,e[57]=b,e[58]=S,e[59]=j,e[60]=L,e[61]=p,e[62]=Se):Se=e[62];let te;e[63]!==pe||e[64]!==Se||e[65]!==M?(te=s.jsxs(Ac,{render:M,children:[pe,Se]}),e[63]=pe,e[64]=Se,e[65]=M,e[66]=te):te=e[66];let Ne;e[67]!==L?(Ne=s.jsx(kc,{className:"min-w-[180px]",children:L({Item:Cc,Separator:um})}),e[67]=L,e[68]=Ne):Ne=e[68];let Y;return e[69]!==v||e[70]!==te||e[71]!==Ne?(Y=s.jsxs(Dc,{open:v,onOpenChange:D,children:[te,Ne]}),e[69]=v,e[70]=te,e[71]=Ne,e[72]=Y):Y=e[72],Y},dv=(t,e)=>t.node===e.node&&t.root===e.root&&t.isExpanded===e.isExpanded&&t.isActive===e.isActive&&t.status===e.status&&t.badge===e.badge&&t.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog,uv=i.memo(cv,dv),fv=()=>{const{t}=At(),{files:e}=Qn(),n=li()??"",r=Tn(n.trim()),o=Af(),a=Df(),c=lc(U=>U.searchFiles),l=Re(U=>U.openContextFile),d=Ua(n),[u,m]=i.useState(""),f=Ha(u,200),g=i.useRef(null),[y,p]=i.useState([]),[x,b]=i.useState(!1),[h,N]=i.useState({}),[w,S]=i.useState({}),j=i.useRef(new Set),k=i.useRef(new Set);i.useEffect(()=>{if(!r){N({}),S({}),j.current=new Set;return}const U=ov(r);U?(N({...U.childrenByDir}),S({...U.loadErrorsByDir}),j.current=new Set(U.loadedDirs)):(N({}),S({}),j.current=new Set)},[r]),i.useEffect(()=>{if(!r)return;const U=wl(r);U.childrenByDir=h},[r,h]),i.useEffect(()=>{if(!r)return;const U=wl(r);U.loadErrorsByDir=w},[r,w]),i.useEffect(()=>{if(!r)return;const U=wl(r);U.loadedDirs=new Set(j.current)},[r,h,w]),i.useEffect(()=>()=>{if(!r)return;const U=Dr.get(r);U&&U.loadedDirs.size===0&&Object.keys(U.childrenByDir).length===0&&av(r)},[r]);const v=i.useMemo(()=>[],[]),D=i.useMemo(()=>[],[]),A=gn(U=>r?U.byRoot[r]?.expandedPaths??v:v),C=gn(U=>r?U.byRoot[r]?.selectedPath??null:null),O=gn(U=>U.setSelectedPath),T=gn(U=>U.addOpenPath),E=gn(U=>U.removeOpenPathsByPrefix),F=gn(U=>U.toggleExpandedPath),R=Re(U=>r?U.contextPanelByDirectory[r]?.tabs??D:D),L=i.useMemo(()=>new Set(R.map(U=>U.mode==="file"?U.targetPath:null).filter(U=>typeof U=="string"&&U.length>0).map(U=>Tn(U))),[R]),[B,V]=i.useState(null),[M,ee]=i.useState(null),[se,J]=i.useState(""),[K,Z]=i.useState(!1),re=!!e.writeFile,pe=!!e.createDirectory,Se=!!e.rename,te=!!e.delete,Ne=!!e.revealPath,Y=i.useMemo(()=>({canRename:Se,canCreateFile:re,canCreateFolder:pe,canDelete:te,canReveal:Ne}),[Se,re,pe,te,Ne]),G=i.useCallback(U=>{e.revealPath&&e.revealPath(U).catch(()=>{de.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),q=i.useCallback((U,z)=>{V(U),ee(z),J(U==="rename"&&z.name||""),Z(!1)},[]),oe=i.useCallback((U,z)=>{const be=z.filter(ge=>ge&&typeof ge.name=="string"&&ge.name.length>0).filter(ge=>o||!ge.name.startsWith(".")).filter(ge=>a||!nv(ge.name)).map(ge=>{const _=ge.name,ye=Tn(ge.path||""),$=ye?tv(ye)?ye:Tn(`${U}/${ye}`):Tn(`${U}/${_}`),Ie=ge.isDirectory?"directory":"file",je=Ie==="file"&&_.includes(".")?_.split(".").pop()?.toLowerCase():void 0;return{name:_,path:$,type:Ie,extension:je}});return ev(be)},[a,o]),le=i.useCallback(async(U,z)=>{const be=Tn(U.trim());if(!be||j.current.has(be)||k.current.has(be))return;k.current=new Set(k.current),k.current.add(be);const ge=e.listDirectory?e.listDirectory(be).then(_=>_.entries.map(ye=>({name:ye.name,path:ye.path,isDirectory:ye.isDirectory}))):Bn.listLocalDirectory(be).then(_=>_.map(ye=>({name:ye.name,path:ye.path,isDirectory:ye.isDirectory})));try{const _=await ge;if(z?.())return;const ye=oe(be,_);j.current=new Set(j.current),j.current.add(be),S($=>{if(!$[be])return $;const Ie={...$};return delete Ie[be],Ie}),N($=>({...$,[be]:ye}))}catch(_){if(z?.())return;const ye=_ instanceof Error?_.message:String(_??"");console.error("Failed to load sidebar directory:",_),S($=>({...$,[be]:ye}))}finally{k.current=new Set(k.current),k.current.delete(be)}},[e,oe]),ve=i.useCallback(async()=>{r&&(j.current=new Set,k.current=new Set,S({}),N(U=>Object.keys(U).length===0?U:{}),await le(r))},[le,r]),Ee=i.useCallback(async U=>{if(!U){await ve();return}const z=Tn(U);j.current=new Set(j.current),j.current.delete(z),k.current=new Set(k.current),k.current.delete(z),await le(z)},[le,ve]);i.useEffect(()=>{r&&(j.current=new Set,k.current=new Set,S({}),N(U=>Object.keys(U).length===0?U:{}),le(r))},[le,r,o,a]),i.useEffect(()=>{if(!r||A.length===0)return;const U=A.map(ge=>Tn(ge)).filter(ge=>!!ge&&ge!==r&&ge.startsWith(`${r}/`)&&!j.current.has(ge)&&!k.current.has(ge)).sort((ge,_)=>ge.split("/").length-_.split("/").length);if(U.length===0)return;let z=!1;const be=()=>z;return(async()=>{for(let ge=0;ge<U.length&&!z;ge+=3){const _=U.slice(ge,ge+3);await Promise.all(_.map(ye=>le(ye,be)))}})(),()=>{z=!0}},[A,le,r]),i.useEffect(()=>{if(!n){p([]),b(!1);return}const U=f.trim();if(!U){p([]),b(!1);return}let z=!1;return b(!0),c(n,U,150,{includeHidden:o,respectGitignore:!a,type:"file"}).then(be=>{if(z)return;const _=be.filter(ye=>a||!rv(ye.path)).map(ye=>({name:ye.name,path:Tn(ye.path),type:"file",extension:ye.extension,relativePath:ye.relativePath}));p(_)}).catch(()=>{z||p([])}).finally(()=>{z||b(!1)}),()=>{z=!0}},[n,f,c,o,a]);const _e=i.useMemo(()=>{const U=new Map;if(!d?.files)return U;for(const z of d.files)z.index==="A"||z.working_dir==="?"?U.set(z.path,"git-added"):z.index==="D"?U.set(z.path,"git-deleted"):(z.index==="M"||z.working_dir==="M")&&U.set(z.path,"git-modified");return U},[d]),Oe=i.useMemo(()=>{const U=new Map;if(!d?.files||!r)return U;for(const z of d.files){const be=z.index==="M"||z.working_dir==="M",ge=z.index==="A"||z.working_dir==="?";if(!be&&!ge)continue;const _=z.path.split("/");if(_.length<=1)continue;let ye=r;for(let $=0;$<_.length-1;$++){ye=`${ye}/${_[$]}`;let Ie=U.get(ye);Ie||(Ie={modified:0,added:0},U.set(ye,Ie)),be&&Ie.modified++,ge&&Ie.added++}}return U},[d,r]),Me=i.useCallback(U=>{if(L.has(U))return"open";if(_e.size===0)return null;const z=U.startsWith(r+"/")?U.slice(r.length+1):U;return _e.get(z)??null},[L,_e,r]),he=i.useCallback(U=>{if(Oe.size===0)return null;const z=Oe.get(U);return z&&z.modified+z.added>0?z:null},[Oe]),Ce=i.useCallback(async U=>{if(!r)return;const z=await Ec(e,U.path);if(!z.ok){de.error(Mc(z.reason));return}O(r,U.path),T(r,U.path),l(r,U.path)},[T,e,l,r,O]),xe=i.useCallback(async U=>{const z=Tn(U);r&&(F(r,z),j.current.has(z)||await le(z))},[le,r,F]),ue=i.useCallback(async U=>{if(U?.preventDefault(),!M||!B)return;Z(!0);const z=()=>Z(!1),be=()=>V(null);if(B==="createFile"){if(!se.trim()){de.error(t("sidebarFilesTree.toast.filenameRequired")),z();return}if(!e.writeFile){de.error(t("sidebarFilesTree.toast.writeNotSupported")),z();return}const ge=M.path,_=ge?`${ge}/`:"",ye=Tn(`${_}${se.trim()}`);await e.writeFile(ye,"").then(async $=>{$.success&&(de.success(t("sidebarFilesTree.toast.fileCreated")),await Ee(ge)),be()}).catch(()=>de.error(t("sidebarFilesTree.toast.operationFailed"))).finally(z);return}if(B==="createFolder"){if(!se.trim()){de.error(t("sidebarFilesTree.toast.folderNameRequired")),z();return}const ge=M.path,_=ge?`${ge}/`:"",ye=Tn(`${_}${se.trim()}`);await e.createDirectory(ye).then(async $=>{$.success&&(de.success(t("sidebarFilesTree.toast.folderCreated")),await Ee(ge)),be()}).catch(()=>de.error(t("sidebarFilesTree.toast.operationFailed"))).finally(z);return}if(B==="rename"){if(!se.trim()){de.error(t("sidebarFilesTree.toast.nameRequired")),z();return}if(!e.rename){de.error(t("sidebarFilesTree.toast.renameNotSupported")),z();return}const ge=M.path,_=ge.split("/").slice(0,-1).join("/"),ye=_?`${_}/`:"",$=Tn(`${ye}${se.trim()}`);await e.rename(ge,$).then(async Ie=>{Ie.success&&(de.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await Ee(_),r&&E(r,ge),(C===ge||C&&C.startsWith(`${ge}/`))&&O(r,null)),be()}).catch(()=>de.error(t("sidebarFilesTree.toast.operationFailed"))).finally(z);return}if(B==="delete"){if(!e.delete){de.error(t("sidebarFilesTree.toast.deleteNotSupported")),z();return}const ge=M.path,_=ge.split("/").slice(0,-1).join("/");await e.delete(ge).then(async ye=>{ye.success&&(de.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await Ee(_),r&&E(r,ge),(C===ge||C&&C.startsWith(ge+"/"))&&O(r,null)),be()}).catch(()=>de.error(t("sidebarFilesTree.toast.operationFailed"))).finally(z);return}z()},[B,M,se,e,Ee,E,r,C,O,t]);function H(U,z){const be=h[U]??[];return be.map((ge,_)=>{const ye=ge.type==="directory",$=ye&&A.includes(ge.path),Ie=C===ge.path,je=_===be.length-1;return s.jsxs("li",{className:"relative",children:[z>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),je&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(uv,{node:ge,root:r,isExpanded:$,isActive:Ie,status:ye?void 0:Me(ge.path),badge:ye?he(ge.path):void 0,permissions:Y,downloadFile:e.downloadFile,onSelect:Ce,onToggle:xe,onRevealPath:G,onOpenDialog:q}),ye&&$&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[w[ge.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:w[ge.path],children:w[ge.path]}),s.jsxs($e,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ee(ge.path)},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,H(ge.path,z+1)]})]},ge.path)})}const ce=!!(r&&h[r]),fe=r?w[r]:null;return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"relative min-w-0 flex-1",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(bn,{ref:g,value:u,onChange:U=>m(U.target.value),placeholder:t("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),u.trim().length>0?s.jsx("button",{type:"button","aria-label":t("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:()=>{m(""),g.current?.focus()},children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]}),re&&s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>q("createFile",{path:n,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFileTitle"),"aria-label":t("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),pe&&s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>q("createFolder",{path:n,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFolderTitle"),"aria-label":t("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>{ve()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(I,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]})]}),s.jsx(Vn,{outerClassName:"flex-1 min-h-0",className:"p-2",children:s.jsx("ul",{className:"flex flex-col",children:x?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"}),t("sidebarFilesTree.state.searching")]}):y.length>0?y.map(U=>{const z=C===U.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Ce(U),draggable:!0,onDragStart:be=>{const ge=U.relativePath||Im(r??"",U.path);!ge||ge==="."||(be.dataTransfer.setData("application/x-openchamber-file-path",ge),be.dataTransfer.effectAllowed="copy")},className:De("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",z?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:U.path,children:[Pm(U.path,U.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:U.relativePath??U.path})]})},U.path)}):fe?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:fe}),s.jsxs($e,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ve()},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):ce&&r?H(r,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),s.jsx(Ls,{open:!!B,onOpenChange:U=>!U&&V(null),children:s.jsxs(Fs,{children:[s.jsxs(Us,{children:[s.jsxs($s,{children:[B==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),B==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),B==="rename"&&t("sidebarFilesTree.dialog.rename.title"),B==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(an,{children:[B==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:M?.path??t("sidebarFilesTree.dialog.rootFallback")}),B==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:M?.path??t("sidebarFilesTree.dialog.rootFallback")}),B==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:M?.name??""}),B==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:M?.name??""})]})]}),B!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(bn,{value:se,onChange:U=>J(U.target.value),placeholder:t(B==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:U=>{U.key==="Enter"&&ue()},autoFocus:!0})}),s.jsxs(sr,{children:[s.jsx($e,{variant:"outline",onClick:()=>V(null),disabled:K,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx($e,{variant:B==="delete"?"destructive":"default",onClick:()=>{ue()},disabled:K||B!=="delete"&&!se.trim(),children:K?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):t(B==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},mv=t=>t==="git"||t==="files"||t==="context",hv="files",pv=()=>!(typeof document<"u"&&document.hidden||typeof navigator<"u"&&!navigator.onLine);function gv(t,e,n,r){const o=gt.c(6),{git:a}=Qn(),c=xn(xv),l=!!(t&&a&&e&&n==="git"&&r!=="git");let d,u;o[0]!==t||o[1]!==c||o[2]!==a||o[3]!==l?(d=()=>{if(!l||!t||!a)return;c(t,a);const m=window.setInterval(()=>{pv()&&c(t,a)},1e4);return()=>window.clearInterval(m)},u=[l,t,a,c],o[0]=t,o[1]=c,o[2]=a,o[3]=l,o[4]=d,o[5]=u):(d=o[4],u=o[5]),i.useEffect(d,u)}function xv(t){return t.ensureStatus}const Tm=()=>{const t=gt.c(17),e=ys(yv),n=ys(wv),r=qs(vv),o=xn(jv);let a;e:{if(e){let p;t[0]!==e||t[1]!==n?(p=n.find(x=>x.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=p):p=t[2],a=p;break e}a=n[0]??null}const c=a;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 d=l;let u;e:{if(!c){u=null;break e}let p;t[6]!==c.label||t[7]!==c.path||t[8]!==r?(p=c.label?.trim()||Ei(c.path,r)||c.path,t[6]=c.label,t[7]=c.path,t[8]=r,t[9]=p):p=t[9],u=p}const m=u;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 y;return t[13]!==g||t[14]!==m||t[15]!==d?(y=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-background",children:s.jsx(py,{projectRef:d,projectLabel:m,canCreateWorktree:g})}),t[13]=g,t[14]=m,t[15]=d,t[16]=y):y=t[16],y},bv=()=>{const t=gt.c(57),{t:e}=At(),n=Re(Sv),r=Re(Nv),o=Re(kv),a=Re(Cv),c=li();gv(c,o,n,a);const l=a==="git"?"git":a==="context"?"context":null;let d,u;t[0]!==l||t[1]!==n||t[2]!==r?(d=()=>{l&&n===l&&r(hv)},u=[l,n,r],t[0]=l,t[1]=n,t[2]=r,t[3]=d,t[4]=u):(d=t[3],u=t[4]),i.useEffect(d,u);let m;t[5]!==e?(m=e("layout.rightSidebar.git"),t[5]=e,t[6]=m):m=t[6];let f;t[7]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"}),t[7]=f):f=t[7];let g;t[8]!==m?(g={id:"git",label:m,icon:f},t[8]=m,t[9]=g):g=t[9];let y;t[10]!==e?(y=e("layout.rightSidebar.files"),t[10]=e,t[11]=y):y=t[11];let p;t[12]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(I,{name:"folder-3",className:"h-3.5 w-3.5"}),t[12]=p):p=t[12];let x;t[13]!==y?(x={id:"files",label:y,icon:p},t[13]=y,t[14]=x):x=t[14];let b;t[15]!==e?(b=e("layout.rightSidebar.context"),t[15]=e,t[16]=b):b=t[16];let h;t[17]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(I,{name:"file-list-2",className:"h-3.5 w-3.5"}),t[17]=h):h=t[17];let N;t[18]!==b?(N={id:"context",label:b,icon:h},t[18]=b,t[19]=N):N=t[19];let w;t[20]!==N||t[21]!==g||t[22]!==x?(w=[g,x,N],t[20]=N,t[21]=g,t[22]=x,t[23]=w):w=t[23];const S=w;let j;t[24]!==l||t[25]!==S?(j=l?S.filter(re=>re.id!==l):S,t[24]=l,t[25]=S,t[26]=j):j=t[26];const k=j,v=o&&n==="git"&&l!=="git";let D;t[27]!==r?(D=re=>{mv(re)&&r(re)},t[27]=r,t[28]=D):D=t[28];const A=D;let C;t[29]!==A||t[30]!==n||t[31]!==k?(C=s.jsx("div",{className:"h-9 bg-background pt-1 px-2",children:s.jsx(To,{items:k,activeId:n,onSelect:A,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[29]=A,t[30]=n,t[31]=k,t[32]=C):C=t[32];const O=n!=="git"&&"hidden";let T;t[33]!==O?(T=De("h-full",O),t[33]=O,t[34]=T):T=t[34];let E;t[35]!==v?(E=s.jsx(Yl,{isActive:v}),t[35]=v,t[36]=E):E=t[36];let F;t[37]!==T||t[38]!==E?(F=s.jsx("div",{className:T,children:E}),t[37]=T,t[38]=E,t[39]=F):F=t[39];const R=n!=="files"&&"hidden";let L;t[40]!==R?(L=De("h-full",R),t[40]=R,t[41]=L):L=t[41];let B;t[42]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(fv,{}),t[42]=B):B=t[42];let V;t[43]!==L?(V=s.jsx("div",{className:L,children:B}),t[43]=L,t[44]=V):V=t[44];const M=n!=="context"&&"hidden";let ee;t[45]!==M?(ee=De("h-full",M),t[45]=M,t[46]=ee):ee=t[46];let se;t[47]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Tm,{}),t[47]=se):se=t[47];let J;t[48]!==ee?(J=s.jsx("div",{className:ee,children:se}),t[48]=ee,t[49]=J):J=t[49];let K;t[50]!==F||t[51]!==V||t[52]!==J?(K=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[F,V,J]}),t[50]=F,t[51]=V,t[52]=J,t[53]=K):K=t[53];let Z;return t[54]!==C||t[55]!==K?(Z=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-background",children:[C,K]}),t[54]=C,t[55]=K,t[56]=Z):Z=t[56],Z};function yv(t){return t.activeProjectId}function wv(t){return t.projects}function vv(t){return t.homeDirectory}function jv(t){return t.directories}function Sv(t){return t.rightSidebarTab}function Nv(t){return t.setRightSidebarTab}function kv(t){return t.isRightSidebarOpen}function Cv(t){return t.activeMainTab}const Av=64,Dv=3,yi=new Map,Iv=(t,e,n=Dv)=>{const r=`${t}\0${n}\0${e}`,o=yi.get(r);if(o)return yi.delete(r),yi.set(r,o),o;const a=Tv(e),c=a?Ah(Dh(e,n),{oldFile:{name:t,contents:a.before},newFile:{name:t,contents:a.after}})??wu(t):Ih(Pv(t,e))[0]?.files[0]??wu(t);for(yi.set(r,c);yi.size>Av;){const l=yi.keys().next().value;if(!l)break;yi.delete(l)}return c},Pv=(t,e)=>!e.trim()||e.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(e)?e:`Index: ${t}
|
|
14
|
+
===================================================================
|
|
15
|
+
--- ${t}
|
|
16
|
+
+++ ${t}
|
|
17
|
+
${e}`,Tv=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const e=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(e.length!==1)return;const n=e[0],r=Number.parseInt(n[1]??"",10),o=Number.parseInt(n[2]??"",10);if(r>1||o>1||!Number.isFinite(r)||!Number.isFinite(o))return;const a=(n.index??0)+n[0].length,c=t.slice(a),l=[],d=[];let u;for(const m of c.split(/\r?\n/)){if(m.startsWith("diff --git ")||m.startsWith("@@ "))break;if(m.startsWith("\\")){if(u==="-"||u===" "){const f=l.at(-1);f&&(f.newline=!1)}if(u==="+"||u===" "){const f=d.at(-1);f&&(f.newline=!1)}continue}if(m.startsWith("-")){l.push({text:m.slice(1),newline:!0}),u="-";continue}if(m.startsWith("+")){d.push({text:m.slice(1),newline:!0}),u="+";continue}m.startsWith(" ")&&(l.push({text:m.slice(1),newline:!0}),d.push({text:m.slice(1),newline:!0}),u=" ")}return{before:yu(l),after:yu(d)}},yu=t=>t.map(e=>e.text+(e.newline?`
|
|
18
|
+
`:"")).join(""),wu=t=>Ph({name:t,contents:""},{name:t,contents:""}),Rv=1100,Ev=15e3,vu=500,ju=300,Mv=1e6,Fv=3,Lv=t=>t<=6?t:t<=12?6:t<=25?4:2,Ov=i.memo(()=>{const t=gt.c(4),{t:e}=At();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}),Rm={"?":{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"}},Bv=Rm.M,Vv=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"},Em=t=>{const e=Vv(t);return Rm[e]??Bv},_v=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},Su=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Nu=t=>!!t.working_dir?.trim()||t.index==="?",$v=(t,e)=>ng(t,e),ku=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Cu=(t,e)=>{const n=t.split(`
|
|
19
|
+
`),r=e.split(`
|
|
20
|
+
`),o=Math.min(n.length,r.length);for(let a=0;a<o;a+=1)if(n[a]!==r[a])return a+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},zv=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},Uv=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),Wv=(t,e,n)=>Uv(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:n}:{original:"",modified:"",patch:e,fileDiff:Iv(t,e),contextMode:n},Mm=(t,e,n)=>{const r=t??0,o=e??0;return!r&&!o?null:s.jsxs("span",{className:De("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",n?.className),children:[r?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",r]}):null,o?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",o]}):null]})},Hv=i.memo(t=>{const e=gt.c(43),{scope:n,workingCount:r,stagedCount:o,onScopeChange:a}=t,{t:c}=At(),[l,d]=i.useState(!1),u=n==="staged"?o:r;let m;e[0]!==n||e[1]!==c?(m=c(n==="staged"?"diffView.scope.staged":"diffView.scope.changed"),e[0]=n,e[1]=c,e[2]=m):m=e[2];const f=m;let g;e[3]!==c?(g=c("diffView.scope.selectorAria"),e[3]=c,e[4]=g):g=e[4];let y;e[5]!==u?(y=s.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",u]}),e[5]=u,e[6]=y):y=e[6];let p;e[7]!==f||e[8]!==y?(p=s.jsxs("span",{className:"whitespace-nowrap",children:[f,y]}),e[7]=f,e[8]=y,e[9]=p):p=e[9];let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=x):x=e[10];let b;e[11]!==g||e[12]!==p?(b=s.jsx(en,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":g,children:[p,x]})}),e[11]=g,e[12]=p,e[13]=b):b=e[13];let h;e[14]!==a?(h=T=>{(T==="working"||T==="staged")&&(a?.(T),d(!1))},e[14]=a,e[15]=h):h=e[15];let N;e[16]!==c?(N=c("diffView.scope.changed"),e[16]=c,e[17]=N):N=e[17];let w;e[18]!==N?(w=s.jsx("span",{children:N}),e[18]=N,e[19]=w):w=e[19];let S;e[20]!==r?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:r}),e[20]=r,e[21]=S):S=e[21];let j;e[22]!==S||e[23]!==w?(j=s.jsx(wd,{value:"working",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[w,S]})}),e[22]=S,e[23]=w,e[24]=j):j=e[24];let k;e[25]!==c?(k=c("diffView.scope.staged"),e[25]=c,e[26]=k):k=e[26];let v;e[27]!==k?(v=s.jsx("span",{children:k}),e[27]=k,e[28]=v):v=e[28];let D;e[29]!==o?(D=s.jsx("span",{className:"typography-meta text-muted-foreground",children:o}),e[29]=o,e[30]=D):D=e[30];let A;e[31]!==v||e[32]!==D?(A=s.jsx(wd,{value:"staged",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[v,D]})}),e[31]=v,e[32]=D,e[33]=A):A=e[33];let C;e[34]!==n||e[35]!==j||e[36]!==A||e[37]!==h?(C=s.jsx(tn,{align:"start",className:"w-40",children:s.jsxs(rg,{value:n,onValueChange:h,children:[j,A]})}),e[34]=n,e[35]=j,e[36]=A,e[37]=h,e[38]=C):C=e[38];let O;return e[39]!==l||e[40]!==C||e[41]!==b?(O=s.jsxs(sn,{open:l,onOpenChange:d,children:[b,C]}),e[39]=l,e[40]=C,e[41]=b,e[42]=O):O=e[42],O}),Gv=i.memo(t=>{const e=gt.c(11),{changedFiles:n,selectedFile:r,onSelectFile:o}=t,{t:a}=At();if(n.length===0)return null;let c;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==a){let d;e[5]!==o||e[6]!==r||e[7]!==a?(d=u=>{const m=Em(u),f=r===u.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>o(u.path),className:De("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(Ur,{filePath:u.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:m.color},title:a(m.descriptionKey),"aria-label":a(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:u.path,children:u.path}),Mm(u.insertions,u.deletions)]})},u.path)},e[5]=o,e[6]=r,e[7]=a,e[8]=d):d=e[8],c=n.map(d),e[0]=n,e[1]=o,e[2]=r,e[3]=a,e[4]=c}else c=e[4];let l;return e[9]!==c?(l=s.jsx(Vn,{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}),Kv=i.memo(t=>{const e=gt.c(20),{filePath:n,diff:r,renderSideBySide:o}=t,{t:a}=At(),c=r.original.length>0,l=r.modified.length>0,d=o?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",u=o?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let f;e[1]!==r.original||e[2]!==n||e[3]!==c||e[4]!==u||e[5]!==o||e[6]!==a?(f=c&&s.jsxs("div",{className:u,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a("diffView.image.original")}),s.jsx("img",{src:r.original,alt:a("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]=u,e[5]=o,e[6]=a,e[7]=f):f=e[7];let g;e[8]!==r.modified||e[9]!==n||e[10]!==l||e[11]!==c||e[12]!==u||e[13]!==o||e[14]!==a?(g=l&&s.jsxs("div",{className:u,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:a("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]=u,e[13]=o,e[14]=a,e[15]=g):g=e[15];let y;return e[16]!==d||e[17]!==f||e[18]!==g?(y=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[f,g]})}),e[16]=d,e[17]=f,e[18]=g,e[19]=y):y=e[19],y}),qv=i.memo(t=>{const e=gt.c(16),{filePath:n,diff:r,renderSideBySide:o,wrapLines:a}=t;let c;e[0]!==n?(c=Di(n)||"text",e[0]=n,e[1]=c):c=e[1];const l=c;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Ov,{}),e[2]=m):m=e[2],m}if(eo(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==o?(m=s.jsx(Kv,{filePath:n,diff:r,renderSideBySide:o}),e[3]=r,e[4]=n,e[5]=o,e[6]=m):m=e[6],m}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let u;return e[8]!==r.fileDiff||e[9]!==r.modified||e[10]!==r.original||e[11]!==n||e[12]!==l||e[13]!==o||e[14]!==a?(u=s.jsx("div",{className:"w-full",style:d,children:s.jsx(dm,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:l,fileName:n,renderSideBySide:o,wrapLines:a,layout:"inline"})}),e[8]=r.fileDiff,e[9]=r.modified,e[10]=r.original,e[11]=n,e[12]=l,e[13]=o,e[14]=a,e[15]=u):u=e[15],u}),Yv=i.memo(t=>{const e=gt.c(7),{filePath:n,staged:r,busyAction:o,disabled:a,onAction:c}=t,{t:l}=At();let d;return e[0]!==o||e[1]!==a||e[2]!==n||e[3]!==c||e[4]!==r||e[5]!==l?(d=s.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-lg backdrop-blur-md",children:r?s.jsx(vl,{label:l("gitView.changes.unstageFileAria",{path:n}),icon:"arrow-go-back",loading:o==="unstage",disabled:a,onClick:()=>c("unstage")}):s.jsxs(s.Fragment,{children:[s.jsx(vl,{label:l("gitView.changes.revertFileAria",{path:n}),icon:"arrow-go-back",loading:o==="discard",disabled:a,tone:"failure",onClick:()=>c("discard")}),s.jsx(vl,{label:l("gitView.changes.stageFileAria",{path:n}),icon:"add",loading:o==="stage",disabled:a,tone:"success",onClick:()=>c("stage")})]})}),e[0]=o,e[1]=a,e[2]=n,e[3]=c,e[4]=r,e[5]=l,e[6]=d):d=e[6],d}),vl=t=>{const e=gt.c(14),{label:n,icon:r,loading:o,disabled:a,tone:c,onClick:l}=t,d=c==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",u=c==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]";let m;e[0]!==d||e[1]!==u?(m=De("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",d,u),e[0]=d,e[1]=u,e[2]=m):m=e[2];let f;e[3]!==l?(f=p=>{p.stopPropagation(),l()},e[3]=l,e[4]=f):f=e[4];let g;e[5]!==r||e[6]!==o?(g=o?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:r,className:r==="add"?"size-4":"size-3.5"}),e[5]=r,e[6]=o,e[7]=g):g=e[7];let y;return e[8]!==a||e[9]!==n||e[10]!==m||e[11]!==f||e[12]!==g?(y=s.jsx($e,{variant:"ghost",size:"sm",className:m,disabled:a,title:n,"aria-label":n,onClick:f,children:g}),e[8]=a,e[9]=n,e[10]=m,e[11]=f,e[12]=g,e[13]=y):y=e[13],y},Qv=i.memo(({directory:t,file:e,layout:n,wrapLines:r,isSelected:o,isExpanded:a,isMounted:c,onSelect:l,onExpandedChange:d,registerSectionRef:u,showOpenInEditorAction:m=!1,isOpeningInEditor:f=!1,onOpenInEditor:g,staged:y=!1,loadFullFiles:p=!1})=>{const{t:x}=At(),{git:b}=Qn(),h=xn(i.useCallback(q=>q.directories.get(t)?.diffCache.get(e.path)??null,[t,e.path])),N=xn(q=>q.setDiff),w=xn(q=>q.fetchStatus),S=Re(q=>q.setDiffFileLayout),[j,k]=i.useState(0),[v,D]=i.useState(null),[A,C]=i.useState(!1),[O,T]=i.useState(null),[E,F]=i.useState(!1),[R,L]=i.useState(null),[B,V]=i.useState(null),M=i.useRef(null),ee=i.useRef(null),se=i.useMemo(()=>Em(e),[e]),J=n==="side-by-side",K=p?"full":"patch",Z=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,re=i.useMemo(()=>y?B:R||(h?{original:h.original,modified:h.modified,isBinary:h.isBinary,contextMode:"full"}:null),[h,R,y,B]),pe=re?.contextMode===K,Se=i.useCallback(q=>{ee.current=q,u(e.path,q)},[e.path,u]),te=i.useCallback(q=>{d(e.path,q)},[e.path,d]),Ne=i.useCallback(()=>{l(e.path)},[e.path,l]);i.useEffect(()=>{y?V(null):L(null),D(null),M.current=null},[Z,y]),i.useEffect(()=>{if(!a||!c)return;if(!t||re&&pe){M.current=null,C(!1);return}const q=`${t}::${e.path}::${y?"staged":"unstaged"}::${Z}::${K}::${j}`;if(M.current===q)return;M.current=q,D(null),C(!0);let oe=!1;const le=p?Mv:Fv,ve=eo(e.path)?b.getGitFileDiff(t,{path:e.path,staged:y}):b.getGitDiff(t,{path:e.path,staged:y,contextLines:le}),Ee=Ev,_e=new Promise((Oe,Me)=>{setTimeout(()=>Me(new Error(`Timed out after ${Ee}ms`)),Ee)});return Promise.race([ve,_e]).then(Oe=>{if(!oe){if("diff"in Oe){const Me=Wv(e.path,Oe.diff,K);y?V(Me):L(Me)}else{const Me={original:Oe.original??"",modified:Oe.modified??"",isBinary:Oe.isBinary,contextMode:"full"};y?V(Me):N(t,e.path,Me)}C(!1)}}).catch(Oe=>{if(oe)return;const Me=Oe instanceof Error?Oe.message:String(Oe);D(Me),C(!1)}),()=>{oe=!0,M.current===q&&(M.current=null)}},[K,re,pe,j,t,e.path,Z,b,a,c,p,N,y]);const Y=i.useCallback(()=>{te(!a),Ne()},[te,Ne,a]),G=i.useCallback(async q=>{if(!(!t||O!==null)){T(q);try{q==="stage"?await b.stageGitFile(t,e.path):q==="unstage"?await b.unstageGitFile(t,e.path):await b.revertGitFile(t,e.path,{scope:"working"}),k(oe=>oe+1),await w(t,b)}catch(oe){const le=q==="unstage"?"gitView.toast.unstageFileFailed":q==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.revertFailed";de.error(oe instanceof Error?oe.message:x(le))}finally{T(oe=>oe===q?null:oe)}}},[t,w,e.path,O,b,x]);return s.jsxs("div",{ref:Se,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[s.jsx("div",{className:"sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:s.jsxs("div",{role:"button",tabIndex:0,onClick:Y,onKeyDown:q=>{q.target===q.currentTarget&&(q.key==="Enter"||q.key===" ")&&(q.preventDefault(),Y())},className:De("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",o?"bg-[var(--interactive-selection)]/35":null),children:[s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:a?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"})}),s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:se.color},title:x(se.descriptionKey),"aria-label":x(se.descriptionKey),children:se.code}),s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(Ur,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const q=e.path.lastIndexOf("/");if(q===-1)return s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const oe=e.path.slice(0,q),le=e.path.slice(q+1);return s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:oe}),s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[s.jsx("span",{className:"text-muted-foreground",children:"/"}),s.jsx("span",{className:"text-foreground",children:le})]})]})})()]})})]}),s.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[Mm(e.insertions,e.deletions),m&&g?s.jsx($e,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:x("diffView.actions.openFileInEditorAtChange"),onClick:q=>{q.stopPropagation(),g(e.path,re)},disabled:f,children:f?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}):null,s.jsx(Gf,{mode:J?"side-by-side":"unified",onModeChange:q=>{const oe=q==="side-by-side"?"side-by-side":"inline";S(e.path,oe)},className:"opacity-70"})]})]})}),a&&s.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!c&&!v?s.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,v?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:x("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:v}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>k(q=>q+1),children:x("diffView.actions.retry")})]}):null,c&&A&&!re&&!v?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"}),x("diffView.state.loadingDiff")]}):null,c&&re&&!E&&e.insertions+e.deletions>vu?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:x("diffView.state.largeDiff",{count:e.insertions+e.deletions})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:x("diffView.state.largeDiffDescription")}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>F(!0),children:x("diffView.actions.renderAnyway")})]}):null,c&&re&&(E||e.insertions+e.deletions<=vu)?s.jsxs(s.Fragment,{children:[s.jsx(qv,{filePath:e.path,diff:re,renderSideBySide:J,wrapLines:r}),s.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:s.jsx("div",{className:"pointer-events-auto",children:s.jsx(Yv,{filePath:e.path,staged:y,busyAction:O,disabled:O!==null,onAction:G})})})]}):null]})]})}),Fm=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:n=!1,showOpenInEditorAction:r=!1,diffScope:o="all",onDiffScopeChange:a,targetFilePath:c=null,flushContent:l=!1})=>{const{t:d}=At(),{git:u,files:m}=Qn(),f=li(),{screenWidth:g,isMobile:y}=Rr(),p=xc(f??null),x=Ua(f??null),b=bc(f??null),h=xn(Ve=>Ve.setActiveDirectory),N=xn(Ve=>Ve.ensureStatus),w=xn(Ve=>Ve.fetchStatus),S=xn(Ve=>Ve.setDiff),[j,k]=i.useState(null),[v,D]=i.useState(!1),[A,C]=i.useState(null),[O,T]=i.useState(()=>new Set),[E,F]=i.useState(()=>new Set),[R,L]=i.useState(!1),[B,V]=i.useState(0),[M,ee]=i.useState(!1),[se,J]=i.useState(!1),K=Re(Ve=>Ve.pendingDiffFile),Z=Re(Ve=>Ve.pendingDiffStaged),re=Re(Ve=>Ve.setPendingDiffFile),pe=Re(Ve=>Ve.diffLayoutPreference),Se=Re(Ve=>Ve.diffFileLayout),te=Re(Ve=>Ve.setDiffFileLayout),Ne=Re(Ve=>Ve.diffWrapLines),Y=Re(Ve=>Ve.setDiffWrapLines),G=Re(Ve=>Ve.openContextFileAtLine),q=dt(Ve=>Ve.currentSessionId),oe=Ne,le=o==="staged"?!0:o==="working"?!1:null,ve=le??v,Ee=y||g<=768,_e=!!q&&!Ee&&!Wr(),Oe=!t&&!Ee&&g>=1024,Me=i.useRef(null),he=i.useRef(new Map),Ce=i.useRef(null),xe=i.useRef(null),ue=i.useRef(!1),H=i.useRef(null),ce=i.useRef(null),fe=i.useCallback(()=>{Ce.current=null,ue.current=!1,C(null),xe.current!==null&&(window.cancelAnimationFrame(xe.current),xe.current=null)},[]),U=i.useCallback(Ve=>{T(tt=>{if(tt.has(Ve))return tt;const nt=new Set(tt);return nt.add(Ve),nt})},[]),z=i.useMemo(()=>{if(!x?.files)return[];const Ve=x.diffStats??{},tt=o==="staged"?Su:o==="working"?Nu:()=>!0;return x.files.filter(tt).map(nt=>({...nt,insertions:Ve[nt.path]?.insertions??0,deletions:Ve[nt.path]?.deletions??0,isNew:_v(nt)})).sort((nt,xt)=>nt.path.localeCompare(xt.path))},[o,x]),be=i.useMemo(()=>x?.files?x.files.filter(Nu).length:0,[x]),ge=i.useMemo(()=>x?.files?x.files.filter(Su).length:0,[x]),_=i.useMemo(()=>z.map(Ve=>Ve.path).join("\0"),[z]);i.useEffect(()=>{const Ve=_?_.split("\0"):[],tt=new Set(Ve),nt=`${f??""}:${o}:${e?"collapsed":"default"}`,xt=ce.current!==nt;ce.current=nt,T(Rt=>{if(xt){const at=e?0:Lv(Ve.length);return new Set(Ve.slice(0,at))}let bt=!1;const ot=new Set;for(const at of Rt){if(!tt.has(at)){bt=!0;continue}ot.add(at)}return bt?ot:Rt}),F(Rt=>{if(xt)return new Set;let bt=!1;const ot=new Set;for(const at of Rt){if(!tt.has(at)){bt=!0;continue}ot.add(at)}return bt?ot:Rt})},[_,o,f,e]);const ye=i.useCallback(()=>{H.current=null;const Ve=Me.current;if(!Ve)return;const tt=Ve.getBoundingClientRect(),nt=tt.top-ju,xt=tt.bottom+ju,Rt={};for(const[bt,ot]of he.current){if(!ot||!O.has(bt))continue;const at=ot.getBoundingClientRect();at.bottom<nt||at.top>xt||(Rt[bt]=!0)}F(bt=>{let ot=!1;const at=new Set(bt);for(const Ut of Object.keys(Rt))at.has(Ut)||(at.add(Ut),ot=!0);return ot?at:bt})},[O]),$=i.useCallback(()=>{typeof window>"u"||H.current===null&&(H.current=window.requestAnimationFrame(ye))},[ye]);i.useEffect(()=>{const Ve=Me.current;if(Ve)return $(),Ve.addEventListener("scroll",$,{passive:!0}),window.addEventListener("resize",$),()=>{Ve.removeEventListener("scroll",$),window.removeEventListener("resize",$),H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null)}},[z,O,$]);const Ie=i.useCallback(Ve=>{const tt=Se[Ve.path];if(tt)return tt;if(pe==="inline")return"inline";if(pe==="side-by-side")return"side-by-side";const nt=g<Rv;return Ve.isNew||nt?"inline":"side-by-side"},[Se,pe,g]),je=i.useMemo(()=>z.length===0?null:z.every(Ve=>Ie(Ve)==="side-by-side")?"side-by-side":"inline",[z,Ie]);i.useEffect(()=>{f&&(h(f),N(f,u))},[f,h,N,u]),i.useEffect(()=>{if(f)return Ir.onGitRefreshHint(Ve=>{ku(Ve.directory)===ku(f)&&w(f,u)})},[f,w,u]),i.useEffect(()=>{o==="all"&&K&&(k(K),D(Z),re(null),ue.current=!0,Ce.current=K,U(K),V(Ve=>Ve+1))},[o,U,K,Z,re]),i.useEffect(()=>{if(o==="all")return;const Ve=c?.trim();Ve&&(k(Ve),D(o==="staged"),ue.current=!0,Ce.current=Ve,U(Ve),V(tt=>tt+1))},[o,U,c]),i.useEffect(()=>{if(!j)return;z.some(tt=>tt.path===j)||(k(null),D(!1))},[z,j]);const Fe=i.useCallback((Ve,tt)=>{const nt=he.current;tt?nt.set(Ve,tt):nt.delete(Ve),$()},[$]),Ae=i.useCallback((Ve,tt)=>{fe(),T(nt=>{const xt=nt.has(Ve);if(tt===xt)return nt;const Rt=new Set(nt);return tt?Rt.add(Ve):Rt.delete(Ve),Rt}),tt||F(nt=>{if(!nt.has(Ve))return nt;const xt=new Set(nt);return xt.delete(Ve),xt}),$()},[fe,$]),ne=i.useCallback(()=>{fe(),T(Ve=>Ve.size>0?new Set:new Set(z.map(tt=>tt.path))),F(new Set),$()},[fe,z,$]),P=i.useCallback(async Ve=>{if(!q)return;const tt=dt.getState().getDirectoryForSession(q)||f||"";if(!tt){de.error(d("diffView.reviewDialog.toast.noSessionDirectory"));return}J(!0);try{await tg({originalSessionID:q,directory:tt,providerID:Ve.providerID,modelID:Ve.modelID,agent:Ve.agent||void 0,variant:Ve.variant||void 0,generateHandoff:Ve.generateHandoff,returnAfterHandoffRequest:Ve.generateHandoff}),ee(!1)}catch(nt){console.error("[review-flow] failed to start review flow",nt),de.error(nt instanceof Error?nt.message:d("diffView.reviewDialog.toast.startFailed"))}finally{J(!1)}},[q,f,d]),me=i.useCallback(Ve=>{const tt=he.current.get(Ve),nt=Me.current;if(!tt||!nt)return!1;const xt=nt.getBoundingClientRect(),bt=tt.getBoundingClientRect().top-xt.top,ot=Math.max(0,nt.scrollHeight-nt.clientHeight);return nt.scrollTop=Math.min(ot,Math.max(0,nt.scrollTop+bt)),!0},[]);i.useEffect(()=>{if(!Ce.current)return;let tt=0;const nt=20;let xt=!1;const Rt=()=>{xt||(xt=!0,Ce.current=null,ue.current=!1,C(null),xe.current!==null&&(window.cancelAnimationFrame(xe.current),xe.current=null))},bt=()=>{if(xt){xe.current=null;return}const ot=Ce.current;if(!ot){Rt(),xe.current=null;return}if(!me(ot)){tt+=1,tt<nt?xe.current=window.requestAnimationFrame(bt):(Rt(),xe.current=null);return}n&&ue.current&&C(ot),Rt()};return xe.current=window.requestAnimationFrame(bt),()=>{xt=!0,xe.current!==null&&(window.cancelAnimationFrame(xe.current),xe.current=null)}},[n,B,me]);const ae=i.useCallback(Ve=>{},[]),Be=i.useCallback(Ve=>{fe(),k(Ve),D(!1),ue.current=!0,Ce.current=Ve,U(Ve),V(tt=>tt+1),me(Ve)},[fe,U,me]),Ge=i.useCallback(Ve=>{const tt=Ve==="side-by-side"?"side-by-side":"inline";z.forEach(nt=>{te(nt.path,tt)})},[z,te]),[Ke,Qe]=i.useState(null),st=i.useCallback(async(Ve,tt)=>{if(!(!f||!Ve)){Qe(Ve);try{let nt=null;if(tt&&!tt.isBinary&&!eo(Ve)&&(nt=Cu(tt.original,tt.modified)),nt===null)try{const at=await u.getGitDiff(f,{path:Ve,staged:ve,contextLines:3});nt=zv(at.diff)}catch{nt=null}let xt=tt;if(nt===null||!xt){const at=await u.getGitFileDiff(f,{path:Ve,staged:ve});xt={original:at.original??"",modified:at.modified??"",isBinary:at.isBinary},ve||S(f,Ve,xt)}const Rt=nt??(xt.isBinary||eo(Ve)?1:Cu(xt.original,xt.modified)),bt=$v(f,Ve),ot=await Ec(m,bt);if(!ot.ok){de.error(Mc(ot.reason));return}G(f,bt,Rt,1)}finally{Qe(nt=>nt===Ve?null:nt)}}},[ve,f,m,u,G,S]),ut=()=>{if(!f)return null;const Ve=tt=>le!==null?le:v&&tt===j;return s.jsxs("div",{className:De("flex min-w-0 flex-1 min-h-0 h-full",l?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[Oe&&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:d("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:z.length})]}),s.jsx(Gv,{changedFiles:z,selectedFile:null,onSelectFile:Be})]}),s.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:s.jsx(Vn,{ref:Me,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:s.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:z.map(tt=>s.jsx(Qv,{directory:f,file:tt,layout:Ie(tt),wrapLines:oe,isSelected:!1,isExpanded:O.has(tt.path),isMounted:E.has(tt.path)||tt.path===A,onSelect:ae,onExpandedChange:Ae,registerSectionRef:Fe,showOpenInEditorAction:r,isOpeningInEditor:Ke===tt.path,onOpenInEditor:(nt,xt)=>{st(nt,xt)},staged:Ve(tt.path),loadFullFiles:R},tt.path))})})})]})},vt=()=>f?b&&!x?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"}),d("diffView.state.loadingRepositoryStatus")]}):p===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.notGitRepository")}):z.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.cleanWorkingTree")}):ut():s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[!y&&(o==="working"||o==="staged"?s.jsx(Hv,{scope:o,workingCount:be,stagedCount:ge,onScopeChange:a}):s.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:b&&!x?d("diffView.state.loadingChanges"):z.length===1?d("diffView.summary.changedFilesSingle",{count:z.length}):d("diffView.summary.changedFilesPlural",{count:z.length})})})),z.length>0&&s.jsxs($e,{variant:"ghost",size:"sm",onClick:ne,className:De("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:O.size>0?d("diffView.actions.collapseAll"):d("diffView.actions.expandAll"),children:[s.jsx(I,{name:"expand-up-down",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:O.size>0?d("diffView.actions.collapseAll"):d("diffView.actions.expandAll")})]}),z.length>0&&_e&&s.jsxs($e,{variant:"default",size:"sm",onClick:()=>ee(!0),disabled:se,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":d("diffView.actions.reviewAria"),children:[se?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"search-eye",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:d("diffView.actions.review")})]}),z.length>0&&s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>L(Ve=>!Ve),"aria-pressed":R,"aria-label":d(R?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:De("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",R&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(I,{name:"file-download",className:"size-4"})})}),s.jsx(Lt,{children:s.jsx("p",{children:d(R?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),z.length>0&&s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>Y(!Ne),className:De("h-5 w-5 p-0 transition-opacity",oe?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:d(oe?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})}),je&&s.jsx(Gf,{mode:je==="side-by-side"?"side-by-side":"unified",onModeChange:Ge})]}),s.jsx(sg,{open:M,onOpenChange:ee,projectDirectory:f??null,submitting:se,onConfirm:P}),vt()]})},Jv=(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)},Au=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Du=(t,e,n)=>{const r=t.state.doc.line(e),o=Math.max(1,Math.min(n,r.length+1)),a=r.from+o-1;t.dispatch({selection:Th.cursor(a),effects:ti.scrollIntoView(a,{y:"center"})})};function Xv({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:o}=At(),[a,c]=i.useState(""),l=i.useRef(null),d=i.useRef(!1),u=i.useRef(null),m=i.useRef(null),f=i.useMemo(()=>Jv(a,n),[a,n]);i.useEffect(()=>{!t||!n||(d.current=!1,l.current=Au(n,n.state.selection),c(""))},[t,n]),i.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),i.useEffect(()=>{if(!(!t||!n||!l.current)){if(f===null){const{selection:b}=l.current;n.dispatch({selection:b,effects:ti.scrollIntoView(b.main.from,{y:"center"})});return}Du(n,f,l.current.character)}},[f,t,n]);const g=i.useCallback(()=>{if(!n||d.current||!l.current)return;const{selection:b}=l.current;n.dispatch({selection:b,effects:ti.scrollIntoView(b.main.from,{y:"center"})})},[n]),y=i.useCallback(b=>{b||g(),e(b)},[e,g]),p=i.useCallback(()=>{!n||f===null||!l.current||(d.current=!0,Du(n,f,l.current.character),e(!1),n.focus())},[f,e,n]);i.useEffect(()=>{if(!t)return;const b=N=>{const w=u.current,S=N.target;!w||!(S instanceof Node)||w.contains(S)||y(!1)},h=N=>{N.key==="Escape"&&(N.preventDefault(),y(!1))};return document.addEventListener("pointerdown",b,!0),document.addEventListener("keydown",h,!0),()=>{document.removeEventListener("pointerdown",b,!0),document.removeEventListener("keydown",h,!0)}},[y,t,r]);const x=i.useMemo(()=>{if(!n)return o("goToLineDialog.helper.editorUnavailable");if(f===null){const b=l.current??Au(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:u,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(bn,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:a,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($e,{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:u,className:De("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(bn,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:a,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:x})]})})}const Zv='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function Iu(){if(typeof document>"u")return!1;const t=document.documentElement.getAttribute("data-theme");return t==="dark"||!t&&window.matchMedia("(prefers-color-scheme: dark)").matches}const e1=i.forwardRef(function({xml:e,readOnly:n,className:r,onChange:o},a){const c=i.useRef(e),l=i.useRef(null),d=i.useRef(!1),[u,m]=i.useState(Iu),f=i.useRef(e),g=i.useRef(e);g.current!==e&&(g.current=e,f.current=e,c.current=e);const y=i.useRef(u);y.current!==u&&(y.current=u,f.current=c.current);const p=i.useRef(null);i.useEffect(()=>{const h=()=>m(Iu());h();const N=new MutationObserver(h);return N.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>N.disconnect()},[]),i.useEffect(()=>{const h=setTimeout(()=>{p.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(h)},[]),i.useImperativeHandle(a,()=>({getXml:()=>c.current}));const x=i.useCallback(()=>{!e&&!d.current&&(d.current=!0,setTimeout(()=>{l.current?.template({})},500))},[e]),b=i.useCallback(h=>{c.current=h.xml,o?.(h.xml)},[o]);return s.jsx("div",{ref:p,className:De("h-full w-full",r),children:s.jsx(Rh,{ref:l,xml:f.current||Zv,autosave:!0,urlParameters:{ui:n?"simple":u?"dark":"kennedy",spin:!0,libraries:!n,chrome:n,nav:n,layers:n,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:x,onAutoSave:b},u?"dark":"light")})}),t1=t=>{const e=Ks(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},s1=t=>{const e=gt.c(8),{label:n,iconDataUrl:r}=t,[o,a]=i.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 m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>a(!0),e[2]=m):m=e[2];let f;return e[3]!==r?(f=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=f):f=e[4],f}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=De("size-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 u;return e[6]!==l?(u=s.jsx("span",{className:d,children:l}),e[6]=l,e[7]=u):u=e[7],u},n1=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Ks=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==="/",a=/^[A-Za-z]:\/$/.test(r);return!o&&!a&&(r=r.replace(/\/+$/,"")),r},r1=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Wi=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,Pa=(t,e)=>{const n=Ks(e),r=Ks(t);if(!n||!r)return!1;const o=Wi(n),a=Wi(r);return a===o||a.startsWith(`${o}/`)},Pu=(t,e)=>{const n=Ks(e),r=Ks(t);if(!Pa(r,n))return[];const a=r.slice(n.length).replace(/^\//,"").split("/"),c=[];let l=n;for(let d=0;d<a.length-1;d++)l=l?`${l}/${a[d]}`:a[d],c.push(l);return c},Jl=(t,e)=>{if(!e)return"";const n=Ks(e);if(!t||!Pa(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},i1=new Set(["node_modules"]),o1=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 a;return e[1]!==o?(a=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=a):a=e[2],a},Tu=t=>{const e=gt.c(11),{name:n}=t,r=i.useRef(null),o=i.useRef(null),[a,c]=i.useState(!1);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{const g=r.current,y=o.current;if(!g||!y)return;const p=()=>{c(y.scrollWidth>g.clientWidth+1)};p();const x=new ResizeObserver(p);return x.observe(g),x.observe(y),()=>{x.disconnect()}},e[0]=l):l=e[0];let d;e[1]!==n?(d=[n],e[1]=n,e[2]=d):d=e[2],i.useLayoutEffect(l,d);let u;e[3]!==n?(u=s.jsx("span",{ref:o,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=u):u=e[4];let m;e[5]!==n||e[6]!==a?(m=a?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]=a,e[7]=m):m=e[7];let f;return e[8]!==u||e[9]!==m?(f=s.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[u,m]}),e[8]=u,e[9]=m,e[10]=f):f=e[10],f},a1=t=>i1.has(t),l1=t=>{const e=Ks(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},c1=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Ru=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")},go=2e5,Lm="openchamber:files:auto-save-enabled",d1=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
|
|
21
|
+
`:`
|
|
22
|
+
`},Om=t=>t.replace(/\r\n/g,`
|
|
23
|
+
`).replace(/\r/g,`
|
|
24
|
+
`),u1=(t,e)=>{const n=Om(t);return e===`\r
|
|
25
|
+
`?n.replace(/\n/g,`\r
|
|
26
|
+
`):n},f1=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Lm)!=="false"}catch{return!0}},Bm=(t,e)=>s.jsx(Ur,{filePath:t,extension:e}),Eu=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},m1=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},Xo=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},h1=t=>{const e=gt.c(83),{node:n,root:r,isExpanded:o,isActive:a,isMobile:c,alwaysShowActions:l,status:d,badge:u,permissions:m,downloadFile:f,contextMenuPath:g,setContextMenuPath:y,rightClickMenuPath:p,setRightClickMenuPath:x,onSelect:b,onToggle:h,onRevealPath:N,onOpenDialog:w}=t,{t:S}=At(),j=n.type==="directory",{canRename:k,canCreateFile:v,canCreateFolder:D,canDelete:A,canReveal:C}=m;let O;e[0]!==v||e[1]!==D||e[2]!==A||e[3]!==k||e[4]!==C||e[5]!==n.path||e[6]!==x?(O=ve=>{!k&&!v&&!D&&!A&&!C||(ve?.preventDefault(),x(n.path))},e[0]=v,e[1]=D,e[2]=A,e[3]=k,e[4]=C,e[5]=n.path,e[6]=x,e[7]=O):O=e[7];const T=O;let E;e[8]!==j||e[9]!==n||e[10]!==b||e[11]!==h?(E=()=>{j?h(n.path):b(n)},e[8]=j,e[9]=n,e[10]=b,e[11]=h,e[12]=E):E=e[12];const F=E;let R;e[13]!==n.path||e[14]!==y||e[15]!==x?(R=ve=>{ve.stopPropagation(),x(null),y(n.path)},e[13]=n.path,e[14]=y,e[15]=x,e[16]=R):R=e[16];const L=R;let B;e[17]!==v||e[18]!==D||e[19]!==A||e[20]!==k||e[21]!==C||e[22]!==f||e[23]!==j||e[24]!==n||e[25]!==w||e[26]!==N||e[27]!==r||e[28]!==S?(B=ve=>{const{Item:Ee,Separator:_e}=ve;return s.jsxs(s.Fragment,{children:[k&&s.jsxs(Ee,{onClick:Oe=>{Oe.stopPropagation(),w("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.rename")]}),s.jsxs(Ee,{onClick:Oe=>{Oe.stopPropagation(),dr(n.path).then(Me=>{if(Me.ok){de.success(S("sidebarFilesTree.toast.pathCopied"));return}de.error(S("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.copyPath")]}),s.jsxs(Ee,{onClick:Oe=>{Oe.stopPropagation();const Me=Jl(r,n.path)||n.path;dr(Me).then(he=>{if(he.ok){de.success(S("filesView.toast.relativePathCopied"));return}de.error(S("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy-2",className:"mr-2 size-4"})," ",S("filesView.tree.menu.copyRelativePath")]}),!j&&f&&s.jsxs(Ee,{onClick:Oe=>{Oe.stopPropagation(),f(n.path).catch(Me=>{console.error("Download failed:",Me),de.error(S("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(I,{name:"download",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.save")]}),C&&s.jsxs(Ee,{onClick:Oe=>{Oe.stopPropagation(),N(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 size-4"})," ",S(yc())]}),j&&(v||D)&&s.jsxs(s.Fragment,{children:[s.jsx(_e,{}),v&&s.jsxs(Ee,{onClick:Oe=>{Oe.stopPropagation(),w("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.newFile")]}),D&&s.jsxs(Ee,{onClick:Oe=>{Oe.stopPropagation(),w("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.newFolder")]})]}),A&&s.jsxs(s.Fragment,{children:[s.jsx(_e,{}),s.jsxs(Ee,{onClick:Oe=>{Oe.stopPropagation(),w("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.delete")]})]})]})},e[17]=v,e[18]=D,e[19]=A,e[20]=k,e[21]=C,e[22]=f,e[23]=j,e[24]=n,e[25]=w,e[26]=N,e[27]=r,e[28]=S,e[29]=B):B=e[29];const V=B,M=p===n.path;let ee;e[30]!==n.path||e[31]!==x?(ee=ve=>x(ve?n.path:null),e[30]=n.path,e[31]=x,e[32]=ee):ee=e[32];const se=c?void 0:T;let J;e[33]!==se?(J=s.jsx("div",{className:"group relative flex items-center",onContextMenu:se}),e[33]=se,e[34]=J):J=e[34];const K=c?void 0:T,Z=a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let re;e[35]!==Z?(re=De("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[35]=Z,e[36]=re):re=e[36];let pe;e[37]!==j||e[38]!==o||e[39]!==n.extension||e[40]!==n.path?(pe=j?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"}):Bm(n.path,n.extension),e[37]=j,e[38]=o,e[39]=n.extension,e[40]=n.path,e[41]=pe):pe=e[41];let Se;e[42]!==n.name||e[43]!==n.path?(Se=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[42]=n.name,e[43]=n.path,e[44]=Se):Se=e[44];let te;e[45]!==j||e[46]!==d?(te=!j&&d&&s.jsx(o1,{status:d}),e[45]=j,e[46]=d,e[47]=te):te=e[47];let Ne;e[48]!==u||e[49]!==j?(Ne=j&&u&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[u.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",u.modified]}),u.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",u.added]})]}),e[48]=u,e[49]=j,e[50]=Ne):Ne=e[50];let Y;e[51]!==F||e[52]!==re||e[53]!==pe||e[54]!==Se||e[55]!==te||e[56]!==Ne||e[57]!==K?(Y=s.jsxs("button",{type:"button",onClick:F,onContextMenu:K,className:re,children:[pe,Se,te,Ne]}),e[51]=F,e[52]=re,e[53]=pe,e[54]=Se,e[55]=te,e[56]=Ne,e[57]=K,e[58]=Y):Y=e[58];let G;e[59]!==l||e[60]!==v||e[61]!==D||e[62]!==A||e[63]!==k||e[64]!==C||e[65]!==g||e[66]!==L||e[67]!==c||e[68]!==n.path||e[69]!==V||e[70]!==y?(G=(k||v||D||A||C)&&s.jsx("div",{className:De("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(sn,{open:g===n.path,onOpenChange:ve=>y(ve?n.path:null),children:[s.jsx(en,{asChild:!0,children:s.jsx($e,{variant:"ghost",size:"icon",className:"size-6",onClick:L,children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})}),s.jsx(tn,{align:"end",side:"bottom",onCloseAutoFocus:()=>y(null),children:V({Item:xs,Separator:Tr})})]})}),e[59]=l,e[60]=v,e[61]=D,e[62]=A,e[63]=k,e[64]=C,e[65]=g,e[66]=L,e[67]=c,e[68]=n.path,e[69]=V,e[70]=y,e[71]=G):G=e[71];let q;e[72]!==Y||e[73]!==G||e[74]!==J?(q=s.jsxs(Ac,{render:J,children:[Y,G]}),e[72]=Y,e[73]=G,e[74]=J,e[75]=q):q=e[75];let oe;e[76]!==V?(oe=s.jsx(kc,{className:"min-w-[180px]",children:V({Item:Cc,Separator:um})}),e[76]=V,e[77]=oe):oe=e[77];let le;return e[78]!==q||e[79]!==oe||e[80]!==M||e[81]!==ee?(le=s.jsxs(Dc,{open:M,onOpenChange:ee,children:[q,oe]}),e[78]=q,e[79]=oe,e[80]=M,e[81]=ee,e[82]=le):le=e[82],le},p1=t=>{const e=gt.c(83),{activeDialog:n,dialogData:r,dialogInputValue:o,onDialogInputChange:a,isDialogSubmitting:c,onDialogSubmit:l,onClose:d,inputRef:u}=t,{t:m}=At(),f=!!n;let g;e[0]!==d?(g=M=>!M&&d(),e[0]=d,e[1]=g):g=e[1];let y;e[2]!==n||e[3]!==m?(y=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=y):y=e[4];let p;e[5]!==n||e[6]!==m?(p=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=p):p=e[7];let x;e[8]!==n||e[9]!==m?(x=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=x):x=e[10];let b;e[11]!==n||e[12]!==m?(b=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=b):b=e[13];let h;e[14]!==y||e[15]!==p||e[16]!==x||e[17]!==b?(h=s.jsxs($s,{children:[y,p,x,b]}),e[14]=y,e[15]=p,e[16]=x,e[17]=b,e[18]=h):h=e[18];let N;e[19]!==n||e[20]!==r?.path||e[21]!==m?(N=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=N):N=e[22];let w;e[23]!==n||e[24]!==r?.path||e[25]!==m?(w=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=w):w=e[26];let S;e[27]!==n||e[28]!==r?.name||e[29]!==m?(S=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=S):S=e[30];let j;e[31]!==n||e[32]!==r?.name||e[33]!==m?(j=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=j):j=e[34];let k;e[35]!==S||e[36]!==j||e[37]!==N||e[38]!==w?(k=s.jsxs(an,{children:[N,w,S,j]}),e[35]=S,e[36]=j,e[37]=N,e[38]=w,e[39]=k):k=e[39];let v;e[40]!==k||e[41]!==h?(v=s.jsxs(Us,{children:[h,k]}),e[40]=k,e[41]=h,e[42]=v):v=e[42];let D;e[43]!==n||e[44]!==o||e[45]!==u||e[46]!==a||e[47]!==l||e[48]!==m?(D=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(bn,{value:o,onChange:M=>a(M.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:M=>{M.key==="Enter"&&l()},ref:u})}),e[43]=n,e[44]=o,e[45]=u,e[46]=a,e[47]=l,e[48]=m,e[49]=D):D=e[49];let A;e[50]!==m?(A=m("filesView.dialog.cancel"),e[50]=m,e[51]=A):A=e[51];let C;e[52]!==c||e[53]!==d||e[54]!==A?(C=s.jsx($e,{variant:"outline",onClick:d,disabled:c,children:A}),e[52]=c,e[53]=d,e[54]=A,e[55]=C):C=e[55];const O=n==="delete"?"destructive":"default";let T;e[56]!==l?(T=()=>{l()},e[56]=l,e[57]=T):T=e[57];let E;e[58]!==n||e[59]!==o||e[60]!==c?(E=c||n!=="delete"&&!o.trim(),e[58]=n,e[59]=o,e[60]=c,e[61]=E):E=e[61];let F;e[62]!==n||e[63]!==c||e[64]!==m?(F=c?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=c,e[64]=m,e[65]=F):F=e[65];let R;e[66]!==O||e[67]!==T||e[68]!==E||e[69]!==F?(R=s.jsx($e,{variant:O,onClick:T,disabled:E,children:F}),e[66]=O,e[67]=T,e[68]=E,e[69]=F,e[70]=R):R=e[70];let L;e[71]!==C||e[72]!==R?(L=s.jsxs(sr,{children:[C,R]}),e[71]=C,e[72]=R,e[73]=L):L=e[73];let B;e[74]!==u||e[75]!==v||e[76]!==D||e[77]!==L?(B=s.jsxs(Fs,{initialFocus:u,children:[v,D,L]}),e[74]=u,e[75]=v,e[76]=D,e[77]=L,e[78]=B):B=e[78];let V;return e[79]!==f||e[80]!==g||e[81]!==B?(V=s.jsx(Ls,{open:f,onOpenChange:g,children:B}),e[79]=f,e[80]=g,e[81]=B,e[82]=V):V=e[82],V},jl=(t,e,n)=>{const r=gt.c(8),[o,a]=i.useState(""),[c,l]=i.useState(0);let d,u;r[0]!==t||r[1]!==n||r[2]!==e?(d=()=>{if(!t){a("");return}let f=!1;a("");const g=$r(),y=sp(g);cc(g).then(x=>{f||!x||(a(t),e(null))}).catch(x=>{f||(e(x instanceof Error?x.message:n),a(t))});const p=np(()=>{f||(a(t),l(g1),e(null))});return()=>{f=!0,y(),p()}},u=[t,e,n],r[0]=t,r[1]=n,r[2]=e,r[3]=d,r[4]=u):(d=r[3],u=r[4]),i.useEffect(d,u);let m;return r[5]!==c||r[6]!==o?(m={readyKey:o,nonce:c},r[5]=c,r[6]=o,r[7]=m):m=r[7],m},Vm=({mode:t="full"})=>{const{t:e}=At(),{files:n,runtime:r}=Qn(),{currentTheme:o,availableThemes:a,lightThemeId:c,darkThemeId:l}=Hr(),{isMobile:d,isTablet:u,screenWidth:m}=Rr(),f=d||u,g=Af(),y=Df(),p=li()??"",x=Ks(p.trim()),b=d||t!=="editor-only",h=t==="editor-only"&&!d,N=lc(W=>W.searchFiles),w=Ua(p),[S,j]=i.useState(""),k=Ha(S,200),v=i.useRef(null),[D,A]=i.useState(!1),[C,O]=i.useState(!0),[T,E]=i.useState(!1),[F,R]=i.useState(!1),[L,B]=i.useState(!1),V=i.useRef(null),M=i.useRef(0),ee=i.useCallback(W=>{M.current=Math.max(0,M.current+(W?1:-1))},[]),se=i.useCallback(W=>W instanceof Element?W.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);i.useEffect(()=>{if(!L)return;const W=Te=>{M.current>0||se(Te.target)||V.current&&!V.current.contains(Te.target)&&B(!1)};return document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[se,L]);const[J,K]=i.useState("edit"),[Z,re]=i.useState("edit"),[pe,Se]=i.useState("tree"),[te,Ne]=i.useState("edit"),[Y,G]=i.useState("preview"),[q,oe]=i.useState(0),le=i.useRef({}),ve=i.useRef({}),Ee=i.useRef({}),_e=i.useRef({}),Oe=i.useMemo(()=>a.find(W=>W.metadata.id===c)??vd(!1),[a,c]),Me=i.useMemo(()=>a.find(W=>W.metadata.id===l)??vd(!0),[a,l]);i.useEffect(()=>{jd(Oe),jd(Me)},[Oe,Me]);const he=i.useMemo(()=>[],[]),Ce=gn(W=>x?W.byRoot[x]?.openPaths??he:he),xe=gn(W=>x?W.byRoot[x]?.selectedPath??null:null),ue=gn(W=>x?W.byRoot[x]?.expandedPaths??he:he),H=gn(W=>W.addOpenPath),ce=gn(W=>W.removeOpenPath),fe=gn(W=>W.removeOpenPathsByPrefix),U=gn(W=>W.setSelectedPath),z=gn(W=>W.toggleExpandedPath),be=gn(W=>W.expandPaths),ge=i.useCallback(W=>{const Te=Ks(W),We=Te.split("/"),qe=We[We.length-1]||Te,ct=qe.includes(".")?qe.split(".").pop()?.toLowerCase():void 0;return{name:qe,path:Te,type:"file",extension:ct}},[]),_=i.useMemo(()=>Ce.map(ge),[Ce,ge]),ye=i.useMemo(()=>{if(xe){const W=Wi(xe);if(Ce.some(Te=>Wi(Te)===W))return xe}return Ce[0]??null},[Ce,xe]),$=i.useMemo(()=>ye?ge(ye):null,[ye,ge]),Ie=$?.path??"";i.useEffect(()=>{if(!x||!xe)return;const W=Wi(xe);Ce.some(We=>Wi(We)===W)||U(x,Ce[0]??null)},[Ce,x,xe,U]);const je=!!(x&&Ie&&!Pa(Ie,x)),Fe=je?Sd(Ie):void 0,Ae=i.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&je,outsideFileGrant:Fe,directory:x||void 0}),[t,je,Fe,x]),ne=i.useRef(null),[P,me]=i.useState({left:!1,right:!1}),ae=i.useCallback(()=>{const W=ne.current;W&&me({left:W.scrollLeft>2,right:W.scrollLeft+W.clientWidth<W.scrollWidth-2})},[]),Be=i.useRef(ae);Be.current=ae,i.useEffect(()=>{const W=ne.current;if(!W)return;const Te=()=>Be.current();Te(),W.addEventListener("scroll",Te,{passive:!0});const We=new ResizeObserver(Te);return We.observe(W),()=>{W.removeEventListener("scroll",Te),We.disconnect()}},[_.length]);const[Ge,Ke]=i.useState({}),[Qe,st]=i.useState({}),ut=i.useRef(new Set),vt=i.useRef(new Set),Ve=i.useRef(new Map),tt=i.useRef(0),[nt,xt]=i.useState([]),[Rt,bt]=i.useState(!1),[ot,at]=i.useState(""),{isPlaying:Ut,play:Nt,stop:_t}=Kf(),[Le,Dt]=i.useState(!1),[Ot,mt]=i.useState(null),[Et,qt]=i.useState(""),Vt=i.useRef(""),[Wt,Yt]=i.useState(null),[Bt,Ht]=i.useState(""),[Jt,rs]=i.useState(!1),[Qt,Xt]=i.useState(`
|
|
27
|
+
`),bs=i.useRef(null),yt=i.useRef(null),Ue=i.useRef(null),Ye=i.useRef(""),Ct=i.useRef(""),kt=i.useRef(null),It=i.useRef(null),rt=i.useRef(null),ts=i.useRef(0),[hs,Gt]=i.useState("idle"),[nn,js]=i.useState(!1),[ss,Os]=i.useState(f1),[Ps,As]=i.useState(!1),yn=i.useRef(null),Ys=i.useRef(null),un=i.useRef(null),wn=i.useRef(!1),zs=i.useRef(null),we=i.useRef(null),Je=i.useRef(null),wt=i.useRef(null),[Pt,$t]=i.useState(0),ft=i.useRef(null),ls=i.useRef({key:"",attempts:0});i.useEffect(()=>()=>{ft.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(ft.current),ft.current=null)},[]);const[cs,Ns]=i.useState(null),[ms,Qs]=i.useState(null),[He,ns]=i.useState(""),[ws,vs]=i.useState(!1),[Ws,Ss]=i.useState(null),[Bs,fs]=i.useState(null),[ci,br]=i.useState(!1),[yr,wr]=i.useState(!1),[Jn,vr]=i.useState(!1),Xn=!!n.writeFile,ur=!!n.createDirectory,Un=!!n.rename,ps=!!n.delete,Ds=!!n.revealPath,Er=pr(W=>W.availableApps),vn=pr(W=>W.isCacheStale),rn=pr(W=>W.initialize),nr=pr(W=>W.loadInstalledApps);i.useEffect(()=>{rn()},[rn]);const Mr=i.useCallback(W=>{n.revealPath&&n.revealPath(W).catch(()=>{de.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),Gr=i.useCallback(async W=>{if(!$?.path||await tp($.path,W.id,W.appName)||await wa($.path,W.appName))return;const qe=t1($.path)||x;qe&&await wa(qe,W.appName)||de.error(e("filesView.toast.openInAppFailed",{app:W.appName}))},[x,$?.path,e]),Fr=i.useCallback((W,Te)=>{Ns(W),Qs(Te),ns(W==="rename"&&Te.name||""),vs(!1)},[]),[gs,Ts]=i.useState(null),Wn=i.useRef(!1),fn=i.useRef(null),[X,et]=i.useState(!1),ht=Re(W=>W.setMainTabGuard),Tt=Re(W=>W.pendingFileNavigation),is=Re(W=>W.setPendingFileNavigation),os=Re(W=>W.pendingFileFocusPath),ds=Re(W=>W.setPendingFileFocusPath),Rs=Re(W=>W.shortcutOverrides),Hs=Re(W=>W.fileEditorKeymap),kn=es(W=>W.settingsDefaultFileViewerPreview),jr=es(W=>W.showMessageTTSButtons),Sr=Re(W=>W.expandedEditorToolbar);i.useEffect(()=>{const W=()=>{Wn.current=!1,fn.current=null,et(!1)};return document.addEventListener("mouseup",W),()=>document.removeEventListener("mouseup",W)},[]),i.useEffect(()=>()=>{zs.current!==null&&window.clearTimeout(zs.current),we.current!==null&&window.clearTimeout(we.current)},[]);const Vs=i.useCallback((W,Te)=>{const We=W.split(`
|
|
28
|
+
`),qe=Math.max(1,Te.start),ct=Math.min(We.length,Te.end);return qe>ct?"":We.slice(qe-1,ct).join(`
|
|
29
|
+
`)},[]),Lr=fm({source:"file",fileLabel:$?.path??null,language:$?.path&&Di($.path)||"text",getCodeForRange:W=>Vs(ot,mm(W)),toStoreRange:W=>({startLine:W.start,endLine:W.end}),fromDraftRange:W=>({start:W.startLine,end:W.endLine})}),{drafts:ln,commentText:En,setCommentText:Cn,editingDraftId:jn,setSelection:An,saveComment:rr,cancel:cn,reset:di,startEdit:Or,deleteDraft:Nr}=Lr;i.useEffect(()=>{Ts(null),di(),ht(null),Ht(""),rs(!1)},[$?.path,di,ht]),i.useEffect(()=>{An(gs)},[gs,An]),i.useEffect(()=>{if(!gs&&!jn)return;const W=We=>{const qe=We.target;qe.closest('[data-comment-input="true"]')||qe.closest('[data-comment-card="true"]')||qe.closest(".cm-gutterElement")||qe.closest("[data-sonner-toast]")||qe.closest("[data-sonner-toaster]")||En.trim()||(Ts(null),cn())},Te=setTimeout(()=>{document.addEventListener("click",W)},100);return()=>{clearTimeout(Te),document.removeEventListener("click",W)}},[cn,En,jn,gs]);const Mi=i.useCallback((W,Te)=>{const We=Te??gs??void 0;Te&&Ts(Te),rr(W,We),Ts(null)},[gs,rr]),ui=i.useCallback((W,Te)=>{const We=[];for(const qe of Te){if(!(qe&&typeof qe.name=="string"&&qe.name.length>0)||!g&&qe.name.startsWith(".")||!y&&a1(qe.name))continue;const ct=qe.name,it=Ks(qe.path||""),Zt=it?r1(it)?it:Ks(`${W}/${it}`):Ks(`${W}/${ct}`),Es=qe.isDirectory?"directory":"file",_s=Es==="file"&&ct.includes(".")?ct.split(".").pop()?.toLowerCase():void 0;We.push({name:ct,path:Zt,type:Es,extension:_s})}return n1(We)},[y,g]),Dn=i.useCallback(async W=>{const Te=Ks(W.trim());if(!Te||ut.current.has(Te)||vt.current.has(Te))return;vt.current=new Set(vt.current),vt.current.add(Te);const We=tt.current+1;tt.current=We,Ve.current=new Map(Ve.current),Ve.current.set(Te,We);const qe=()=>Ve.current.get(Te)===We;await(n.listDirectory?n.listDirectory(Te).then(it=>it.entries.map(Zt=>({name:Zt.name,path:Zt.path,isDirectory:Zt.isDirectory}))):Bn.listLocalDirectory(Te).then(it=>it.map(Zt=>({name:Zt.name,path:Zt.path,isDirectory:Zt.isDirectory})))).then(it=>{if(!qe())return;const Zt=ui(Te,it);ut.current=new Set(ut.current),ut.current.add(Te),st(Es=>{if(!Es[Te])return Es;const _s={...Es};return delete _s[Te],_s}),Ke(Es=>({...Es,[Te]:Zt}))}).catch(it=>{if(!qe())return;const Zt=it instanceof Error?it.message:String(it??"");console.error("Failed to load files directory:",it),st(Es=>({...Es,[Te]:Zt}))}).finally(()=>{qe()&&(Ve.current=new Map(Ve.current),Ve.current.delete(Te),vt.current=new Set(vt.current),vt.current.delete(Te))})},[n,ui]),ir=i.useCallback(async()=>{x&&(ut.current=new Set,vt.current=new Set,Ve.current=new Map,st({}),Ke(W=>Object.keys(W).length===0?W:{}),await Dn(x))},[Dn,x]),Sn=i.useCallback(async W=>{if(!W){await ir();return}const Te=Ks(W);ut.current=new Set(ut.current),ut.current.delete(Te),vt.current=new Set(vt.current),vt.current.delete(Te),await Dn(Te)},[Dn,ir]),Hn=i.useRef(""),mn=i.useRef("");i.useEffect(()=>{if(!x)return;const W=`${x}|h${g?"1":"0"}|g${y?"1":"0"}`,Te=Hn.current!==x,We=mn.current!==W;!Te&&!We||(Te&&(Hn.current=x,at(""),mt(null),qt(""),Yt(null),A(!1)),We&&(mn.current=W,ut.current=new Set,vt.current=new Set,Ve.current=new Map,st({}),Ke(qe=>Object.keys(qe).length===0?qe:{}),Dn(x)))},[Dn,x,y,g]),i.useEffect(()=>{if(!n.listDirectory)return;const W=()=>{if(!document.hidden&&ue.length>0)for(const Te of ue)Sn(Te)};return document.addEventListener("visibilitychange",W),()=>document.removeEventListener("visibilitychange",W)},[ue,n.listDirectory,Sn]),i.useEffect(()=>{if(!n.listDirectory||ue.length===0)return;const W=setInterval(()=>{if(!document.hidden)for(const Te of ue)Sn(Te)},8e3);return()=>clearInterval(W)},[ue,n.listDirectory,Sn]);const fi=i.useCallback(async W=>{if(W?.preventDefault(),!ms||!cs)return;vs(!0);const Te=()=>{Ns(null)},We=ct=>{de.error(ct)},qe=()=>{vs(!1)};if(cs==="createFile"){if(!He.trim()){We(e("sidebarFilesTree.toast.filenameRequired")),qe();return}if(!n.writeFile){We(e("sidebarFilesTree.toast.writeNotSupported")),qe();return}const ct=ms.path,it=ct?`${ct}/`:"",Zt=Ks(`${it}${He.trim()}`);await n.writeFile(Zt,"").then(async Es=>{Es.success&&(de.success(e("sidebarFilesTree.toast.fileCreated")),await Sn(ct)),Te()}).catch(()=>We(e("sidebarFilesTree.toast.operationFailed"))).finally(qe);return}if(cs==="createFolder"){if(!He.trim()){We(e("sidebarFilesTree.toast.folderNameRequired")),qe();return}const ct=ms.path,it=ct?`${ct}/`:"",Zt=Ks(`${it}${He.trim()}`);await n.createDirectory(Zt).then(async Es=>{Es.success&&(de.success(e("sidebarFilesTree.toast.folderCreated")),await Sn(ct)),Te()}).catch(()=>We(e("sidebarFilesTree.toast.operationFailed"))).finally(qe);return}if(cs==="rename"){if(!He.trim()){We(e("sidebarFilesTree.toast.nameRequired")),qe();return}if(!n.rename){We(e("sidebarFilesTree.toast.renameNotSupported")),qe();return}const ct=ms.path,it=ct.split("/").slice(0,-1).join("/"),Zt=it?`${it}/`:"",Es=Ks(`${Zt}${He.trim()}`);await n.rename(ct,Es).then(async _s=>{_s.success&&(de.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Sn(it),x&&fe(x,ct),($?.path===ct||$?.path.startsWith(`${ct}/`))&&(x&&U(x,null),at(""),mt(null),qt(""),Yt(null),d&&A(!1))),Te()}).catch(()=>We(e("sidebarFilesTree.toast.operationFailed"))).finally(qe);return}if(cs==="delete"){if(!n.delete){We(e("sidebarFilesTree.toast.deleteNotSupported")),qe();return}const ct=ms.path,it=ct.split("/").slice(0,-1).join("/");await n.delete(ct).then(async Zt=>{Zt.success&&(de.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Sn(it),x&&fe(x,ct),($?.path===ct||$?.path.startsWith(`${ct}/`))&&(x&&U(x,null),at(""),mt(null),qt(""),Yt(null),d&&A(!1))),Te()}).catch(()=>We(e("sidebarFilesTree.toast.operationFailed"))).finally(qe);return}qe()},[cs,ms,He,n,Sn,d,fe,x,$?.path,U,e]);i.useEffect(()=>{if(!p){xt([]),bt(!1);return}const W=k.trim();if(!W){xt([]),bt(!1);return}let Te=!1;return bt(!0),N(p,W,150,{includeHidden:g,respectGitignore:!y,type:"file"}).then(We=>{if(Te)return;const ct=We.filter(it=>y||!l1(it.path)).map(it=>({name:it.name,path:Ks(it.path),type:"file",extension:it.extension,relativePath:it.relativePath}));xt(ct)}).catch(()=>{Te||xt([])}).finally(()=>{Te||bt(!1)}),()=>{Te=!0}},[p,k,N,g,y]);const Fi=i.useCallback(async(W,Te)=>{if(n.readFile)return(await n.readFile(W,{...Te??{},directory:x||void 0})).content??"";const We=new URLSearchParams({path:W});Te?.allowOutsideWorkspace&&We.set("allowOutsideWorkspace","true"),Te?.outsideFileGrant&&We.set("outsideFileGrant",Te.outsideFileGrant),Te?.optional&&We.set("optional","true"),x&&We.set("directory",x);const qe=await Cs(`/api/fs/read?${We.toString()}`,{cache:Te?.optional?"no-store":"default"});if(!qe.ok){const ct=await qe.json().catch(()=>({error:qe.statusText}));throw new Error(ct.error||e("filesView.error.readFileFailed"))}return qe.text()},[n,x,e]),Mn=i.useCallback(async(W,Te)=>{if(n.statFile){const We=await n.statFile(W,{...Te??{},directory:x||void 0});return{path:We.path,size:We.size,mtimeMs:We.mtimeMs}}return null},[n,x]);i.useEffect(()=>{if(!x||!n.statFile||Ce.length===0)return;let W=!1;const Te=[...Ce];return Promise.all(Te.map(async We=>{try{const qe=await n.statFile?.(We,{directory:x||void 0});!W&&qe&&!qe.isFile&&fe(x,We)}catch(qe){!W&&Ru(qe)&&fe(x,We)}})),()=>{W=!0}},[n,Ce,fe,x]);const mi=i.useMemo(()=>ot.length>go?`${ot.slice(0,go)}
|
|
30
|
+
|
|
31
|
+
… truncated …`:ot,[ot]),Js=Bt!==mi,or=i.useCallback(async()=>{if(!$||!n.writeFile)return de.error(e("filesView.toast.savingNotSupported")),!1;if(!Js)return!0;if(Bt===""&&ot!==""&&Wt!==$.path)return console.warn(`[saveDraft] refusing to save empty draft for "${$.path}" (${ot.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;rs(!0);try{const W=u1(Bt,Qt);return(await n.writeFile($.path,W))?.success?(at(Bt),$?.path&&Nd($.path)&&(Ye.current=Bt,Ct.current=Bt),Mn($.path).then(We=>{We&&(rt.current=We)}).catch(()=>{}),!0):(de.error(e("filesView.toast.writeFileFailed")),!1)}catch(W){return de.error(W instanceof Error?W.message:e("filesView.toast.saveFailed")),!1}finally{rs(!1)}},[Bt,ot,n,Js,Qt,Wt,Mn,$,e]);i.useEffect(()=>{if(!Js){ht(null);return}const W=Te=>wn.current?(wn.current=!1,!0):(As(!0),Ys.current=Te,!1);return ht(W),()=>{Re.getState().mainTabGuard===W&&ht(null)}},[Js,ht]),i.useEffect(()=>{try{window.localStorage.setItem(Lm,ss?"true":"false")}catch{}},[ss]),i.useEffect(()=>{ss||(Gt("idle"),yt.current&&(clearTimeout(yt.current),yt.current=null))},[ss]);const hi=1500;i.useEffect(()=>{const W=!!($&&n.writeFile);if(!(!ss||!Js||!W||Jt))return yt.current=setTimeout(()=>{or().then(Te=>{Te&&(Gt("saved"),setTimeout(()=>Gt("idle"),2e3))})},hi),()=>{yt.current&&(clearTimeout(yt.current),yt.current=null)}},[ss,Bt,Js,$,n.writeFile,Jt,or]),i.useEffect(()=>{Gt("idle")},[$?.path]),i.useEffect(()=>{const W=Te=>{hc(Te)&&(Te.key.toLowerCase()==="s"?(Te.preventDefault(),yt.current&&(clearTimeout(yt.current),yt.current=null),Jt||or().then(We=>{We&&(Gt("saved"),setTimeout(()=>Gt("idle"),2e3))})):Te.key.toLowerCase()==="f"&&(Te.preventDefault(),R(!0)))};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[Jt,or]);const Li=i.useCallback(async W=>{const Te=ts.current+1;ts.current=Te;const We=()=>{if(!x)return!1;const _s=gn.getState().byRoot[x],fr=_s?.selectedPath??_s?.openPaths[0]??null;return ts.current===Te&&fr===W.path};mt(null),qt(""),Yt(null);const qe=eo(W.path),ct=W.path.toLowerCase().endsWith(".svg"),it=kd(W.path);if(d&&A(!0),r.isDesktop&&qe&&!ct){at(""),Ht(""),Dt(!0);return}if(!r.isDesktop&&qe&&!ct){at(""),Ht(""),Yt(W.path),Dt(!1);return}if(it){at(""),Ht(""),Yt(W.path),Dt(!1);return}Dt(!0);const Zt=Sd(W.path),Es={allowOutsideWorkspace:t==="editor-only"&&!!x&&!Pa(W.path,x),outsideFileGrant:Zt};await Fi(W.path,Es).then(_s=>{if(!We())return;const fr=Om(_s);Xt(d1(_s)),at(fr),Ye.current=fr,Ct.current=fr,Ht(fr.length>go?`${fr.slice(0,go)}
|
|
32
|
+
|
|
33
|
+
… truncated …`:fr),Yt(W.path),Mn(W.path,Es).then(lr=>{lr&&We()&&(rt.current=lr)}).catch(()=>{})}).catch(_s=>{if(We()){if(c1(_s)){if(Dt(!1),x&&U(x,null),mt(null),at(""),Ht(""),Yt(null),rt.current=null,S.trim().length>0&&j(""),d&&A(!1),x){const lr=[...Pu(W.path,x),W.path];lr.length>0&&be(x,lr);for(const tl of lr)ut.current.has(tl)||Dn(tl)}return}if(Ru(_s)){x&&fe(x,W.path),at(""),Ht(""),mt(null),rt.current=null,d&&A(!1);return}at(""),Ht(""),mt(_s instanceof Error?_s.message:e("filesView.error.readFileFailed")),rt.current=null}}).finally(()=>{We()&&Dt(!1)})},[be,d,Dn,t,Fi,Mn,fe,x,r.isDesktop,S,U,e]),Kr=i.useCallback(async(W,Te)=>{if(!x)return;const We=Pu(W,x),qe=Te?[...We,W]:We;qe.length>0&&be(x,qe);const ct=qe.map(it=>{if(!ut.current.has(it))return Dn(it)}).filter(Boolean);await Promise.all(ct)},[be,Dn,x]),pi=i.useCallback((W,Te)=>{const We=Te.findIndex(qe=>qe.path===W);return We===-1||Te.length<=1?null:Te[We+1]??Te[We-1]??null},[]),Xs=i.useCallback(async W=>{if(wn.current)wn.current=!1;else if(Js){As(!0),yn.current=W;return}x&&(U(x,W.path),H(x,W.path),Kr(W.path,!1)),mt(null),qt(""),at(""),Ye.current="",Ct.current="",Ht(""),Yt(null),d&&A(!0)},[H,Kr,Js,d,x,U]);i.useEffect(()=>{$?.path&&Kr($.path,!1)},[Kr,$?.path]),i.useEffect(()=>{if(!$){ts.current+=1,Dt(!1);return}Wt!==$.path&&Li($)},[Li,Wt,$]);const Oi=i.useRef(Js);Oi.current=Js,i.useEffect(()=>{if(!$?.path||Wt!==$.path)return;let W=!1;const Te=window.setInterval(()=>{document.hidden||Mn($.path,Ae).then(We=>{if(W||!We)return;const qe=rt.current;if(!qe||qe.path!==$.path){rt.current=We;return}const ct=We.mtimeMs!==void 0&&qe.mtimeMs!==void 0&&We.mtimeMs!==qe.mtimeMs,it=We.size!==qe.size;!ct&&!it||Oi.current||(rt.current=We,Yt(null))}).catch(()=>{})},2e3);return()=>{W=!0,window.clearInterval(Te)}},[Wt,Mn,$?.path,Ae]);const uo=i.useCallback(()=>{const W=yn.current,Te=Ys.current,We=un.current;if(yn.current=null,Ys.current=null,un.current=null,wn.current=!0,As(!1),Ht(mi),We){x&&ce(x,We),$?.path===We&&(W?Xs(W):(x&&U(x,null),at(""),mt(null),qt(""),Yt(null),d&&A(!1)));return}if(W){Xs(W);return}Te&&(ht(null),Re.getState().setActiveMainTab(Te))},[mi,Xs,d,ce,x,$?.path,ht,U]),fo=i.useCallback(async()=>{const W=yn.current,Te=Ys.current,We=un.current;if(!await or()){wn.current=!1;return}if(yn.current=null,Ys.current=null,un.current=null,wn.current=!0,As(!1),We){x&&ce(x,We),$?.path===We&&(W?await Xs(W):(x&&U(x,null),at(""),mt(null),qt(""),Yt(null),d&&A(!1)));return}if(W){await Xs(W);return}Te&&(ht(null),Re.getState().setActiveMainTab(Te))},[Xs,d,ce,x,or,$?.path,ht,U]),Bi=i.useCallback(W=>{const Te=$?.path===W,We=pi(W,_);if(Te&&Js){As(!0),yn.current=We,un.current=W;return}if(x&&ce(x,W),!!Te){if(We){Xs(We);return}x&&U(x,null),at(""),mt(null),qt(""),Yt(null),d&&A(!1)}},[pi,Xs,Js,d,_,ce,x,$?.path,U]),Q=i.useCallback(W=>{if(Ce.includes(W))return"open";if(w?.files){const Te=W.startsWith(x+"/")?W.slice(x.length+1):W,We=w.files.find(qe=>qe.path===Te);if(We){if(We.index==="A"||We.working_dir==="?")return"git-added";if(We.index==="D")return"git-deleted";if(We.index==="M"||We.working_dir==="M")return"git-modified"}}return null},[Ce,w,x]),ke=i.useCallback(W=>{if(!w?.files)return null;const Te=W.startsWith(x+"/")?W.slice(x.length+1):W,We=Te?`${Te}/`:"";let qe=0,ct=0;for(const it of w.files)it.path.startsWith(We)&&((it.index==="M"||it.working_dir==="M")&&qe++,(it.index==="A"||it.working_dir==="?")&&ct++);return qe+ct>0?{modified:qe,added:ct}:null},[w,x]),Pe=i.useCallback(async W=>{const Te=Ks(W);x&&(z(x,Te),ut.current.has(Te)||await Dn(Te))},[Dn,x,z]),ze=i.useMemo(()=>({canRename:Un,canCreateFile:Xn,canCreateFolder:ur,canDelete:ps,canReveal:Ds}),[Un,Xn,ur,ps,Ds]);function pt(W,Te){const We=Ge[W]??[];return We.map((qe,ct)=>{const it=qe.type==="directory",Zt=it&&ue.includes(qe.path),Es=$?.path===qe.path,_s=ct===We.length-1;return s.jsxs("li",{className:"relative",children:[Te>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),_s&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(h1,{node:qe,root:x,isExpanded:Zt,isActive:Es,isMobile:d,alwaysShowActions:f,status:it?void 0:Q(qe.path),badge:it?ke(qe.path):void 0,permissions:ze,downloadFile:n.downloadFile,contextMenuPath:Ws,setContextMenuPath:Ss,rightClickMenuPath:Bs,setRightClickMenuPath:fs,onSelect:Xs,onToggle:Pe,onRevealPath:Mr,onOpenDialog:Fr}),it&&Zt&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[Qe[qe.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:Qe[qe.path],children:Qe[qe.path]}),s.jsxs($e,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Sn(qe.path)},children:[s.jsx(I,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,pt(qe.path,Te+1)]})]},qe.path)})}const jt=!!($?.path&&eo($.path)),us=!!($?.path&&$.path.toLowerCase().endsWith(".svg")),Kt=!!($?.path&&kd($.path)),on=i.useMemo(()=>Ks(Tt?.path??""),[Tt?.path]),ar=!!(Tt&&on&&Ie&&Ie===on&&!Le&&!Ot&&!jt&&!Kt),kr=i.useMemo(()=>Jl(x,Ie),[Ie,x]),ie=!!($&&(!jt||us)&&!Kt&&ot.length>0),lt=!!($&&kr.length>0),Xe=!!($&&!je&&!jt&&!Kt&&n.writeFile&&ot.length<=go),St=!!($?.path&&Eu($.path)),zt=!!($?.path&&m1($.path)),ks=!!($?.path&&Xo($.path)),Gs=!!($?.path&&Nd($.path)),hn=!!($&&!jt&&!Kt)&&!St&&!Gs&&!(ks&&te==="preview"),pn=i.useMemo(()=>Ie?qf(Ie):null,[Ie]),[Kn,qr]=i.useState(null);i.useEffect(()=>{let W=!1;const Te=$?.path;if(!Te||pn){qr(null);return}return qr(null),ig(Te).then(We=>{W||qr(We)}),()=>{W=!0}},[$?.path,pn]),i.useEffect(()=>{!Xe&&J==="edit"&&K("view")},[Xe,J]);const gi="openchamber:files:md-viewer-mode",xi="openchamber:files:html-viewer-mode",Qa="openchamber:files:json-viewer-mode";i.useEffect(()=>{const W=$?.path;if(!W)return;const Te=kn?"view":"edit";K(le.current[W]??Te);let We=kn?"preview":"edit";try{const it=localStorage.getItem(gi);(it==="preview"||it==="edit")&&(We=it)}catch{}re(ve.current[W]??We);let qe=kn?"preview":"edit";try{const it=localStorage.getItem(xi);(it==="preview"||it==="edit")&&(qe=it)}catch{}Ne(Ee.current[W]??qe),G(_e.current[W]??"preview");let ct=kn?"tree":"text";try{const it=localStorage.getItem(Qa);(it==="tree"||it==="text")&&(ct=it)}catch{}Se(ct)},[$?.path,kn]);const hh=i.useCallback(W=>{const Te=$?.path;Te&&(le.current[Te]=W),K(W)},[$?.path]),ph=i.useCallback(W=>{const Te=$?.path;Te&&(ve.current[Te]=W),re(W);try{localStorage.setItem(gi,W)}catch{}},[$?.path]),mo=i.useCallback(()=>Z,[Z]),gh=i.useCallback(W=>{Se(W);try{localStorage.setItem(Qa,W)}catch{}},[]),xh=i.useCallback(W=>{const Te=$?.path;Te&&(Ee.current[Te]=W),Ne(W);try{localStorage.setItem(xi,W)}catch{}},[$?.path]),bh=i.useCallback(W=>{const Te=$?.path;if(Te&&(_e.current[Te]=W),Ue.current&&(clearTimeout(Ue.current),Ue.current=null),kt.current!==null&&(cancelAnimationFrame(kt.current),kt.current=null),W==="edit")Ht(Ye.current||ot),G(W);else{Ye.current=Bt;const We=Te;G("edit"),kt.current=requestAnimationFrame(()=>{kt.current=requestAnimationFrame(()=>{kt.current=null,!(x&&We&&gn.getState().byRoot[x]?.selectedPath!==We)&&(oe(qe=>qe+1),G("preview"))})});return}},[Bt,ot,x,$?.path]),Ja=i.useCallback(async(W,Te)=>{if(!n.writeFile||Te===Ct.current)return!1;if(!(await n.writeFile(W,Te))?.success)return de.error(e("filesView.toast.writeFileFailed")),!1;Ye.current=Te,Ct.current=Te,Ht(Te);const qe=await Mn(W,Ae).catch(()=>null);return qe&&(rt.current=qe),!0},[n,Mn,Ae,e]);i.useEffect(()=>()=>{Ue.current&&(clearTimeout(Ue.current),Ue.current=null),kt.current!==null&&(cancelAnimationFrame(kt.current),kt.current=null)},[Y,$?.path]);const yh=i.useCallback(W=>{if(Ye.current=W,!$?.path||Y!=="preview"||!n.writeFile)return;Ue.current&&clearTimeout(Ue.current);const Te=$.path;Ue.current=setTimeout(()=>{Ue.current=null,Ja(Te,W).then(We=>{We&&(js(!0),setTimeout(()=>js(!1),1500))}).catch(We=>{de.error(We instanceof Error?We.message:e("filesView.toast.saveFailed"))})},hi)},[Y,n.writeFile,Ja,$?.path,e]),wh=i.useMemo(()=>Gs&&(Ye.current||Bt)||ot,[Bt,ot,Gs]),_c=i.useCallback(()=>te,[te]);i.useEffect(()=>{const W=We=>{const qe=We?"view":"edit",ct=We?"preview":"edit",it=We?"tree":"text";for(const Zt of Ce)le.current[Zt]=qe,Eu(Zt)&&(ve.current[Zt]=ct),Xo(Zt)&&(Ee.current[Zt]=ct);K(qe),re(ct),Ne(ct),Se(it);try{localStorage.setItem(gi,ct),localStorage.setItem(xi,ct),localStorage.setItem(Qa,it)}catch{}},Te=We=>{const qe=!!We.detail?.enabled;W(qe)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",Te),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",Te)}},[Ce]),i.useEffect(()=>{if(!Tt||!x)return;const W=()=>{typeof window>"u"||ft.current===null&&(ft.current=window.requestAnimationFrame(()=>{ft.current=null,$t(Br=>Br+1)}))},Te=(Br,bi)=>{if(Br.state.doc.length!==bi.length)return!1;if(bi.length===0)return!0;const sl=Math.min(128,bi.length);if(Br.state.sliceDoc(0,sl)!==bi.slice(0,sl))return!1;const sd=Math.max(0,bi.length-sl);return Br.state.sliceDoc(sd,bi.length)===bi.slice(sd)},We=Ks(Tt.path);if(!We){is(null),ls.current={key:"",attempts:0};return}const qe=`${We}:${Tt.line}:${Tt.column??1}`;if(ls.current.key!==qe&&(ls.current={key:qe,attempts:0}),$?.path!==We){if(Ps)return;Xs(ge(We));return}if(Le||Wt!==We)return;if(Ot||jt||Kt){is(null),ls.current={key:"",attempts:0};return}if(!Xe)return;if(J!=="edit"){K("edit");return}const ct=Je.current;if(!ct){W();return}if(!Te(ct,Bt)){W();return}const it=Math.max(1,Math.min(Tt.line,ct.state.doc.lines)),Zt=ct.state.doc.line(it),Es=Math.max(1,Tt.column||1),_s=Math.max(0,Zt.to-Zt.from),fr=Math.min(_s,Es-1),lr=Zt.from+fr;if(!(ct.state.selection.main.head===lr)||ls.current.attempts===0){ls.current.attempts+=1,ct.dispatch({selection:{anchor:lr},effects:ti.scrollIntoView(lr,{y:"center"})}),ct.focus(),W();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Br=Je.current;Br&&(Br.dispatch({selection:{anchor:lr},effects:ti.scrollIntoView(lr,{y:"center"})}),Br.focus())}),is(null),ls.current={key:"",attempts:0}},[Xe,Ps,Bt,Pt,Ot,Le,jt,Kt,Wt,Xs,Tt,x,$?.path,is,J,ge]),i.useEffect(()=>{if(!os||!x)return;const W=Ks(os);if(!W){ds(null);return}if($?.path!==W){if(Ps)return;Xs(ge(W));return}if(!(Le||Wt!==W||Ot||jt||Kt)){if(Xe&&J==="edit"){const Te=Je.current;if(!Te)return;Te.focus()}ds(null)}},[Xe,Ps,Ot,Le,Xs,jt,Kt,Wt,os,x,$?.path,ds,J,ge]);const Vi=i.useCallback(W=>{if(!d||!W||!W.hasFocus||typeof window>"u")return;const Te=window.visualViewport;if(!Te)return;const We=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,We-(Te.offsetTop+Te.height))<=0)return;const ct=W.state.selection.main.head,it=W.coordsAtPos(ct);if(!it)return;const Zt=Math.round(Te.offsetTop+Te.height),_s=it.bottom+20-Zt;_s<=0||(W.scrollDOM.scrollTop+=_s)},[d]);i.useEffect(()=>{if(!d||typeof window>"u")return;const W=()=>{window.requestAnimationFrame(()=>{Vi(Je.current)})},Te=window.visualViewport;return Te?.addEventListener("resize",W),Te?.addEventListener("scroll",W,{passive:!0}),document.addEventListener("selectionchange",W),()=>{Te?.removeEventListener("resize",W),Te?.removeEventListener("scroll",W),document.removeEventListener("selectionchange",W)}},[d,Vi]),i.useEffect(()=>{if(!Xe||J!=="edit"||d)return;const W=ni("open_go_to_line",Rs),Te=We=>{const qe=We.target;if(qe?.closest('[role="dialog"]'))return;const ct=!!qe?.closest(".cm-editor");qe?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!ct||!document.activeElement?.closest(".cm-editor")||ia(We,W)&&(We.preventDefault(),vr(!0))};return window.addEventListener("keydown",Te),()=>window.removeEventListener("keydown",Te)},[Xe,d,Rs,J]);const $c=i.useMemo(()=>{if(!$?.path)return[zl(o)];const W=Di($.path),Te=[zl(o,W?{syntaxColors:!1}:void 0)],We=pn??Kn;return We&&Te.push(We),W&&Te.push(hm({language:W,themeName:o.metadata.id,theme:Yf(o)})),C&&Te.push(ti.lineWrapping),d&&Te.push(ti.updateListener.of(qe=>{qe.view.hasFocus&&(qe.selectionSet||qe.focusChanged||qe.viewportChanged||qe.geometryChanged)&&window.requestAnimationFrame(()=>{Vi(qe.view)})})),Te},[o,$?.path,pn,Kn,C,d,Vi]),zc=i.useMemo(()=>({light:Oe.metadata.id,dark:Me.metadata.id}),[Oe.metadata.id,Me.metadata.id]),Vo=$?.path&&jt&&!r.isDesktop&&!us?`${$.path}|${Ae.allowOutsideWorkspace?"outside":"workspace"}|${Ae.outsideFileGrant??""}`:"",_o=$?.path&&Kt?`${$.path}|${Ae.allowOutsideWorkspace?"outside":"workspace"}|${Ae.outsideFileGrant??""}`:"",$o=$?.path&&ks&&te==="preview"&&!r.isVSCode?$.path:"",Xa=e("filesView.error.readFileFailed"),{readyKey:Uc,nonce:Wc}=jl(Vo,mt,Xa),{readyKey:Hc,nonce:vh}=jl($o,mt,Xa),{readyKey:Gc,nonce:Kc}=jl(_o,mt,Xa),qc=!!(Vo&&Uc!==Vo),jh=!!($o&&Hc!==$o),Yc=!!(_o&&Gc!==_o),Qc=$?.path&&jt?r.isDesktop?us?`data:${Cd($.path)};utf8,${encodeURIComponent(ot)}`:Et:us?`data:${Cd($.path)};utf8,${encodeURIComponent(ot)}`:Uc===Vo?Ai().authenticatedAsset("/api/fs/raw",{path:$.path,allowOutsideWorkspace:Ae.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ae.outsideFileGrant,directory:x||void 0}):"":"",Jc=$?.path&&Kt&&Gc===_o?Ai().authenticatedAsset("/api/fs/raw",{path:$.path,allowOutsideWorkspace:Ae.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ae.outsideFileGrant,directory:x||void 0}):"",Xc=i.useCallback(W=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:Jc,className:"h-full w-full border-0",title:W.name},Kc)}),[Jc,Kc]);i.useEffect(()=>{let W=!1;return(async()=>{if(!r.isDesktop||!$?.path||!jt||us){Vt.current&&(URL.revokeObjectURL(Vt.current),Vt.current=""),qt("");return}mt(null),Vt.current&&(URL.revokeObjectURL(Vt.current),Vt.current=""),await(n.readFileBinary?n.readFileBinary($.path,Ae).then(qe=>qe.dataUrl):(async()=>{const qe=await Cs("/api/fs/raw",{query:{path:$.path,allowOutsideWorkspace:Ae.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ae.outsideFileGrant,directory:x||void 0}});if(!qe.ok)throw new Error(e("filesView.error.readFileFailed"));const ct=await qe.blob(),it=URL.createObjectURL(ct);return W?(URL.revokeObjectURL(it),""):(Vt.current=it,it)})()).then(qe=>{W||(qt(qe),Yt($.path))}).catch(qe=>{Vt.current&&(URL.revokeObjectURL(Vt.current),Vt.current=""),W||(qt(""),mt(qe instanceof Error?qe.message:e("filesView.error.readFileFailed")),Yt(null))}).finally(()=>{W||Dt(!1)})})(),()=>{W=!0}},[n,jt,us,x,r.isDesktop,$?.path,Ae,e]),i.useEffect(()=>()=>{Vt.current&&(URL.revokeObjectURL(Vt.current),Vt.current="")},[]);const Sh=i.useCallback(()=>Ns(null),[]),Nh=i.useMemo(()=>xm({drafts:ln,editingDraftId:jn,commentText:En,onTextChange:Cn,selection:gs,isDragging:X,fileLabel:$?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:W=>({start:W.startLine,end:W.endLine}),onSave:Mi,onCancel:()=>{Ts(null),cn()},onEdit:W=>{Or(W),Ts({start:W.startLine,end:W.endLine})},onDelete:Nr}),[cn,En,Nr,jn,ln,Mi,X,gs,$?.path,Cn,Or]),Zc=i.useCallback((W,Te)=>s.jsx("div",{className:"h-full",children:s.jsx(Eh,{file:{name:W.name,contents:Te,lang:Di(W.path)||void 0},options:{disableFileHeader:!0,overflow:C?"wrap":"scroll",theme:zc,themeType:o.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[o.metadata.variant,zc,C]),Za=({exitFullscreenOnly:W=!1,layout:Te="floating"}={})=>{if(!$)return null;const qe=Te==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",ct=(it,Zt)=>s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:Zt})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:it})]});return s.jsxs("div",{className:qe,children:[Xe&&J==="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")]}):ss&&hs==="saved"&&!Js?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")]}):Js?ct(e(ss?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${rl()}+S`}),s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>{or()},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(ss?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${rl()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${rl()}+S`}),children:s.jsx(I,{name:"save-3",className:"size-4"})})):null,ct(e(ss?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>Os(it=>!it),className:De("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ss?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ss?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(ss?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:ss?s.jsx(I,{name:"file-check-fill",className:"size-4"}):s.jsx(I,{name:"file-check",className:"size-4"})}))]}),s.jsxs(sn,{onOpenChange:ee,children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(en,{asChild:!0,children:s.jsx($e,{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(Lt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(tn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Er.map(it=>s.jsxs(xs,{className:"flex items-center gap-2",onClick:()=>{Gr(it)},children:[s.jsx(s1,{label:it.label,iconDataUrl:it.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:it.label})]},it.id)),vn?s.jsxs(xs,{className:"flex items-center gap-2",onClick:()=>{nr(!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]})]}),!jt&&!Kt&&s.jsxs(s.Fragment,{children:[ct(e(C?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>O(!C),className:De("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"})})),J==="edit"&&s.jsxs(s.Fragment,{children:[ct(e("filesView.editor.findInFile"),s.jsx($e,{variant:"ghost",size:"sm",onClick:it=>{R(!F),it.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"})})),ct(e("filesView.editor.goToLine"),s.jsx($e,{variant:"ghost",size:"sm",onClick:it=>{vr(Zt=>!Zt),it.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(Xv,{open:Jn,onOpenChange:vr,view:Je.current,variant:"inline"})]})]}),hn&&Xe&&!zt&&!ks&&s.jsx(aa,{currentMode:J==="view"?"preview":"edit",onToggle:()=>{hh(J==="view"?"edit":"view")}}),(St||Xo($?.path??""))&&s.jsx(aa,{currentMode:St?mo():_c(),onToggle:()=>{Xo($?.path??"")?xh(_c()==="preview"?"edit":"preview"):ph(mo()==="preview"?"edit":"preview")}}),St&&mo()==="preview"&&jr&&s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(Ut?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{Ut?_t():ot.trim()&&Nt(ot)},children:Ut?s.jsx(I,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"volume-up",className:"size-4"})})}),s.jsx(Lt,{sideOffset:8,children:e(Ut?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),Gs&&s.jsxs(s.Fragment,{children:[s.jsx(aa,{currentMode:Y,onToggle:()=>bh(Y==="preview"?"edit":"preview")}),Y==="preview"&&s.jsx($e,{variant:"ghost",size:"sm",onClick:async()=>{const it=It.current?.getXml();if(Ue.current&&(clearTimeout(Ue.current),Ue.current=null),$?.path&&it){if(!await Ja($.path,it))return;js(!0),setTimeout(()=>js(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:nn?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"save-3",className:"size-4"})})]}),zt&&ct(e(pe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>gh(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"})})),ie&&ct(e("filesView.editor.copyFileContents"),s.jsx($e,{variant:"ghost",size:"sm",onClick:async()=>{(await dr(ot)).ok?(br(!0),zs.current!==null&&window.clearTimeout(zs.current),zs.current=window.setTimeout(()=>{br(!1)},1200)):de.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:ci?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"size-4"})})),lt&&ct(e("filesView.editor.copyFilePathTitle",{path:kr}),s.jsx($e,{variant:"ghost",size:"sm",onClick:async()=>{(await dr(kr)).ok?(wr(!0),we.current!==null&&window.clearTimeout(we.current),we.current=window.setTimeout(()=>{wr(!1)},1200)):de.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:kr}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:kr}),children:yr?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&&ct(e("filesView.editor.saveFile"),s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>{const it=n.downloadFile;it&&it($.path).catch(Zt=>{console.error("Download failed:",Zt),de.error(e("sidebarFilesTree.toast.operationFailed"))})},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"})})),W?ct(e("filesView.editor.exitFullscreen"),s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>E(!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"})})):!d&&t==="full"&&ct(e(T?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>E(!T),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(T?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(T?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:T?s.jsx(I,{name:"fullscreen-exit",className:"size-4"}):s.jsx(I,{name:"fullscreen",className:"size-4"})}))]})},el=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Ls,{open:Ps,onOpenChange:W=>{W||As(!0)},children:s.jsxs(Fs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Us,{children:[s.jsx($s,{children:e("filesView.unsaved.title")}),s.jsx(an,{children:e("filesView.unsaved.description")})]}),s.jsxs(sr,{children:[s.jsx($e,{variant:"outline",onClick:()=>{fo()},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($e,{variant:"destructive",onClick:uo,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:De("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:[d&&D&&s.jsx("button",{type:"button",onClick:()=>A(!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"})}),d?$?s.jsxs(sn,{children:[s.jsx(en,{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(Ur,{filePath:$.path,extension:$.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Tu,{name:$.name}),s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(tn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:_.map(W=>{const Te=$?.path===W.path;return s.jsxs(xs,{onSelect:We=>{if(We.target.closest("[data-close-open-file]")){We.preventDefault();return}Te||Xs(W)},className:De("flex min-w-0 items-center justify-between gap-2 overflow-hidden",Te&&"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(Ur,{filePath:W.path,extension:W.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Tu,{name:W.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:We=>{We.preventDefault(),We.stopPropagation()},onClick:We=>{We.preventDefault(),We.stopPropagation(),Bi(W.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:W.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},W.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):_.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[P.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"}),P.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:ne,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:_.map(W=>{const Te=$?.path===W.path;return s.jsxs("div",{title:Jl(x,W.path),className:De("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",Te?"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(Ur,{filePath:W.path,extension:W.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Te||Xs(W)},className:"max-w-[12rem] truncate text-left",children:W.name}),s.jsx("button",{type:"button",onClick:We=>{We.stopPropagation(),Bi(W.path)},className:De("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!Te&&!f&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:W.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},W.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,Sr&&!d&&$?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[kr?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:kr,children:kr}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Za({layout:"docked"})})]}):null]}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[$&&!F&&!(Sr&&!d)&&s.jsx("div",{ref:V,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>B(!0),onMouseLeave:()=>{M.current>0||B(!1)},children:L?Za():s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>B(!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(Lt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})}),s.jsx(Vn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:$?Le||qc||Yc?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")]}):Ot?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Ot}):jt?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Qc,alt:$?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},Wc)}):Kt?Xc($):$&&Gs&&Y==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(e1,{ref:It,xml:wh,onChange:yh},`${$.path}:${q}`)}):$&&zt&&pe==="tree"?s.jsx(Zs,{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(og,{jsonString:ot,maxHeight:"100%",initiallyExpandedDepth:2})})}):$&&St&&mo()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[ot.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(ot.length/1024)})}),s.jsx(Zs,{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(Po,{content:ot,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):$&&ks&&te==="preview"?jh?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!r.isVSCode&&Hc===$o?(()=>{const W=$.path.split("/").map(Te=>encodeURIComponent(Te)).join("/");return Ai().authenticatedAsset(`/api/fs/serve${W.startsWith("/")?W:`/${W}`}`)})():void 0,srcDoc:r.isVSCode?(()=>{const W=$.path.substring(0,$.path.lastIndexOf("/")+1);return W?ot.replace(/<head([^>]*)>/i,`<head$1><base href="${W}">`):ot})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},vh)}):$&&hn&&J==="view"?Zc($,Bt):s.jsxs("div",{className:De("relative h-full",ar&&"overflow-hidden"),ref:wt,children:[s.jsx("div",{className:De("h-full",ar&&"invisible"),children:s.jsx(Ul,{value:Bt,onChange:Ht,readOnly:!Xe,vimMode:Hs==="vim",extensions:$c,className:"h-full",blockWidgets:Nh,onViewReady:W=>{Je.current=W,$t(Te=>Te+1),window.requestAnimationFrame(()=>{Vi(W)})},onViewDestroy:()=>{Je.current&&(Je.current=null),$t(W=>W+1)},enableSearch:!0,searchOpen:F,onSearchOpenChange:R,highlightLines:gs?{start:Math.min(gs.start,gs.end),end:Math.max(gs.start,gs.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(W,Te,We)=>{if(!(We instanceof MouseEvent)||We.button!==0)return!1;We.preventDefault();const qe=W.state.doc.lineAt(Te.from).number;if(gs&&!We.shiftKey&&Math.min(gs.start,gs.end)===qe&&Math.max(gs.start,gs.end)===qe)return Ts(null),cn(),Wn.current=!1,fn.current=null,et(!1),!0;if(d&&gs&&!We.shiftKey){const ct=Math.min(gs.start,gs.end,qe),it=Math.max(gs.start,gs.end,qe);return Ts({start:ct,end:it}),Wn.current=!1,fn.current=null,et(!1),!0}if(Wn.current=!0,fn.current=qe,et(!0),gs&&We.shiftKey){const ct=Math.min(gs.start,qe),it=Math.max(gs.end,qe);Ts({start:ct,end:it})}else Ts({start:qe,end:qe});return!0},mouseover:(W,Te,We)=>{if(!(We instanceof MouseEvent)||We.buttons!==1||!Wn.current||fn.current===null)return!1;const qe=W.state.doc.lineAt(Te.from).number,ct=Math.min(fn.current,qe),it=Math.max(fn.current,qe);return Ts({start:ct,end:it}),et(!0),!1},mouseup:()=>(Wn.current=!1,fn.current=null,et(!1),!1)}}})}),ar&&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")})})]})]}),kh=!!(x&&Ge[x]),ed=x?Qe[x]:null,td=s.jsxs("section",{className:De("flex min-h-0 flex-col overflow-hidden",d?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:De("flex flex-col gap-2 py-2",d?"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(bn,{ref:v,value:S,onChange:W=>j(W.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:()=>{j(""),v.current?.focus()},children:s.jsx(I,{name:"close",className:"size-4"})})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>Fr("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(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>Fr("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(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($e,{variant:"ghost",size:"sm",onClick:()=>{ir()},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(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(Vn,{outerClassName:"flex-1 min-h-0",className:De("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Rt?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")]}):nt.length>0?nt.map(W=>{const Te=$?.path===W.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Xs(W)},className:De("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Te?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Bm(W.path,W.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:W.path,children:W.relativePath??W.path})]})},W.path)}):ed?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:ed}),s.jsxs($e,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ir()},children:[s.jsx(I,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):kh?pt(x,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Ch=t==="full"&&T&&$&&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:Za({exitFullscreenOnly:!0})}),s.jsx(Vn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Le||qc||Yc?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…"]}):Ot?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Ot}):jt?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Qc,alt:$.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},Wc)}):Kt?Xc($):St&&mo()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[ot.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(ot.length/1024)})}),s.jsx(Zs,{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(Po,{content:ot,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):hn&&J==="view"?Zc($,Bt):s.jsxs("div",{className:De("relative h-full",ar&&"overflow-hidden"),children:[s.jsx("div",{className:De("h-full",ar&&"invisible"),children:s.jsx(Ul,{value:Bt,onChange:Ht,readOnly:!Xe,vimMode:Hs==="vim",extensions:$c,className:"h-full",onViewReady:W=>{Je.current=W,window.requestAnimationFrame(()=>{Vi(W)})},onViewDestroy:()=>{Je.current&&(Je.current=null)}})}),ar&&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(p1,{activeDialog:cs,dialogData:ms,dialogInputValue:He,onDialogInputChange:ns,isDialogSubmitting:ws,onDialogSubmit:fi,onClose:Sh,inputRef:bs}),Ch,d?D?el:td: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:el})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[m>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:td}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:el})]})]})};function g1(t){return t+1}const gr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Sl=(t,e)=>{const n=gr(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},x1=(t,e,n)=>Sl(Sl(Sl(t,".opencode"),"plans"),`${e}-${n}.md`),b1=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,y1=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},w1=(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},v1=(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 a=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 a?{id:a.id,path:a.path}:null},_m=({targetPath:t=null})=>{const{t:e}=At(),n=dt(ae=>ae.currentSessionId),r=dt(ae=>ae.createSession),o=dt(ae=>ae.initializeNewOpenChamberSession),a=dt(ae=>ae.sendMessage),c=dt(ae=>ae.setCurrentSession),l=wc(),d=qs(ae=>ae.homeDirectory),u=mc(ae=>ae.planModeEnabled),m=ys(ae=>ae.projects),f=ys(ae=>ae.activeProjectId),g=xn(ae=>ae.directories),y=li()??"",p=Re(ae=>ae.setActiveMainTab),x=Re(ae=>ae.setSessionSwitcherOpen),b=Qn(),{isMobile:h}=Rr(),{currentTheme:N}=Hr(),w=i.useMemo(()=>n?l.find(ae=>ae.id===n)??null:null,[n,l]),S=i.useMemo(()=>{const ae=typeof w?.directory=="string"?w.directory:"";return gr(ae||"")},[w?.directory]),j=i.useMemo(()=>gr(y||S),[y,S]),k=i.useMemo(()=>v1(j,m,f),[f,j,m]),v=i.useMemo(()=>k?g.get(k.path)?.isGitRepo===!0:!1,[k,g]),[D,A]=i.useState(null),[C,O]=i.useState(!1),[T,E]=i.useState(null),F=i.useMemo(()=>!T||!S||!d?T:w1(T,{currentDirectory:S,homeDirectory:d}),[T,S,d]),[R,L]=i.useState(""),{isPlaying:B,play:V,stop:M}=Kf(),ee=es(ae=>ae.showMessageTTSButtons),[se,J]=i.useState(null),K=i.useMemo(()=>F&&F.split("/").pop()||e("planView.file.defaultName"),[F,e]),Z=i.useMemo(()=>R.trim()&&ag(R).title||e("planView.title.default"),[R,e]),re=i.useMemo(()=>Z.trim()||e("planView.title.default"),[Z,e]),[pe,Se]=i.useState(!1),[te,Ne]=i.useState(!1),[Y,G]=i.useState("edit"),q=i.useRef(null),[oe,le]=i.useState(null),ve=i.useRef(null),Ee=i.useRef(null),_e="openchamber:plan:md-viewer-mode";i.useEffect(()=>{try{const ae=localStorage.getItem(_e);if(!ae)return;const Be=JSON.parse(ae);(Be==="preview"||Be==="edit")&&G(Be)}catch{}},[]);const Oe=i.useCallback(ae=>{G(ae);try{localStorage.setItem(_e,JSON.stringify(ae))}catch{}},[]),Me=i.useRef(!1),he=i.useRef(null),[Ce,xe]=i.useState(!1);i.useEffect(()=>{const ae=()=>{Me.current=!1,he.current=null,xe(!1)};return document.addEventListener("mouseup",ae),()=>document.removeEventListener("mouseup",ae)},[]);const ue=i.useCallback((ae,Be)=>{const Ge=ae.split(`
|
|
34
|
+
`),Ke=Math.max(1,Be.start),Qe=Math.min(Ge.length,Be.end);return Ke>Qe?"":Ge.slice(Ke-1,Qe).join(`
|
|
35
|
+
`)},[]),H=fm({source:"plan",fileLabel:K,language:T&&Di(T)||"markdown",getCodeForRange:ae=>ue(R,mm(ae)),toStoreRange:ae=>({startLine:ae.start,endLine:ae.end}),fromDraftRange:ae=>({start:ae.startLine,end:ae.endLine})}),{drafts:ce,commentText:fe,setCommentText:U,editingDraftId:z,setSelection:be,saveComment:ge,cancel:_,reset:ye,startEdit:$,deleteDraft:Ie}=H;i.useEffect(()=>{le(null),ye()},[R,ye]),i.useEffect(()=>{be(oe)},[oe,be]);const je=i.useCallback(()=>{le(null),_()},[_]),Fe=i.useCallback((ae,Be)=>{Be&&le(Be),ge(ae,Be??oe??void 0),le(null)},[oe,ge]);i.useEffect(()=>{if(!oe)return;const ae=Ge=>{const Ke=Ge.target;Ke.closest('[data-comment-card="true"]')||Ke.closest('[data-comment-input="true"]')||Ke.closest(".oc-block-widget")||Ke.closest(".cm-gutterElement")||Ke.closest("[data-sonner-toast]")||Ke.closest("[data-sonner-toaster]")||fe.trim()||(le(null),_())},Be=window.setTimeout(()=>{document.addEventListener("click",ae)},100);return()=>{window.clearTimeout(Be),document.removeEventListener("click",ae)}},[_,fe,z,h,oe]);const Ae=i.useMemo(()=>{const ae=T?Di(T):null,Be=!!ae&&ae!=="markdown",Ge=[zl(N,Be?{syntaxColors:!1}:void 0)],Ke=qf(T||"plan.md");return Ke&&Ge.push(Ke),Be&&ae&&Ge.push(hm({language:ae,themeName:N.metadata.id,theme:Yf(N)})),Ge.push(ti.lineWrapping),Ge},[N,T]);i.useEffect(()=>{if(!u&&!t){E(null),L(""),Se(!1);return}let ae=!1;const Be=async Ke=>{if(b.files?.readFile)return(await b.files.readFile(Ke))?.content??"";const Qe=Lo()?.files;if(Qe?.readFile)return(await Qe.readFile(Ke,{optional:!0}))?.content??"";const st=await Cs(`/api/fs/read?path=${encodeURIComponent(Ke)}&optional=true`,{cache:"no-store"});if(!st.ok)throw new Error(`Failed to read plan file (${st.status})`);return st.text()};return(async()=>{if(E(null),L(""),J(null),t){Se(!0);try{const Ke=await Be(t);if(ae)return;E(t),L(Ke)}catch{if(ae)return;E(null),L("")}finally{ae||Se(!1)}return}if(!w?.slug||!w?.time?.created||!S){E(null),L("");return}Se(!0);try{const Ke=x1(S,w.time.created,w.slug),Qe=y1(b1(w.time.created,w.slug),d||null);let st=null,ut=null;try{ut=await Be(Ke),st=Ke}catch{}if(!st)try{ut=await Be(Qe),st=Qe}catch{}if(ae)return;if(!st||ut===null){E(null),L("");return}E(st),L(ut)}catch{if(ae)return;E(null),L("")}finally{ae||Se(!1)}})(),()=>{ae=!0}},[d,u,b.files,S,w?.slug,w?.time?.created,t]),i.useEffect(()=>{if(!T){J(null);return}const ae=window.setTimeout(async()=>{J(null);try{if(b.files?.writeFile){if(!(await b.files.writeFile(T,R))?.success)throw new Error(e("planView.error.writeFailed"))}else{const Be=await Cs("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:T,content:R})});if(!Be.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:Be.status}))}}catch(Be){J(Be instanceof Error?Be.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(ae)}},[R,T,b.files,e]),i.useEffect(()=>()=>{q.current!==null&&window.clearTimeout(q.current)},[]);const ne=i.useCallback(()=>{p("chat"),x(!1)},[p,x]),P=i.useCallback(async ae=>{if(!k||!D)return;const Be=await Rn(D.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:re}),Ke=[{synthetic:!0,text:await Rn(D.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:re,plan_path:T??""})}];O(!0);try{ne();let Qe=null,st=k.path;if(D.target==="worktree"){if(!v)return;const vt=await Uf(k.path,Wf());if(!vt?.id)return;Qe=vt.id,st=vt.path}else{const vt=await r(void 0,k.path,null);if(!vt?.id)return;Qe=vt.id,st=vt.directory??k.path,o(vt.id,es.getState().agents??[])}if(!Qe)return;const ut=pc.getState();ut.saveSessionModelSelection(Qe,ae.providerID,ae.modelID),ae.agent.trim()&&(ut.saveSessionAgentSelection(Qe,ae.agent),ut.saveAgentModelForSession(Qe,ae.agent,ae.providerID,ae.modelID),ut.saveAgentModelVariantForSession(Qe,ae.agent,ae.providerID,ae.modelID,ae.variant||void 0)),c(Qe,st),await a(Be,ae.providerID,ae.modelID,ae.agent.trim()||void 0,void 0,void 0,Ke,ae.variant||void 0),A(null)}finally{O(!1)}},[v,r,k,o,D,T,ne,a,re,c]),me=i.useMemo(()=>xm({drafts:ce,editingDraftId:z,commentText:fe,onTextChange:U,selection:oe,isDragging:Ce,fileLabel:K,newWidgetId:"plan-new-comment-input",mapDraftToRange:ae=>({start:ae.startLine,end:ae.endLine}),onSave:Fe,onCancel:je,onEdit:ae=>{$(ae),le({start:ae.startLine,end:ae.endLine})},onDelete:Ie}),[fe,Ie,z,je,Fe,Ce,oe,ce,K,U,$]);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:Z}),se?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:se,children:e("planView.error.saveFailed")}):null]}),T?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(sn,{children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx(en,{asChild:!0,children:s.jsx($e,{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(Lt,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(tn,{align:"end",children:[s.jsx(xs,{onClick:()=>A({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(xs,{onClick:()=>A({action:"improve",target:"worktree"}),disabled:!v,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(sn,{children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx(en,{asChild:!0,children:s.jsx($e,{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(Lt,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(tn,{align:"end",children:[s.jsx(xs,{onClick:()=>A({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(xs,{onClick:()=>A({action:"implement",target:"worktree"}),disabled:!v,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(aa,{currentMode:Y,onToggle:()=>Oe(Y==="preview"?"edit":"preview")}),Y==="preview"&&ee&&s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e(B?"planView.tts.stopSpeaking":"planView.tts.readAloud"),onClick:()=>{B?M():R.trim()&&V(R)},children:B?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"volume-up",className:"h-4 w-4"})})}),s.jsx(Lt,{sideOffset:8,children:e(B?"planView.tts.stopSpeaking":"planView.tts.readAloud")})]}),s.jsx($e,{variant:"ghost",size:"sm",onClick:async()=>{(await dr(R)).ok&&(Ne(!0),q.current!==null&&window.clearTimeout(q.current),q.current=window.setTimeout(()=>{Ne(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:te?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(wm,{open:D!==null,onOpenChange:ae=>{!ae&&!C&&A(null)},target:D?.target??"session",projectDirectory:k?.path??null,submitting:C,onConfirm:P}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Vn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:pe?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:Y==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(Zs,{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(Po,{content:R,className:"typography-markdown-body",enableFileReferences:!1})})}):s.jsx("div",{className:"relative h-full",ref:Ee,children:s.jsx(Ul,{value:R,onChange:L,readOnly:!1,className:"h-full",extensions:Ae,onViewReady:ae=>{ve.current=ae},onViewDestroy:()=>{ve.current=null},blockWidgets:me,highlightLines:oe?{start:Math.min(oe.start,oe.end),end:Math.max(oe.start,oe.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ae,Be,Ge)=>{if(!(Ge instanceof MouseEvent)||Ge.button!==0)return!1;Ge.preventDefault();const Ke=ae.state.doc.lineAt(Be.from).number;if(oe&&!Ge.shiftKey&&Math.min(oe.start,oe.end)===Ke&&Math.max(oe.start,oe.end)===Ke)return le(null),_(),Me.current=!1,he.current=null,xe(!1),!0;if(h&&oe&&!Ge.shiftKey){const Qe=Math.min(oe.start,oe.end,Ke),st=Math.max(oe.start,oe.end,Ke);return le({start:Qe,end:st}),Me.current=!1,he.current=null,xe(!1),!0}if(Me.current=!0,he.current=Ke,xe(!0),oe&&Ge.shiftKey){const Qe=Math.min(oe.start,Ke),st=Math.max(oe.end,Ke);le({start:Qe,end:st})}else le({start:Ke,end:Ke});return!0},mouseover:(ae,Be,Ge)=>{if(!(Ge instanceof MouseEvent)||Ge.buttons!==1||!Me.current||he.current===null)return!1;const Ke=ae.state.doc.lineAt(Be.from).number,Qe=Math.min(he.current,Ke),st=Math.max(he.current,Ke);return le({start:Qe,end:st}),xe(!0),!1},mouseup:()=>(Me.current=!1,he.current=null,xe(!1),!1)}}})})})})})})]})},j1=8,Fc=t=>t,Xl=t=>{const e=Fc(t).type;return typeof e=="string"?e:""},S1=t=>{const e=Fc(t).tool;return typeof e=="string"?e:""},N1=t=>{const e=Fc(t).text;return typeof e=="string"?e:""},k1=t=>{const e=Xl(t);return e==="tool"?S1(t).trim().toLowerCase()||"tool":e||"unknown"},C1=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=k1(n);e.includes(r)||e.push(r)}return e.join(" + ")},A1=(t,e=j1)=>typeof t!="string"?"":t.length<=e?t:t.slice(-e),D1=t=>t.replace(/\s+/g," ").trim(),I1=t=>{for(const n of t)if(Xl(n)==="text"){const r=D1(N1(n));if(r.length===0)continue;return r}const e=t.filter(n=>Xl(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},P1=(t,e,n)=>`${n(t)} / ${n(e)}`,T1=t=>{if(t==="12h")return!0;if(t==="24h")return!1},R1=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=T1(e);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:n===!1?"2-digit":"numeric",minute:"2-digit",...n===void 0?{}:{hour12:n}})},Zl={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},ca={user:0,assistant:0,tool:0,other:0},ji=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Nl=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(u=>u.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Zl,total:ji(n)};if(!n||typeof n!="object")return Zl;const r=n,o=ji(r.input),a=ji(r.output),c=ji(r.reasoning),l=ji(r.cache?.read),d=ji(r.cache?.write);return{input:o,output:a,reasoning:c,cacheRead:l,cacheWrite:d,total:o+a+c+l+d}},E1=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},er=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+er(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+er(n),0):0,M1=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...ca,assistant:er(n.text)+er(n.content)};const o=E1(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:er(n.input)+er(n.output)+er(n.error)+er(n.call?.input)+er(n.call?.output)+er(n.call?.error)+er(n.raw)+Math.round(er(n.metadata)*.25)+Math.round(er(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}},Mu=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),F1=t=>{const e=Oo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},L1=(t,e)=>{if(t.length===0)return{...ca};const n=t.reduce((r,o)=>{const a=F1(o);let c={...ca};for(const l of o.parts)c=Mu(c,M1(l,a));return Mu(r,c)},{...ca});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)}},Si=t=>t.toLocaleString(Zi()),O1=t=>!Number.isFinite(t)||t<=0?new Intl.NumberFormat(Zi(),{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(Zi(),{style:"currency",currency:"USD",minimumFractionDigits:t<.01?4:2,maximumFractionDigits:t<.01?4:2}).format(t),B1=(t,e)=>!t||!Number.isFinite(t)?"-":gc(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),V1=(t,e,n)=>{const r=t.find(a=>a.id===e),o=r?.models?.find(a=>a.id===n);return{providerName:r?.name||e||"-",modelName:o?.name||n||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},_1=()=>{const t=gt.c(202),{t:e}=At(),n=Re($1);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[o,a]=i.useState(r),[c,l]=i.useState(null),d=i.useRef(null),u=dt(z1),m=wc(),f=lg(u??""),g=es(U1);let y;t[1]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null),a(W1),l(null)},t[1]=y):y=t[1];let p;t[2]!==u?(p=[u],t[2]=u,t[3]=p):p=t[3],i.useEffect(y,p);let x,b;t[4]===Symbol.for("react.memo_cache_sentinel")?(x=()=>()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},b=[],t[4]=x,t[5]=b):(x=t[4],b=t[5]),i.useEffect(x,b);let h;t[6]===Symbol.for("react.memo_cache_sentinel")?(h=async(mt,Et)=>{(await dr(Et)).ok?(l(mt),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{l(Vt=>Vt===mt?null:Vt),d.current=null},2e3)):l(null)},t[6]=h):h=t[6];const N=h;let w;t[7]!==u||t[8]!==m?(w=u?m.find(mt=>mt.id===u)??null:null,t[7]=u,t[8]=m,t[9]=w):w=t[9];const S=w;let j,k,v,D,A,C;if(t[10]!==g||t[11]!==f){j=f.filter(H1);let mt;t[18]!==f?(mt=f.filter(G1),t[18]=f,t[19]=mt):mt=t[19],C=mt;let Et=null;for(let Vt=j.length-1;Vt>=0;Vt=Vt-1,Vt){const Wt=j[Vt];if(Nl(Wt).total>0){Et=Wt;break}}D=Et?Nl(Et):Zl,k=cg({input:D.input,cache:{read:D.cacheRead,write:D.cacheWrite}}),A=j.reduce(K1,0);const qt=Et?.info??null;v=V1(g,qt?.providerID||"",qt?.modelID||""),t[10]=g,t[11]=f,t[12]=j,t[13]=k,t[14]=v,t[15]=D,t[16]=A,t[17]=C}else j=t[12],k=t[13],v=t[14],D=t[15],A=t[16],C=t[17];const O=v,T=O.contextLimit,E=T&&T>0?Math.min(999,D.total/T*100):0;let F;if(t[20]!==f){const mt=[...f].reverse().find(q1)?.info?.system||"";F=L1(f,mt),t[20]=f,t[21]=F}else F=t[21];const R=F,L=R.user,B=R.assistant,V=R.tool,M=Math.max(0,D.input-L-B-V),ee=L+B+V+M,se=f[0]?.info?.time?.created,J=f.length>0?f[f.length-1]?.info?.time?.created:null;let K;t[22]!==S?.title||t[23]!==e?(K=S?.title||e("contextSidebar.session.untitled"),t[22]=S?.title,t[23]=e,t[24]=K):K=t[24];const Z=S?.time?.created??se??null,re=J??S?.time?.created??null;let pe;t[25]!==B||t[26]!==M||t[27]!==V||t[28]!==L?(pe={user:L,assistant:B,tool:V,other:M},t[25]=B,t[26]=M,t[27]=V,t[28]=L,t[29]=pe):pe=t[29];let Se;t[30]!==j.length||t[31]!==ee||t[32]!==k||t[33]!==T||t[34]!==O||t[35]!==f.length||t[36]!==Z||t[37]!==re||t[38]!==pe||t[39]!==K||t[40]!==D||t[41]!==A||t[42]!==E||t[43]!==C.length?(Se={sessionTitle:K,messagesCount:f.length,userMessagesCount:C.length,assistantMessagesCount:j.length,createdAt:Z,lastActivityAt:re,providerModel:O,tokenBreakdown:D,usagePercent:E,cacheHitRate:k,totalAssistantCost:A,contextLimit:T,breakdown:pe,breakdownTotal:ee},t[30]=j.length,t[31]=ee,t[32]=k,t[33]=T,t[34]=O,t[35]=f.length,t[36]=Z,t[37]=re,t[38]=pe,t[39]=K,t[40]=D,t[41]=A,t[42]=E,t[43]=C.length,t[44]=Se):Se=t[44];const te=Se;if(!u){let mt;t[45]!==e?(mt=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=mt):mt=t[46];let Et;return t[47]!==mt?(Et=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:mt}),t[47]=mt,t[48]=Et):Et=t[48],Et}let Ne;t[49]!==e?(Ne=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=Ne):Ne=t[50];let Y;t[51]!==Ne||t[52]!==te.breakdown.user?(Y={key:"user",label:Ne,value:te.breakdown.user,color:"var(--status-success)"},t[51]=Ne,t[52]=te.breakdown.user,t[53]=Y):Y=t[53];let G;t[54]!==e?(G=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=G):G=t[55];let q;t[56]!==G||t[57]!==te.breakdown.assistant?(q={key:"assistant",label:G,value:te.breakdown.assistant,color:"var(--primary-base)"},t[56]=G,t[57]=te.breakdown.assistant,t[58]=q):q=t[58];let oe;t[59]!==e?(oe=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=oe):oe=t[60];let le;t[61]!==oe||t[62]!==te.breakdown.tool?(le={key:"tool",label:oe,value:te.breakdown.tool,color:"var(--status-warning)"},t[61]=oe,t[62]=te.breakdown.tool,t[63]=le):le=t[63];let ve;t[64]!==e?(ve=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=ve):ve=t[65];let Ee;t[66]!==ve||t[67]!==te.breakdown.other?(Ee={key:"other",label:ve,value:te.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=ve,t[67]=te.breakdown.other,t[68]=Ee):Ee=t[68];let _e;t[69]!==Y||t[70]!==q||t[71]!==le||t[72]!==Ee?(_e=[Y,q,le,Ee],t[69]=Y,t[70]=q,t[71]=le,t[72]=Ee,t[73]=_e):_e=t[73];const Oe=_e;let Me;t[74]!==te.sessionTitle?(Me=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:te.sessionTitle}),t[74]=te.sessionTitle,t[75]=Me):Me=t[75];let he;t[76]!==te.providerModel.modelName||t[77]!==te.providerModel.providerName?(he=s.jsxs("span",{children:[te.providerModel.providerName," / ",te.providerModel.modelName]}),t[76]=te.providerModel.modelName,t[77]=te.providerModel.providerName,t[78]=he):he=t[78];let Ce;t[79]!==n||t[80]!==te.createdAt?(Ce=te.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:B1(te.createdAt,n)})]}),t[79]=n,t[80]=te.createdAt,t[81]=Ce):Ce=t[81];let xe;t[82]!==he||t[83]!==Ce?(xe=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:[he,Ce]}),t[82]=he,t[83]=Ce,t[84]=xe):xe=t[84];let ue;t[85]!==Me||t[86]!==xe?(ue=s.jsxs("div",{className:"mb-6",children:[Me,xe]}),t[85]=Me,t[86]=xe,t[87]=ue):ue=t[87];let H;t[88]!==e?(H=e("contextSidebar.section.context"),t[88]=e,t[89]=H):H=t[89];let ce;t[90]!==H?(ce=s.jsx("span",{className:"typography-micro text-muted-foreground",children:H}),t[90]=H,t[91]=ce):ce=t[91];let fe;t[92]!==te.tokenBreakdown.total?(fe=Si(te.tokenBreakdown.total),t[92]=te.tokenBreakdown.total,t[93]=fe):fe=t[93];let U;t[94]!==te.contextLimit?(U=te.contextLimit?` / ${Si(te.contextLimit)}`:"",t[94]=te.contextLimit,t[95]=U):U=t[95];let z;t[96]!==fe||t[97]!==U?(z=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[fe,U]}),t[96]=fe,t[97]=U,t[98]=z):z=t[98];let be;t[99]!==ce||t[100]!==z?(be=s.jsxs("div",{className:"flex items-baseline justify-between",children:[ce,z]}),t[99]=ce,t[100]=z,t[101]=be):be=t[101];let ge;t[102]!==te.usagePercent?(ge=te.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,te.usagePercent)}%`,backgroundColor:te.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[102]=te.usagePercent,t[103]=ge):ge=t[103];let _;t[104]!==ge?(_=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ge}),t[104]=ge,t[105]=_):_=t[105];let ye;t[106]!==e||t[107]!==te.usagePercent?(ye=e("contextSidebar.context.percentUsed",{percent:te.usagePercent.toFixed(1)}),t[106]=e,t[107]=te.usagePercent,t[108]=ye):ye=t[108];let $;t[109]!==ye?($=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:ye}),t[109]=ye,t[110]=$):$=t[110];let Ie;t[111]!==be||t[112]!==_||t[113]!==$?(Ie=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[be,_,$]}),t[111]=be,t[112]=_,t[113]=$,t[114]=Ie):Ie=t[114];let je;t[115]!==e?(je=e("contextSidebar.stats.messages"),t[115]=e,t[116]=je):je=t[116];let Fe;t[117]!==te.messagesCount?(Fe=Si(te.messagesCount),t[117]=te.messagesCount,t[118]=Fe):Fe=t[118];let Ae;t[119]!==je||t[120]!==Fe?(Ae={label:je,value:Fe},t[119]=je,t[120]=Fe,t[121]=Ae):Ae=t[121];let ne;t[122]!==e?(ne=e("contextSidebar.stats.user"),t[122]=e,t[123]=ne):ne=t[123];let P;t[124]!==te.userMessagesCount?(P=Si(te.userMessagesCount),t[124]=te.userMessagesCount,t[125]=P):P=t[125];let me;t[126]!==ne||t[127]!==P?(me={label:ne,value:P},t[126]=ne,t[127]=P,t[128]=me):me=t[128];let ae;t[129]!==e?(ae=e("contextSidebar.stats.assistant"),t[129]=e,t[130]=ae):ae=t[130];let Be;t[131]!==te.assistantMessagesCount?(Be=Si(te.assistantMessagesCount),t[131]=te.assistantMessagesCount,t[132]=Be):Be=t[132];let Ge;t[133]!==ae||t[134]!==Be?(Ge={label:ae,value:Be},t[133]=ae,t[134]=Be,t[135]=Ge):Ge=t[135];let Ke;t[136]!==e?(Ke=e("contextSidebar.stats.cost"),t[136]=e,t[137]=Ke):Ke=t[137];let Qe;t[138]!==te.totalAssistantCost?(Qe=O1(te.totalAssistantCost),t[138]=te.totalAssistantCost,t[139]=Qe):Qe=t[139];let st;t[140]!==Ke||t[141]!==Qe?(st={label:Ke,value:Qe},t[140]=Ke,t[141]=Qe,t[142]=st):st=t[142];let ut;t[143]!==Ae||t[144]!==me||t[145]!==Ge||t[146]!==st?(ut=[Ae,me,Ge,st],t[143]=Ae,t[144]=me,t[145]=Ge,t[146]=st,t[147]=ut):ut=t[147];const vt=ut;let Ve;t[148]!==vt?(Ve=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:vt.map(Y1)}),t[148]=vt,t[149]=Ve):Ve=t[149];let tt;t[150]!==e?(tt=e("contextSidebar.section.lastAssistantMessage"),t[150]=e,t[151]=tt):tt=t[151];let nt;t[152]!==tt?(nt=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:tt}),t[152]=tt,t[153]=nt):nt=t[153];let xt;t[154]!==e||t[155]!==te.cacheHitRate.hasInput||t[156]!==te.cacheHitRate.percent||t[157]!==te.tokenBreakdown.cacheRead||t[158]!==te.tokenBreakdown.cacheWrite||t[159]!==te.tokenBreakdown.input||t[160]!==te.tokenBreakdown.output||t[161]!==te.tokenBreakdown.reasoning?(xt=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:te.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:te.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:te.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:te.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:te.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:te.cacheHitRate.hasInput?te.cacheHitRate.percent:null,format:"percent"}].map(Q1)}),t[154]=e,t[155]=te.cacheHitRate.hasInput,t[156]=te.cacheHitRate.percent,t[157]=te.tokenBreakdown.cacheRead,t[158]=te.tokenBreakdown.cacheWrite,t[159]=te.tokenBreakdown.input,t[160]=te.tokenBreakdown.output,t[161]=te.tokenBreakdown.reasoning,t[162]=xt):xt=t[162];let Rt;t[163]!==nt||t[164]!==xt?(Rt=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[nt,xt]}),t[163]=nt,t[164]=xt,t[165]=Rt):Rt=t[165];let bt;t[166]!==Oe||t[167]!==te.breakdownTotal?(bt=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Oe.map(mt=>mt.value<=0||te.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${mt.value/te.breakdownTotal*100}%`,backgroundColor:mt.color}},mt.key))}),t[166]=Oe,t[167]=te.breakdownTotal,t[168]=bt):bt=t[168];let ot;t[169]!==Oe||t[170]!==te.breakdownTotal?(ot=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:Oe.map(mt=>{const Et=te.breakdownTotal>0?mt.value/te.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:mt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[mt.label," ",s.jsxs("span",{className:"tabular-nums",children:[Et.toFixed(0),"%"]})]})]},mt.key)})}),t[169]=Oe,t[170]=te.breakdownTotal,t[171]=ot):ot=t[171];let at;t[172]!==bt||t[173]!==ot?(at=s.jsxs("div",{className:"mb-6",children:[bt,ot]}),t[172]=bt,t[173]=ot,t[174]=at):at=t[174];let Ut;t[175]!==e?(Ut=e("contextSidebar.section.rawMessages"),t[175]=e,t[176]=Ut):Ut=t[176];let Nt;t[177]!==Ut?(Nt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ut}),t[177]=Ut,t[178]=Nt):Nt=t[178];let _t;if(t[179]!==c||t[180]!==o||t[181]!==f||t[182]!==e||t[183]!==n){let mt;t[185]!==c||t[186]!==o||t[187]!==e||t[188]!==n?(mt=Et=>{const Vt=Oo(Et.info).role,Wt=Vt==="assistant",Yt=Vt==="user",Bt=o[Et.info.id]===!0,Ht=c===Et.info.id,Jt=Et.info.time?.created??null,rs=C1(Et.parts),Qt=Wt?Nl({info:Et.info,parts:Et.parts}):null,Xt=Yt?I1(Et.parts):"",bs=A1(Et.info.id),yt=R1(Jt,n),Ue=rs||"—",Ye=Qt?P1(Qt.input,Qt.output,Si):"",Ct=Vt||"unknown",kt=rs,It=Bt?JSON.stringify({info:Et.info,parts:Et.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":Bt,onClick:()=>{a(rt=>({...rt,[Et.info.id]:rt[Et.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:"auto minmax(0, 1fr) 5rem 4.5rem"},children:[Yt?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",style:{gridColumn:"span 2"},children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",Xt]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:Wt?"min-w-0 truncate text-muted-foreground":"typography-ui-label text-foreground",children:Wt?Ue:Ct}),s.jsx("span",{className:Wt?"text-right text-muted-foreground tabular-nums":"min-w-0 truncate text-muted-foreground",children:Wt?Ye:kt})]}),s.jsx("span",{className:"text-right font-mono text-muted-foreground",children:bs}),s.jsx("span",{className:"text-right text-muted-foreground",children:yt})]})}),Bt&&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:rt=>{rt.stopPropagation(),N(Et.info.id,It)},"aria-label":e(Ht?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Ht?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Ht?s.jsx(I,{name:"check",className:"size-3.5"}):s.jsx(I,{name:"file-copy",className:"size-3.5"})})}),s.jsx(dg,{language:"json",code:It,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},Et.info.id)},t[185]=c,t[186]=o,t[187]=e,t[188]=n,t[189]=mt):mt=t[189],_t=[...f].reverse().map(mt),t[179]=c,t[180]=o,t[181]=f,t[182]=e,t[183]=n,t[184]=_t}else _t=t[184];let Le;t[190]!==_t?(Le=s.jsx("div",{className:"mt-2.5 space-y-1",children:_t}),t[190]=_t,t[191]=Le):Le=t[191];let Dt;t[192]!==Nt||t[193]!==Le?(Dt=s.jsxs("div",{children:[Nt,Le]}),t[192]=Nt,t[193]=Le,t[194]=Dt):Dt=t[194];let Ot;return t[195]!==ue||t[196]!==Ie||t[197]!==Ve||t[198]!==Rt||t[199]!==at||t[200]!==Dt?(Ot=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:[ue,Ie,Ve,Rt,at,Dt]})}),t[195]=ue,t[196]=Ie,t[197]=Ve,t[198]=Rt,t[199]=at,t[200]=Dt,t[201]=Ot):Ot=t[201],Ot};function $1(t){return t.timeFormatPreference}function z1(t){return t.currentSessionId}function U1(t){return t.providers}function W1(t){return Object.keys(t).length>0?{}:t}function H1(t){return Oo(t.info).role==="assistant"}function G1(t){return Oo(t.info).isUser}function K1(t,e){const n=ji(e.info.cost);return t+n}function q1(t){return Oo(t.info).isUser&&typeof t.info.system=="string"}function Y1(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 Q1(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:t.value!==null&&t.value!==void 0?t.format==="percent"?`${t.value.toFixed(1)}%`:Si(t.value):"—"})]},t.label)}const J1=(t,e,n)=>JSON.stringify({sessionID:t,directory:e||"",readOnly:n===!0}),X1=(t,e,n,r)=>{if(typeof window>"u")return"";const o=new URL(window.location.pathname,window.location.origin);return o.searchParams.set("ocPanel","session-chat"),o.searchParams.set("sessionId",t),n?o.searchParams.set("readOnly","1"):o.searchParams.delete("readOnly"),e&&e.trim().length>0?o.searchParams.set("directory",e):o.searchParams.delete("directory"),o.searchParams.set("themeMode",r.mode),o.searchParams.set("lightThemeId",r.lightThemeId),o.searchParams.set("darkThemeId",r.darkThemeId),o.searchParams.set("themeVariant",r.currentTheme.metadata.variant==="dark"?"dark":"light"),o.searchParams.set("currentTheme",JSON.stringify(r.currentTheme)),o.hash="",o.toString()},Z1=(t,e,n,r,o,a)=>{const c=J1(n,r,o),l=t.get(e);if(l?.signature===c)return l.src;const d=X1(n,r,o,a);return t.set(e,{signature:c,src:d}),d},e0=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.x=="number"&&typeof e.y=="number"},Fu=t=>!t||typeof t!="object"?!1:Object.values(t).every(e=>typeof e=="string"),qi=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"&&e0(e.center)&&Fu(e.attributes)&&Fu(e.computedStyle)&&Array.isArray(e.ancestry)},Lc=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:o,intro:a})=>{const c=r.text.trim(),l=Object.entries(r.attributes).map(([y,p])=>`${y}="${p}"`).join(" "),d=r.computedStyle,u=r.bounds,m=r.center,f=a.replace(/[.:]+$/g,""),g=r.ancestry.map(y=>y.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(u.x)}, y=${Math.round(u.y)}, width=${Math.round(u.width)}, height=${Math.round(u.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(y=>typeof y=="string").join(`
|
|
36
|
+
`)},$m=async(t,e)=>{if(typeof window<"u")try{const n=t.getBoundingClientRect(),r=await zr("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,x)=>{o.onload=()=>p(),o.onerror=()=>x(new Error("Failed to load desktop preview screenshot")),o.src=`data:${r.mime};base64,${r.base64}`});const a=Math.max(1,o.naturalWidth||r.width||Math.floor(n.width)),c=Math.max(1,o.naturalHeight||r.height||Math.floor(n.height)),d=Math.min(1,1200/a),u=document.createElement("canvas");u.width=Math.floor(a*d),u.height=Math.floor(c*d);const m=u.getContext("2d");if(!m)return null;m.scale(d,d),m.drawImage(o,0,0,a,c);const f=a/Math.max(1,n.width),g=c/Math.max(1,n.height);m.fillStyle="rgba(37, 99, 235, 0.28)",m.strokeStyle="rgb(37, 99, 235)",m.lineWidth=Math.max(2,2*f),m.fillRect(e.bounds.x*f,e.bounds.y*g,e.bounds.width*f,e.bounds.height*g),m.strokeRect(e.bounds.x*f,e.bounds.y*g,e.bounds.width*f,e.bounds.height*g);const y=await new Promise(p=>u.toBlob(p,"image/jpeg",.82));return y?new File([y],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(n){return console.warn("[preview] failed to capture annotation screenshot:",n),null}return await p0(t,e)},Oc=async(t,e,n,r,o,a)=>{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),d=Math.max(1,c.naturalHeight||n),m=Math.min(1,1200/l),f=document.createElement("canvas");f.width=Math.floor(l*m),f.height=Math.floor(d*m);const g=f.getContext("2d");if(!g)return null;g.scale(m,m),g.drawImage(c,0,0,l,d);const y=l/Math.max(1,r||l),p=d/Math.max(1,o||d);g.fillStyle="rgba(37, 99, 235, 0.14)",g.strokeStyle="rgb(37, 99, 235)",g.lineWidth=Math.max(2,2*y),g.fillRect(a.bounds.x*y,a.bounds.y*p,a.bounds.width*y,a.bounds.height*p),g.strokeRect(a.bounds.x*y,a.bounds.y*p,a.bounds.width*y,a.bounds.height*p);const x=await new Promise(b=>f.toBlob(b,"image/jpeg",.82));return x?new File([x],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Yi="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",Yn=new Map,kl=new Map,t0=3e4,Bc=t=>{const e=Yn.get(t);return e?e.expiresAt-Date.now()<=t0?(Yn.delete(t),null):e:null},s0=t=>{try{return new URL(t).origin}catch{return t}};function zm(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 Um=t=>new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(typeof r.result=="string"?r.result:Yi),r.onerror=()=>n(r.error??new Error("Failed to read image blob")),r.readAsDataURL(t)}),n0=async(t,e=.82)=>{const n=await new Promise(r=>t.toBlob(r,"image/jpeg",e));return n&&(await Um(n)).split(",",2)[1]||""},r0=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},da=(...t)=>{r0()&&console.info("[preview-capture]",...t)},Wm=(t,e=8)=>{const n=[];try{const r=t.querySelectorAll("*");for(const o of r){const a=o.scrollTop||0,c=o.scrollLeft||0;if(a<=0&&c<=0)continue;const l=o.tagName.toLowerCase(),d=o.id?`#${o.id}`:"",u=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(n.push({selector:`${l}${d}${u}`,scrollTop:a,scrollLeft:c,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),n.length>=e)break}}catch{}return n},ko="data-oc-fixed-pin",i0=(t,e,n)=>{if(e<=0&&n<=0)return()=>{};const r=t.defaultView;if(!r)return()=>{};const o=[],a=[];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(ko,JSON.stringify({top:l.top+n,left:l.left+e,width:l.width,height:l.height})),o.push(c);const d=c.tagName.toLowerCase(),u=typeof c.className=="string"&&c.className?`.${c.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";a.push({selector:`${d}${u}`,top:Math.round(l.top),left:Math.round(l.left),width:Math.round(l.width),height:Math.round(l.height)})}}catch{}return da("tagged fixed elements",a),()=>{for(const c of o)try{c.removeAttribute(ko)}catch{}}},o0={name:"oc-fixed-pin",afterClone(t){const e=t?.clone;if(!(!e||typeof e.querySelectorAll!="function"))for(const n of e.querySelectorAll(`[${ko}]`)){let r;try{r=JSON.parse(n.getAttribute(ko)||"")}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(ko)}}},Hi="data-oc-scroll-pin",a0=t=>{const e=[],n=Wm(t,64);try{const a=t.documentElement,c=t.body;for(const l of t.querySelectorAll("*")){const d=l.scrollTop||0,u=l.scrollLeft||0;if(d<=0&&u<=0)continue;const m=l!==a&&l!==c;m&&l.setAttribute(Hi,JSON.stringify({top:d,left:u})),e.push({el:l,top:d,left:u,tagged:m})}}catch{}return{reapply:()=>{for(const a of e)try{a.el.scrollHeight,a.el.scrollTop!==a.top&&(a.el.scrollTop=a.top),a.el.scrollLeft!==a.left&&(a.el.scrollLeft=a.left)}catch{}},cleanup:()=>{for(const a of e)if(a.tagged)try{a.el.removeAttribute(Hi)}catch{}},snapshot:n}},l0={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(`[${Hi}]`)){let o;try{o=JSON.parse(r.getAttribute(Hi)||"")}catch{r.removeAttribute(Hi);continue}const a=`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=a;else{r.style.overflow="hidden";const l=n.createElement("div");for(l.style.transform=a,l.style.willChange="transform",l.style.display="inline-block",l.style.width="100%";r.firstChild;)l.appendChild(r.firstChild);r.appendChild(l)}r.removeAttribute(Hi)}}},Cl=async(t,e)=>{try{const n=await fetch(t,{credentials:e});return n.ok?await Um(await n.blob()):null}catch{return null}},c0=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const e=t.origin,n=Bc(e);if(n)return`${n.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const r=kl.get(e),o=r??(async()=>{try{const c=await Cs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!c.ok)return Yn.delete(e),null;const l=await c.json(),d=typeof l.proxyBasePath=="string"?l.proxyBasePath:"",u=typeof l.expiresAt=="number"?l.expiresAt:0;if(!d)return Yn.delete(e),null;const m={proxyBasePath:d,expiresAt:u};return Yn.set(e,m),m}catch{return Yn.delete(e),null}finally{kl.delete(e)}})();r||kl.set(e,o);const a=await o;return a?`${a.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},Hm=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 Cl(n.toString(),"include")??Yi;const r=await c0(n),o=r?await Cl(r,"include"):null;return o||(await Cl(n.toString(),"omit")??Yi)}catch{return Yi}},d0=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 a=o[2]||"";if(!a||a.startsWith("data:"))continue;const c=await Hm(a,e);r=r.replace(o[0],`url("${c}")`)}return r},Lu=t=>t.complete?Promise.resolve():new Promise(e=>{t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0})}),Gm=t=>{const e=t.style.cssText;return()=>{t.style.cssText=e}},u0=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},f0=(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 d=l.textContent?.replace(/\s+/g," ").trim()??"";if(!d||!d.includes(" "))continue;const u=l.getBoundingClientRect();if(u.width<=0||u.height<=0||u.right<0||u.bottom<0||u.left>e||u.top>n)continue;const m=o.getComputedStyle(l);if(m.display==="none"||m.visibility==="hidden"||Number(m.opacity)===0)continue;const f=m.getPropertyValue("text-wrap"),g=m.getPropertyValue("text-wrap-mode"),y=m.whiteSpace.includes("nowrap")||f==="nowrap"||g==="nowrap",p=u.height<=u0(m)*1.7;!y&&(!p||u.width>e*.72)||(r.push(Gm(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]?.()}},m0=(t,e,n,r)=>{const o=[],a=t.defaultView??window,c=a.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,l=a.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,d=Array.from(t.querySelectorAll("*")).filter(u=>{const m=a.getComputedStyle(u);if(m.position!=="fixed"||m.display==="none"||m.visibility==="hidden"||Number(m.opacity)===0)return!1;const f=u.getBoundingClientRect();return f.width>0&&f.height>0&&f.right>=0&&f.bottom>=0&&f.left<=e&&f.top<=n}).filter((u,m,f)=>!f.some((g,y)=>y<m&&g.contains(u)));for(const u of d){const m=u.getBoundingClientRect(),f=a.getComputedStyle(u),g=Math.ceil(m.width)+8,y=Math.ceil(m.height)+2;r?.add(u),o.push(Gm(u)),u.style.position="absolute",u.style.top=`${m.top+l}px`,u.style.left=`${m.left+c}px`,u.style.right="auto",u.style.bottom="auto",u.style.width=`${g}px`,u.style.minWidth=`${g}px`,u.style.height=`${y}px`,u.style.minHeight=`${y}px`,u.style.margin="0",u.style.boxSizing="border-box",u.style.transform="none",f.zIndex!=="auto"&&(u.style.zIndex=f.zIndex)}return()=>{for(let u=o.length-1;u>=0;u-=1)o[u]?.()}},Km=async(t,e,n,r={})=>{const o=[],a=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(m0(t,e,n,f)),o.push(f0(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 d=Array.from(t.querySelectorAll("picture"));for(const f of d){const g=Array.from(f.querySelectorAll("source"));if(g.length===0)continue;const y=g.map(p=>({source:p,srcset:p.getAttribute("srcset"),sizes:p.getAttribute("sizes")}));o.push(()=>{for(const p of y)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 u=Array.from(t.images).filter(f=>c(f));await Promise.all(u.map(async f=>{const g=l.get(f)||f.currentSrc||f.src||f.getAttribute("src")||"";if(!g)return;await Lu(f);const y=await Hm(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",y||Yi),await Lu(f)}));const m=Array.from(t.querySelectorAll("*")).filter(c);return await Promise.all(m.map(async f=>{const g=a.getComputedStyle(f).backgroundImage;if(!g||g==="none"||!g.includes("url("))return;const y=await d0(g,t);if(y===g)return;const p=f.style.backgroundImage;o.push(()=>{f.style.backgroundImage=p}),f.style.backgroundImage=y})),()=>{for(let f=o.length-1;f>=0;f-=1)try{o[f]?.()}catch{}}};async function h0(t,e){try{const n=t.contentWindow,r=t.contentDocument??n?.document,o=r?.documentElement;if(!n||!r||!o)return null;const a=t.getBoundingClientRect(),c=Math.max(1,Math.ceil(n.innerWidth||t.clientWidth||a.width)),l=Math.max(1,Math.ceil(n.innerHeight||t.clientHeight||a.height)),d=r.body,u=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,m=n.scrollX||0,f=n.scrollY||0,g=n.pageXOffset||0,y=n.pageYOffset||0,p=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,x=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,b=o.scrollLeft||0,h=o.scrollTop||0,N=d?.scrollLeft||0,w=d?.scrollTop||0,S=u?.scrollLeft||0,j=u?.scrollTop||0,k=Math.max(m,g,p,b,N,S),v=Math.max(f,y,x,h,w,j);da("scroll sources",{windowScrollX:m,windowScrollY:f,pageScrollX:g,pageScrollY:y,visualViewportScrollX:p,visualViewportScrollY:x,rootScrollX:b,rootScrollY:h,bodyScrollX:N,bodyScrollY:w,scrollingElementScrollX:S,scrollingElementScrollY:j,scrollingElementTag:u?.tagName?.toLowerCase()??null,resolvedScrollX:k,resolvedScrollY:v,nestedScrolledElements:Wm(r)});const D=Math.max(c,o.scrollWidth||0,d?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),A=Math.max(l,o.scrollHeight||0,d?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),C=Math.min(2,Math.max(1,window.devicePixelRatio||1)),O=o.style.scrollBehavior,T=d?.style.scrollBehavior??"";o.style.scrollBehavior="auto",d&&(d.style.scrollBehavior="auto");const E=a0(r);da("nested scroll snapshot",E.snapshot);let F=()=>{},R=()=>{};try{await r.fonts?.ready.catch(()=>{}),F=await Km(r,c,l,{applyLayoutWorkarounds:!1}),n.scrollTo(k,v),R=i0(r,k,v),E.reapply();const L={backgroundColor:zm(r),cache:"disabled",dpr:C,embedFonts:!0,fast:!1,height:A,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[o0,l0],quality:.82,width:D},V=await(await Lh(o,L)).toCanvas();if(!V.width||!V.height)return null;const M=V.width/Math.max(1,D),ee=V.height/Math.max(1,A),se=Math.min(V.width,Math.max(1,Math.round(c*M))),J=Math.min(V.height,Math.max(1,Math.round(l*ee))),K=Math.max(0,V.width-se),Z=Math.max(0,V.height-J),re=Math.min(K,Math.max(0,Math.round(k*M))),pe=Math.min(Z,Math.max(0,Math.round(v*ee)));da("capture geometry",{viewportWidth:c,viewportHeight:l,captureWidth:D,captureHeight:A,canvasWidth:V.width,canvasHeight:V.height,xScale:M,yScale:ee,sourceX:re,sourceY:pe,sourceWidth:se,sourceHeight:J});const Se=r.createElement("canvas");Se.width=se,Se.height=J;const te=Se.getContext("2d");if(!te)return null;te.drawImage(V,re,pe,se,J,0,0,se,J);const Ne=await n0(Se,.82);return Ne?await Oc(Ne,c,l,c,l,e):null}finally{R(),E.cleanup(),F(),n.scrollTo(k,v),E.reapply(),o.style.scrollBehavior=O,d&&(d.style.scrollBehavior=T)}}catch(n){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",n),null}}async function p0(t,e){const n=await h0(t,e);if(n)return n;try{const r=t.contentWindow,o=t.contentDocument??r?.document,a=o?.documentElement;if(!r||!o||!a)return null;const c=t.getBoundingClientRect(),l=Math.max(1,Math.ceil(r.innerWidth||t.clientWidth||c.width)),d=Math.max(1,Math.ceil(r.innerHeight||t.clientHeight||c.height)),u=r.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,m=r.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,f=o.body,g=Math.max(d,a.scrollHeight||0,f?.scrollHeight||0),y=Math.min(2,Math.max(1,window.devicePixelRatio||1)),p=a.style.scrollBehavior,x=f?.style.scrollBehavior??"";a.style.scrollBehavior="auto",f&&(f.style.scrollBehavior="auto");let b="",h=()=>{};try{await o.fonts?.ready.catch(()=>{}),h=await Km(o,l,d,{applyLayoutWorkarounds:!0}),r.scrollTo(u,m);const w=await Mh(a).catch(()=>"");b=await Fh(a,{quality:.82,pixelRatio:y,width:l,height:d,backgroundColor:zm(o),imagePlaceholder:Yi,fontEmbedCSS:w||void 0,style:{transform:`translate(${-u}px, ${-m}px)`,transformOrigin:"top left",minWidth:`${l}px`,minHeight:`${g}px`},cacheBust:!0})}finally{h(),r.scrollTo(u,m),a.style.scrollBehavior=p,f&&(f.style.scrollBehavior=x)}const N=b.split(",",2)[1]||"";return N?await Oc(N,l,d,l,d,e):null}catch(r){return console.warn("[preview] failed to capture iframe DOM screenshot:",r),null}}const qm=380,g0=1400,Ym=600,x0=24,Ou=200,b0=(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",y0=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},Qm=t=>Number.isFinite(t)?Math.min(g0,Math.max(qm,Math.round(t))):Ym,w0=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},Al=(t,e)=>{const n=Qm(t),r=w0(e);return r===null?n:Math.min(n,Math.max(1,r))},v0=(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},j0=(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"),S0=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},N0=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return S0(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"?e("contextPanel.mode.diff"):j0(t.mode,e)},k0=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Ur,{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"})},C0=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,Jm=`new Promise((resolve) => {
|
|
37
|
+
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
38
|
+
if (existing) existing.remove();
|
|
39
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
40
|
+
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
41
|
+
}
|
|
42
|
+
const overlay = document.createElement('div');
|
|
43
|
+
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
44
|
+
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
45
|
+
document.documentElement.appendChild(overlay);
|
|
46
|
+
const cssEscape = (value) => {
|
|
47
|
+
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
48
|
+
};
|
|
49
|
+
const selectorPart = (element) => {
|
|
50
|
+
const tag = element.tagName.toLowerCase();
|
|
51
|
+
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
52
|
+
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
53
|
+
return tag + className;
|
|
54
|
+
};
|
|
55
|
+
const metadata = (element) => {
|
|
56
|
+
const rect = element.getBoundingClientRect();
|
|
57
|
+
const style = getComputedStyle(element);
|
|
58
|
+
const ancestry = [];
|
|
59
|
+
let current = element;
|
|
60
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
61
|
+
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
62
|
+
current = current.parentElement;
|
|
63
|
+
}
|
|
64
|
+
const attrs = {};
|
|
65
|
+
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
66
|
+
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
67
|
+
return {
|
|
68
|
+
frame: 'top',
|
|
69
|
+
tag: element.tagName.toLowerCase(),
|
|
70
|
+
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
71
|
+
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
72
|
+
path,
|
|
73
|
+
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
74
|
+
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
75
|
+
attributes: attrs,
|
|
76
|
+
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
77
|
+
ancestry,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const move = (event) => {
|
|
81
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
82
|
+
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
83
|
+
const rect = element.getBoundingClientRect();
|
|
84
|
+
overlay.style.display = 'block';
|
|
85
|
+
overlay.style.left = rect.left + 'px';
|
|
86
|
+
overlay.style.top = rect.top + 'px';
|
|
87
|
+
overlay.style.width = rect.width + 'px';
|
|
88
|
+
overlay.style.height = rect.height + 'px';
|
|
89
|
+
};
|
|
90
|
+
const cleanup = () => {
|
|
91
|
+
window.removeEventListener('mousemove', move, true);
|
|
92
|
+
window.removeEventListener('click', click, true);
|
|
93
|
+
window.removeEventListener('keydown', keydown, true);
|
|
94
|
+
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
95
|
+
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const cancel = () => {
|
|
99
|
+
cleanup();
|
|
100
|
+
overlay.remove();
|
|
101
|
+
resolve(null);
|
|
102
|
+
};
|
|
103
|
+
const click = (event) => {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
107
|
+
const result = element ? metadata(element) : null;
|
|
108
|
+
cleanup();
|
|
109
|
+
overlay.remove();
|
|
110
|
+
resolve(result);
|
|
111
|
+
};
|
|
112
|
+
const keydown = (event) => {
|
|
113
|
+
if (event.key !== 'Escape') return;
|
|
114
|
+
cancel();
|
|
115
|
+
};
|
|
116
|
+
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
117
|
+
window.addEventListener('mousemove', move, true);
|
|
118
|
+
window.addEventListener('click', click, true);
|
|
119
|
+
window.addEventListener('keydown', keydown, true);
|
|
120
|
+
});`,ua=`(() => {
|
|
121
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
122
|
+
window.__openchamberDesktopBrowserCancelInspect();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
126
|
+
if (overlay) overlay.remove();
|
|
127
|
+
})()`,A0=`(() => {
|
|
128
|
+
if (window.__openchamberSameWebviewNavigationInstalled) return;
|
|
129
|
+
window.__openchamberSameWebviewNavigationInstalled = true;
|
|
130
|
+
|
|
131
|
+
const navigate = (rawUrl) => {
|
|
132
|
+
if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
|
|
133
|
+
try {
|
|
134
|
+
const url = new URL(rawUrl, window.location.href);
|
|
135
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
|
|
136
|
+
window.location.assign(url.href);
|
|
137
|
+
return true;
|
|
138
|
+
} catch (_error) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const originalOpen = window.open.bind(window);
|
|
144
|
+
window.open = (url, target, features) => {
|
|
145
|
+
if (navigate(url)) return null;
|
|
146
|
+
return originalOpen(url, target, features);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
document.addEventListener('click', (event) => {
|
|
150
|
+
if (event.defaultPrevented) return;
|
|
151
|
+
const target = event.target;
|
|
152
|
+
if (!(target instanceof Element)) return;
|
|
153
|
+
const anchor = target.closest('a[target="_blank"][href]');
|
|
154
|
+
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
155
|
+
if (!navigate(anchor.href)) return;
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
event.stopPropagation();
|
|
158
|
+
}, true);
|
|
159
|
+
})()`,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"}},Bu=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)},D0=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Xm=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},Vu=(t,e,n)=>{const r=Xm(e);t.postMessage(n,r)},I0=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}},P0=({rawUrl:t,onNavigate:e})=>{const{t:n}=At(),{currentTheme:r}=Hr(),[o,a]=i.useReducer(he=>he+1,0),[c,l]=i.useReducer(he=>he+1,0),[d,u]=i.useState({status:"idle"}),[m,f]=i.useState(""),g=i.useRef(null),y=i.useRef(1),[p,x]=i.useState(!1),[b,h]=i.useState(!1),[N,w]=i.useState("all"),[S,j]=i.useState([]),[k,v]=i.useState(!1),[D,A]=i.useState(null),C=dt(he=>he.currentSessionId),O=dt(he=>he.newSessionDraft?.open),T=vc(he=>he.addDraft),E=ai(he=>he.addAttachedFile);let F=null;try{F=t?new URL(t):null}catch{F=null}const R=F?F.hostname==="localhost"||F.hostname==="127.0.0.1"||F.hostname==="::1"||F.hostname==="[::1]"||F.hostname==="0.0.0.0":!1,L=F?F.hostname==="0.0.0.0"?new URL(F.toString().replace("0.0.0.0","127.0.0.1")):F:null,B=L?L.toString():"",V=B?`${$r()||"same-origin"}|${B}`:"",M=r.metadata.variant;i.useEffect(()=>{if(!B||!R){u({status:"idle"});return}const he=Bc(V);if(he?.previewToken){u({status:"ready",proxyBasePath:he.proxyBasePath,previewToken:he.previewToken,expiresAt:he.expiresAt});return}he&&Yn.delete(V);let Ce=!1;return u({status:"loading"}),(async()=>{try{const xe=await Cs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:B})});if(!xe.ok){Yn.delete(V);const U=await xe.json().catch(()=>({})),z=typeof U?.error=="string"?U.error:`HTTP ${xe.status}`;Ce||u({status:"error",message:z});return}const ue=await xe.json(),H=typeof ue.proxyBasePath=="string"?ue.proxyBasePath:"",ce=typeof ue.previewToken=="string"?ue.previewToken:"",fe=typeof ue.expiresAt=="number"?ue.expiresAt:0;if(!H||!ce){Yn.delete(V),Ce||u({status:"error",message:n("contextPanel.preview.proxyError")});return}Yn.set(V,{proxyBasePath:H,previewToken:ce,expiresAt:fe}),Ce||u({status:"ready",proxyBasePath:H,previewToken:ce,expiresAt:fe})}catch(xe){if(Yn.delete(V),!Ce){const ue=xe instanceof Error?xe.message:String(xe);u({status:"error",message:ue})}}})(),()=>{Ce=!0}},[R,V,c,n,B]);const ee=L&&(L.protocol==="http:"||L.protocol==="https:")?L.toString():"",se=R&&d.status==="ready"?`${d.proxyBasePath}|${d.previewToken||""}|${o}`:"";i.useEffect(()=>{if(!se){f("");return}let he=!1;return f(""),cc($r()).then(Ce=>{!he&&Ce&&f(se)}).catch(()=>{}),()=>{he=!0}},[se]);const J=R&&d.status==="ready"&&L&&m===se?(()=>{const he=L.pathname||"/",Ce=new URLSearchParams(L.search);Ce.set("ocPreview",String(o)),Ce.set("oc_preview_token",d.previewToken||"");const xe=Ce.toString(),ue=L.hash||"";return Ai().authenticatedAsset(`${d.proxyBasePath}${he}${xe?`?${xe}`:""}${ue}`)})():"",K=R?J:ee,Z=R?I0(J):ee,re=R&&(d.status==="loading"||d.status==="idle"||m!==se),pe=R&&d.status==="error",Se=i.useCallback(he=>{const Ce=C??(O?"draft":null);if(!Ce){de.error(n("contextPanel.preview.inspect.attachNoSession"));return}const xe=t||K||"",ue=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},H=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let ce=!1;try{const fe=g.current,U=fe?await $m(fe,he):null;U&&(await E(U),ce=!0)}catch{ce=!1}T({sessionKey:Ce,source:"preview-annotation",fileLabel:xe||"preview",startLine:1,endLine:1,code:Lc({pageUrl:xe,viewport:ue,devicePixelRatio:H,target:he,screenshotAttached:ce,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),de.success(n("contextPanel.preview.inspect.attached"))})()},[E,T,C,K,O,t,n]);i.useEffect(()=>{x(!1),j([]),h(!1),w("all"),v(!1),A(null),y.current=1},[K]),i.useEffect(()=>{const he=g.current?.contentWindow;!p||!he||Vu(he,J,{source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:k})},[p,k,J]),i.useEffect(()=>{const he=g.current?.contentWindow;!p||!he||Vu(he,J,{source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:M})},[p,M,J]),i.useEffect(()=>{if(!k||typeof window>"u")return;const he=Ce=>{Ce.key==="Escape"&&(Ce.preventDefault(),Ce.stopImmediatePropagation(),v(!1))};return window.addEventListener("keydown",he,!0),()=>window.removeEventListener("keydown",he,!0)},[k]),i.useEffect(()=>{if(!R||typeof window>"u")return;const he=ue=>{if(typeof ue=="string")return ue;if(ue==null)return"";try{return JSON.stringify(ue)}catch{return String(ue)}},Ce=ue=>{const H=y.current;y.current+=1,j(ce=>{const fe=[...ce,{...ue,id:H}];return fe.length>Ou?fe.slice(fe.length-Ou):fe})},xe=ue=>{if(ue.source!==g.current?.contentWindow)return;const H=ue.data;if(!(!H||H.source!=="openchamber-preview-bridge"||H.version!==1)){if(H.type==="ready"){x(!0);return}if(H.type==="console"){const ce=H.level==="error"||H.level==="warn"||H.level==="info"||H.level==="debug"?H.level:"log",fe=Array.isArray(H.args)?H.args.map(he).filter(Boolean):[];Ce({level:ce,message:fe.join(" "),ts:typeof H.ts=="number"?H.ts:Date.now()});return}if(H.type==="runtime-error"){const ce=he(H.filename),fe=typeof H.line=="number"?H.line:null,U=typeof H.column=="number"?H.column:null,z=ce?`${ce}${fe!==null?`:${fe}${U!==null?`:${U}`:""}`:""}`:"",be=he(H.stack);Ce({level:"runtime",message:he(H.message)||n("contextPanel.preview.console.runtimeError"),details:[z,be].filter(Boolean).join(`
|
|
160
|
+
`),ts:typeof H.ts=="number"?H.ts:Date.now()});return}if(H.type==="resource-error"){const ce=he(H.tag)||"resource",fe=he(H.url);Ce({level:"resource",message:fe?`${ce}: ${fe}`:ce,details:he(H.outerHTML),ts:typeof H.ts=="number"?H.ts:Date.now()});return}if(H.type==="hover"){A(qi(H.target)?H.target:null);return}if(H.type==="select"&&qi(H.target)){A(H.target),v(!1),Se(H.target);return}if(H.type==="navigate-preview"){const ce=typeof H.url=="string"?H.url:"",fe=H.navigation==="external"?"external":"proxy";if(ce&&fe==="external"){Pi(ce);return}ce&&e(ce)}}};return window.addEventListener("message",xe),()=>{window.removeEventListener("message",xe)}},[Se,R,e,n]);const te=S.filter(he=>he.level==="error"||he.level==="runtime"||he.level==="resource").length,Ne=S.filter(he=>b0(he,N)),Y=i.useCallback(()=>{const he=[`Preview URL: ${t||K||""}`,`Events: ${S.length}`,""].join(`
|
|
161
|
+
`),Ce=S.map(xe=>{const ue=new Date(xe.ts).toISOString(),H=xe.details?`
|
|
162
|
+
${xe.details}`:"";return`[${ue}] [${xe.level}] ${xe.message}${H}`}).join(`
|
|
163
|
+
`);dr(`${he}${Ce}`).then(xe=>{xe.ok?de.success(n("contextPanel.preview.console.copied")):de.error(n("contextPanel.preview.console.copyFailed"))})},[S,K,t,n]),G=i.useCallback(()=>{const he=C??(O?"draft":null);if(!he){de.error(n("contextPanel.preview.console.attachNoSession"));return}const Ce=[`Preview URL: ${t||K||""}`,`Events: ${S.length}`,""].join(`
|
|
164
|
+
`),xe=S.map(ue=>{const H=new Date(ue.ts).toISOString(),ce=ue.details?`
|
|
165
|
+
${ue.details}`:"";return`[${H}] [${ue.level}] ${ue.message}${ce}`}).join(`
|
|
166
|
+
`);T({sessionKey:he,source:"preview-console",fileLabel:t||K||"preview",startLine:1,endLine:Math.max(1,S.length),code:`${Ce}${xe}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),de.success(n("contextPanel.preview.console.attached"))},[T,S,C,K,O,t,n]),[q,oe]=i.useState("unknown"),le=i.useRef(0),ve=i.useRef(0),Ee=15e3;i.useEffect(()=>{if(!J){oe("unknown"),le.current=0,ve.current=0;return}let he=!1;return le.current||(le.current=Date.now(),ve.current=0),oe("unknown"),(async()=>{const xe=await(async()=>{try{return await Cs(J,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(he)return;if(!xe){oe("unreachable");return}if(xe.status===403||xe.status===404){Yn.delete(V),u({status:"loading"}),l();return}if(xe.status!==502){oe("reachable");return}const ue=le.current||Date.now();if(Date.now()-ue<Ee){oe("starting"),ve.current+=1;const ce=ve.current,fe=Math.min(2e3,250*Math.pow(2,Math.min(4,ce)));setTimeout(()=>{he||a()},fe).unref?.();return}oe("unreachable")})(),()=>{he=!0}},[V,J,o]);const _e=R&&d.status==="ready"&&(q==="unknown"||q==="starting"),Oe=R&&d.status==="ready"&&q==="unreachable",Me=i.useCallback(he=>{if(!R||d.status!=="ready"||typeof window>"u")return;const Ce=he.currentTarget.contentWindow;if(Ce)try{const xe=Ce.location,ue=Xm(J);if(xe.origin!==ue||xe.pathname.startsWith(d.proxyBasePath))return;const H=`${d.proxyBasePath}${xe.pathname}${xe.search}${xe.hash}`;Ce.location.replace(H)}catch{}},[R,J,d]);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:Z||t,children:Z||t||n("contextPanel.preview.empty")}),s.jsx($e,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>a(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!K,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx($e,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{ee&&Pi(ee)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!ee,children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})}),R?s.jsx($e,{type:"button",size:"sm",variant:k?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(he=>!he),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($e,{type:"button",size:"sm",variant:b?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>h(he=>!he),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"}),te>0?s.jsx("span",{className:"typography-micro text-status-error",children:te}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[_e?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")})]}):Oe?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($e,{type:"button",size:"sm",variant:"outline",onClick:()=>a(),children:n("contextPanel.preview.actions.retry")})]}):K&&(!R||q==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:g,src:K,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:M},onLoad:Me,sandbox:R?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${K}:${o}`),k&&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]}):re?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")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.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($e,{type:"button",size:"xs",variant:"ghost",onClick:G,disabled:S.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx($e,{type:"button",size:"xs",variant:"ghost",onClick:Y,disabled:S.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx($e,{type:"button",size:"xs",variant:"ghost",onClick:()=>j([]),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(he=>s.jsx($e,{type:"button",size:"xs",variant:N===he?"secondary":"ghost",onClick:()=>w(he),children:n(he==="all"?"contextPanel.preview.console.filter.all":he==="errors"?"contextPanel.preview.console.filter.errors":he==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},he))}),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")}):Ne.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):Ne.map(he=>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:De("shrink-0 uppercase",he.level==="error"||he.level==="runtime"||he.level==="resource"?"text-status-error":he.level==="warn"?"text-status-warning":"text-muted-foreground"),children:he.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:he.message})]})},he.id))})]}):null]})]})},T0=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,R0=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=At(),o=i.useRef(null),a=Re(Y=>Y.setContextPanelTabTargetPath),c=Co(t),l=c!=="about:blank"?c:"",[d,u]=i.useState(l),[m,f]=i.useState(l),[g,y]=i.useState(()=>l?[l]:[]),[p,x]=i.useState(()=>l?0:-1),[b,h]=i.useReducer(Y=>Y+1,0),[N,w]=i.useState(!!l),[S,j]=i.useState(!1),[k,v]=i.useState(null),[D,A]=i.useState({status:"idle"}),[C,O]=i.useState(""),T=dt(Y=>Y.currentSessionId),E=dt(Y=>Y.newSessionDraft?.open),F=vc(Y=>Y.addDraft),R=ai(Y=>Y.addAttachedFile),L=i.useCallback(Y=>{!Y||Y==="about:blank"||!e||!n||a(e,n,Y)},[e,n,a]),B=i.useCallback((Y,G)=>{const q=Co(Y),oe=q!=="about:blank"?q:"";f(oe),u(oe),w(!!oe),L(oe),y(le=>{if(!oe)return x(-1),[];if(G?.replaceHistory)return le;const ve=p>=0?le.slice(0,p+1):[];if(ve[ve.length-1]===oe)return x(ve.length-1),ve;const _e=[...ve,oe];return x(_e.length-1),_e})},[p,L]),V=i.useCallback(Y=>{const G=g[Y];G&&(x(Y),f(G),u(G),w(!0),L(G))},[g,L]),M=i.useCallback(()=>{if(m){w(!0);try{o.current?.contentWindow?.location.reload()}catch{h()}}},[m]);i.useEffect(()=>{if(!m){A({status:"idle"});return}const Y=s0(m),G=Bc(Y);if(G?.previewToken){A({status:"ready",proxyBasePath:G.proxyBasePath,previewToken:G.previewToken,expiresAt:G.expiresAt});return}G&&Yn.delete(Y);let q=!1;return A({status:"loading"}),w(!0),(async()=>{try{const oe=await Cs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:m,allowExternal:!0})});if(!oe.ok){const Oe=await oe.json().catch(()=>({})),Me=typeof Oe?.error=="string"?Oe.error:`HTTP ${oe.status}`;q||A({status:"error",message:Me});return}const le=await oe.json(),ve=typeof le.proxyBasePath=="string"?le.proxyBasePath:"",Ee=typeof le.previewToken=="string"?le.previewToken:"",_e=typeof le.expiresAt=="number"?le.expiresAt:0;if(!ve||!Ee){q||A({status:"error",message:r("contextPanel.preview.proxyError")});return}Yn.set(Y,{proxyBasePath:ve,previewToken:Ee,expiresAt:_e}),q||A({status:"ready",proxyBasePath:ve,previewToken:Ee,expiresAt:_e})}catch(oe){if(!q){const le=oe instanceof Error?oe.message:String(oe);A({status:"error",message:le})}}})(),()=>{q=!0}},[m,r]);const ee=m&&D.status==="ready"?`${D.proxyBasePath}|${D.previewToken||""}|${b}`:"";i.useEffect(()=>{if(!ee){O("");return}let Y=!1;return O(""),cc($r()).then(G=>{!Y&&G&&O(ee)}).catch(()=>{}),()=>{Y=!0}},[ee]);const se=i.useMemo(()=>{if(C!==ee||!m||D.status!=="ready")return"";try{const Y=new URL(m),G=Y.pathname||"/",q=new URLSearchParams(Y.search);q.set("ocPreview",String(b)),q.set("oc_preview_token",D.previewToken||"");const oe=q.toString();return Ai().authenticatedAsset(`${D.proxyBasePath}${G}${oe?`?${oe}`:""}${Y.hash}`)}catch{return""}},[m,D,ee,b,C]),J=se||(D.status==="error"?m:""),K=i.useCallback(Y=>{if(!Y||!m||D.status!=="ready")return"";try{const G=new URL(Y,window.location.origin),q=D.proxyBasePath.endsWith("/")?D.proxyBasePath.slice(0,-1):D.proxyBasePath;if(G.origin!==window.location.origin||!G.pathname.startsWith(q))return"";const oe=G.pathname.slice(q.length)||"/",le=new URL(m).origin;return new URL(`${oe}${G.search}${G.hash}`,le).toString()}catch{return""}},[m,D]),Z=i.useCallback(Y=>{if(!Y||!m||D.status!=="ready")return"";try{const G=new URL(Y,window.location.origin),q=new URL(m).origin;if(G.origin!==window.location.origin||q===window.location.origin)return"";const oe=D.proxyBasePath.endsWith("/")?D.proxyBasePath.slice(0,-1):D.proxyBasePath;return G.pathname.startsWith(oe)?"":new URL(`${G.pathname}${G.search}${G.hash}`,q).toString()}catch{return""}},[m,D]),re=i.useCallback(Y=>{const G=o.current?.contentWindow;G&&G.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:Y},window.location.origin)},[]),pe=i.useCallback(async Y=>{const G=T??(E?"draft":null);if(!G){de.error(r("contextPanel.preview.inspect.attachNoSession"));return}const q=o.current,oe=q?.contentWindow,le=q?.getBoundingClientRect(),ve={width:Number.isFinite(oe?.innerWidth)?oe?.innerWidth??le?.width??0:le?.width??0,height:Number.isFinite(oe?.innerHeight)?oe?.innerHeight??le?.height??0:le?.height??0},Ee=q?await $m(q,Y):null,_e=!!Ee;Ee&&await R(Ee),F({sessionKey:G,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:Lc({pageUrl:m,viewport:ve,devicePixelRatio:window.devicePixelRatio||1,target:Y,screenshotAttached:_e,intro:r(_e?"contextPanel.preview.inspect.attachAnnotationWithScreenshot":"contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),de.success(r("contextPanel.preview.inspect.attached"))},[R,F,T,m,E,r]),Se=i.useCallback(()=>{const Y=o.current;v(null),re(!1),Y&&Bu(Y,ua).catch(()=>{})},[re]);i.useEffect(()=>{if(!S)return;const Y=G=>{G.key==="Escape"&&(G.preventDefault(),G.stopImmediatePropagation(),j(!1),Se())};return window.addEventListener("keydown",Y,!0),()=>window.removeEventListener("keydown",Y,!0)},[Se,S]),i.useEffect(()=>()=>Se(),[Se]),i.useEffect(()=>{const Y=G=>{if(G.source!==o.current?.contentWindow)return;const q=G.data;if(!(!q||q.source!=="openchamber-preview-bridge"||q.version!==1)){if(q.type==="ready"){const oe=typeof q.url=="string"?q.url:"",le=K(oe);le&&le!==m&&B(le);return}if(q.type==="hover"){v(qi(q.target)?q.target:null);return}if(q.type==="select"&&qi(q.target)){v(null),j(!1),re(!1),pe(q.target);return}if(q.type==="navigate-preview"){const oe=typeof q.url=="string"?q.url:"",le=Z(oe);if(le){B(le);return}oe&&B(oe)}}};return window.addEventListener("message",Y),()=>window.removeEventListener("message",Y)},[B,pe,m,K,Z,re]);const te=i.useCallback(()=>{const Y=o.current;if(!(!Y||!m)){if(S){j(!1),Se();return}if(se){v(null),j(!0),re(!0);return}j(!0),(async()=>{try{const G=await Bu(Y,Jm);if(j(!1),!G||!qi(G))return;await pe(G)}catch{j(!1),de.error(r("contextPanel.browser.inspectUnavailable"))}})()}},[pe,Se,m,S,re,se,r]),Ne=i.useCallback(()=>{try{const Y=o.current?.contentWindow?.location.href||"",G=Z(Y);if(G){w(!0),B(G);return}}catch{}w(!1),S&&se&&re(!0)},[B,Z,S,re,se]);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($e,{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($e,{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($e,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:M,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:Y=>{Y.preventDefault(),B(d)},children:s.jsx("input",{value:d,onChange:Y=>u(Y.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($e,{type:"button",variant:S?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:te,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($e,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:()=>{Pi(m)},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:[J?s.jsxs("div",{className:"absolute inset-0",children:[s.jsx("iframe",{ref:o,src:J,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:Ne},`${J}:${b}`),S&&k?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:k.bounds.x,top:k.bounds.y,width:k.bounds.width,height:k.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:[k.tag,k.text?` · ${k.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(jc,{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]})]})},E0=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=At(),o=i.useRef(null),a=Re(A=>A.setContextPanelTabTargetPath),c=Co(t),l=c!=="about:blank"?c:"",[d,u]=i.useState(l),[m,f]=i.useState(l),[g,y]=i.useState(!1),[p,x]=i.useState(!0),b=i.useRef(null),h=p,N=i.useCallback(A=>{!A||A==="about:blank"||!e||!n||a(e,n,A)},[e,n,a]),w=dt(A=>A.currentSessionId),S=dt(A=>A.newSessionDraft?.open),j=vc(A=>A.addDraft),k=ai(A=>A.addAttachedFile);i.useEffect(()=>{const A=o.current;if(!A)return;const C=()=>{try{const L=A.getURL();L&&L!=="about:blank"&&(f(L),u(L),N(L))}catch{}},O=L=>{const B=L.detail;typeof B?.url=="string"&&B.url&&(f(B.url),u(B.url),N(B.url))},T=()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>x(!0),200)},E=()=>{b.current&&clearTimeout(b.current),x(!1),C()},F=L=>{const B=L.detail;if(B?.disposition==="new-window"||B?.disposition==="foreground-tab"||B?.disposition==="background-tab"){L.preventDefault();const V=o.current;typeof V?.loadURL=="function"&&B.url&&V.loadURL(B.url)}},R=()=>{try{A.executeJavaScript?.(A0,!0).catch(()=>{})}catch{}};A.addEventListener("did-navigate",O),A.addEventListener("did-navigate-in-page",O),A.addEventListener("did-start-loading",T),A.addEventListener("did-stop-loading",E),A.addEventListener("new-window",F),A.addEventListener("dom-ready",R);try{A.isLoading()||(x(!1),C())}catch{}return R(),()=>{b.current&&clearTimeout(b.current),A.removeEventListener("did-navigate",O),A.removeEventListener("did-navigate-in-page",O),A.removeEventListener("did-start-loading",T),A.removeEventListener("did-stop-loading",E),A.removeEventListener("new-window",F),A.removeEventListener("dom-ready",R)}},[N]),i.useEffect(()=>{const A=setTimeout(()=>x(!1),3e4);return()=>clearTimeout(A)},[]),i.useEffect(()=>{if(!g)return;const A=C=>{if(C.key!=="Escape")return;C.preventDefault(),C.stopImmediatePropagation(),y(!1);const O=o.current;try{O?.executeJavaScript?.(ua).catch(()=>{})}catch{}};return window.addEventListener("keydown",A,!0),()=>window.removeEventListener("keydown",A,!0)},[g]),i.useEffect(()=>{const A=o.current;return()=>{try{const C=A?.getURL?.();C&&C!=="about:blank"&&a(e,n,C)}catch{}try{A?.executeJavaScript?.(ua).catch(()=>{})}catch{}}},[e,n,a]);const v=i.useCallback(A=>{const C=o.current;if(typeof C?.loadURL!="function")return;const O=Co(A);try{C.loadURL(O)}catch{}},[]),D=i.useCallback(()=>{const A=o.current;if(A){if(g){y(!1);try{A.executeJavaScript?.(ua).catch(()=>{})}catch{}return}y(!0),A.executeJavaScript?.(Jm,!0).then(async C=>{if(y(!1),!C||!qi(C))return;const O=w??(S?"draft":null);if(!O){de.error(r("contextPanel.preview.inspect.attachNoSession"));return}const T=typeof A.getWebContentsId=="function"?A.getWebContentsId():null;if(T==null)return;const E=await ug("desktop_browser_capture_page",{webContentsId:T}),F=await A.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(F?.width)?F.width:E.width,L=Number.isFinite(F?.height)?F.height:E.height,B=await Oc(E.base64,E.width,E.height,R,L,C),V=!!B;B&&await k(B),j({sessionKey:O,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:Lc({pageUrl:m,viewport:{width:R,height:L},devicePixelRatio:window.devicePixelRatio||1,target:C,screenshotAttached:V,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),de.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>y(!1))}},[k,j,w,m,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($e,{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($e,{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($e,{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:A=>{A.preventDefault(),v(d)},children:s.jsx("input",{value:d,onChange:A=>u(A.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($e,{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($e,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{Pi(m)},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"}}),(!m||m==="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(jc,{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]})]})},M0=()=>{const{t}=At(),e=li()??"",n=i.useMemo(()=>y0(e),[e]),r=Re(H=>n?H.contextPanelByDirectory[n]:void 0),o=Re(H=>H.closeContextPanel),a=Re(H=>H.closeContextPanelTab),c=Re(H=>H.openContextPanelTab),l=Re(H=>H.toggleContextPanelExpanded),d=Re(H=>H.setContextPanelWidth),u=Re(H=>H.setActiveContextPanelTab),m=Re(H=>H.reorderContextPanelTabs),f=gn(H=>H.setSelectedPath),g=Re(H=>H.openContextPreview),{themeMode:y,setThemeMode:p,lightThemeId:x,darkThemeId:b,currentTheme:h}=Hr(),N=i.useMemo(()=>r?.tabs??[],[r?.tabs]),w=N.find(H=>H.id===r?.activeTabId)??N[N.length-1]??null,S=!!(r?.isOpen&&w),j=!!(S&&r?.expanded),k=Qm(r?.width??Ym),[v,D]=i.useState(!1),[A,C]=i.useState(!1),O=i.useRef(0),T=i.useRef(k),E=i.useRef(null),F=i.useRef(null),R=i.useRef(null),L=i.useRef(new Map),B=i.useRef(new Map),V=i.useRef(!1),M=i.useRef(S),ee=i.useRef(null),se=i.useCallback(()=>{C(!0),ee.current!==null&&window.cancelAnimationFrame(ee.current),ee.current=window.requestAnimationFrame(()=>{ee.current=null,C(!1)})},[]);i.useEffect(()=>()=>{ee.current!==null&&window.cancelAnimationFrame(ee.current)},[]),i.useLayoutEffect(()=>{const H=M.current;if(M.current=S,!S){C(!1);return}H||se()},[S,se]),i.useEffect(()=>{if(!S||V.current){V.current=S;return}const H=window.requestAnimationFrame(()=>{R.current?.focus({preventScroll:!0})});return V.current=!0,()=>window.cancelAnimationFrame(H)},[S]);const J=i.useCallback(H=>{const ce=R.current;ce&&ce.style.setProperty("--oc-context-panel-width",`${Al(H,ce)}px`)},[]),K=i.useCallback(H=>{if(!(!S||j||!n)){try{H.currentTarget.setPointerCapture(H.pointerId)}catch{}F.current=H.pointerId,D(!0),O.current=H.clientX,T.current=k,E.current=k,J(k),H.preventDefault()}},[J,n,j,S,k]),Z=i.useCallback(H=>{if(!v||F.current!==H.pointerId)return;const ce=O.current-H.clientX,fe=Al(T.current+ce,R.current);E.current!==fe&&(E.current=fe,J(fe))},[J,v]),re=i.useCallback(H=>{if(F.current!==H.pointerId||!n)return;try{H.currentTarget.releasePointerCapture(H.pointerId)}catch{}const ce=Al(E.current??k,R.current);se(),J(ce),E.current=ce,d(n,ce),D(!1),F.current=null},[J,n,d,se,k]);i.useEffect(()=>{v||(E.current=null)},[v]);const pe=i.useCallback(()=>{n&&o(n)},[o,n]),Se=i.useCallback(()=>{n&&l(n)},[n,l]),te=i.useCallback(H=>{H.key==="Escape"&&(H.preventDefault(),H.stopPropagation(),pe())},[pe]);i.useEffect(()=>{if(!(!n||!w)&&w.mode==="file"&&w.targetPath){f(n,w.targetPath,{allowOutsideRoot:!0});return}},[w,n,f]);const Ne=w?.mode==="chat"?w.id:null,Y=i.useCallback((H,ce,fe)=>Z1(B.current,H,ce,n||null,fe,{mode:y,lightThemeId:x,darkThemeId:b,currentTheme:h}),[h,b,n,x,y]);i.useEffect(()=>{const H=new Set(N.map(ce=>ce.id));for(const ce of B.current.keys())H.has(ce)||B.current.delete(ce)},[N]);const G=i.useCallback(H=>{!n||w?.mode!=="diff"||c(n,{mode:"diff",targetPath:w.targetPath,stagedDiff:H==="staged"})},[w,n,c]),q=i.useCallback(()=>{if(typeof window>"u")return;const H={themeMode:y,lightThemeId:x,darkThemeId:b,currentTheme:h};for(const ce of L.current.values()){const fe=ce.contentWindow;if(!fe)continue;const U=fe.__openchamberApplyThemeSync;if(typeof U=="function")try{U(H);continue}catch{}fe.postMessage({type:"openchamber:theme-sync",payload:H},window.location.origin)}},[h,b,x,y]),oe=i.useCallback(()=>{if(!(typeof window>"u"))for(const[H,ce]of L.current.entries()){const fe=ce.contentWindow;if(!fe)continue;const U={visible:Ne===H},z=fe.__openchamberSetEmbeddedVisibility;if(typeof z=="function")try{z(U);continue}catch{}fe.postMessage({type:"openchamber:embedded-visibility",payload:U},window.location.origin)}},[Ne]);i.useEffect(()=>{if(typeof window>"u")return;const H=ce=>{if(ce.origin!==window.location.origin||!Array.from(L.current.values()).some(_=>_.contentWindow===ce.source)||ce.data?.type!=="openchamber:cycle-theme-request")return;const z=["light","dark","system"],ge=(z.indexOf(y)+1)%z.length;p(z[ge])};return window.addEventListener("message",H),()=>window.removeEventListener("message",H)},[p,y]),i.useLayoutEffect(()=>{N.some(ce=>ce.mode==="chat")&&(q(),oe())},[b,x,oe,q,N,y]);const le=i.useMemo(()=>N.map(H=>{const ce=N0(H,t),fe=D0(ce,x0),U=v0(H.targetPath,e);return{id:H.id,label:fe,icon:k0(H),title:U?`${ce}: ${U}`:ce,closeLabel:t("contextPanel.tab.closeTabAria",{label:fe})}}),[e,t,N]),ve=w?.mode==="context"?s.jsx(_1,{}):w?.mode==="plan"?s.jsx(_m,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(P0,{rawUrl:w.targetPath??"",onNavigate:H=>g(e,H)}):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")})]}),Ee=i.useMemo(()=>N.filter(H=>H.mode==="chat"),[N]),_e=i.useMemo(()=>N.filter(H=>H.mode==="browser"),[N]),Oe=i.useMemo(()=>N.filter(H=>H.mode==="diff"),[N]),Me=T0()?E0:R0,he=i.useMemo(()=>N.some(H=>H.mode==="file"),[N]),Ce=w?.mode==="file",xe=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-transparent",children:[s.jsx(To,{items:le,activeId:w?.id??null,onSelect:H=>{n&&u(n,H)},onClose:H=>{n&&a(n,H)},onReorder:(H,ce)=>{n&&m(n,H,ce)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx($e,{type:"button",variant:"ghost",size:"sm",onClick:Se,className:"h-7 w-7 p-0",title:t(j?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(j?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:j?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($e,{type:"button",variant:"ghost",size:"sm",onClick:pe,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"})})]})]}),ue=S?j?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",minWidth:`min(${qm}px, 100%)`,maxWidth:"100%","--oc-context-panel-width":`${v?E.current??k:k}px`}:{"--oc-context-panel-width":`${v?E.current??k:k}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:"hidden",visibility:"hidden"};return s.jsxs("aside",{ref:R,"data-context-panel":"true",tabIndex:-1,inert:!S||void 0,className:De("flex min-h-0 flex-col overflow-hidden bg-background",!j&&"border-l border-border/40",j?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",!S&&"pointer-events-none",v||!S||A?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:te,style:ue,children:[!j&&s.jsx("div",{className:De("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",v&&"bg-[var(--interactive-border)]"),onPointerDown:K,onPointerMove:Z,onPointerUp:re,onPointerCancel:re,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),xe,s.jsxs("div",{className:De("relative min-h-0 flex-1 overflow-hidden",v&&"pointer-events-none"),children:[he?s.jsx("div",{className:De("absolute inset-0",Ce?"block":"hidden"),children:s.jsx(Vm,{mode:"editor-only"})}):null,Ee.map(H=>{const ce=C0(H.dedupeKey);if(!ce)return null;const fe=Y(H.id,ce,H.readOnly);return fe?s.jsx("iframe",{ref:U=>{if(!U){L.current.delete(H.id);return}L.current.set(H.id,U)},src:fe,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ce}),className:De("absolute inset-0 h-full w-full border-0 bg-background",Ne===H.id?"block":"hidden"),onLoad:()=>{q(),oe()}},H.id):null}),_e.map(H=>s.jsx("div",{className:De("absolute inset-0",w?.id!==H.id&&"hidden"),children:s.jsx(Me,{initialUrl:H.targetPath??"",directory:n,tabID:H.id})},H.id)),Oe.map(H=>s.jsx("div",{className:De("absolute inset-0",w?.id!==H.id&&"hidden"),children:s.jsx(Fm,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:H.stagedDiff?"staged":"working",onDiffScopeChange:G,targetFilePath:H.targetPath,flushContent:!0})},H.id)),w?.mode!=="chat"&&!Ce&&w?.mode!=="browser"&&w?.mode!=="diff"?ve:null]})]})},ec=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==="/",a=/^[A-Za-z]:\/$/.test(r);return!o&&!a&&(r=r.replace(/\/+$/,"")),r},F0=()=>{const t=gt.c(171),{t:e}=At(),n=Re(L0),r=Re(O0),o=Re(B0),a=Re(V0),c=Re(_0),l=Re($0),d=Re(z0),u=Re(U0),m=Re(W0),f=Re(H0),g=Re(G0),y=Re(K0),p=dt(q0),x=dt(Y0),b=xr(Q0),h=qs(J0),N=ys(X0),w=li(),S=lc(Z0),{files:j,git:k}=Qn(),v=xn(ej),{isMobile:D}=Rr();let A;t[0]!==w?(A=w?ec(w):null,t[0]=w,t[1]=A):A=t[1];const C=A,[O,T]=i.useState(""),E=Ha(O,200);let F;t[2]!==E?(F=E.trim(),t[2]=E,t[3]=F):F=t[3];const R=F;let L;t[4]!==O?(L=O.trim(),t[4]=O,t[5]=L):L=t[5];const B=L;let V,M;t[6]!==n?(V=()=>{n&&T("")},M=[n],t[6]=n,t[7]=V,t[8]=M):(V=t[7],M=t[8]),i.useEffect(V,M);let ee,se;t[9]!==b||t[10]!==v||t[11]!==k||t[12]!==n?(ee=()=>{if(!n||!k)return;const Le=setTimeout(()=>{const Dt=new Set;for(const Ot of b){const mt=Pr(Ot);!mt||Dt.has(mt)||(Dt.add(mt),v(mt,k))}},0);return()=>clearTimeout(Le)},se=[n,b,k,v],t[9]=b,t[10]=v,t[11]=k,t[12]=n,t[13]=ee,t[14]=se):(ee=t[13],se=t[14]),i.useEffect(ee,se);let J;t[15]!==r?(J=()=>r(!1),t[15]=r,t[16]=J):J=t[16];const K=J;let Z;t[17]!==K?(Z=Le=>()=>{K(),Le()},t[17]=K,t[18]=Z):Z=t[18];const re=Z;let pe;t[19]!==N?.id||t[20]!==N?.path||t[21]!==h||t[22]!==D||t[23]!==f||t[24]!==p||t[25]!==re||t[26]!==o||t[27]!==l||t[28]!==a||t[29]!==e||t[30]!==m||t[31]!==u||t[32]!==d?(pe=()=>{const Le=[{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:re(()=>{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:re(tj)},{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:re(sj)},{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:re(()=>{if(D){const{isSessionSwitcherOpen:Dt}=Re.getState();l(!Dt)}else d()})},{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:re(()=>u())},{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:re(()=>m())},{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:re(()=>{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:re(()=>a(!0))}];return Fa()&&Le.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:re(()=>{zr("desktop_open_draft_mini_chat_window",{directory:ec(h||N?.path||""),projectId:N?.id??null}).catch(nj)})}),Le},t[19]=N?.id,t[20]=N?.path,t[21]=h,t[22]=D,t[23]=f,t[24]=p,t[25]=re,t[26]=o,t[27]=l,t[28]=a,t[29]=e,t[30]=m,t[31]=u,t[32]=d,t[33]=pe):pe=t[33],N?.id,N?.path;let Se;t[34]!==pe?(Se=pe(),t[34]=pe,t[35]=Se):Se=t[35];const te=Se;let Ne;t[36]===Symbol.for("react.memo_cache_sentinel")?(Ne=cr(),t[36]=Ne):Ne=t[36];const Y=Ne;let G,q;t[37]===Symbol.for("react.memo_cache_sentinel")?(G=Wr(),q=!Y&&dc(),t[37]=G,t[38]=q):(G=t[37],q=t[38]);let oe;t[39]!==D?(oe={isVSCode:G,isWeb:q,isDesktop:Y,isMobile:D},t[39]=D,t[40]=oe):oe=t[40];const le=oe;let ve;if(t[41]!==re||t[42]!==a||t[43]!==c||t[44]!==le){let Le;t[46]!==le?(Le=Ot=>Ot.isAvailable?Ot.isAvailable(le):!0,t[46]=le,t[47]=Le):Le=t[47];let Dt;t[48]!==re||t[49]!==a||t[50]!==c?(Dt=Ot=>{const mt=Fx(Ot.slug)??"settings-3",Et=(Ot.keywords??[]).join(" ");return{id:`settings:${Ot.slug}`,title:Ot.title,icon:Ot.slug==="mcp"?s.jsx($l,{className:"mr-2 h-4 w-4"}):s.jsx(I,{name:mt,className:"mr-2 h-4 w-4"}),searchText:`${Ot.title} ${Ot.group} ${Et}`,onSelect:re(()=>{c(Ot.slug),a(!0)})}},t[48]=re,t[49]=a,t[50]=c,t[51]=Dt):Dt=t[51],ve=Mx.filter(rj).filter(Le).map(Dt),t[41]=re,t[42]=a,t[43]=c,t[44]=le,t[45]=ve}else ve=t[45];const Ee=ve,_e=ij;let Oe;if(t[52]!==b){let Le;t[54]===Symbol.for("react.memo_cache_sentinel")?(Le=(Dt,Ot)=>_e(Ot)-_e(Dt),t[54]=Le):Le=t[54],Oe=[...b].sort(Le),t[52]=b,t[53]=Oe}else Oe=t[53];const Me=Oe,he=Qf(),Ce=dt(oj);let xe;t[55]!==he||t[56]!==Ce?(xe=(Le,Dt)=>{const Ot=Ce.get(Le);return Ot?.branch?Ot.branch.trim()||null:Dt&&he.get(Dt)?.trim()||null},t[55]=he,t[56]=Ce,t[57]=xe):xe=t[57];const ue=xe;let H;t[58]===Symbol.for("react.memo_cache_sentinel")?(H=[],t[58]=H):H=t[58];const[ce,fe]=i.useState(H),[U,z]=i.useState(!1);let be,ge;t[59]!==C||t[60]!==n||t[61]!==S||t[62]!==R?(be=()=>{if(!n){fe([]),z(!1);return}if(!C||R.length===0){fe([]),z(!1);return}let Le=!1;return z(!0),S(C,R,10,{type:"file"}).then(Dt=>{Le||fe(Dt.map(aj))}).catch(()=>{Le||fe([])}).finally(()=>{Le||z(!1)}),()=>{Le=!0}},ge=[n,C,R,S],t[59]=C,t[60]=n,t[61]=S,t[62]=R,t[63]=be,t[64]=ge):(be=t[63],ge=t[64]),i.useEffect(be,ge);const _=B.length>0;let ye;e:{if(!_){let Dt;t[65]!==te?(Dt=te.map(lj),t[65]=te,t[66]=Dt):Dt=t[66],ye=Dt;break e}let Le;t[67]!==te||t[68]!==B?(Le=Uo(te,B,cj,{limit:7,noFuzzy:!0}),t[67]=te,t[68]=B,t[69]=Le):Le=t[69],ye=Le}const $=ye;let Ie;e:{if(!_){let Dt;t[70]===Symbol.for("react.memo_cache_sentinel")?(Dt=[],t[70]=Dt):Dt=t[70],Ie=Dt;break e}let Le;t[71]!==B||t[72]!==Ee?(Le=Uo(Ee,B,dj,{limit:7,noFuzzy:!0}),t[71]=B,t[72]=Ee,t[73]=Le):Le=t[73],Ie=Le}const je=Ie;let Fe;e:{if(!_){let Dt;t[74]!==Me?(Dt=Me.slice(0,5).map(uj),t[74]=Me,t[75]=Dt):Dt=t[75],Fe=Dt;break e}let Le;t[76]!==B||t[77]!==Me?(Le=Uo(Me,B,fj,{limit:7,threshold:.2}),t[76]=B,t[77]=Me,t[78]=Le):Le=t[78],Fe=Le}const Ae=Fe;let ne;e:{if(!_||ce.length===0){let Dt;t[79]===Symbol.for("react.memo_cache_sentinel")?(Dt=[],t[79]=Dt):Dt=t[79],ne=Dt;break e}let Le;t[80]!==ce||t[81]!==B?(Le=Uo(ce,B,mj,{limit:10,threshold:.4}),t[80]=ce,t[81]=B,t[82]=Le):Le=t[82],ne=Le}const P=ne;let me,ae,Be,Ge,Ke,Qe,st,ut,vt,Ve,tt,nt,xt,Rt,bt;if(t[83]!==ue||t[84]!==K||t[85]!==C||t[86]!==j||t[87]!==_||t[88]!==n||t[89]!==g||t[90]!==O||t[91]!==$||t[92]!==P||t[93]!==Ae||t[94]!==je||t[95]!==r||t[96]!==x||t[97]!==y||t[98]!==e){const Le=$.map(hj),Dt=je.map(pj),Ot=Ae.map(gj);bt=_?P.map(xj):[];let mt;e:{if(!_){mt=["commands","sessions"];break e}const Ue=bj,Ye=[{key:"commands",score:Ue($)},{key:"settings",score:Ue(je)},{key:"sessions",score:Ue(Ae)},{key:"files",score:Ue(P)}];Ye.sort(yj),mt=Ye.map(wj)}const Et=mt;let qt;t[114]!==K||t[115]!==x?(qt=Ue=>{K(),x(Ue.id,Pr(Ue))},t[114]=K,t[115]=x,t[116]=qt):qt=t[116];const Vt=qt;let Wt;t[117]!==K||t[118]!==C||t[119]!==j||t[120]!==g?(Wt=async Ue=>{if(!C)return;const Ye=await Ec(j,Ue);if(!Ye.ok){de.error(Mc(Ye.reason));return}g(C,Ue),K()},t[117]=K,t[118]=C,t[119]=j,t[120]=g,t[121]=Wt):Wt=t[121];const Yt=Wt;let Bt;t[122]!==y?(Bt=Ue=>La(ni(Ue,y)),t[122]=y,t[123]=Bt):Bt=t[123];const Ht=Bt;Ge=Ls,nt=n,xt=r;let Jt;t[124]!==e?(Jt=e("commandPalette.title"),t[124]=e,t[125]=Jt):Jt=t[125];let rs;t[126]!==Jt?(rs=s.jsx($s,{children:Jt}),t[126]=Jt,t[127]=rs):rs=t[127];let Qt;t[128]!==e?(Qt=e("commandPalette.description"),t[128]=e,t[129]=Qt):Qt=t[129];let Xt;t[130]!==Qt?(Xt=s.jsx(an,{children:Qt}),t[130]=Qt,t[131]=Xt):Xt=t[131],t[132]!==rs||t[133]!==Xt?(Rt=s.jsxs(Us,{className:"sr-only",children:[rs,Xt]}),t[132]=rs,t[133]=Xt,t[134]=Rt):Rt=t[134],Be=Fs,Ve="overflow-hidden p-0",tt=!0,ae=Oa,st=!1,ut="[&_[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 bs;t[135]!==e?(bs=e("commandPalette.input.placeholder"),t[135]=e,t[136]=bs):bs=t[136],t[137]!==O||t[138]!==bs?(vt=s.jsx(Ba,{value:O,onValueChange:T,placeholder:bs}),t[137]=O,t[138]=bs,t[139]=vt):vt=t[139],me=Va;let yt;t[140]!==e?(yt=e("commandPalette.empty.noResults"),t[140]=e,t[141]=yt):yt=t[141],t[142]!==yt?(Ke=s.jsx(_a,{children:yt}),t[142]=yt,t[143]=Ke):Ke=t[143],Qe=Et.map(Ue=>Ue==="commands"&&Le.length>0?s.jsx(ri,{children:Le.map(Ye=>s.jsxs(oi,{value:Ye.id,onSelect:Ye.onSelect,children:[Ye.icon,s.jsx("span",{children:Ye.title}),Ye.shortcutId?s.jsx(fg,{children:Ht(Ye.shortcutId)}):null]},Ye.id))},"commands"):Ue==="settings"&&Dt.length>0?s.jsx(ri,{children:Dt.map(vj)},"settings"):Ue==="sessions"&&Ot.length>0?s.jsx(ri,{children:Ot.map(Ye=>{const Ct=Ye.title||e("commandPalette.session.untitled"),kt=Pr(Ye),It=ue(Ye.id,kt);return s.jsxs(oi,{value:`session:${Ye.id}`,onSelect:()=>Vt(Ye),children:[s.jsx(I,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Ct}),It?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:It})]}):null]},Ye.id)})},"sessions"):Ue==="files"&&bt.length>0?s.jsx(ri,{children:bt.map(Ye=>{const Ct=mg(Ye.relativePath||Ye.name,{maxLength:80});return s.jsxs(oi,{value:`file:${Ye.path}`,onSelect:()=>{Yt(Ye.path)},children:[s.jsx(Ur,{filePath:Ye.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Ye.relativePath,children:Ct})]},`file:${Ye.path}`)})},"files"):null),t[83]=ue,t[84]=K,t[85]=C,t[86]=j,t[87]=_,t[88]=n,t[89]=g,t[90]=O,t[91]=$,t[92]=P,t[93]=Ae,t[94]=je,t[95]=r,t[96]=x,t[97]=y,t[98]=e,t[99]=me,t[100]=ae,t[101]=Be,t[102]=Ge,t[103]=Ke,t[104]=Qe,t[105]=st,t[106]=ut,t[107]=vt,t[108]=Ve,t[109]=tt,t[110]=nt,t[111]=xt,t[112]=Rt,t[113]=bt}else me=t[99],ae=t[100],Be=t[101],Ge=t[102],Ke=t[103],Qe=t[104],st=t[105],ut=t[106],vt=t[107],Ve=t[108],tt=t[109],nt=t[110],xt=t[111],Rt=t[112],bt=t[113];let ot;t[144]!==_||t[145]!==U||t[146]!==e||t[147]!==bt?(ot=_&&U&&bt.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[144]=_,t[145]=U,t[146]=e,t[147]=bt,t[148]=ot):ot=t[148];let at;t[149]!==me||t[150]!==Ke||t[151]!==Qe||t[152]!==ot?(at=s.jsxs(me,{children:[Ke,Qe,ot]}),t[149]=me,t[150]=Ke,t[151]=Qe,t[152]=ot,t[153]=at):at=t[153];let Ut;t[154]!==ae||t[155]!==st||t[156]!==ut||t[157]!==vt||t[158]!==at?(Ut=s.jsxs(ae,{shouldFilter:st,className:ut,children:[vt,at]}),t[154]=ae,t[155]=st,t[156]=ut,t[157]=vt,t[158]=at,t[159]=Ut):Ut=t[159];let Nt;t[160]!==Be||t[161]!==Ve||t[162]!==tt||t[163]!==Ut?(Nt=s.jsx(Be,{className:Ve,showCloseButton:tt,children:Ut}),t[160]=Be,t[161]=Ve,t[162]=tt,t[163]=Ut,t[164]=Nt):Nt=t[164];let _t;return t[165]!==Ge||t[166]!==nt||t[167]!==xt||t[168]!==Rt||t[169]!==Nt?(_t=s.jsxs(Ge,{open:nt,onOpenChange:xt,children:[Rt,Nt]}),t[165]=Ge,t[166]=nt,t[167]=xt,t[168]=Rt,t[169]=Nt,t[170]=_t):_t=t[170],_t};function L0(t){return t.isCommandPaletteOpen}function O0(t){return t.setCommandPaletteOpen}function B0(t){return t.setActiveMainTab}function V0(t){return t.setSettingsDialogOpen}function _0(t){return t.setSettingsPage}function $0(t){return t.setSessionSwitcherOpen}function z0(t){return t.toggleSidebar}function U0(t){return t.toggleRightSidebar}function W0(t){return t.toggleBottomTerminal}function H0(t){return t.openContextOverview}function G0(t){return t.openContextFile}function K0(t){return t.shortcutOverrides}function q0(t){return t.openNewSessionDraft}function Y0(t){return t.setCurrentSession}function Q0(t){return t.activeSessions}function J0(t){return t.currentDirectory}function X0(t){return t.getActiveProject()}function Z0(t){return t.searchFiles}function ej(t){return t.ensureStatus}function tj(){Jf()}function sj(){Ir.requestDirectoryDialog()}function nj(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function rj(t){return t.slug!=="home"}function ij(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function oj(t){return t.worktreeMetadata}function aj(t){return{path:ec(t.path),name:t.name,relativePath:t.relativePath}}function lj(t){return{item:t,score:0}}function cj(t){return t.searchText}function dj(t){return t.searchText}function uj(t){return{item:t,score:0}}function fj(t){return t.title||""}function mj(t){return t.name}function hj(t){return t.item}function pj(t){return t.item}function gj(t){return t.item}function xj(t){return t.item}function bj(t){return t.length?t[0].score:1/0}function yj(t,e){return t.score-e.score}function wj(t){return t.key}function vj(t){return s.jsxs(oi,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const _u=(t,e,n)=>pg(t)?La(ni(t,n)):e,jj=()=>{const t=gt.c(68),{t:e}=At(),n=Re(Sj),r=Re(Nj),o=Re(kj);let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=hg(),t[0]=a):a=t[0];const c=a;let l,d,u,m,f,g,y,p,x;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:""}]}];d=Ls,p=n,x=r,l=Fs,g="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let L;t[14]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(I,{name:"settings-3",className:"h-5 w-5"}),t[14]=L):L=t[14];let B;t[15]!==e?(B=e("helpDialog.title"),t[15]=e,t[16]=B):B=t[16];let V;t[17]!==B?(V=s.jsxs($s,{className:"flex items-center gap-2",children:[L,B]}),t[17]=B,t[18]=V):V=t[18];let M;t[19]!==e?(M=e("helpDialog.description"),t[19]=e,t[20]=M):M=t[20];let ee;t[21]!==M?(ee=s.jsx(an,{children:M}),t[21]=M,t[22]=ee):ee=t[22],t[23]!==V||t[24]!==ee?(y=s.jsxs(Us,{children:[V,ee]}),t[23]=V,t[24]=ee,t[25]=y):y=t[25],f="flex-1 overflow-y-auto mt-3 pr-1",u="space-y-4",m=R.map(se=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(se.categoryKey)}),s.jsx("div",{className:"space-y-1",children:se.items.map(J=>{const K=J.id?_u(J.id,Array.isArray(J.keys)?J.keys[0]:J.keys,o):Array.isArray(J.keys)?J.keys:J.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:[J.icon&&s.jsx(I,{name:J.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(J.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(K)?K:[K]).map((Z,re)=>s.jsxs(i.Fragment,{children:[re>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:Z})]},`${Z}-${re}`))})]},J.id||J.descriptionKey)})})]},se.categoryKey)),t[1]=n,t[2]=r,t[3]=o,t[4]=e,t[5]=l,t[6]=d,t[7]=u,t[8]=m,t[9]=f,t[10]=g,t[11]=y,t[12]=p,t[13]=x}else l=t[5],d=t[6],u=t[7],m=t[8],f=t[9],g=t[10],y=t[11],p=t[12],x=t[13];let b;t[26]!==u||t[27]!==m?(b=s.jsx("div",{className:u,children:m}),t[26]=u,t[27]=m,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:_u("open_command_palette",`${c} P`,o)}),t[34]=o,t[35]=e,t[36]=S):S=t[36];let j;t[37]!==S?(j=s.jsxs("li",{children:["• ",S]}),t[37]=S,t[38]=j):j=t[38];let k;t[39]!==e?(k=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=k):k=t[40];let v;t[41]!==k?(v=s.jsxs("li",{children:["• ",k]}),t[41]=k,t[42]=v):v=t[42];let D;t[43]!==e?(D=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=D):D=t[44];let A;t[45]!==D?(A=s.jsxs("li",{children:["• ",D]}),t[45]=D,t[46]=A):A=t[46];let C;t[47]!==j||t[48]!==v||t[49]!==A?(C=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[j,v,A]}),t[47]=j,t[48]=v,t[49]=A,t[50]=C):C=t[50];let O;t[51]!==w||t[52]!==C?(O=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]=O):O=t[53];let T;t[54]!==O||t[55]!==f||t[56]!==b?(T=s.jsxs("div",{className:f,children:[b,O]}),t[54]=O,t[55]=f,t[56]=b,t[57]=T):T=t[57];let E;t[58]!==l||t[59]!==T||t[60]!==g||t[61]!==y?(E=s.jsxs(l,{className:g,children:[y,T]}),t[58]=l,t[59]=T,t[60]=g,t[61]=y,t[62]=E):E=t[62];let F;return t[63]!==d||t[64]!==E||t[65]!==p||t[66]!==x?(F=s.jsx(d,{open:p,onOpenChange:x,children:E}),t[63]=d,t[64]=E,t[65]=p,t[66]=x,t[67]=F):F=t[67],F};function Sj(t){return t.isHelpDialogOpen}function Nj(t){return t.setHelpDialogOpen}function kj(t){return t.shortcutOverrides}const Cj=()=>{const t=gt.c(32),{t:e}=At(),n=Re(Aj),r=Re(Dj),o=Re(Ij);let a;t[0]!==o||t[1]!==e?(a=async()=>{if(!o)return;if((await dr(o)).ok){de.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}de.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=o,t[1]=e,t[2]=a):a=t[2];const c=a;let l;t[3]!==e?(l=e("openCodeStatusDialog.title"),t[3]=e,t[4]=l):l=t[4];let d;t[5]!==l?(d=s.jsx($s,{children:l}),t[5]=l,t[6]=d):d=t[6];let u;t[7]!==e?(u=e("openCodeStatusDialog.description"),t[7]=e,t[8]=u):u=t[8];let m;t[9]!==u?(m=s.jsx(an,{children:u}),t[9]=u,t[10]=m):m=t[10];let f;t[11]!==d||t[12]!==m?(f=s.jsxs(Us,{children:[d,m]}),t[11]=d,t[12]=m,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 y;t[16]!==c||t[17]!==g?(y=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]=y):y=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 x;t[22]!==p?(x=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]=x):x=t[23];let b;t[24]!==f||t[25]!==y||t[26]!==x?(b=s.jsxs(Fs,{className:"max-w-2xl",children:[f,y,x]}),t[24]=f,t[25]=y,t[26]=x,t[27]=b):b=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==b?(h=s.jsx(Ls,{open:n,onOpenChange:r,children:b}),t[28]=n,t[29]=r,t[30]=b,t[31]=h):h=t[31],h};function Aj(t){return t.isOpenCodeStatusDialogOpen}function Dj(t){return t.setOpenCodeStatusDialogOpen}function Ij(t){return t.openCodeStatusText}const Pj=180,$u=600,Tj=1,Rj=6,Ej=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const o=i.useRef(new Map),a=i.useRef([]),c=i.useRef(new Set),l=i.useMemo(()=>Wr(),[]),d=i.useCallback(()=>{if(!(l||typeof window>"u"))for(;c.current.size<Tj&&a.current.length>0;){const m=a.current.shift();if(!m)break;dt.getState().currentSessionId!==m&&(Ad(m).renderable||(c.current.add(m),r(m).catch(()=>{}).finally(()=>{c.current.delete(m),d()})))}},[r,l]),u=i.useCallback(m=>{if(l||!m||m===t||typeof window>"u"||Ad(m).renderable||c.current.has(m)||a.current.includes(m))return;a.current.length>=Rj&&a.current.shift();const f=o.current.get(m);f!==void 0&&window.clearTimeout(f);const g=window.setTimeout(()=>{o.current.delete(m),a.current.push(m),d()},Pj);o.current.set(m,g)},[t,l,d]);i.useEffect(()=>{if(l||!t||e.length===0)return;const m=window.setTimeout(()=>{const f=e.findIndex(g=>g.id===t);f<0||(u(e[f-1]?.id),u(e[f+1]?.id))},$u);return()=>window.clearTimeout(m)},[t,l,u,e]),i.useEffect(()=>{if(l||!t||n.length===0)return;const m=window.setTimeout(()=>{const f=n.indexOf(t);f<0||(u(n[f-1]),u(n[f+1]))},$u);return()=>window.clearTimeout(m)},[t,l,n,u]),i.useEffect(()=>{const m=o.current;return()=>{m.forEach(f=>{clearTimeout(f)}),m.clear(),a.current=[]}},[])};let Qi=null,Ji=null,fa=null,Eo=0,Ta=null;const Ii=new Set,Mj=3e4,Fj=45e3,Zm=()=>{fa&&(clearTimeout(fa),fa=null)},eh=()=>{if(Ji||Ii.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Eo,5)),Mj);Ji=setTimeout(()=>{Ji=null,Eo+=1,Vc()},t)},Mo=()=>{Zm(),Qi&&Qi.close(),Qi=null},zu=()=>{Zm(),Ii.size!==0&&(fa=setTimeout(()=>{Mo(),eh()},Fj))},Lj=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}},Oj=t=>{if(t.type==="openchamber:event-stream-ready"){Eo=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(),a=e?.status,c=a==="running"||a==="error"?a:"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 d of Ii)d(l)},Vc=()=>{if(typeof window>"u"||Ii.size===0||typeof EventSource!="function"||Qi&&Qi.readyState!==EventSource.CLOSED)return;Mo();const t=new EventSource(Ai().sse("/api/openchamber/events"));t.onopen=()=>{zu()},t.onmessage=e=>{zu();const n=Lj(e.data);n&&Oj(n)},t.onerror=()=>{Mo(),eh()},Qi=t},Bj=()=>{Ta||typeof window>"u"||(Ta=If(()=>{Mo(),Eo=0,Vc()}))},Vj=()=>{Ta?.(),Ta=null},th=t=>(Ii.add(t),Bj(),Vc(),()=>{Ii.delete(t),Ii.size===0&&(Ji&&(clearTimeout(Ji),Ji=null),Eo=0,Mo(),Vj())}),Ya=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},ro=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},_j=async t=>{const e=ro(t),n=await Cs(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Ya(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Uu=async(t,e)=>{const n=ro(t),r=await Cs(`/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 Ya(r,"Failed to save scheduled task"));const o=await r.json().catch(()=>null);return!o||!Array.isArray(o.tasks)?[]:o.tasks},$j=async(t,e)=>{const n=ro(t),r=ro(e),o=await Cs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Ya(o,"Failed to delete scheduled task"));const a=await o.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},zj=async(t,e)=>{const n=ro(t),r=ro(e),o=await Cs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Ya(o,"Failed to run scheduled task"));const a=await o.json().catch(()=>null);return{sessionId:typeof a?.sessionId=="string"&&a.sessionId.length>0?a.sessionId:void 0}};function sh(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return kf.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function Uj(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},o=kf.CronExpressionParser.parse(t,r),a=[];for(let c=0;c<n;c+=1){const l=o.next();l&&a.push(l.toDate())}return a}catch{return[]}}const Wj=[{expression:"*/5 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.every5min"},{expression:"0 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.everyHour"},{expression:"0 9 * * 1",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.monday9am"},{expression:"0 9,17 * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.9am5pm"},{expression:"0 0 1 * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.firstOfMonth"}],nh=[0,1,2,3,4,5,6],tc=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"],Wu=()=>{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}`},ma=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]),a=new Date(n,r-1,o);return Number.isNaN(a.getTime())||a.getFullYear()!==n||a.getMonth()!==r-1||a.getDate()!==o?null:a},Hu=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Hj=(t,e,n)=>{const r=ma(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Gu=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),Gj=(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(),d=new Date(n,r,0).getDate(),u=[];for(let m=0;m<42;m+=1){const f=m-c+1;if(f<=0){const g=d+f;u.push({date:new Date(n,r-1,g),inCurrentMonth:!1});continue}if(f>l){u.push({date:new Date(n,r+1,f-l),inCurrentMonth:!1});continue}u.push({date:new Date(n,r,f),inCurrentMonth:!0})}return u},Kj=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",a=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(a).padStart(2,"0"),minute:r,meridiem:o}},wi=(t,e,n)=>{const r=Number(t),o=Number(e),a=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=a%12;return n==="PM"&&(l+=12),`${String(l).padStart(2,"0")}:${String(c).padStart(2,"0")}`},co=(t,e)=>{const{max:n,min:r=0,loop:o=!1}=e;let a=Number.parseInt(t,10);return Number.isFinite(a)?(o?(a>n&&(a=r),a<r&&(a=n)):(a>n&&(a=n),a<r&&(a=r)),String(a).padStart(2,"0")):"00"},Ku=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:co(t,{min:1,max:12}),Zo=t=>/^[0-5][0-9]$/.test(t)?t:co(t,{max:59}),qj=(t,e)=>co(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),qu=(t,e)=>co(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),Yj=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}},Qj=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}},Jj=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return nh.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},Xj=(t,e)=>[...t.slice(e),...t.slice(0,e)],qn=t=>{const e=gt.c(6),{htmlFor:n,required:r,children:o}=t;let a;e[0]!==r?(a=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=a):a=e[1];let c;return e[2]!==o||e[3]!==n||e[4]!==a?(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,a]})}),e[2]=o,e[3]=n,e[4]=a,e[5]=c):c=e[5],c},Yu=t=>{const e=gt.c(84),{value:n,onChange:r,use24Hour:o,hourAriaLabel:a,minuteAriaLabel:c,periodAriaLabel:l,amLabel:d,pmLabel:u}=t;let m;e[0]!==n?(m=Kj(n),e[0]=n,e[1]=m):m=e[1];const f=m,g=Ze.useRef(null),y=Ze.useRef(null),[p,x]=Ze.useState(null),[b,h]=Ze.useState(null),N=Ze.useRef(null),w=Ze.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=xe=>{N.current=xe,x(xe)},e[2]=S):S=e[2];const j=S;let k;e[3]===Symbol.for("react.memo_cache_sentinel")?(k=xe=>{w.current=xe,h(xe)},e[3]=k):k=e[3];const v=k,D=iS,A=oS,C=aS;let O;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==o?(O=xe=>{const ue=xe.replace(/\D/g,"").slice(0,2);j(ue),ue.length===2&&(r(o?C(D(ue),f.minute):wi(Ku(ue),f.minute,f.meridiem)),j(null),y.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=o,e[8]=O):O=e[8];const T=O;let E;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==o?(E=()=>{const xe=N.current;if(xe!==null&&(j(null),xe.length!==0)){if(o){r(C(D(xe.padStart(2,"0")),f.minute));return}r(wi(Ku(xe.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=o,e[13]=E):E=e[13];const F=E;let R;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==o?(R=xe=>{const ue=xe.replace(/\D/g,"").slice(0,2);v(ue),ue.length===2&&(r(o?C(f.hour24,Zo(ue)):wi(f.hour12,Zo(ue),f.meridiem)),v(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 L=R;let B;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==o?(B=()=>{const xe=w.current;xe!==null&&(v(null),xe.length!==0&&r(o?C(f.hour24,Zo(xe.padStart(2,"0"))):wi(f.hour12,Zo(xe.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]=B):B=e[25];const V=B;let M;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==o?(M=xe=>r(o?C(A(f.hour24,xe),f.minute):wi(qj(f.hour12,xe),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]=M):M=e[32];const ee=M;let se;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==o?(se=xe=>r(o?C(f.hour24,qu(f.minute,xe)):wi(f.hour12,qu(f.minute,xe),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]=se):se=e[39];const J=se;let K;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(K=xe=>{xe!==f.meridiem&&r(wi(f.hour12,f.minute,xe))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=K):K=e[44];const Z=K;let re;e[45]!==F||e[46]!==ee?(re=xe=>{if(xe.key==="ArrowRight"){xe.preventDefault(),F(),y.current?.focus();return}(xe.key==="ArrowUp"||xe.key==="ArrowDown")&&(xe.preventDefault(),j(null),ee(xe.key==="ArrowUp"?1:-1))},e[45]=F,e[46]=ee,e[47]=re):re=e[47];const pe=re;let Se;e[48]!==V||e[49]!==J?(Se=xe=>{if(xe.key==="ArrowLeft"&&(xe.currentTarget.selectionStart??0)===0){xe.preventDefault(),V(),g.current?.focus();return}(xe.key==="ArrowUp"||xe.key==="ArrowDown")&&(xe.preventDefault(),v(null),J(xe.key==="ArrowUp"?1:-1))},e[48]=V,e[49]=J,e[50]=Se):Se=e[50];const te=Se,Ne=o?"px-2":"pl-2 pr-1";let Y;e[51]!==Ne?(Y=De("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",Ne),e[51]=Ne,e[52]=Y):Y=e[52];const G=p??(o?f.hour24:f.hour12);let q;e[53]!==T?(q=xe=>T(xe.target.value),e[53]=T,e[54]=q):q=e[54];let oe;e[55]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>j(""),e[55]=oe):oe=e[55];let le;e[56]!==F||e[57]!==a||e[58]!==pe||e[59]!==G||e[60]!==q?(le=s.jsx("input",{ref:g,inputMode:"numeric",value:G,onChange:q,onKeyDown:pe,onFocus:oe,onBlur:F,maxLength:2,"aria-label":a,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]=F,e[57]=a,e[58]=pe,e[59]=G,e[60]=q,e[61]=le):le=e[61];let ve;e[62]===Symbol.for("react.memo_cache_sentinel")?(ve=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=ve):ve=e[62];const Ee=b??f.minute;let _e;e[63]!==L?(_e=xe=>L(xe.target.value),e[63]=L,e[64]=_e):_e=e[64];let Oe;e[65]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>v(""),e[65]=Oe):Oe=e[65];let Me;e[66]!==V||e[67]!==c||e[68]!==te||e[69]!==Ee||e[70]!==_e?(Me=s.jsx("input",{ref:y,inputMode:"numeric",value:Ee,onChange:_e,onKeyDown:te,onFocus:Oe,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]=te,e[69]=Ee,e[70]=_e,e[71]=Me):Me=e[71];let he;e[72]!==d||e[73]!==f.meridiem||e[74]!==l||e[75]!==u||e[76]!==Z||e[77]!==o?(he=o?null:s.jsxs(_n,{value:f.meridiem,onValueChange:xe=>Z(xe),children:[s.jsx($n,{"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(Nn,{})}),s.jsxs(zn,{children:[s.jsx(Is,{value:"AM",children:d}),s.jsx(Is,{value:"PM",children:u})]})]}),e[72]=d,e[73]=f.meridiem,e[74]=l,e[75]=u,e[76]=Z,e[77]=o,e[78]=he):he=e[78];let Ce;return e[79]!==Y||e[80]!==le||e[81]!==Me||e[82]!==he?(Ce=s.jsxs("div",{className:Y,children:[le,ve,Me,he]}),e[79]=Y,e[80]=le,e[81]=Me,e[82]=he,e[83]=Ce):Ce=e[83],Ce},Qu=t=>new Date(t.getFullYear(),t.getMonth(),1),Zj=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Ju=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),eS=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,a)=>o.localeCompare(a));return r.length>0?r:["09:00"]},Xu=(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==="cron"?"cron":t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:eS(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Wu(),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,cronExpression:t.schedule.kind==="cron"&&typeof t.schedule.cron=="string"?t.schedule.cron:""},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:Wu(),onceTime:"09:00",weekdays:[1],timezone:n,cronExpression:""},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},tS=(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.kind==="cron"){if(!t.schedule.cronExpression.trim())return e("sessions.scheduledTasks.editor.validation.cronRequired");if(!sh(t.schedule.cronExpression).valid)return e("sessions.scheduledTasks.editor.validation.cronInvalid")}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")},sS=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))},nS=t=>{const e=gt.c(64),{draft:n,setDraft:r,locale:o,t:a}=t,c=n.schedule.cronExpression;let l;e[0]!==c?(l=c.trim()?sh(c):null,e[0]=c,e[1]=l):l=e[1];const d=l;let u;e:{if(!d?.valid||!c.trim()){let M;e[2]===Symbol.for("react.memo_cache_sentinel")?(M=[],e[2]=M):M=e[2],u=M;break e}let V;e[3]!==c||e[4]!==n.schedule.timezone?(V=Uj(c,n.schedule.timezone),e[3]=c,e[4]=n.schedule.timezone,e[5]=V):V=e[5],u=V}const m=u;let f;e[6]!==n.schedule.timezone||e[7]!==o?(f=V=>new Intl.DateTimeFormat(o,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(V),e[6]=n.schedule.timezone,e[7]=o,e[8]=f):f=e[8];const g=f;let y;e[9]!==a?(y=a("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=a,e[10]=y):y=e[10];let p;e[11]!==y?(p=s.jsx(qn,{htmlFor:"sched-cron",required:!0,children:y}),e[11]=y,e[12]=p):p=e[12];let x;e[13]!==r?(x=V=>r(M=>({...M,schedule:{...M.schedule,cronExpression:V.target.value}})),e[13]=r,e[14]=x):x=e[14];let b;e[15]!==a?(b=a("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=a,e[16]=b):b=e[16];let h;e[17]!==c||e[18]!==x||e[19]!==b?(h=s.jsx(bn,{id:"sched-cron",value:c,onChange:x,placeholder:b,className:"w-full max-w-xs font-mono"}),e[17]=c,e[18]=x,e[19]=b,e[20]=h):h=e[20];let N;e[21]!==c||e[22]!==d||e[23]!==a?(N=d&&!d.valid&&c.trim()?s.jsx("span",{className:"typography-micro text-destructive",children:a("sessions.scheduledTasks.editor.validation.cronInvalid")}):null,e[21]=c,e[22]=d,e[23]=a,e[24]=N):N=e[24];let w;e[25]!==p||e[26]!==h||e[27]!==N?(w=s.jsxs("div",{className:"flex flex-col gap-1",children:[p,h,N]}),e[25]=p,e[26]=h,e[27]=N,e[28]=w):w=e[28];let S;e[29]!==g||e[30]!==m||e[31]!==a?(S=m.length>0?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("sessions.scheduledTasks.editor.cronExpression.nextRuns")}),s.jsx("span",{className:"typography-micro text-foreground",children:m.map(g).join(", ")})]}):null,e[29]=g,e[30]=m,e[31]=a,e[32]=S):S=e[32];let j;e[33]!==a?(j=a("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=a,e[34]=j):j=e[34];let k;e[35]!==j?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:j}),e[35]=j,e[36]=k):k=e[36];let v;e[37]!==r||e[38]!==a?(v=Wj.map(V=>s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 typography-micro text-foreground hover:bg-interactive-hover",onClick:()=>r(M=>({...M,schedule:{...M.schedule,cronExpression:V.expression}})),children:[s.jsx("span",{className:"font-mono",children:V.expression}),s.jsx("span",{className:"text-muted-foreground",children:a(V.labelKey)})]},V.expression)),e[37]=r,e[38]=a,e[39]=v):v=e[39];let D;e[40]!==v?(D=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:v}),e[40]=v,e[41]=D):D=e[41];let A;e[42]!==k||e[43]!==D?(A=s.jsxs("div",{className:"flex flex-col gap-1",children:[k,D]}),e[42]=k,e[43]=D,e[44]=A):A=e[44];let C;e[45]!==a?(C=a("sessions.scheduledTasks.editor.timezone.label"),e[45]=a,e[46]=C):C=e[46];let O;e[47]!==C?(O=s.jsx(qn,{children:C}),e[47]=C,e[48]=O):O=e[48];let T;e[49]!==r?(T=V=>{r(M=>({...M,schedule:{...M.schedule,timezone:V}}))},e[49]=r,e[50]=T):T=e[50];let E;e[51]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx($n,{className:"w-fit max-w-full",children:s.jsx(Nn,{})}),e[51]=E):E=e[51];let F;e[52]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(zn,{children:tc.map(lS)}),e[52]=F):F=e[52];let R;e[53]!==n.schedule.timezone||e[54]!==T?(R=s.jsxs(_n,{value:n.schedule.timezone,onValueChange:T,children:[E,F]}),e[53]=n.schedule.timezone,e[54]=T,e[55]=R):R=e[55];let L;e[56]!==O||e[57]!==R?(L=s.jsxs("div",{className:"flex flex-col gap-1",children:[O,R]}),e[56]=O,e[57]=R,e[58]=L):L=e[58];let B;return e[59]!==w||e[60]!==S||e[61]!==A||e[62]!==L?(B=s.jsxs("div",{className:"flex flex-col gap-3",children:[w,S,A,L]}),e[59]=w,e[60]=S,e[61]=A,e[62]=L,e[63]=B):B=e[63],B};function rS(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:a,locale:c}=At(),l=es(ne=>ne.loadProviders),d=es(ne=>ne.loadAgents),u=es(ne=>ne.providers),m=es(ne=>ne.currentProviderId),f=es(ne=>ne.currentModelId),g=es(ne=>ne.currentVariant||""),y=es(ne=>ne.currentAgentName||""),p=Re(ne=>ne.timeFormatPreference),x=Re(ne=>ne.weekStartPreference),b=Re(ne=>ne.isMobile),[h,N]=Ze.useState(()=>Xu(n,{providerID:m,modelID:f,variant:g,agent:y})),[w,S]=Ze.useState(!1),[j,k]=Ze.useState(!1),[v,D]=Ze.useState(!1),[A,C]=Ze.useState(""),[O,T]=Ze.useState(!1),[E,F]=Ze.useState(""),[R,L]=Ze.useState(!1),[B,V]=Ze.useState(""),[M,ee]=Ze.useState(()=>{const ne=ma(n?.schedule?.date||"")||new Date;return new Date(ne.getFullYear(),ne.getMonth(),1)}),se=Ze.useRef(null),J=Ze.useRef(null),K=Ze.useRef(null),Z=Ze.useRef(null),re=Ze.useRef(null),pe=Ze.useMemo(()=>Qj(c),[c]),Se=Ze.useMemo(()=>Yj(c),[c]),te=Ze.useMemo(()=>p==="24h"?!0:p==="12h"?!1:pe,[p,pe]),Ne=Ze.useMemo(()=>x==="sunday"?0:x==="monday"?1:Se,[x,Se]),Y=Ze.useMemo(()=>{const ne=Jj(c);return Xj(nh.map(P=>({value:P,label:ne[P]||""})),Ne)},[c,Ne]);Ze.useEffect(()=>{e&&(l({source:"scheduledTaskEditor"}),d({source:"scheduledTaskEditor"}))},[e,l,d]),Ze.useEffect(()=>{if(!e)return;N(Xu(n,{providerID:m,modelID:f,variant:g,agent:y}));const ne=ma(n?.schedule?.date||"")||new Date;ee(new Date(ne.getFullYear(),ne.getMonth(),1)),k(!1),T(!1),D(!1),F(""),C("")},[e,n,m,f,g,y]),Ze.useEffect(()=>{if(!j)return;const ne=P=>{se.current&&!se.current.contains(P.target)&&k(!1)};return document.addEventListener("mousedown",ne),()=>{document.removeEventListener("mousedown",ne)}},[j]);const G=Ze.useMemo(()=>{const P=u.find(me=>me.id===h.execution.providerID)?.models?.find(me=>me.id===h.execution.modelID);return P?.variants?Object.keys(P.variants):[]},[u,h.execution.providerID,h.execution.modelID]),q=G.length>0,oe=Ze.useMemo(()=>!q||!h.execution.variant?"__default":G.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,q,G]);Ze.useEffect(()=>{q||!h.execution.variant||N(ne=>({...ne,execution:{...ne.execution,variant:""}}))},[q,h.execution.variant]);const le=Ze.useCallback((ne,P)=>{N(me=>{const ae=new Set(me.schedule.weekdays);return P?ae.add(ne):ae.delete(ne),{...me,schedule:{...me.schedule,weekdays:Array.from(ae).sort((Be,Ge)=>Be-Ge)}}})},[]),ve=Ze.useCallback((ne,P)=>{N(me=>{const ae=me.schedule.times.slice();return ae[ne]=P,{...me,schedule:{...me.schedule,times:ae}}})},[]),Ee=Ze.useCallback(ne=>{N(P=>{const me=P.schedule.times.filter((ae,Be)=>Be!==ne);return{...P,schedule:{...P.schedule,times:me.length>0?me:["09:00"]}}})},[]),_e=Ze.useCallback(()=>{N(ne=>({...ne,schedule:{...ne.schedule,times:[...ne.schedule.times,"12:00"]}}))},[]),Oe=Ze.useMemo(()=>Zj(),[]),Me=Ze.useMemo(()=>Qu(Oe),[Oe]),he=Ze.useMemo(()=>{const ne=ma(h.schedule.onceDate);return ne?Ju(ne,Oe)?a("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format(ne):null},[h.schedule.onceDate,c,a,Oe]),Ce=Ze.useMemo(()=>Qu(M).getTime()<=Me.getTime(),[M,Me]),xe=Ze.useMemo(()=>Y.map(ne=>ne.label),[Y]),ue=Ze.useCallback(ne=>{N(P=>({...P,schedule:{...P.schedule,onceDate:ne}}))},[]),H=Ze.useCallback((ne,P)=>{if(ne.startsWith("/")){const Ge=ne.indexOf(" "),Ke=ne.indexOf(`
|
|
167
|
+
`),Qe=Math.min(Ge===-1?ne.length:Ge,Ke===-1?ne.length:Ke);if(P<=Qe&&Ge===-1){F(ne.substring(1,Qe)),T(!0),D(!1),L(!1);return}}T(!1);const me=ne.substring(0,P),ae=me.lastIndexOf("#");if(ae!==-1){const Ge=ae>0?me[ae-1]:null,Ke=me.substring(ae+1);if((!Ge||/\s/.test(Ge))&&!Ke.includes(" ")&&!Ke.includes(`
|
|
168
|
+
`)){V(Ke),L(!0),D(!1);return}}L(!1);const Be=me.lastIndexOf("@");if(Be!==-1){const Ge=Be>0?me[Be-1]:null,Ke=me.substring(Be+1);(!Ge||/\s/.test(Ge))&&!Ke.includes(" ")&&!Ke.includes(`
|
|
169
|
+
`)?(C(Ke),D(!0)):D(!1);return}D(!1)},[]),ce=Ze.useCallback(ne=>{N(P=>({...P,execution:{...P.execution,prompt:ne}}))},[]),fe=Ze.useCallback(ne=>{const P=h.execution.prompt,ae=J.current?.selectionStart??P.length,Ge=P.substring(0,ae).lastIndexOf("@"),Ke=ne.relativePath&&ne.relativePath.trim().length>0?ne.relativePath.trim():ne.path||ne.name,Qe=Ge!==-1?Ge:ae,st=`${P.substring(0,Qe)}@${Ke} ${P.substring(ae)}`,ut=Qe+Ke.length+2;ce(st),D(!1),C(""),requestAnimationFrame(()=>{const vt=J.current;vt&&(vt.selectionStart=ut,vt.selectionEnd=ut,vt.focus()),H(st,ut)})},[h.execution.prompt,ce,H]),U=Ze.useCallback(ne=>{const P=h.execution.prompt,ae=J.current?.selectionStart??P.length,Ge=P.substring(0,ae).lastIndexOf("@"),Ke=Ge!==-1?Ge:ae,Qe=`${P.substring(0,Ke)}@${ne} ${P.substring(ae)}`,st=Ke+ne.length+2;ce(Qe),D(!1),C(""),requestAnimationFrame(()=>{const ut=J.current;ut&&(ut.selectionStart=st,ut.selectionEnd=st,ut.focus()),H(Qe,st)})},[h.execution.prompt,ce,H]),z=Ze.useCallback(ne=>{const P=`/${ne.name} `;ce(P),T(!1),F(""),L(!1),requestAnimationFrame(()=>{const me=J.current;me&&(me.focus(),me.selectionStart=me.value.length,me.selectionEnd=me.value.length),H(P,P.length)})},[ce,H]),be=Ze.useCallback((ne,P)=>{const me=h.execution.prompt,Be=J.current?.selectionStart??me.length,Ke=me.substring(0,Be).lastIndexOf("#"),Qe=Ke!==-1?Ke:Be,st=`${me.substring(0,Qe)}#${P} ${me.substring(Be)}`,ut=Qe+P.length+2;ce(st),L(!1),V(""),requestAnimationFrame(()=>{const vt=J.current;vt&&(vt.selectionStart=ut,vt.selectionEnd=ut,vt.focus()),H(st,ut)})},[h.execution.prompt,ce,H]),ge=Ze.useCallback(ne=>{if(O&&Z.current&&(ne.key==="Enter"||ne.key==="ArrowUp"||ne.key==="ArrowDown"||ne.key==="Escape"||ne.key==="Tab")){ne.preventDefault(),Z.current.handleKeyDown(ne.key);return}v&&K.current&&(ne.key==="Enter"||ne.key==="ArrowUp"||ne.key==="ArrowDown"||ne.key==="Escape"||ne.key==="Tab")&&(ne.preventDefault(),K.current.handleKeyDown(ne.key)),R&&re.current&&(ne.key==="Enter"||ne.key==="ArrowUp"||ne.key==="ArrowDown"||ne.key==="Escape"||ne.key==="Tab")&&(ne.preventDefault(),re.current.handleKeyDown(ne.key))},[O,v,R]),_=Ze.useCallback(async()=>{const ne=tS(h,a);if(ne){de.error(ne);return}const P={...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==="cron"?{cron:h.schedule.cronExpression.trim()}:h.schedule.kind==="once"?{date:h.schedule.onceDate,time:h.schedule.onceTime}:{times:sS(h.schedule.times),...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(P),r(!1)}catch(me){de.error(me instanceof Error?me.message:a("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[h,r,o,a]),ye=Ze.useId(),$=Ze.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),Ie=a(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),je=a("sessions.scheduledTasks.editor.description"),Fe=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(qn,{htmlFor:"sched-name",required:!0,children:a("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(bn,{id:"sched-name",value:h.name,onChange:ne=>N(P=>({...P,name:ne.target.value})),placeholder:a("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(qn,{children:a("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(_n,{value:h.schedule.kind,onValueChange:ne=>{N(P=>({...P,schedule:{...P.schedule,kind:ne,...ne==="cron"&&!P.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx($n,{className:"w-fit max-w-full",children:s.jsx(Nn,{children:ne=>a(ne==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":ne==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":ne==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(zn,{children:[s.jsx(Is,{value:"daily",children:a("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Is,{value:"weekly",children:a("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Is,{value:"once",children:a("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(Is,{value:"cron",children:a("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),h.schedule.kind==="cron"?s.jsx(nS,{draft:h,setDraft:N,locale:c,t:a}):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:se,children:[s.jsx(qn,{children:a("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:()=>k(ne=>!ne),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:Hj(h.schedule.onceDate,a("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),j?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:()=>ee(ne=>Gu(ne,-1)),"aria-label":a("sessions.scheduledTasks.editor.date.previousMonth"),disabled:Ce,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(M)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>ee(ne=>Gu(ne,1)),"aria-label":a("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:xe.map((ne,P)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:ne},`${ne}-${P}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:Gj(M,Ne).map(({date:ne,inCurrentMonth:P})=>{const me=Hu(ne),ae=me===h.schedule.onceDate,Be=Ju(ne,Oe),Ge=ne.getTime()<Oe.getTime(),Ke=ae?"bg-interactive-selection text-interactive-selection-foreground":Ge?"text-muted-foreground/40":P?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{Ge||(ue(me),k(!1))},disabled:Ge,className:["h-8 rounded-md typography-ui-label",Ke,Be&&!ae?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",Ge?"cursor-not-allowed opacity-45":""].join(" "),children:ne.getDate()},me)})}),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:he||""}),s.jsx($e,{type:"button",size:"xs",variant:"ghost",onClick:()=>{ue(Hu(Oe)),ee(new Date(Oe.getFullYear(),Oe.getMonth(),1))},children:a("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(qn,{children:a("sessions.scheduledTasks.editor.time.label")}),s.jsx(Yu,{value:h.schedule.onceTime,use24Hour:te,hourAriaLabel:a("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:a("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:a("sessions.scheduledTasks.editor.time.periodAria"),amLabel:a("sessions.scheduledTasks.editor.time.period.am"),pmLabel:a("sessions.scheduledTasks.editor.time.period.pm"),onChange:ne=>N(P=>({...P,schedule:{...P.schedule,onceTime:ne}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(qn,{children:a("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(_n,{value:h.schedule.timezone,onValueChange:ne=>{N(P=>({...P,schedule:{...P.schedule,timezone:ne}}))},children:[s.jsx($n,{className:"w-fit max-w-full",children:s.jsx(Nn,{})}),s.jsx(zn,{children:tc.map(ne=>s.jsx(Is,{value:ne,children:ne},ne))})]})]})]})]}):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(qn,{children:a("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:Y.map(ne=>{const P=h.schedule.weekdays.includes(ne.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",P?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(Ri,{checked:P,onChange:me=>le(ne.value,me),ariaLabel:ne.label}),s.jsx("button",{type:"button",onClick:()=>le(ne.value,!P),className:"group-hover:text-foreground",children:ne.label})]},ne.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(qn,{children:a("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((ne,P)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yu,{value:ne,use24Hour:te,hourAriaLabel:a("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:a("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:a("sessions.scheduledTasks.editor.time.periodAria"),amLabel:a("sessions.scheduledTasks.editor.time.period.am"),pmLabel:a("sessions.scheduledTasks.editor.time.period.pm"),onChange:me=>ve(P,me)}),h.schedule.times.length>1?s.jsx($e,{type:"button",size:"icon",variant:"ghost",onClick:()=>Ee(P),"aria-label":a("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]},P))}),s.jsx("div",{children:s.jsxs($e,{type:"button",size:"sm",variant:"outline",onClick:_e,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",a("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(qn,{children:a("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(_n,{value:h.schedule.timezone,onValueChange:ne=>{N(P=>({...P,schedule:{...P.schedule,timezone:ne}}))},children:[s.jsx($n,{className:"w-fit max-w-full",children:s.jsx(Nn,{})}),s.jsx(zn,{children:tc.map(ne=>s.jsx(Is,{value:ne,children:ne},ne))})]})]})]}),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(qn,{required:!0,children:a("sessions.scheduledTasks.editor.model.label")}),s.jsx(_f,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(ne,P)=>{N(me=>({...me,execution:{...me.execution,providerID:ne,modelID:P,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(qn,{children:a("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(_n,{value:oe,disabled:!q,onValueChange:ne=>{N(P=>({...P,execution:{...P.execution,variant:ne==="__default"?"":ne}}))},children:[s.jsx($n,{className:"w-fit max-w-full",children:s.jsx(Nn,{children:ne=>ne==="__default"?a("sessions.scheduledTasks.editor.thinkingLevel.default"):ne})}),s.jsxs(zn,{children:[s.jsx(Is,{value:"__default",children:a("sessions.scheduledTasks.editor.thinkingLevel.default")}),G.map(ne=>s.jsx(Is,{value:ne,children:ne},ne))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(qn,{children:a("sessions.scheduledTasks.editor.agent.label")}),s.jsx($f,{agentName:h.execution.agent,filter:ne=>zf(ne.mode),onChange:ne=>N(P=>({...P,execution:{...P.execution,agent:ne}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(qn,{htmlFor:"sched-prompt",required:!0,children:a("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(Ci,{id:"sched-prompt",ref:J,value:h.execution.prompt,onChange:ne=>{const P=ne.target.value;ce(P);const me=ne.target.selectionStart??P.length;H(P,me)},onKeyDown:ge,rows:8,placeholder:a("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),O?s.jsx(Xf,{ref:Z,searchQuery:E,onCommandSelect:z,onClose:()=>T(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,v?s.jsx(Zf,{ref:K,searchQuery:A,onFileSelect:fe,onAgentSelect:U,onClose:()=>D(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,R?s.jsx(em,{ref:re,searchQuery:B,onSnippetSelect:be,onClose:()=>L(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Ae=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(Ri,{checked:h.enabled,onChange:ne=>N(P=>({...P,enabled:ne})),ariaLabel:a("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:a("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx($e,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:w,children:a("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx($e,{type:"button",size:"sm",onClick:_,disabled:w,children:a(w?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return b?s.jsx($a,{open:e,title:Ie,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:ne=>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:Ie}),ne]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:je})]}),footer:Ae,children:Fe}):s.jsx(Ls,{open:e,onOpenChange:ne=>{!ne&&$()||r(ne)},children:s.jsxs(Fs,{"aria-describedby":ye,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(an,{id:ye,className:"sr-only",children:je}),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($s,{className:"typography-ui-label font-medium text-foreground",children:Ie}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:je})]})}),s.jsx(za,{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:Fe})}),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:Ae})})]})})}function iS(t){return co(t,{min:0,max:23})}function oS(t,e){return co(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function aS(t,e){const n=Number(t),r=Number(e),o=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,a=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(o).padStart(2,"0")}:${String(a).padStart(2,"0")}`}function lS(t){return s.jsx(Is,{value:t,children:t},t)}const cS=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))},dS=(t,e)=>{const n=cS(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(a=>r(a)).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"),a=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:a,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:o,time:a})}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||""})},uS=(t,e)=>!t||!Number.isFinite(t)?"":Tf(t,e),Zu=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),o=6e4,a=60*o,c=24*a,l=n>=0;if(r<o)return e(l?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<a){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/a),g=Math.round(r%a/o),y=g>0?`${f}h ${g}m`:`${f}h`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:y}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:y})}const d=Math.floor(r/c),u=Math.round(r%c/a),m=u>0?`${d}d ${u}h`:`${d}d`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},fS={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"}},mS=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function hS(){const{t}=At(),e=Re(R=>R.isScheduledTasksDialogOpen),n=Re(R=>R.setScheduledTasksDialogOpen),r=Re(R=>R.isMobile),o=Re(R=>R.timeFormatPreference),a=ys(R=>R.projects),c=ys(R=>R.getActiveProject()),l=qs(R=>R.homeDirectory),{currentTheme:d}=Hr(),[u,m]=Ze.useState(""),[f,g]=Ze.useState([]),[y,p]=Ze.useState(!0),[x,b]=Ze.useState(!1),[h,N]=Ze.useState(null),[w,S]=Ze.useState(null),j=Ze.useMemo(()=>a.find(R=>R.id===u)||null,[a,u]),k=Ze.useCallback(R=>{const L=R.label?.trim()||Ei(R.path,l||void 0),B=R.icon?Sc[R.icon]:null,V=R.color?Ga[R.color]:void 0,M=B?s.jsx(I,{name:B,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(Ka,{project:{id:R.id,iconImage:R.iconImage??null},options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:M})}):M,s.jsx("span",{className:"truncate",children:L})]})},[l,d.metadata.variant,d.colors.surface.foreground]),v=Ze.useCallback(async(R,L)=>{if(!R){g([]);return}L?.silent||p(!0);try{const B=await _j(R);B.sort((V,M)=>{if(V.enabled!==M.enabled)return V.enabled?-1:1;const ee=V.name.localeCompare(M.name);return ee!==0?ee:(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(M.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),g(B)}catch(B){de.error(B instanceof Error?B.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),L?.silent||g([])}finally{L?.silent||p(!1)}},[t]);Ze.useEffect(()=>{if(!e)return;const R=c?.id||a[0]?.id||"";m(R),R?v(R):(g([]),p(!1))},[e,c,a,v]),Ze.useEffect(()=>{if(!e)return;let R=null;const L=th(B=>{B.type==="scheduled-task-ran"&&B.projectId===u&&(R&&clearTimeout(R),R=setTimeout(()=>{v(u,{silent:!0})},400))});return()=>{R&&clearTimeout(R),L()}},[e,u,v]);const D=Ze.useCallback(async R=>{if(!u)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Uu(u,R),await v(u),de.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[u,v,t]),A=Ze.useCallback(async(R,L)=>{if(u){S(R.id),g(B=>B.map(V=>V.id===R.id?{...V,enabled:L}:V));try{await Uu(u,{...R,enabled:L}),await v(u,{silent:!0})}catch(B){de.error(B instanceof Error?B.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await v(u,{silent:!0})}finally{S(null)}}},[u,v,t]),C=Ze.useCallback(async R=>{if(!(!u||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:R.name})))){S(R.id);try{await $j(u,R.id),await v(u,{silent:!0}),de.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(B){de.error(B instanceof Error?B.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{S(null)}}},[u,v,t]),O=Ze.useCallback(async R=>{if(u){S(R.id);try{await zj(u,R.id),await Promise.all([v(u,{silent:!0}),Sa()]),de.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(L){de.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{S(null)}}},[u,v,t]),T=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(_n,{value:u||"__none",onValueChange:R=>{const L=R==="__none"?"":R;m(L),L?v(L):g([])},children:[s.jsx($n,{className:r?"w-full":void 0,children:j?s.jsx(Nn,{children:k(j)}):s.jsx(Nn,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(zn,{children:[a.length===0?s.jsx(Is,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(R=>s.jsx(Is,{value:R.id,children:k(R)},R.id))]})]})]}),E=()=>{N(null),b(!0)},F=s.jsxs("div",{className:"space-y-4",children:[r?T:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[T,s.jsxs($e,{onClick:E,disabled:!u,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:y?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(u?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:f.map(R=>{const L=w===R.id,B=R.state?.lastStatus||"idle",V=fS[B],M=t(B==="success"?"sessions.scheduledTasks.dialog.status.success":B==="error"?"sessions.scheduledTasks.dialog.status.error":B==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),ee=R.state?.nextRunAt,se=R.state?.lastRunAt;return s.jsxs("div",{className:De("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:dS(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")}),ee?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Zu(ee,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:uS(ee,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")}),B==="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")]}):se?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"}),M]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Zu(se,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:mS("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:De("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",R.enabled?"text-foreground":"text-muted-foreground",L&&"cursor-not-allowed opacity-50"),children:[s.jsx(Ri,{checked:R.enabled,onChange:J=>{A(R,J)},ariaLabel:R.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:R.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:R.name}),disabled:L}),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($e,{variant:"outline",size:"sm",onClick:()=>{O(R)},disabled:L,children:[s.jsx(I,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{N(R),b(!0)},disabled:L,"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($e,{variant:"destructive",size:"sm",onClick:()=>{C(R)},disabled:L,"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($a,{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($e,{className:"w-full",onClick:E,disabled:!u,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:F}):s.jsx(Ls,{open:e,onOpenChange:n,children:s.jsxs(Fs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(Us,{children:[s.jsx($s,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(an,{children:t("sessions.scheduledTasks.dialog.description")})]}),F]})}),s.jsx(rS,{open:x,task:h,onOpenChange:b,onSave:D})]})}const pS=(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)]),a=(l=>l.filter(d=>Ro(d,t.normalizedPath,r)))(e.archivedSessions),c=e.sessions.filter(l=>l.time?.archived||as(l.directory??null)?!1:Ro(l,t.normalizedPath,r));return no([...a,...c])},gS=t=>{const e=gt.c(12),{normalizedProjects:n,sessions:r,archivedSessions:o,availableWorktreesByProject:a,isVSCode:c,isSessionsLoading:l,foldersMap:d,createFolder:u,addSessionToFolder:m,cleanupSessions:f}=t;let g,y;e[0]!==m||e[1]!==o||e[2]!==a||e[3]!==f||e[4]!==u||e[5]!==d||e[6]!==l||e[7]!==c||e[8]!==n||e[9]!==r?(g=()=>{l||n.forEach(p=>{const x=Ic(p.normalizedPath),b=pS(p,{sessions:r,archivedSessions:o,availableWorktreesByProject:a,isVSCode:c}),h=new Set(b.map(xS)),N=d[x]??[],w=new Map(N.map(bS));b.forEach(S=>{const j=Jx(S,p.normalizedPath),k=j.toLowerCase();let v=w.get(k);v||(v=u(x,j),w.set(k,v)),v.sessionIds.includes(S.id)||m(x,v.id,S.id)}),f(x,h)})},y=[n,r,o,a,c,l,d,u,m,f],e[0]=m,e[1]=o,e[2]=a,e[3]=f,e[4]=u,e[5]=d,e[6]=l,e[7]=c,e[8]=n,e[9]=r,e[10]=g,e[11]=y):(g=e[10],y=e[11]),i.useEffect(g,y)};function xS(t){return t.id}function bS(t){return[t.name.toLowerCase(),t]}const yS=t=>{const e=gt.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:o,availableWorktreesByProject:a,projectRepoStatus:c,projectRootBranches:l,lastRepoStatus:d,buildGroupedSessions:u,hasSessionSearchQuery:m,normalizedSessionSearchQuery:f,filterSessionNodesForSearch:g,buildGroupSearchText:y,foldersMap:p}=t;let x;if(e[0]!==a||e[1]!==u||e[2]!==o||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==c||e[7]!==l){let C;e[9]!==a||e[10]!==u||e[11]!==o||e[12]!==r||e[13]!==d||e[14]!==c||e[15]!==l?(C=O=>{const T=no([...r(O),...o(O)]),E=a.get(O.normalizedPath)??[],F=c.has(O.id)?!!c.get(O.id):d,R=u(T,O.normalizedPath,E,l.get(O.id)??null,F);return{project:O,groups:R}},e[9]=a,e[10]=u,e[11]=o,e[12]=r,e[13]=d,e[14]=c,e[15]=l,e[16]=C):C=e[16],x=n.map(C),e[0]=a,e[1]=u,e[2]=o,e[3]=r,e[4]=d,e[5]=n,e[6]=c,e[7]=l,e[8]=x}else x=e[8];const b=x,h=b;let N;if(e[17]!==y||e[18]!==g||e[19]!==p||e[20]!==m||e[21]!==f||e[22]!==h){e:{const C=new WeakMap;if(!m){N=C;break e}const O=T=>T.reduce((E,F)=>E+1+O(F.children),0);h.forEach(T=>{T.groups.forEach(E=>{const F=g(E.sessions,f),R=O(F),L=y(E).includes(f),B=as(E.directory??null),M=(B?p[B]??[]:[]).filter(ee=>ee.name.toLowerCase().includes(f)).length;C.set(E,{filteredNodes:F,matchedSessionCount:R,folderNameMatchCount:M,groupMatches:L,hasMatch:L||R>0||M>0})})}),N=C}e[17]=y,e[18]=g,e[19]=p,e[20]=m,e[21]=f,e[22]=h,e[23]=N}else N=e[23];const w=N;let S;e:{if(!m){S=h;break e}let C;if(e[24]!==w||e[25]!==h){let O;e[27]!==w?(O=T=>({...T,groups:T.groups.filter(E=>w.get(E)?.hasMatch===!0)}),e[27]=w,e[28]=O):O=e[28],C=h.map(O).filter(wS),e[24]=w,e[25]=h,e[26]=C}else C=e[26];S=C}const j=S,k=m?j:h;let v;e:{if(!m){v=0;break e}let C;if(e[29]!==w||e[30]!==k){let O;e[32]!==w?(O=(T,E)=>T+E.groups.reduce((F,R)=>{const L=w.get(R);if(!L)return F;const B=L.folderNameMatchCount+(L.groupMatches?1:0);return F+L.matchedSessionCount+B},0),e[32]=w,e[33]=O):O=e[33],C=k.reduce(O,0),e[29]=w,e[30]=k,e[31]=C}else C=e[31];v=C}const D=v;let A;return e[34]!==w||e[35]!==b||e[36]!==D||e[37]!==j||e[38]!==k||e[39]!==h?(A={projectSections:b,visibleProjectSections:h,groupSearchDataByGroup:w,searchableProjectSections:j,sectionsForRender:k,searchMatchCount:D},e[34]=w,e[35]=b,e[36]=D,e[37]=j,e[38]=k,e[39]=h,e[40]=A):A=e[40],A};function wS(t){return t.groups.length>0}const vS=t=>{const e=gt.c(26),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:a,currentSessionId:c,handleSessionSelect:l,newSessionDraftOpen:d,mobileVariant:u,openNewSessionDraft:m,setActiveMainTab:f,setSessionSwitcherOpen:g}=t;let y,p;if(e[0]!==n){p=new Map,y=new Map;const k=(v,D,A,C)=>{p.has(v)||p.set(v,new Map);const O=p.get(v);C.forEach(T=>{const E=as(T.worktree?.path??T.session.directory??A??D);O.set(T.session.id,{directory:E}),y.has(v)||y.set(v,{id:T.session.id,directory:E}),T.children.length>0&&k(v,D,E,T.children)})};n.forEach(v=>{v.groups.forEach(D=>{k(v.project.id,v.project.normalizedPath,D.directory,D.sessions)})}),e[0]=n,e[1]=y,e[2]=p}else y=e[1],p=e[2];let x;e[3]!==y||e[4]!==p?(x={metaByProject:p,firstSessionByProject:y},e[3]=y,e[4]=p,e[5]=x):x=e[5];const b=x,h=i.useRef(null);let N,w;e[6]!==r||e[7]!==o||e[8]!==c||e[9]!==l||e[10]!==u||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==b||e[15]!==f||e[16]!==a||e[17]!==g?(N=()=>{if(!r||d||Re.getState().isNewWorktreeDialogOpen||h.current===r)return;const k=n.find(E=>E.project.id===r);if(!k)return;h.current=r;const v=b.metaByProject.get(r);if(c&&v&&v.has(c)){a(E=>{if(E.get(r)===c)return E;const F=new Map(E);return F.set(r,c),F});return}if(!v||v.size===0){f("chat"),u&&g(!1),m({directoryOverride:k.project.normalizedPath});return}const D=o.get(r),A=D&&v.has(D)?D:null,C=b.firstSessionByProject.get(r)?.id??null,O=A??C;if(!O||O===c)return;const T=v.get(O)?.directory??null;l(O,T,r)},w=[r,o,c,l,d,u,m,n,b,f,g,a],e[6]=r,e[7]=o,e[8]=c,e[9]=l,e[10]=u,e[11]=d,e[12]=m,e[13]=n,e[14]=b,e[15]=f,e[16]=a,e[17]=g,e[18]=N,e[19]=w):(N=e[18],w=e[19]),i.useLayoutEffect(N,w);let S,j;e[20]!==r||e[21]!==c||e[22]!==b||e[23]!==a?(S=()=>{if(!r||!c)return;const k=b.metaByProject.get(r);!k||!k.has(c)||a(v=>{if(v.get(r)===c)return v;const D=new Map(v);return D.set(r,c),D})},j=[r,c,b,a],e[20]=r,e[21]=c,e[22]=b,e[23]=a,e[24]=S,e[25]=j):(S=e[24],j=e[25]),i.useEffect(S,j)},jS=t=>{const e=gt.c(4);let n;e[0]!==t?(n=(a,c)=>{const l=t.get(a);if(!l||l.length===0)return c;const d=new Map(c.map(SS)),u=[];return l.forEach(m=>{const f=d.get(m);f&&(u.push(f),d.delete(m))}),c.forEach(m=>{d.has(m.id)&&u.push(m)}),u},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 SS(t){return[t.id,t]}const ea=t=>!!t.time?.archived,NS=t=>{const{t:e}=At(),n=i.useCallback(c=>[c.label,c.branch??"",c.description??"",c.directory??""].join(" ").toLowerCase(),[]),r=i.useCallback(c=>{const l=as(c.directory??null)??"";return`${(c.title||e("sessions.sidebar.session.untitled")).trim()} ${l}`.toLowerCase()},[e]),o=i.useCallback((c,l)=>l?c.flatMap(d=>{if(r(d.session).includes(l))return[d];const m=o(d.children,l);return m.length===0?[]:[{...d,children:m}]}):c,[r]),a=i.useCallback((c,l,d,u,m)=>{const f=as(l??null),g=no(c).sort((T,E)=>Ki(T,E,t.pinnedSessionIds)),y=new Map(g.map(T=>[T.id,T])),p=new Map;g.forEach(T=>{const E=T.parentID;if(!E)return;const F=y.get(E);if(!F||ea(F)!==ea(T))return;const R=p.get(E)??[];R.push(T),p.set(E,R)}),p.forEach(T=>T.sort((E,F)=>Ki(E,F,t.pinnedSessionIds)));const x=new Map;d.forEach(T=>{if(T.path){const E=as(T.path)??T.path;x.set(E,T)}});const b=T=>{const E=as(T.directory??null),F=t.worktreeMetadata.get(T.id)??null;if(F)return F;if(E){const R=x.get(E)??null;if(R&&E!==f)return R}return null},h=T=>{const E=p.get(T.id)??[];return{session:T,children:E.map(F=>h(F)),worktree:b(T)}},N=g.filter(T=>{const E=T.parentID;if(!E)return!0;const F=y.get(E);return F?ea(F)!==ea(T):!0}),w=new Map,S="__archived__",j=T=>{if(T.time?.archived)return S;if(t.isVSCode)return f??"__project_root__";const F=as(t.worktreeMetadata.get(T.id)?.path??null)??Pr(T);return F?F!==f&&x.has(F)?F:F===f?f??"__project_root__":S:S};N.forEach(T=>{const E=h(T),F=j(T);w.has(F)||w.set(F,[]),w.get(F)?.push(E)});const k=f??"__project_root__",v=[{id:"root",label:m&&u&&u!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:u}):e("sessions.sidebar.grouping.projectRoot"),branch:u??null,description:f?Na(f,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:w.get(k)??[]}],D=new Map;d.forEach(T=>{const E=as(T.path)??T.path,F=w.get(E)??[],R=F.length>0,L=F.reduce((B,V)=>{const M=Number(V.session.time?.updated??V.session.time?.created??0);return Number.isFinite(M)?Math.max(B,M):B},0);D.set(E,{hasActiveSession:R,lastUpdatedAt:L})});const A=[...d].sort((T,E)=>{const F=as(T.path)??T.path,R=as(E.path)??E.path,L=D.get(F)??{hasActiveSession:!1,lastUpdatedAt:0},B=D.get(R)??{hasActiveSession:!1,lastUpdatedAt:0};if(L.hasActiveSession!==B.hasActiveSession)return L.hasActiveSession?-1:1;if(L.hasActiveSession&&B.hasActiveSession)return B.lastUpdatedAt-L.lastUpdatedAt;const V=(T.label||T.branch||T.name||T.path||"").toLowerCase(),M=(E.label||E.branch||E.name||E.path||"").toLowerCase();return V.localeCompare(M)});(t.isVSCode?[]:A).forEach(T=>{const E=as(T.path)??T.path,F=t.gitBranches.get(E)?.trim()||null,R=T.branch?.trim()||null,B=!!(F&&R&&T.label&&_d(T.label)===_d(R))?F:T.label||T.name||Ei(E,t.homeDirectory)||E;v.push({id:`worktree:${E}`,label:B,branch:F||R,description:Na(E,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:T,directory:E,folderScopeKey:E,sessions:w.get(E)??[]})});const O=w.get(S)??[];return O.length>0&&v.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?Ic(f):null,sessions:O}),v},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:a}},kS=t=>{const e=gt.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:o,sessionSearchContainerRef:a}=t;let c,l;e[0]!==n||e[1]!==o?(c=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(m)},l=[n,o],e[0]=n,e[1]=o,e[2]=c,e[3]=l):(c=e[2],l=e[3]),i.useEffect(c,l);let d,u;e[4]!==n||e[5]!==a||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=f=>{a.current&&(a.current.contains(f.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},u=[n,r,a],e[4]=n,e[5]=a,e[6]=r,e[7]=d,e[8]=u):(d=e[7],u=e[8]),i.useEffect(d,u)},CS=t=>{const e=gt.c(42),{t:n}=At(),[r,o]=i.useState(null),a=i.useRef(null);let c,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{a.current&&clearTimeout(a.current)},l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),i.useEffect(c,l);let d;e[2]!==t?(d=(L,B,V)=>{const M=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(V&&V!==t.activeProjectId&&t.setActiveProjectIdOnly(V),B&&B!==t.currentDirectory&&t.setDirectory(B,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),L===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(L),M();return}t.setCurrentSession(L,B??null),t.onSessionSelected?.(L),M()},e[2]=t,e[3]=d):d=e[3];const u=d;let m;e[4]!==t?(m=(L,B)=>{t.setEditingId(L),t.setEditTitle(B)},e[4]=t,e[5]=m):m=e[5];const f=m;let g;e[6]!==t?(g=async L=>{if(!t.editingId)return;const B=(L??t.editTitle).trim();B&&await t.updateSessionTitle(t.editingId,B),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=g):g=e[7];const y=g;let p;e[8]!==t?(p=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=p):p=e[9];const x=p;let b;e[10]!==t||e[11]!==n?(b=async L=>{const B=await t.shareSession(L.id);B&&B.share?.url?de.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):de.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=(L,B)=>{dr(L).then(V=>{if(!V.ok){de.error(n("sessions.sidebar.session.share.copyUrlError"));return}o(B),a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{o(null),a.current=null},2e3)}).catch(()=>{de.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 L=>{await t.unshareSession(L)?de.success(n("sessions.sidebar.session.unshare.success")):de.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=S):S=e[17];const j=S;let k;e[18]!==t.childrenMap?(k=L=>{const B=[],V=M=>{(t.childrenMap.get(M)??[]).forEach(se=>{B.push(se),V(se.id)})};return V(L),B},e[18]=t.childrenMap,e[19]=k):k=e[19];const v=k,D=DS;let A;e[20]!==t||e[21]!==v||e[22]!==n?(A=async(L,B,V)=>{const M=B?.archivedBucket===!0||B?.hardDelete===!0,ee=V?.descendantIds??D(v(L.id),M).map(IS);if(ee.length===0){(M?await t.deleteSession(L.id):await t.archiveSession(L.id))?de.success(n(M?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):de.error(n(M?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const se=[L.id,...ee];if(M){if(await t.deleteSession(L.id)){const re=ee.length+1;de.success(re===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:re}):n("sessions.sidebar.bulkActions.deletedPlural",{count:re}))}else de.error(n("sessions.sidebar.session.delete.error"));return}const{archivedIds:J,failedIds:K}=await t.archiveSessions(se);J.length>0&&de.success(J.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:J.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:J.length})),K.length>0&&de.error(K.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:K.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:K.length}))},e[20]=t,e[21]=v,e[22]=n,e[23]=A):A=e[23];const C=A;let O;e[24]!==t||e[25]!==v||e[26]!==C?(O=(L,B)=>{const V=B?.archivedBucket===!0||B?.hardDelete===!0,M=D(v(L.id),V).map(PS);if(!t.showDeletionDialog){C(L,B,{descendantIds:M});return}t.setDeleteSessionConfirm({session:L,descendantCount:M.length,descendantIds:M,archivedBucket:V})},e[24]=t,e[25]=v,e[26]=C,e[27]=O):O=e[27];const T=O;let E;e[28]!==t||e[29]!==C?(E=async()=>{if(!t.deleteSessionConfirm)return;const{session:L,archivedBucket:B,descendantIds:V}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await C(L,{archivedBucket:B},{descendantIds:V})},e[28]=t,e[29]=C,e[30]=E):E=e[30];const F=E;let R;return e[31]!==F||e[32]!==r||e[33]!==x||e[34]!==w||e[35]!==T||e[36]!==y||e[37]!==f||e[38]!==u||e[39]!==h||e[40]!==j?(R={copiedSessionId:r,handleSessionSelect:u,handleSessionDoubleClick:f,handleSaveEdit:y,handleCancelEdit:x,handleShareSession:h,handleCopyShareUrl:w,handleUnshareSession:j,handleDeleteSession:T,confirmDeleteSession:F},e[31]=F,e[32]=r,e[33]=x,e[34]=w,e[35]=T,e[36]=y,e[37]=f,e[38]=u,e[39]=h,e[40]=j,e[41]=R):R=e[41],R};function AS(t){return!t.time?.archived}function DS(t,e){return e?t:t.filter(AS)}function IS(t){return t.id}function PS(t){return t.id}const TS=["project:active:","project:archived:","recent:active:","recent:archived:"],RS=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:o,sessions:a,setPinnedSessionIds:c,groupOrderByProject:l,activeSessionByProject:d,collapsedGroups:u,setExpandedParents:m,setCollapsedProjects:f}=t,g=i.useRef(null),y=i.useRef(null),p=i.useCallback(()=>{if(e)return;const b=y.current;if(y.current=null,g.current=null,!b)return;const{projects:h}=ys.getState(),N=h.map(w=>({...w,sidebarCollapsed:b.has(w.id)}));ac({projects:N}).catch(()=>{})},[e]),x=i.useCallback(b=>{typeof window>"u"||e||(y.current=b,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{p()},700))},[e,p]);return i.useEffect(()=>()=>{typeof window<"u"&&g.current!==null&&window.clearTimeout(g.current),g.current=null,y.current=null},[]),i.useEffect(()=>{try{const b=r.getItem(o.sessionExpanded);if(b){const N=JSON.parse(b);Array.isArray(N)&&m(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(j=>{typeof j!="string"||j.length===0||TS.forEach(k=>S.add(`${k}${j}`))}),S.size>0){m(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,m]),i.useEffect(()=>{if(!n)return;const b=new Set(a.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,a,c]),i.useEffect(()=>{try{const b=Object.fromEntries(l.entries());r.setItem(o.groupOrder,JSON.stringify(b))}catch{}},[l,o.groupOrder,r]),i.useEffect(()=>{try{const b=Object.fromEntries(d.entries());r.setItem(o.projectActiveSession,JSON.stringify(b))}catch{}},[d,o.projectActiveSession,r]),i.useEffect(()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(u)))}catch{}},[u,o.groupCollapse,r]),{scheduleCollapsedProjectsPersist:x}},ES=t=>{const{normalizedProjects:e,gitRepoStatus:n,setProjectRepoStatus:r,setProjectRootBranches:o}=t,{git:a}=Qn(),c=xn(f=>f.ensureStatus);i.useEffect(()=>{if(!a||e.length===0){r(new Map);return}e.forEach(f=>{c(f.normalizedPath,a)})},[e,a,c,r]),i.useEffect(()=>{const f=new Map;e.forEach(g=>{f.set(g.id,n.get(g.normalizedPath)?.isGitRepo??null)}),r(f)},[e,n,r]);const l=i.useMemo(()=>e.map(f=>{const g=n.get(f.normalizedPath)?.branch??"";return`${f.id}:${g}`}).join("|"),[e,n]),d=i.useRef(new Map),u=i.useRef(new Map),m=5*6e4;i.useEffect(()=>{let f=!1;const g=setTimeout(()=>{(async()=>{const p=new Set(e.map(S=>S.id));for(const S of d.current.keys())p.has(S)||(d.current.delete(S),u.current.delete(S));const x=Date.now(),b=e.filter(S=>{const j=n.get(S.normalizedPath);if(j?.isGitRepo===!1)return d.current.delete(S.id),u.current.delete(S.id),!1;if(j?.isGitRepo!==!0||j.branch===null)return!1;const k=j.branch.trim(),v=`${S.normalizedPath}\0${k}`,D=d.current.get(S.id);if(D===v){const A=u.current.get(S.id);return A&&(A.at=x),!1}return!(D!==void 0&&x-(u.current.get(S.id)?.at??0)<m)});if(b.length===0)return;const h=await Am(b,2,async S=>{const j=n.get(S.normalizedPath)?.branch?.trim()??"",k=`${S.normalizedPath}\0${j}`,v=await Wa(S.normalizedPath,j?{knownBranch:j}:void 0).catch(()=>null);return{id:S.id,inputKey:k,branch:v}});if(f)return;const N=h.filter(S=>S.branch);if(N.length===0)return;const w=Date.now();o(S=>{const j=new Map(S);return N.forEach(({id:k,branch:v})=>{v&&j.set(k,v)}),j}),N.forEach(({id:S,inputKey:j,branch:k})=>{d.current.set(S,j),k&&u.current.set(S,{branch:k,at:w})})})()},150);return()=>{f=!0,clearTimeout(g)}},[e,l,n,o])},MS=t=>{const e=gt.c(19),{isVSCode:n,sessions:r,archivedSessions:o,availableWorktreesByProject:a,normalizedProjects:c}=t;let l;if(e[0]!==a||e[1]!==n||e[2]!==c){if(l=new Set,c.forEach(b=>{b.normalizedPath&&l.add(b.normalizedPath)}),!n)for(const b of a.values())for(const h of b){const N=as(h.path);N&&l.add(N)}e[0]=a,e[1]=n,e[2]=c,e[3]=l}else l=e[3];const d=l;let u;e[4]!==d||e[5]!==r?(u=new Map,r.forEach(b=>{const h=Pr(b);if(!h||!d.has(h))return;const N=u.get(h)??[];N.push(b),u.set(h,N)}),e[4]=d,e[5]=r,e[6]=u):u=e[6];const m=u;let f;e[7]!==a||e[8]!==n||e[9]!==m?(f=b=>{const h=n?[]:a.get(b.normalizedPath)??[],N=[b.normalizedPath,...h.map(FS).filter(LS)],w=new Set,S=[];return N.forEach(j=>{(m.get(j)??[]).forEach(v=>{w.has(v.id)||(w.add(v.id),S.push(v))})}),S},e[7]=a,e[8]=n,e[9]=m,e[10]=f):f=e[10];const g=f;let y;e[11]!==o||e[12]!==a||e[13]!==n||e[14]!==r?(y=b=>{if(n){const k=o.filter(D=>{const A=as(D.directory??null),C=as(D.project?.worktree??null);return A?A===b.normalizedPath:C===b.normalizedPath}),v=r.filter(D=>D.time?.archived||as(D.directory??null)?!1:as(D.project?.worktree??null)===b.normalizedPath);return no([...k,...v])}const h=n?[]:a.get(b.normalizedPath)??[],N=new Set([b.normalizedPath,...h.map(OS).filter(BS)]),S=(k=>k.filter(v=>Ro(v,b.normalizedPath,N)))(o),j=r.filter(k=>{if(k.time?.archived||as(k.directory??null))return!1;const D=as(k.project?.worktree??null);return D?D===b.normalizedPath||D.startsWith(`${b.normalizedPath}/`):!1});return no([...S,...j])},e[11]=o,e[12]=a,e[13]=n,e[14]=r,e[15]=y):y=e[15];const p=y;let x;return e[16]!==p||e[17]!==g?(x={getSessionsForProject:g,getArchivedSessionsForProject:p},e[16]=p,e[17]=g,e[18]=x):x=e[18],x};function FS(t){return as(t.path)??t.path}function LS(t){return!!t}function OS(t){return as(t.path)??t.path}function BS(t){return!!t}const VS=t=>{const e=gt.c(10),{isSessionsLoading:n,hasLoadedGlobalSessions:r,sessions:o,archivedSessions:a,normalizedProjects:c,isVSCode:l,availableWorktreesByProject:d,cleanupSessions:u}=t;let m,f;e[0]!==a||e[1]!==d||e[2]!==u||e[3]!==r||e[4]!==n||e[5]!==l||e[6]!==c||e[7]!==o?(m=()=>{if(n||!r)return;const g=new Map;o.forEach(x=>{const b=as(x.directory??null);if(!b)return;const h=g.get(b);if(h){h.add(x.id);return}g.set(b,new Set([x.id]))}),c.forEach(x=>{const b=Ic(x.normalizedPath),h=l?[]:d.get(x.normalizedPath)??[],N=new Set([x.normalizedPath,...h.map(_S).filter($S)]),w=no([...a,...o.filter(S=>S.time?.archived||as(S.directory??null)?!1:Ro(S,x.normalizedPath,N))]).filter(S=>Ro(S,x.normalizedPath,N));g.set(b,new Set(w.map(zS)))});const y=Fn.getState().foldersMap;new Set([...Object.keys(y),...g.keys()]).forEach(x=>{u(x,g.get(x)??new Set)})},f=[a,d,u,r,n,l,c,o],e[0]=a,e[1]=d,e[2]=u,e[3]=r,e[4]=n,e[5]=l,e[6]=c,e[7]=o,e[8]=m,e[9]=f):(m=e[8],f=e[9]),i.useEffect(m,f)};function _S(t){return as(t.path)??t.path}function $S(t){return!!t}function zS(t){return t.id}const US=t=>{const e=gt.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[c,l]=i.useState(a);let d;e[1]!==n||e[2]!==o?(d=()=>{if(!n)return;const m=new IntersectionObserver(f=>{f.forEach(g=>{const y=g.target.dataset.projectId;y&&l(p=>{const x=new Set(p);return g.isIntersecting?x.delete(y):x.add(y),x})})},{threshold:0});return o.current.forEach(f=>{f&&m.observe(f)}),()=>m.disconnect()},e[1]=n,e[2]=o,e[3]=d):d=e[3];let u;return e[4]!==n||e[5]!==o||e[6]!==r?(u=[n,o,r],e[4]=n,e[5]=o,e[6]=r,e[7]=u):u=e[7],i.useEffect(d,u),c},WS=/^#(?:[\da-fA-F]{3}|[\da-fA-F]{6})$/,Dl=t=>{if(!t)return null;const e=t.trim();return e&&WS.test(e)?e.toLowerCase():null},HS=t=>{const e=gt.c(198),{open:n,onOpenChange:r,projectId:o,projectName:a,projectPath:c,initialIcon:l,initialColor:d,initialIconBackground:u,onSave:m}=t,f=l===void 0?null:l,g=d===void 0?null:d,y=u===void 0?null:u,{t:p}=At(),x=ys(GS),b=ys(KS),h=ys(qS);let N;e[0]!==o?(N=rt=>rt.projects.find(ts=>ts.id===o)?.iconImage??null,e[0]=o,e[1]=N):N=e[1];const w=ys(N),{currentTheme:S}=Hr(),[j,k]=i.useState(a),[v,D]=i.useState(f),[A,C]=i.useState(g);let O;e[2]!==y?(O=Dl(y),e[2]=y,e[3]=O):O=e[3];const[T,E]=i.useState(O),[F,R]=i.useState(!1),[L,B]=i.useState(!1),[V,M]=i.useState(!1),[ee,se]=i.useState(!1),[J,K]=i.useState(null),[Z,re]=i.useState(null),[pe,Se]=i.useState(!1),te=i.useRef(null);let Ne;e[4]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>{K(null),re(YS)},e[4]=Ne):Ne=e[4];const Y=Ne;let G,q;e[5]!==g||e[6]!==f||e[7]!==y||e[8]!==n||e[9]!==a?(G=()=>{n&&(k(a),D(f),C(g),E(Dl(y)),se(!1),Y(),Se(!1))},q=[n,a,f,g,y,Y],e[5]=g,e[6]=f,e[7]=y,e[8]=n,e[9]=a,e[10]=G,e[11]=q):(G=e[10],q=e[11]),i.useEffect(G,q);let oe,le;e[12]===Symbol.for("react.memo_cache_sentinel")?(le=()=>()=>{Y()},oe=[Y],e[12]=oe,e[13]=le):(oe=e[12],le=e[13]),i.useEffect(le,oe);let ve,Ee,_e;if(e[14]!==A||e[15]!==w||e[16]!==v||e[17]!==T||e[18]!==j||e[19]!==r||e[20]!==m||e[21]!==ee||e[22]!==J||e[23]!==o||e[24]!==b||e[25]!==p||e[26]!==x){let rt;e[30]!==A||e[31]!==v||e[32]!==T||e[33]!==j||e[34]!==r||e[35]!==m||e[36]!==ee||e[37]!==J||e[38]!==o||e[39]!==b||e[40]!==p||e[41]!==x?(rt=async()=>{const ts=j.trim();if(!ts)return;if(J){R(!0);const Gt=await x(o,J);if(R(!1),!Gt.ok){de.error(Gt.error||p("projectEditDialog.toast.failedToUploadIcon"));return}de.success(p("projectEditDialog.toast.iconUpdated")),Y(),se(!1)}const hs=ee&&_e;if(hs){B(!0);const Gt=await b(o);if(B(!1),!Gt.ok){de.error(Gt.error||p("projectEditDialog.toast.failedToRemoveIcon"));return}de.success(p("projectEditDialog.toast.iconRemoved")),se(!1),E(null)}m({label:ts,icon:v,color:A,iconBackground:Dl(hs?null:T)}),r(!1)},e[30]=A,e[31]=v,e[32]=T,e[33]=j,e[34]=r,e[35]=m,e[36]=ee,e[37]=J,e[38]=o,e[39]=b,e[40]=p,e[41]=x,e[42]=rt):rt=e[42],Ee=rt,ve=A?Ga[A]??null:null,_e=!!w,e[14]=A,e[15]=w,e[16]=v,e[17]=T,e[18]=j,e[19]=r,e[20]=m,e[21]=ee,e[22]=J,e[23]=o,e[24]=b,e[25]=p,e[26]=x,e[27]=ve,e[28]=Ee,e[29]=_e}else ve=e[27],Ee=e[28],_e=e[29];const Oe=!!(J&&Z),Me=w?.source==="custom",he=_e&&!ee||Oe,Ce=he,ue=!pe&&(Oe||_e&&!ee);let H;e[43]===Symbol.for("react.memo_cache_sentinel")?(H=()=>{Se(!1)},e[43]=H):H=e[43];const ce=w?.updatedAt;let fe;e[44]!==o||e[45]!==ce?(fe=[o,ce],e[44]=o,e[45]=ce,e[46]=fe):fe=e[46],i.useEffect(H,fe);let U;e[47]!==F||e[48]!==o?(U=rt=>{!o||!rt||F||(se(!1),Se(!1),K(rt),re(ts=>(ts&&URL.revokeObjectURL(ts),URL.createObjectURL(rt))))},e[47]=F,e[48]=o,e[49]=U):U=e[49];const z=U;let be;e[50]!==Oe||e[51]!==Ce||e[52]!==_e||e[53]!==L||e[54]!==o?(be=()=>{!o||!Ce||L||(Oe&&Y(),se(!!_e),Se(!1))},e[50]=Oe,e[51]=Ce,e[52]=_e,e[53]=L,e[54]=o,e[55]=be):be=e[55];const ge=be;let _;e[56]!==h||e[57]!==V||e[58]!==o||e[59]!==p?(_=async()=>{!o||V||(Y(),se(!1),Se(!1),M(!0),h(o).then(rt=>{if(!rt.ok){de.error(rt.error||p("projectEditDialog.toast.failedToDiscoverIcon"));return}if(rt.skipped){de.success(p("projectEditDialog.toast.customIconAlreadySet"));return}de.success(p("projectEditDialog.toast.iconDiscovered"))}).finally(()=>{M(!1)}))},e[56]=h,e[57]=V,e[58]=o,e[59]=p,e[60]=_):_=e[60];const ye=_;let $;e[61]!==p?($=p("projectEditDialog.title"),e[61]=p,e[62]=$):$=e[62];let Ie;e[63]!==$?(Ie=s.jsx(Us,{className:"min-w-0",children:s.jsx($s,{children:$})}),e[63]=$,e[64]=Ie):Ie=e[64];let je;e[65]!==p?(je=p("projectEditDialog.field.name"),e[65]=p,e[66]=je):je=e[66];let Fe;e[67]!==je?(Fe=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:je}),e[67]=je,e[68]=Fe):Fe=e[68];let Ae;e[69]===Symbol.for("react.memo_cache_sentinel")?(Ae=rt=>k(rt.target.value),e[69]=Ae):Ae=e[69];let ne;e[70]!==p?(ne=p("projectEditDialog.field.namePlaceholder"),e[70]=p,e[71]=ne):ne=e[71];let P;e[72]!==Ee?(P=rt=>{rt.key==="Enter"&&(rt.preventDefault(),Ee())},e[72]=Ee,e[73]=P):P=e[73];let me;e[74]!==j||e[75]!==ne||e[76]!==P?(me=s.jsx(bn,{value:j,onChange:Ae,placeholder:ne,onKeyDown:P,autoFocus:!0}),e[74]=j,e[75]=ne,e[76]=P,e[77]=me):me=e[77];let ae;e[78]!==c?(ae=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:c,children:c}),e[78]=c,e[79]=ae):ae=e[79];let Be;e[80]!==Fe||e[81]!==me||e[82]!==ae?(Be=s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[Fe,me,ae]}),e[80]=Fe,e[81]=me,e[82]=ae,e[83]=Be):Be=e[83];let Ge;e[84]!==p?(Ge=p("projectEditDialog.field.color"),e[84]=p,e[85]=Ge):Ge=e[85];let Ke;e[86]!==Ge?(Ke=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:Ge}),e[86]=Ge,e[87]=Ke):Ke=e[87];let Qe;e[88]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>C(null),e[88]=Qe):Qe=e[88];const st=A===null?"border-foreground scale-110":"border-border hover:border-border/80";let ut;e[89]!==st?(ut=De("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",st),e[89]=st,e[90]=ut):ut=e[90];let vt;e[91]!==p?(vt=p("projectEditDialog.option.none"),e[91]=p,e[92]=vt):vt=e[92];let Ve;e[93]===Symbol.for("react.memo_cache_sentinel")?(Ve=s.jsx("span",{className:"w-4 h-0.5 bg-muted-foreground/40 rotate-45 rounded-full"}),e[93]=Ve):Ve=e[93];let tt;e[94]!==ut||e[95]!==vt?(tt=s.jsx("button",{type:"button",onClick:Qe,className:ut,title:vt,children:Ve}),e[94]=ut,e[95]=vt,e[96]=tt):tt=e[96];let nt;e[97]!==A?(nt=gg.map(rt=>s.jsx("button",{type:"button",onClick:()=>C(rt.key),className:De("w-8 h-8 rounded-lg border-2 transition-all",A===rt.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:rt.cssVar},title:rt.label},rt.key)),e[97]=A,e[98]=nt):nt=e[98];let xt;e[99]!==tt||e[100]!==nt?(xt=s.jsxs("div",{className:"flex gap-2 flex-wrap",children:[tt,nt]}),e[99]=tt,e[100]=nt,e[101]=xt):xt=e[101];let Rt;e[102]!==Ke||e[103]!==xt?(Rt=s.jsxs("div",{className:"min-w-0 space-y-2",children:[Ke,xt]}),e[102]=Ke,e[103]=xt,e[104]=Rt):Rt=e[104];let bt;e[105]!==p?(bt=p("projectEditDialog.field.icon"),e[105]=p,e[106]=bt):bt=e[106];let ot;e[107]!==bt?(ot=s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:bt}),e[107]=bt,e[108]=ot):ot=e[108];let at;e[109]!==z?(at=s.jsx("input",{ref:te,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:rt=>{const ts=rt.target.files?.[0]??null;z(ts),rt.currentTarget.value=""}}),e[109]=z,e[110]=at):at=e[110];let Ut;e[111]===Symbol.for("react.memo_cache_sentinel")?(Ut=()=>D(null),e[111]=Ut):Ut=e[111];const Nt=v===null?"border-foreground scale-110 bg-[var(--surface-elevated)]":"border-border hover:border-border/80";let _t;e[112]!==Nt?(_t=De("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",Nt),e[112]=Nt,e[113]=_t):_t=e[113];let Le;e[114]!==p?(Le=p("projectEditDialog.option.none"),e[114]=p,e[115]=Le):Le=e[115];let Dt;e[116]===Symbol.for("react.memo_cache_sentinel")?(Dt=s.jsx("span",{className:"w-4 h-0.5 bg-muted-foreground/40 rotate-45 rounded-full"}),e[116]=Dt):Dt=e[116];let Ot;e[117]!==_t||e[118]!==Le?(Ot=s.jsx("button",{type:"button",onClick:Ut,className:_t,title:Le,children:Dt}),e[117]=_t,e[118]=Le,e[119]=Ot):Ot=e[119];let mt;e[120]!==ve||e[121]!==v?(mt=xg.map(rt=>{const ts=rt.Icon;return s.jsx("button",{type:"button",onClick:()=>D(rt.key),className:De("w-8 h-8 rounded-lg border-2 transition-all flex items-center justify-center",v===rt.key?"border-foreground scale-110 bg-[var(--surface-elevated)]":"border-border hover:border-border/80"),title:rt.label,children:s.jsx(I,{name:ts,className:"w-4 h-4",style:ve?{color:ve}:void 0})},rt.key)}),e[120]=ve,e[121]=v,e[122]=mt):mt=e[122];let Et;e[123]!==Ot||e[124]!==mt?(Et=s.jsxs("div",{className:"flex gap-2 flex-wrap",children:[Ot,mt]}),e[123]=Ot,e[124]=mt,e[125]=Et):Et=e[125];let qt;e[126]!==w||e[127]!==S||e[128]!==he||e[129]!==Oe||e[130]!==T||e[131]!==Z||e[132]!==o||e[133]!==ue||e[134]!==p?(qt=he&&ue&&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:T?{backgroundColor:T}:void 0,children:Oe&&Z?s.jsx("img",{src:Z,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>Se(!0)}):s.jsx(Ka,{project:{id:o,iconImage:w},options:{themeVariant:S.metadata.variant,iconColor:S.colors.surface.foreground},className:"h-full w-full object-contain",onError:()=>Se(!0)})})})]}),e[126]=w,e[127]=S,e[128]=he,e[129]=Oe,e[130]=T,e[131]=Z,e[132]=o,e[133]=ue,e[134]=p,e[135]=qt):qt=e[135];let Vt;e[136]!==ye||e[137]!==Me||e[138]!==V||e[139]!==F||e[140]!==p?(Vt=!Me&&s.jsxs(s.Fragment,{children:[s.jsx($e,{size:"sm",variant:"outline",onClick:()=>te.current?.click(),disabled:F,children:p(F?"projectEditDialog.actions.uploading":"projectEditDialog.actions.uploadIcon")}),s.jsx($e,{size:"sm",variant:"outline",onClick:()=>{ye()},disabled:V,children:p(V?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")})]}),e[136]=ye,e[137]=Me,e[138]=V,e[139]=F,e[140]=p,e[141]=Vt):Vt=e[141];let Wt;e[142]!==ge||e[143]!==Ce||e[144]!==L||e[145]!==p?(Wt=Ce&&s.jsx($e,{size:"sm",variant:"outline",onClick:()=>{ge()},disabled:L,children:p(L?"projectEditDialog.actions.removing":"projectEditDialog.actions.removeProjectIcon")}),e[142]=ge,e[143]=Ce,e[144]=L,e[145]=p,e[146]=Wt):Wt=e[146];let Yt;e[147]!==L||e[148]!==ee||e[149]!==p?(Yt=ee&&s.jsx($e,{size:"sm",variant:"outline",onClick:()=>se(!1),disabled:L,children:p("projectEditDialog.actions.undoRemove")}),e[147]=L,e[148]=ee,e[149]=p,e[150]=Yt):Yt=e[150];let Bt;e[151]!==Vt||e[152]!==Wt||e[153]!==Yt?(Bt=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[Vt,Wt,Yt]}),e[151]=Vt,e[152]=Wt,e[153]=Yt,e[154]=Bt):Bt=e[154];let Ht;e[155]!==ot||e[156]!==at||e[157]!==Et||e[158]!==qt||e[159]!==Bt?(Ht=s.jsxs("div",{className:"min-w-0 space-y-2",children:[ot,at,Et,qt,Bt]}),e[155]=ot,e[156]=at,e[157]=Et,e[158]=qt,e[159]=Bt,e[160]=Ht):Ht=e[160];let Jt;e[161]!==he||e[162]!==T||e[163]!==p?(Jt=he&&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:T??"#000000",onChange:rt=>E(rt.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(bn,{value:T??"",onChange:rt=>E(rt.target.value),placeholder:"#000000",className:"h-8 w-[8.5rem]"}),s.jsx($e,{size:"sm",variant:"outline",onClick:()=>E(null),children:p("projectEditDialog.actions.clear")})]})]}),e[161]=he,e[162]=T,e[163]=p,e[164]=Jt):Jt=e[164];let rs;e[165]!==Be||e[166]!==Rt||e[167]!==Ht||e[168]!==Jt?(rs=s.jsxs("div",{className:"min-w-0 space-y-5 py-1",children:[Be,Rt,Ht,Jt]}),e[165]=Be,e[166]=Rt,e[167]=Ht,e[168]=Jt,e[169]=rs):rs=e[169];let Qt;e[170]!==r?(Qt=()=>r(!1),e[170]=r,e[171]=Qt):Qt=e[171];let Xt;e[172]!==p?(Xt=p("projectEditDialog.actions.cancel"),e[172]=p,e[173]=Xt):Xt=e[173];let bs;e[174]!==Qt||e[175]!==Xt?(bs=s.jsx($e,{variant:"ghost",onClick:Qt,children:Xt}),e[174]=Qt,e[175]=Xt,e[176]=bs):bs=e[176];let yt;e[177]!==L||e[178]!==F||e[179]!==j?(yt=!j.trim()||F||L,e[177]=L,e[178]=F,e[179]=j,e[180]=yt):yt=e[180];let Ue;e[181]!==p?(Ue=p("projectEditDialog.actions.save"),e[181]=p,e[182]=Ue):Ue=e[182];let Ye;e[183]!==Ee||e[184]!==yt||e[185]!==Ue?(Ye=s.jsx($e,{onClick:Ee,disabled:yt,children:Ue}),e[183]=Ee,e[184]=yt,e[185]=Ue,e[186]=Ye):Ye=e[186];let Ct;e[187]!==bs||e[188]!==Ye?(Ct=s.jsxs(sr,{children:[bs,Ye]}),e[187]=bs,e[188]=Ye,e[189]=Ct):Ct=e[189];let kt;e[190]!==Ie||e[191]!==rs||e[192]!==Ct?(kt=s.jsxs(Fs,{className:"max-w-md",children:[Ie,rs,Ct]}),e[190]=Ie,e[191]=rs,e[192]=Ct,e[193]=kt):kt=e[193];let It;return e[194]!==r||e[195]!==n||e[196]!==kt?(It=s.jsx(Ls,{open:n,onOpenChange:r,children:kt}),e[194]=r,e[195]=n,e[196]=kt,e[197]=It):It=e[197],It};function GS(t){return t.uploadProjectIcon}function KS(t){return t.removeProjectIcon}function qS(t){return t.discoverProjectIcon}function YS(t){return t&&URL.revokeObjectURL(t),null}const QS=t=>{const e=gt.c(86),{folder:n,sessions:r,subFolderItems:o,isCollapsed:a,onToggle:c,onRename:l,onDelete:d,renderSessionNode:u,getRenderExtras:m,groupDirectory:f,projectId:g,mobileVariant:y,alwaysShowActions:p,isRenaming:x,renameDraft:b,onRenameDraftChange:h,onRenameSave:N,onRenameCancel:w,droppableRef:S,isDropTarget:j,onNewSession:k,onNewSubFolder:v,depth:D,hideActions:A,archivedBucket:C}=t,T=p===void 0?y===void 0?!1:y:p,E=x===void 0?!1:x,F=b===void 0?"":b,R=j===void 0?!1:j,L=D===void 0?0:D,B=A===void 0?!1:A,V=C===void 0?!1:C,{t:M}=At(),[ee,se]=i.useState(!1),[J,K]=i.useState(""),Z=i.useRef(null),re=E||ee,pe=E?F:J;let Se;e[0]!==n.name?(Se=()=>{K(n.name),se(!0)},e[0]=n.name,e[1]=Se):Se=e[1];const te=Se;let Ne;e[2]!==pe||e[3]!==n.name||e[4]!==E||e[5]!==l||e[6]!==N?(Ne=()=>{const P=pe.trim();P&&P!==n.name&&l(P),E&&N&&N(),se(!1),K("")},e[2]=pe,e[3]=n.name,e[4]=E,e[5]=l,e[6]=N,e[7]=Ne):Ne=e[7];const Y=Ne;let G;e[8]!==E||e[9]!==w?(G=()=>{E&&w&&w(),se(!1),K("")},e[8]=E,e[9]=w,e[10]=G):G=e[10];const q=G;let oe;e[11]!==E||e[12]!==h?(oe=P=>{E&&h?h(P):K(P)},e[11]=E,e[12]=h,e[13]=oe):oe=e[13];const le=oe;let ve,Ee;e[14]!==E?(ve=()=>{if(!E)return;const P=()=>{const Be=Z.current;Be&&(Be.focus(),Be.select())},me=requestAnimationFrame(P),ae=window.setTimeout(P,0);return()=>{cancelAnimationFrame(me),window.clearTimeout(ae)}},Ee=[E],e[14]=E,e[15]=ve,e[16]=Ee):(ve=e[15],Ee=e[16]),i.useEffect(ve,Ee);const _e=a?"folder":"folder-open",Me=L>0&&"ml-3";let he;e[17]!==Me?(he=De("oc-folder",Me),e[17]=Me,e[18]=he):he=e[18];const Ce=R&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let xe;e[19]!==Ce?(xe=De("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Ce),e[19]=Ce,e[20]=xe):xe=e[20];const ue=re?void 0:c,H=re?void 0:"button",ce=re?void 0:0;let fe;e[21]!==c||e[22]!==re?(fe=re?void 0:P=>{(P.key==="Enter"||P.key===" ")&&(P.preventDefault(),c())},e[21]=c,e[22]=re,e[23]=fe):fe=e[23];let U;e[24]!==n.name||e[25]!==a||e[26]!==M?(U=a?M("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):M("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=a,e[26]=M,e[27]=U):U=e[27];const z=V?T?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let be;e[28]!==z?(be=De("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",z),e[28]=z,e[29]=be):be=e[29];const ge=R?"text-primary":"text-muted-foreground";let _;e[30]!==ge?(_=De("h-3.5 w-3.5 flex-shrink-0",ge),e[30]=ge,e[31]=_):_=e[31];let ye;e[32]!==_e||e[33]!==_?(ye=s.jsx(I,{name:_e,className:_}),e[32]=_e,e[33]=_,e[34]=ye):ye=e[34];let $;e[35]!==pe||e[36]!==n.name||e[37]!==q||e[38]!==le||e[39]!==Y||e[40]!==a||e[41]!==R||e[42]!==re||e[43]!==r||e[44]!==M?($=re?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:XS,onMouseDown:ZS,onSubmit:P=>{P.preventDefault(),Y()},children:[s.jsx("input",{ref:Z,value:pe,onChange:P=>le(P.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:M("sessions.sidebar.folderItem.namePlaceholder"),onClick:eN,onPointerDown:tN,onMouseDown:sN,onKeyDown:P=>{if(P.key==="Escape"){P.stopPropagation(),q();return}(P.key===" "||P.key==="Enter")&&P.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:nN,onPointerDown:rN,onMouseDown:iN,children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),q()},onPointerDown:oN,onMouseDown:aN,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:De("typography-ui-label font-semibold truncate",R?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),a?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]=pe,e[36]=n.name,e[37]=q,e[38]=le,e[39]=Y,e[40]=a,e[41]=R,e[42]=re,e[43]=r,e[44]=M,e[45]=$):$=e[45];let Ie;e[46]!==be||e[47]!==ye||e[48]!==$?(Ie=s.jsxs("div",{className:be,children:[ye,$]}),e[46]=be,e[47]=ye,e[48]=$,e[49]=Ie):Ie=e[49];let je;e[50]!==T||e[51]!==V||e[52]!==L||e[53]!==n.name||e[54]!==te||e[55]!==B||e[56]!==d||e[57]!==k||e[58]!==v||e[59]!==re||e[60]!==M?(je=!re&&(!B||V)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:De("flex items-center gap-0.5 transition-opacity",T?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",V&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!V&&k?s.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),k()},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":M("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:M("sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,!V&&v&&L===0?s.jsx("button",{type:"button",onClick:P=>{P.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":M("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:M("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(I,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,V?null:s.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),te()},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":M("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:P=>{P.stopPropagation(),d()},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":V?M("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):M("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=T,e[51]=V,e[52]=L,e[53]=n.name,e[54]=te,e[55]=B,e[56]=d,e[57]=k,e[58]=v,e[59]=re,e[60]=M,e[61]=je):je=e[61];let Fe;e[62]!==S||e[63]!==xe||e[64]!==ue||e[65]!==H||e[66]!==ce||e[67]!==fe||e[68]!==U||e[69]!==Ie||e[70]!==je?(Fe=s.jsxs("div",{ref:S,className:xe,onClick:ue,role:H,tabIndex:ce,onKeyDown:fe,"aria-label":U,children:[Ie,je]}),e[62]=S,e[63]=xe,e[64]=ue,e[65]=H,e[66]=ce,e[67]=fe,e[68]=U,e[69]=Ie,e[70]=je,e[71]=Fe):Fe=e[71];let Ae;e[72]!==V||e[73]!==m||e[74]!==f||e[75]!==a||e[76]!==g||e[77]!==u||e[78]!==r||e[79]!==o||e[80]!==M?(Ae=a?null:s.jsxs("div",{className:"pb-1 pl-2",children:[o,r.length>0?r.map(P=>u(P,0,f??null,g??null,V,void 0,"project",m?.(P))):o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:M("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=V,e[73]=m,e[74]=f,e[75]=a,e[76]=g,e[77]=u,e[78]=r,e[79]=o,e[80]=M,e[81]=Ae):Ae=e[81];let ne;return e[82]!==he||e[83]!==Fe||e[84]!==Ae?(ne=s.jsxs("div",{className:he,children:[Fe,Ae]}),e[82]=he,e[83]=Fe,e[84]=Ae,e[85]=ne):ne=e[85],ne},JS=i.memo(QS);function XS(t){return t.stopPropagation()}function ZS(t){return t.stopPropagation()}function eN(t){return t.stopPropagation()}function tN(t){return t.stopPropagation()}function sN(t){return t.stopPropagation()}function nN(t){return t.stopPropagation()}function rN(t){return t.stopPropagation()}function iN(t){return t.stopPropagation()}function oN(t){return t.stopPropagation()}function aN(t){return t.stopPropagation()}const lN=t=>{const e=gt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:a}=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 d;e[4]!==c||e[5]!==l?(d={id:c,data:l},e[4]=c,e[5]=l,e[6]=d):d=e[6];const{attributes:u,listeners:m,setNodeRef:f,isDragging:g}=Bh(d);let y;e[7]!==m?(y=h=>{h.stopPropagation(),m?.onPointerDown&&m.onPointerDown(h)},e[7]=m,e[8]=y):y=e[8];const p=y,x=g?"opacity-30":void 0;let b;return e[9]!==u||e[10]!==a||e[11]!==p||e[12]!==f||e[13]!==x?(b=s.jsx("div",{ref:f,...u,onPointerDown:p,className:x,children:a}),e[9]=u,e[10]=a,e[11]=p,e[12]=f,e[13]=x,e[14]=b):b=e[14],b},cN=t=>{const e=gt.c(11),{folderId:n,children:r}=t,o=`folder-drop:${n}`;let a;e[0]!==n?(a={type:"folder",folderId:n},e[0]=n,e[1]=a):a=e[1];let c;e[2]!==o||e[3]!==a?(c={id:o,data:a},e[2]=o,e[3]=a,e[4]=c):c=e[4];const{setNodeRef:l,isOver:d}=Oh(c);let u;e[5]!==r||e[6]!==d||e[7]!==l?(u=r(l,d),e[5]=r,e[6]=d,e[7]=l,e[8]=u):u=e[8];let m;return e[9]!==u?(m=s.jsx(s.Fragment,{children:u}),e[9]=u,e[10]=m):m=e[10],m},dN=t=>{const e=gt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:a}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[0]=c):c=e[0];const l=ga(yo(xa,c)),[d,u]=i.useState(null),[m,f]=i.useState("Session"),[g,y]=i.useState(null),[p,x]=i.useState(null);if(!n){let v;return e[1]!==a?(v=s.jsx(s.Fragment,{children:a}),e[1]=a,e[2]=v):v=e[2],v}let b;e[3]!==o?(b=v=>{u(null),y(null),x(null);const{active:D,over:A}=v;if(!A)return;const C=D.data.current,O=A.data.current;C?.type==="session"&&C.sessionId&&O?.type==="folder"&&O.folderId&&o(C.sessionId,O.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=v=>{const D=v.active.data.current;if(D?.type==="session"&&D.sessionId){u(D.sessionId),f(D.sessionTitle??"Session");const A=v.active.rect.current.initial?.width,C=v.active.rect.current.initial?.height;y(typeof A=="number"?A:null),x(typeof C=="number"?C:null)}},w=()=>{u(null),y(null),x(null)},e[5]=N,e[6]=w):(N=e[5],w=e[6]);let S;e[7]!==p||e[8]!==d||e[9]!==m||e[10]!==g||e[11]!==r?(S=d&&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:m})]}):null,e[7]=p,e[8]=d,e[9]=m,e[10]=g,e[11]=r,e[12]=S):S=e[12];let j;e[13]!==S?(j=s.jsx(Bl,{children:S}),e[13]=S,e[14]=j):j=e[14];let k;return e[15]!==a||e[16]!==h||e[17]!==l||e[18]!==j?(k=s.jsxs(ba,{sensors:l,collisionDetection:ya,onDragStart:N,onDragCancel:w,onDragEnd:h,children:[a,j]}),e[15]=a,e[16]=h,e[17]=l,e[18]=j,e[19]=k):k=e[19],k},Gi=(t,e,n)=>{if(!e)return;const r=o=>{let a=o.session.id===e;for(const c of o.children)a=r(c)||a;return a&&n.add(o.session.id),a};for(const o of t)r(o)},_r=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(_r(n,e))return!0;return!1},Ra=t=>t.children.length===0?"":t.children.map(n=>n.children.length===0?n.session.id:`${n.session.id}:${Ra(n)}`).join("|"),Fo=(t,e,n,r)=>{if(!e)return null;const o=r?"archived":"active";let a=null;const c=l=>{if(`${n}:${o}:${l.session.id}`===e)return a=l.session.id,!0;for(const u of l.children)if(c(u))return!0;return!1};return t.forEach(l=>c(l)),a},Ar=io()(rc(t=>({displayMode:"minimal",showRecentSection:!0,showArchivedSessions:!1,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",version:1,migrate:(t,e)=>{const n=t??{};return e<1?{...n,displayMode:"minimal"}:n}})),uN=50,fN=30,ef=28,$i=(t,e)=>e?t.sessions.some(n=>_r(n,e)):!1,mN=(t,e,n)=>{const r=o=>{const a=o.session.id;return e.has(a)!==n.has(a)?!0:o.children.some(r)};return t.sessions.some(r)},hN=(t,e,n)=>{const r=o=>{const a=o.session.id;return e.get(a)!==n.get(a)?!0:o.children.some(r)};return t.sessions.some(r)},pN=(t,e,n)=>{const r=t.isArchivedBucket?"archived":"active",o=a=>{const c=`project:${r}:${a.session.id}`;return e.has(c)!==n.has(c)?!0:a.children.some(o)};return t.sessions.some(o)},gN=(t,e,n)=>{const r=o=>{const a=o.session.id;return(e.get(a)??o.session)!==(n.get(a)??o.session)?!0:o.children.some(r)};return t.sessions.some(r)},tf=t=>{if(t.projectId)return t.projectRepoStatus.has(t.projectId)?t.projectRepoStatus.get(t.projectId):void 0},xN=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.projectRepoStatus!==e.projectRepoStatus&&tf(t)!==tf(e)||t.pinnedSessionIds!==e.pinnedSessionIds&&mN(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.expandedParents!==e.expandedParents&&pN(e.group,t.expandedParents,e.expandedParents)||t.sessionOrderIndex!==e.sessionOrderIndex&&hN(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.currentSessionId!==e.currentSessionId&&($i(t.group,t.currentSessionId)||$i(e.group,e.currentSessionId))||t.editingId!==e.editingId&&($i(t.group,t.editingId)||$i(e.group,e.editingId))||t.editTitle!==e.editTitle&&($i(t.group,t.editingId)||$i(e.group,e.editingId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=Fo(t.group.sessions,t.openSidebarMenuKey,"project",!!t.group.isArchivedBucket),r=Fo(e.group.sessions,e.openSidebarMenuKey,"project",!!e.group.isArchivedBucket);if(n||r)return!1}if(t.liveSessionById!==e.liveSessionById&&gN(e.group,t.liveSessionById,e.liveSessionById))return!1;if(t.prVisualStateByDirectoryBranch!==e.prVisualStateByDirectoryBranch){const n=t.group?.directory&&t.group?.branch?t.prVisualStateByDirectoryBranch.get(`${t.group.directory}::${t.group.branch.trim()}`):void 0,r=e.group?.directory&&e.group?.branch?e.prVisualStateByDirectoryBranch.get(`${e.group.directory}::${e.group.branch.trim()}`):void 0;if(!Object.is(n,r))return!1}return t.hasSessionSearchQuery===e.hasSessionSearchQuery&&t.normalizedSessionSearchQuery===e.normalizedSessionSearchQuery&&t.hideDirectoryControls===e.hideDirectoryControls&&t.collapsedFolderIds===e.collapsedFolderIds&&t.toggleFolderCollapse===e.toggleFolderCollapse&&t.renameFolder===e.renameFolder&&t.deleteFolder===e.deleteFolder&&t.showDeletionDialog===e.showDeletionDialog&&t.setDeleteFolderConfirm===e.setDeleteFolderConfirm&&t.renderSessionNode===e.renderSessionNode&&t.lastRepoStatus===e.lastRepoStatus&&t.showMoreGroupSessions===e.showMoreGroupSessions&&t.resetGroupSessionLimit===e.resetGroupSessionLimit&&t.mobileVariant===e.mobileVariant&&t.alwaysShowActions===e.alwaysShowActions&&t.activeProjectId===e.activeProjectId&&t.setActiveProjectIdOnly===e.setActiveProjectIdOnly&&t.setActiveMainTab===e.setActiveMainTab&&t.setSessionSwitcherOpen===e.setSessionSwitcherOpen&&t.openNewSessionDraft===e.openNewSessionDraft&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.renamingFolderId===e.renamingFolderId&&t.renameFolderDraft===e.renameFolderDraft&&t.setRenameFolderDraft===e.setRenameFolderDraft&&t.setRenamingFolderId===e.setRenamingFolderId&&t.onToggleCollapsedGroup===e.onToggleCollapsedGroup&&t.dragHandleProps===e.dragHandleProps&&t.scrollContainerRef===e.scrollContainerRef};function bN(t){const{t:e}=At(),{group:n,groupKey:r,projectId:o,hideGroupLabel:a,hasSessionSearchQuery:c,normalizedSessionSearchQuery:l,groupSearchDataByGroup:d,visibleSessionCount:u,collapsedGroups:m,hideDirectoryControls:f,collapsedFolderIds:g,toggleFolderCollapse:y,renameFolder:p,deleteFolder:x,showDeletionDialog:b,setDeleteFolderConfirm:h,renderSessionNode:N,projectRepoStatus:w,lastRepoStatus:S,showMoreGroupSessions:j,resetGroupSessionLimit:k,mobileVariant:v,alwaysShowActions:D,activeProjectId:A,setActiveProjectIdOnly:C,setActiveMainTab:O,setSessionSwitcherOpen:T,openNewSessionDraft:E,addSessionToFolder:F,createFolderAndStartRename:R,renamingFolderId:L,renameFolderDraft:B,setRenameFolderDraft:V,setRenamingFolderId:M,pinnedSessionIds:ee,sessionOrderIndex:se,currentSessionId:J,editingId:K,openSidebarMenuKey:Z,prVisualStateByDirectoryBranch:re,onToggleCollapsedGroup:pe,dragHandleProps:Se,compactBodyPadding:te=!1,scrollContainerRef:Ne}=t,Y=i.useCallback((Ue,Ye)=>{const Ct=se.get(Ue.session.id),kt=se.get(Ye.session.id);if(Ct!==void 0||kt!==void 0){if(Ct===void 0)return 1;if(kt===void 0)return-1;if(Ct!==kt)return Ct-kt}return Ki(Ue.session,Ye.session,ee)},[ee,se]),G=c?d.get(n):null,q=Ar(Ue=>Ue.displayMode),oe=Fn(Ue=>Ue.foldersMap),le=q==="minimal"&&!Wr(),ve=c?!1:m.has(r),Ee=f?10:5,_e=Math.max(Ee,u??Ee),Oe=c?G?.groupMatches===!0:!1,Me=c,he=i.useMemo(()=>[...Me?G?.filteredNodes??[]:n.sessions].sort(Y),[Y,n.sessions,G?.filteredNodes,Me]),Ce=n.folderScopeKey??as(n.directory??null),xe=i.useMemo(()=>Ce?oe[Ce]??[]:[],[Ce,oe]),ue=i.useMemo(()=>{const Ue=new Map,Ye=Ct=>{Ct.forEach(kt=>{Ue.set(kt.session.id,kt),kt.children.length>0&&Ye(kt.children)})};return Ye(he),Ue},[he]),H=i.useMemo(()=>xe.map(Ue=>{const Ye=Ue.sessionIds.map(Ct=>ue.get(Ct)).filter(Ct=>!!Ct).sort(Y);return{folder:Ue,nodes:Ye}}),[xe,ue,Y]),ce=i.useMemo(()=>{const Ue=new Map(H.map(It=>[It.folder.id,It])),Ye=new Map;for(const{folder:It}of H){if(!It.parentId)continue;const rt=Ye.get(It.parentId);rt?rt.push(It.id):Ye.set(It.parentId,[It.id])}const Ct=new Map,kt=It=>{const rt=Ct.get(It);if(rt!==void 0)return rt;const ts=Ue.get(It);if(!ts)return Ct.set(It,!1),!1;const hs=Ye.get(It)??[];if(n.isArchivedBucket&&ts.nodes.length===0){const js=hs.some(ss=>kt(ss));return Ct.set(It,js),js}if(!c||ts.folder.name.toLowerCase().includes(l)||ts.nodes.length>0)return Ct.set(It,!0),!0;const nn=hs.some(js=>kt(js));return Ct.set(It,nn),nn};return H.filter(({folder:It})=>kt(It.id))},[H,n.isArchivedBucket,c,l]),fe=i.useMemo(()=>new Set(ce.flatMap(Ue=>Ue.folder.sessionIds)),[ce]),U=i.useMemo(()=>he.filter(Ue=>!fe.has(Ue.session.id)),[he,fe]),z=i.useMemo(()=>ce.filter(({folder:Ue})=>!Ue.parentId),[ce]),be="project",ge=i.useMemo(()=>{const Ue=new Set;return Gi(he,J,Ue),ce.forEach(({nodes:Ye})=>{Gi(Ye,J,Ue)}),Ue},[he,ce,J]),_=i.useMemo(()=>{const Ue=new Set;return Gi(he,K,Ue),ce.forEach(({nodes:Ye})=>{Gi(Ye,K,Ue)}),Ue},[he,ce,K]),ye=i.useMemo(()=>{if(!Z)return null;const Ue=Fo(he,Z,be,!!n.isArchivedBucket);if(Ue)return Ue;for(const{nodes:Ye}of ce){const Ct=Fo(Ye,Z,be,!!n.isArchivedBucket);if(Ct)return Ct}return null},[Z,he,ce,n.isArchivedBucket]),$=i.useCallback(Ue=>{const Ye=new WeakMap,Ct=kt=>{Ye.set(kt,Ra(kt));for(const It of kt.children)Ct(It)};return Ue.forEach(Ct),Ye},[]),Ie=i.useMemo(()=>$(he),[$,he]),je=i.useMemo(()=>{const Ue=new WeakMap;return ce.forEach(({nodes:Ye})=>{Ye.forEach(Ct=>Ue.set(Ct,Ra(Ct)))}),Ue},[ce]),Fe=i.useCallback(Ue=>Ie.get(Ue)??je.get(Ue)??"",[Ie,je]),Ae=i.useCallback(Ue=>({subtreeContainsActive:ge,subtreeContainsEditing:_,menuOpenSessionId:ye,nodeStructureKey:Fe(Ue)}),[ge,_,ye,Fe]),ne=U.length,P=n.isArchivedBucket||c?U:U.slice(0,_e),me=ne-P.length,ae=!n.isArchivedBucket&&!c&&ne>Ee&&me===0,Be=n.isArchivedBucket===!0&&!c&&P.length>=uN,Ge=n.isArchivedBucket!==!0&&!c&&P.length>=fN,Ke=Be||Ge,Qe=i.useRef(null),st=i.useRef(null),[ut,vt]=i.useState(null),[Ve,tt]=i.useState(0),[,nt]=i.useState(0);i.useEffect(()=>{if(!Ke)return;const Ue=Qe.current;if(!Ue||typeof ResizeObserver>"u")return;const Ye=new ResizeObserver(()=>nt(Ct=>Ct+1));return Ye.observe(Ue),()=>Ye.disconnect()},[Ke]),i.useLayoutEffect(()=>{if(!Ke){ut!==null&&vt(null),st.current=null,Ve!==0&&tt(0);return}const Ue=Qe.current;if(!Ue)return;let Ye=ut;const Ct=Ne?.current??null;if(Ct&&Ct.contains(Ue)){if(Ye=Ct,Ye!==ut){st.current=Ye,vt(Ye);return}}else if(!Ye||!Ye.contains(Ue)){let It=Ue.parentElement;for(;It;){const rt=window.getComputedStyle(It);if(rt.overflowY==="auto"||rt.overflowY==="scroll"){Ye=It;break}It=It.parentElement}if(Ye!==ut){st.current=Ye,vt(Ye);return}}if(!Ye)return;const kt=Ue.getBoundingClientRect().top-Ye.getBoundingClientRect().top+Ye.scrollTop;tt(It=>Math.abs(It-kt)<1?It:kt)});const xt=i.useCallback(Ue=>{const Ye=[],Ct=kt=>{kt.forEach(It=>{Ye.push(It.session),It.children.length>0&&Ct(It.children)})};return Ct(Ue),Ye},[]),Rt=i.useMemo(()=>n.isArchivedBucket?xt(he):[],[xt,he,n.isArchivedBucket]),bt=i.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Ue=new Map,Ye=new Map;for(const{folder:kt}of ce){if(!kt.parentId)continue;const It=Ye.get(kt.parentId)??[];It.push(kt.id),Ye.set(kt.parentId,It)}const Ct=(kt,It)=>{if(It.has(kt))return[];It.add(kt);const rt=ce.find(({folder:Gt})=>Gt.id===kt),ts=rt?xt(rt.nodes):[],hs=Ye.get(kt)??[];for(const Gt of hs)ts.push(...Ct(Gt,It));return ts};for(const{folder:kt}of ce)Ue.set(kt.id,Ct(kt.id,new Set));return Ue},[ce,xt,n.isArchivedBucket]);if(c&&!Oe&&z.length===0&&U.length===0)return null;const ot=o&&w.has(o)?!!w.get(o):S,at=as(n.directory??null),Ut=n.branch?.trim()??null,Nt=at&&Ut?re.get(`${at}::${Ut}`)??null:null,_t=!!(Nt&&n.branch),Le=!Nt&&!n.isMain&&!!n.branch,Dt=Nt?.visualState??null,Ot=Nt&&Nt.state==="open"&&Nt.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Nt.checks.success,total:Nt.checks.total}):null,mt=Nt&&Nt.state==="open"&&Nt.checks?[Nt.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Nt.checks.failure}):null,Nt.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Nt.checks.pending}):null].filter(Ue=>!!Ue).join(", "):null,Et=Nt&&Nt.state==="open"?Nt.mergeableState==="blocked"||Nt.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Nt.mergeableState==="clean"||Nt.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,qt=Nt&&Nt.state==="open"&&Nt.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Nt.mergeableState}):null,Vt=Nt?.base??null,Wt=Nt?.head??null,Yt=(()=>{if(!Nt)return n.branch&&Xx(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Nt.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Nt.canMerge===!0||Nt.mergeableState==="clean"||Nt.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:Nt.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}})(),Bt=Yt?.color??(Dt?`var(--pr-${Dt})`:void 0),Ht=Ue=>{Ue.preventDefault(),Ue.stopPropagation();const Ye=Nt?.url;Ye&&Pi(Ye)},Jt=(Ue,Ye,Ct)=>{const kt=ce.filter(({folder:ts})=>ts.parentId===Ue.id),It=kt.length>0?s.jsx(s.Fragment,{children:kt.map(({folder:ts,nodes:hs})=>Jt(ts,hs,Ct+1))}):void 0,rt=bt.get(Ue.id)??[];return s.jsx(cN,{folderId:Ue.id,children:(ts,hs)=>s.jsx(JS,{folder:Ue,sessions:Ye,subFolderItems:It,isCollapsed:c?!1:g.has(Ue.id),onToggle:()=>y(Ue.id),onRename:Gt=>{Ce&&p(Ce,Ue.id,Gt)},onDelete:()=>{if(n.isArchivedBucket){Ir.requestDelete({sessions:rt,mode:"session"});return}if(!Ce)return;if(!b){x(Ce,Ue.id);return}const Gt=ce.filter(({folder:js})=>js.parentId===Ue.id).length,nn=Ye.length;h({scopeKey:Ce,folderId:Ue.id,folderName:Ue.name,subFolderCount:Gt,sessionCount:nn})},renderSessionNode:N,getRenderExtras:Fe?Gt=>({subtreeContainsActive:ge,subtreeContainsEditing:_,menuOpenSessionId:ye,nodeStructureKey:Fe(Gt),childRenderExtrasFor:Ae}):void 0,groupDirectory:n.directory,projectId:o,mobileVariant:v,alwaysShowActions:D,isRenaming:L===Ue.id,renameDraft:L===Ue.id?B:void 0,onRenameDraftChange:Gt=>V(Gt),onRenameSave:()=>{const Gt=B.trim();Gt&&Ce&&p(Ce,Ue.id,Gt),M(null),V("")},onRenameCancel:()=>{M(null),V("")},droppableRef:ts,isDropTarget:hs,depth:Ct,onNewSession:()=>{o&&o!==A&&C(o),O("chat"),v&&T(!1),E({directoryOverride:n.directory,targetFolderId:Ue.id})},onNewSubFolder:Ct===0?()=>{Ce&&R(Ce,Ue.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Ue.id)},rs=()=>z.map(({folder:Ue,nodes:Ye})=>Jt(Ue,Ye,0)),Qt=!!(!n.isMain&&n.worktree),Xt=D?Qt?"pr-14":"pr-7":le?Qt?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":Qt?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",bs=s.jsxs(dN,{scopeKey:Ce,hasFolders:ce.length>0,onSessionDroppedOnFolder:(Ue,Ye)=>{Ce&&F(Ce,Ye,Ue)},children:[rs(),Ke?s.jsx("div",{ref:Qe,children:s.jsx(Vh,{data:P,itemSize:ef,bufferSize:ef*8,scrollRef:st,startMargin:Ve,children:Ue=>N(Ue,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsActive:ge,subtreeContainsEditing:_,menuOpenSessionId:ye,nodeStructureKey:Fe(Ue),childRenderExtrasFor:Ae})})}):P.map(Ue=>N(Ue,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsActive:ge,subtreeContainsEditing:_,menuOpenSessionId:ye,nodeStructureKey:Fe(Ue),childRenderExtrasFor:Ae})),ne===0&&ce.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:()=>j(r,P.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,ae?s.jsx("button",{type:"button",onClick:()=>k(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]}),yt=te?"pb-2 pl-1":"pb-3 pl-4";return a?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:De("oc-group-body",yt),children:bs})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:De("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>pe(r),role:"button",tabIndex:0,onKeyDown:Ue=>{(Ue.key==="Enter"||Ue.key===" ")&&(Ue.preventDefault(),pe(r))},"aria-label":ve?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!ve,children:[s.jsx("div",{ref:Se?.setActivatorNodeRef,className:De("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",Xt),...Se?.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:_t&&Nt?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Mt,{children:[s.jsx(Ft,{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:De("h-3.5 w-3.5 shrink-0",D?"hidden":"group-hover/gh:hidden"),style:Bt?{color:Bt}:void 0}),s.jsx("span",{className:De("text-muted-foreground h-3.5 w-3.5 items-center justify-center",D?"inline-flex":"hidden group-hover/gh:inline-flex"),children:ve?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"})})]}),Nt.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:Ue=>Ue.stopPropagation(),onClick:Ht,children:["#",Nt.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Nt.number]})]})}),s.jsx(Lt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Vt||Wt?s.jsx("div",{className:"text-muted-foreground truncate",children:Vt&&Wt?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Vt}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Wt})]}):s.jsx("span",{children:Vt??Wt??""})}):null,qt?s.jsx("div",{className:"text-muted-foreground truncate",children:qt}):null,Et||Ot?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Et??"",Et&&Ot?" • ":"",Ot??"",mt?` (${mt})`:""]}):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:De("h-3.5 w-3.5 shrink-0 text-muted-foreground",D?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:De("text-muted-foreground h-3.5 w-3.5 items-center justify-center",D?"inline-flex":"hidden group-hover/gh:inline-flex"),children:ve?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:vo(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:De("h-3.5 w-3.5 shrink-0 text-muted-foreground",D?"hidden":"group-hover/gh:hidden"),style:Bt?{color:Bt}:void 0}),s.jsx("span",{className:De("text-muted-foreground h-3.5 w-3.5 items-center justify-center",D?"inline-flex":"hidden group-hover/gh:inline-flex"),children:ve?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:vo(n.label,l)})]}):vo(n.label,l)}),Le&&Yt?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||ot?_t&&Nt?s.jsxs(Mt,{children:[s.jsx(Ft,{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:Bt?{color:Bt}:void 0})})}),s.jsx(Lt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Vt||Wt?s.jsx("div",{className:"text-muted-foreground truncate",children:Vt&&Wt?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Vt}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Wt})]}):s.jsx("span",{children:Vt??Wt??""})}):null,qt?s.jsx("div",{className:"text-muted-foreground truncate",children:qt}):null,Et||Ot?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Et??"",Et&&Ot?" • ":"",Ot??"",mt?` (${mt})`:""]}):null]})})]}):s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Bt?{color:Bt}:void 0}):null,s.jsx("span",{className:De("min-w-0 truncate text-[11px] font-medium",!Yt.color&&"text-muted-foreground/80"),style:Yt.color?{color:Yt.color}:void 0,children:Yt.label})]}):null]})}),n.isArchivedBucket&&Rt.length>0?s.jsx("div",{className:De("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(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ue=>{Ue.stopPropagation(),Ir.requestDelete({sessions:Rt,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(Lt,{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:De("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(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ue=>{Ue.stopPropagation(),Ir.requestDelete({sessions:Rt,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(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:De("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(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ue=>{Ue.stopPropagation(),o&&o!==A&&C(o),O("chat"),v&&T(!1),E({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(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),ve?null:s.jsx("div",{className:De("oc-group-body",yt),children:bs})]})}const yN=i.memo(bN,xN);function wN(t){const e=gt.c(182),{t:n}=At(),{hideDirectoryControls:r,showRecentControls:o,handleOpenDirectoryDialog:a,openNewSessionDraft:c,canOpenMultiRun:l,openMultiRunLauncher:d,headerActionIconClass:u,headerActionButtonClass:m,isSessionSearchOpen:f,setIsSessionSearchOpen:g,sessionSearchInputRef:y,sessionSearchQuery:p,setSessionSearchQuery:x,hasSessionSearchQuery:b,searchMatchCount:h,collapseAllProjects:N,expandAllProjects:w,openScheduledTasksDialog:S,selectionModeEnabled:j,onToggleSelectionMode:k}=t,v=Ar(AN),D=Ar(CN),A=Ar(kN),C=Ar(NN),O=Ar(SN),T=Ar(jN);let E;e[0]===Symbol.for("react.memo_cache_sentinel")?(E=Wr(),e[0]=E):E=e[0];const F=!E;if(r)return null;let R;e[1]!==n?(R=n("sessions.sidebar.header.actions.addProject"),e[1]=n,e[2]=R):R=e[2];let L;e[3]!==u?(L=s.jsx(I,{name:"folder-add",className:u}),e[3]=u,e[4]=L):L=e[4];let B;e[5]!==a||e[6]!==m||e[7]!==R||e[8]!==L?(B=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":R,children:L})}),e[5]=a,e[6]=m,e[7]=R,e[8]=L,e[9]=B):B=e[9];let V;e[10]!==n?(V=n("sessions.sidebar.header.actions.addProject"),e[10]=n,e[11]=V):V=e[11];let M;e[12]!==V?(M=s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:V})}),e[12]=V,e[13]=M):M=e[13];let ee;e[14]!==B||e[15]!==M?(ee=s.jsxs(Mt,{children:[B,M]}),e[14]=B,e[15]=M,e[16]=ee):ee=e[16];let se;e[17]!==n?(se=n("sessions.sidebar.header.actions.newSession"),e[17]=n,e[18]=se):se=e[18];let J;e[19]!==u?(J=s.jsx(I,{name:"chat-new",className:u}),e[19]=u,e[20]=J):J=e[20];let K;e[21]!==m||e[22]!==c||e[23]!==se||e[24]!==J?(K=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:m,"aria-label":se,children:J})}),e[21]=m,e[22]=c,e[23]=se,e[24]=J,e[25]=K):K=e[25];let Z;e[26]!==n?(Z=n("sessions.sidebar.header.actions.newSession"),e[26]=n,e[27]=Z):Z=e[27];let re;e[28]!==Z?(re=s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Z})}),e[28]=Z,e[29]=re):re=e[29];let pe;e[30]!==re||e[31]!==K?(pe=s.jsxs(Mt,{children:[K,re]}),e[30]=re,e[31]=K,e[32]=pe):pe=e[32];let Se;e[33]!==n?(Se=n("sessions.sidebar.header.actions.newMultiRun"),e[33]=n,e[34]=Se):Se=e[34];const te=!l;let Ne;e[35]!==u?(Ne=s.jsx(bg,{className:u}),e[35]=u,e[36]=Ne):Ne=e[36];let Y;e[37]!==m||e[38]!==d||e[39]!==Se||e[40]!==te||e[41]!==Ne?(Y=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:m,"aria-label":Se,disabled:te,children:Ne})}),e[37]=m,e[38]=d,e[39]=Se,e[40]=te,e[41]=Ne,e[42]=Y):Y=e[42];let G;e[43]!==n?(G=n("sessions.sidebar.header.actions.newMultiRun"),e[43]=n,e[44]=G):G=e[44];let q;e[45]!==G?(q=s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:G})}),e[45]=G,e[46]=q):q=e[46];let oe;e[47]!==Y||e[48]!==q?(oe=s.jsxs(Mt,{children:[Y,q]}),e[47]=Y,e[48]=q,e[49]=oe):oe=e[49];let le;e[50]!==n?(le=n("sessions.sidebar.header.actions.scheduledTasks"),e[50]=n,e[51]=le):le=e[51];let ve;e[52]!==u?(ve=s.jsx(I,{name:"calendar-schedule",className:u}),e[52]=u,e[53]=ve):ve=e[53];let Ee;e[54]!==m||e[55]!==S||e[56]!==le||e[57]!==ve?(Ee=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,className:m,"aria-label":le,children:ve})}),e[54]=m,e[55]=S,e[56]=le,e[57]=ve,e[58]=Ee):Ee=e[58];let _e;e[59]!==n?(_e=n("sessions.sidebar.header.actions.scheduledTasks"),e[59]=n,e[60]=_e):_e=e[60];let Oe;e[61]!==_e?(Oe=s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:_e})}),e[61]=_e,e[62]=Oe):Oe=e[62];let Me;e[63]!==Ee||e[64]!==Oe?(Me=s.jsxs(Mt,{children:[Ee,Oe]}),e[63]=Ee,e[64]=Oe,e[65]=Me):Me=e[65];let he;e[66]!==pe||e[67]!==oe||e[68]!==Me||e[69]!==ee?(he=s.jsxs("div",{className:"flex items-center gap-1.5",children:[ee,pe,oe,Me]}),e[66]=pe,e[67]=oe,e[68]=Me,e[69]=ee,e[70]=he):he=e[70];let Ce;e[71]!==g?(Ce=()=>g(vN),e[71]=g,e[72]=Ce):Ce=e[72];let xe;e[73]!==n?(xe=n("sessions.sidebar.header.actions.searchSessions"),e[73]=n,e[74]=xe):xe=e[74];let ue;e[75]!==u?(ue=s.jsx(I,{name:"search",className:u}),e[75]=u,e[76]=ue):ue=e[76];let H;e[77]!==m||e[78]!==f||e[79]!==Ce||e[80]!==xe||e[81]!==ue?(H=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ce,className:m,"aria-label":xe,"aria-expanded":f,children:ue})}),e[77]=m,e[78]=f,e[79]=Ce,e[80]=xe,e[81]=ue,e[82]=H):H=e[82];let ce;e[83]!==n?(ce=n("sessions.sidebar.header.actions.searchSessions"),e[83]=n,e[84]=ce):ce=e[84];let fe;e[85]!==ce?(fe=s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ce})}),e[85]=ce,e[86]=fe):fe=e[86];let U;e[87]!==H||e[88]!==fe?(U=s.jsxs(Mt,{children:[H,fe]}),e[87]=H,e[88]=fe,e[89]=U):U=e[89];const z=j&&"bg-interactive-hover text-primary";let be;e[90]!==m||e[91]!==z?(be=De(m,z),e[90]=m,e[91]=z,e[92]=be):be=e[92];let ge;e[93]!==j||e[94]!==n?(ge=n(j?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[93]=j,e[94]=n,e[95]=ge):ge=e[95];let _;e[96]!==u?(_=s.jsx(I,{name:"checkbox-multiple",className:u}),e[96]=u,e[97]=_):_=e[97];let ye;e[98]!==k||e[99]!==j||e[100]!==be||e[101]!==ge||e[102]!==_?(ye=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:k,className:be,"aria-label":ge,"aria-pressed":j,children:_})}),e[98]=k,e[99]=j,e[100]=be,e[101]=ge,e[102]=_,e[103]=ye):ye=e[103];let $;e[104]!==j||e[105]!==n?($=n(j?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[104]=j,e[105]=n,e[106]=$):$=e[106];let Ie;e[107]!==$?(Ie=s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:$})}),e[107]=$,e[108]=Ie):Ie=e[108];let je;e[109]!==ye||e[110]!==Ie?(je=s.jsxs(Mt,{children:[ye,Ie]}),e[109]=ye,e[110]=Ie,e[111]=je):je=e[111];let Fe;e[112]!==n?(Fe=n("sessions.sidebar.header.actions.sessionDisplayMode"),e[112]=n,e[113]=Fe):Fe=e[113];let Ae;e[114]!==u?(Ae=s.jsx(I,{name:"equalizer-2",className:u}),e[114]=u,e[115]=Ae):Ae=e[115];let ne;e[116]!==m||e[117]!==Fe||e[118]!==Ae?(ne=s.jsx(Ft,{asChild:!0,children:s.jsx(en,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":Fe,children:Ae})})}),e[116]=m,e[117]=Fe,e[118]=Ae,e[119]=ne):ne=e[119];let P;e[120]!==n?(P=n("sessions.sidebar.header.displayMode.label"),e[120]=n,e[121]=P):P=e[121];let me;e[122]!==P?(me=s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:P})}),e[122]=P,e[123]=me):me=e[123];let ae;e[124]!==ne||e[125]!==me?(ae=s.jsxs(Mt,{children:[ne,me]}),e[124]=ne,e[125]=me,e[126]=ae):ae=e[126];let Be;e[127]!==v||e[128]!==C||e[129]!==n?(Be=F?s.jsxs(s.Fragment,{children:[s.jsxs(xs,{onClick:()=>C("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),v==="default"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(xs,{onClick:()=>C("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),v==="minimal"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]})]}):null,e[127]=v,e[128]=C,e[129]=n,e[130]=Be):Be=e[130];let Ge;e[131]!==A||e[132]!==o||e[133]!==D||e[134]!==n||e[135]!==T||e[136]!==O?(Ge=o?s.jsxs(s.Fragment,{children:[F?s.jsx(Tr,{}):null,s.jsxs(xs,{onClick:O,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(xs,{onClick:T,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showArchived")}),A?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]})]}):null,e[131]=A,e[132]=o,e[133]=D,e[134]=n,e[135]=T,e[136]=O,e[137]=Ge):Ge=e[137];let Ke;e[138]===Symbol.for("react.memo_cache_sentinel")?(Ke=s.jsx(Tr,{}),e[138]=Ke):Ke=e[138];let Qe;e[139]===Symbol.for("react.memo_cache_sentinel")?(Qe=s.jsx(I,{name:"contract-up-down",className:"h-4 w-4"}),e[139]=Qe):Qe=e[139];let st;e[140]!==n?(st=n("sessions.sidebar.header.displayMode.collapseAll"),e[140]=n,e[141]=st):st=e[141];let ut;e[142]!==st?(ut=s.jsx("span",{children:st}),e[142]=st,e[143]=ut):ut=e[143];let vt;e[144]!==N||e[145]!==ut?(vt=s.jsxs(xs,{onClick:N,className:"flex items-center gap-2",children:[Qe,ut]}),e[144]=N,e[145]=ut,e[146]=vt):vt=e[146];let Ve;e[147]===Symbol.for("react.memo_cache_sentinel")?(Ve=s.jsx(I,{name:"expand-up-down",className:"h-4 w-4"}),e[147]=Ve):Ve=e[147];let tt;e[148]!==n?(tt=n("sessions.sidebar.header.displayMode.expandAll"),e[148]=n,e[149]=tt):tt=e[149];let nt;e[150]!==tt?(nt=s.jsx("span",{children:tt}),e[150]=tt,e[151]=nt):nt=e[151];let xt;e[152]!==w||e[153]!==nt?(xt=s.jsxs(xs,{onClick:w,className:"flex items-center gap-2",children:[Ve,nt]}),e[152]=w,e[153]=nt,e[154]=xt):xt=e[154];let Rt;e[155]!==Be||e[156]!==Ge||e[157]!==vt||e[158]!==xt?(Rt=s.jsxs(tn,{align:"end",className:"min-w-[160px]",children:[Be,Ge,Ke,vt,xt]}),e[155]=Be,e[156]=Ge,e[157]=vt,e[158]=xt,e[159]=Rt):Rt=e[159];let bt;e[160]!==ae||e[161]!==Rt?(bt=s.jsxs(sn,{children:[ae,Rt]}),e[160]=ae,e[161]=Rt,e[162]=bt):bt=e[162];let ot;e[163]!==U||e[164]!==je||e[165]!==bt?(ot=s.jsxs("div",{className:"flex items-center gap-1.5",children:[U,je,bt]}),e[163]=U,e[164]=je,e[165]=bt,e[166]=ot):ot=e[166];let at;e[167]!==he||e[168]!==ot?(at=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[he,ot]}),e[167]=he,e[168]=ot,e[169]=at):at=e[169];let Ut;e[170]!==b||e[171]!==f||e[172]!==h||e[173]!==y||e[174]!==p||e[175]!==g||e[176]!==x||e[177]!==n?(Ut=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:y,value:p,onChange:_t=>x(_t.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:_t=>{_t.key==="Escape"&&(_t.stopPropagation(),b?x(""):g(!1))}}),p.length>0?s.jsx("button",{type:"button",onClick:()=>x(""),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[170]=b,e[171]=f,e[172]=h,e[173]=y,e[174]=p,e[175]=g,e[176]=x,e[177]=n,e[178]=Ut):Ut=e[178];let Nt;return e[179]!==at||e[180]!==Ut?(Nt=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:[at,Ut]})}),e[179]=at,e[180]=Ut,e[181]=Nt):Nt=e[181],Nt}function vN(t){return!t}function jN(t){return t.toggleArchivedSessions}function SN(t){return t.toggleRecentSection}function NN(t){return t.setDisplayMode}function kN(t){return t.showArchivedSessions}function CN(t){return t.showRecentSection}function AN(t){return t.displayMode}const sf=7;function DN({sections:t,renderSessionNode:e,currentSessionId:n,editingId:r,openSidebarMenuKey:o,variant:a="section",initialVisibleCount:c=sf,batchSize:l=sf}){const{t:d}=At(),[u,m]=i.useState(new Set),[f,g]=i.useState(new Map),y=a==="flat",p=i.useCallback(w=>{g(S=>{if(!S.has(w))return S;const j=new Map(S);return j.delete(w),j})},[]),x=i.useCallback(w=>{p(w),m(S=>{const j=new Set(S);return j.has(w)?j.delete(w):j.add(w),j})},[p]),b=i.useCallback((w,S,j)=>{g(k=>{const v=Math.min(j,S+l),D=new Map(k);return D.set(w,v),D})},[l]),h=i.useCallback(w=>{const S=new Set;Gi(w,n,S);const j=new Set;Gi(w,r,j);const k=Fo(w,o,"recent",!1),v=new WeakMap,D=C=>{v.set(C,Ra(C)),C.children.forEach(D)};w.forEach(D);const A=C=>({subtreeContainsActive:S,subtreeContainsEditing:j,menuOpenSessionId:k,nodeStructureKey:v.get(C)??"",childRenderExtrasFor:A});return C=>({subtreeContainsActive:S,subtreeContainsEditing:j,menuOpenSessionId:k,nodeStructureKey:v.get(C)??"",childRenderExtrasFor:A})},[n,r,o]),N=t.filter(w=>w.items.length>0);return N.length===0?null:s.jsx("div",{className:De(y?"space-y-0.5 pb-2":"space-y-2 pb-2 pt-1"),children:N.map(w=>{const S=u.has(w.key),j=Math.max(c,f.get(w.key)??c),k=w.items.slice(0,j),v=w.items.length-k.length,D=!y&&w.items.length>c&&v===0,A=h(k.map(O=>O.node)),C=O=>e(O.node,0,O.groupDirectory,O.projectId,!1,O.secondaryMeta,"recent",A(O.node));return y?s.jsxs("div",{className:"space-y-0.5",children:[k.map(C),v>0?s.jsx("button",{type:"button",onClick:()=>b(w.key,k.length,w.items.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:d("sessions.sidebar.group.showMore")}):null]},w.key):s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>x(w.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":!S,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:S?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:w.title})]}),S?null:s.jsxs("div",{className:De("space-y-0.5 pl-7"),children:[k.map(C),v>0?s.jsx("button",{type:"button",onClick:()=>b(w.key,k.length,w.items.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:d("sessions.sidebar.group.showMore")}):null,D?s.jsx("button",{type:"button",onClick:()=>p(w.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:d("sessions.sidebar.group.showFewer")}):null]})]},w.key)})})}const Il="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 IN(t){const e=gt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:a,showRuntimeButtons:c,showUpdateButton:l}=t,d=c===void 0?!0:c,u=l===void 0?!0:l,{t:m}=At();let f;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(f=d?s.jsxs(s.Fragment,{children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Il,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(I,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(Lt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Il,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(I,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(Lt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:Il,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(I,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(Lt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=f):f=e[5];let g;e[6]!==a||e[7]!==u||e[8]!==m?(g=u?s.jsx($e,{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:a,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=a,e[7]=u,e[8]=m,e[9]=g):g=e[9];let y;return e[10]!==f||e[11]!==g?(y=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]=y):y=e[12],y}const PN=t=>{const e=gt.c(58),{id:n,projectLabel:r,projectDescription:o,projectIcon:a,projectColor:c,projectIconImage:l,projectIconBackground:d,isCollapsed:u,isActiveProject:m,isRepo:f,isDesktopShell:g,isStuck:y,hideDirectoryControls:p,alwaysShowActions:x,onToggle:b,onNewSession:h,onNewWorktreeSession:N,onRenameStart:w,onClose:S,sentinelRef:j,children:k,showCreateButtons:v,hideHeader:D,openSidebarMenuKey:A,setOpenSidebarMenuKey:C}=t,O=v===void 0?!0:v,T=D===void 0?!1:D,{t:E}=At(),{currentTheme:F}=Hr();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:L,listeners:B,setNodeRef:V,transform:M,transition:ee,isDragging:se}=ic(R),J=i.useRef(!1),K=`project:${n}`,Z=A===K,[re,pe]=i.useState(!1),Se=a?Sc[a]:null,te=c?Ga[c]??null:null;let Ne;e[2]!==K||e[3]!==C?(Ne=fe=>{fe&&pe(!1),C(fe?K:null)},e[2]=K,e[3]=C,e[4]=Ne):Ne=e[4];const Y=Ne;let G;e[5]!==p||e[6]!==f||e[7]!==S||e[8]!==h||e[9]!==w||e[10]!==O||e[11]!==E?(G=fe=>s.jsxs(s.Fragment,{children:[O&&!f&&!p&&h&&s.jsxs(fe,{onClick:h,children:[s.jsx(I,{name:"add",className:"mr-1.5 h-4 w-4"}),E("sessions.sidebar.project.actions.newSession")]}),s.jsxs(fe,{onClick:w,children:[s.jsx(I,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),E("sessions.sidebar.session.menu.rename")]}),s.jsxs(fe,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1.5 h-4 w-4"}),E("sessions.sidebar.project.actions.closeProject")]})]}),e[5]=p,e[6]=f,e[7]=S,e[8]=h,e[9]=w,e[10]=O,e[11]=E,e[12]=G):G=e[12];const q=G,oe=EN,le=MN,ve=FN;let Ee;e[13]===Symbol.for("react.memo_cache_sentinel")?(Ee=fe=>{(fe.button===2||fe.button===0&&fe.ctrlKey)&&(J.current=!0)},e[13]=Ee):Ee=e[13];const _e=Ee;let Oe;e[14]!==b?(Oe=()=>{if(J.current){J.current=!1;return}b()},e[14]=b,e[15]=Oe):Oe=e[15];const Me=Oe;let he;e[16]!==M?(he=oc.Transform.toString(M),e[16]=M,e[17]=he):he=e[17];let Ce;e[18]!==he||e[19]!==ee?(Ce={transform:he,transition:ee},e[18]=he,e[19]=ee,e[20]=Ce):Ce=e[20];const xe=se&&"opacity-30";let ue;e[21]!==xe?(ue=De("relative",xe),e[21]=xe,e[22]=ue):ue=e[22];let H;e[23]!==x||e[24]!==L||e[25]!==F||e[26]!==Y||e[27]!==Me||e[28]!==p||e[29]!==T||e[30]!==te||e[31]!==n||e[32]!==m||e[33]!==u||e[34]!==re||e[35]!==g||e[36]!==Z||e[37]!==f||e[38]!==y||e[39]!==B||e[40]!==h||e[41]!==N||e[42]!==o||e[43]!==d||e[44]!==l||e[45]!==Se||e[46]!==r||e[47]!==q||e[48]!==j||e[49]!==O||e[50]!==E?(H=T?null:s.jsxs(s.Fragment,{children:[g&&s.jsx("div",{ref:j,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(Dc,{open:re,onOpenChange:pe,children:[s.jsx(Ac,{render:s.jsx("div",{className:De("w-full text-left group/project select-none"),style:{backgroundColor:g&&y?"transparent":void 0},onContextMenu:fe=>{p||(fe.preventDefault(),pe(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...L,children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:_e,onClick:Me,...B,className:De("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?x?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":x?"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:De("h-3.5 w-3.5 items-center justify-center text-muted-foreground",x?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:u?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:De("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",x?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx(Ka,{project:{id:n,iconImage:l},options:{themeVariant:F.metadata.variant,iconColor:F.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Se?s.jsx(I,{name:Se,className:"h-3.5 w-3.5",style:te?{color:te}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:te?{color:te}:void 0})})}):Se?s.jsx(I,{name:Se,className:De("h-3.5 w-3.5",x?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:te?{color:te}:void 0}):s.jsx(I,{name:"folder",className:De("h-3.5 w-3.5 text-muted-foreground/80",x?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:te?{color:te}:void 0})]}),s.jsx("span",{className:De("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Lt,{side:"right",sideOffset:8,children:o})]}),s.jsxs("div",{className:De("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",O?"right-7":"right-0.5"),children:[O&&f&&!p&&N?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:fe=>{fe.stopPropagation(),N()},className:De("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",x?"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":E("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(I,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:E("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,p?null:s.jsxs(sn,{open:Z,onOpenChange:Y,children:[s.jsx(en,{asChild:!0,children:s.jsx("button",{type:"button",className:De("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",Z?"opacity-100 pointer-events-auto":x?"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":E("sessions.sidebar.project.actions.projectMenu"),onPointerDown:le,onMouseDown:ve,onClick:oe,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(tn,{align:"end",className:"min-w-[180px]",children:q(xs)})]})]}),O&&h?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:fe=>{fe.stopPropagation(),h()},className:De("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",x?"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":E(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(Lt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:E(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(kc,{className:"min-w-[180px]",children:q(Cc)})]})]}),e[23]=x,e[24]=L,e[25]=F,e[26]=Y,e[27]=Me,e[28]=p,e[29]=T,e[30]=te,e[31]=n,e[32]=m,e[33]=u,e[34]=re,e[35]=g,e[36]=Z,e[37]=f,e[38]=y,e[39]=B,e[40]=h,e[41]=N,e[42]=o,e[43]=d,e[44]=l,e[45]=Se,e[46]=r,e[47]=q,e[48]=j,e[49]=O,e[50]=E,e[51]=H):H=e[51];let ce;return e[52]!==k||e[53]!==V||e[54]!==ue||e[55]!==H||e[56]!==Ce?(ce=s.jsxs("div",{ref:V,style:Ce,className:ue,children:[H,k]}),e[52]=k,e[53]=V,e[54]=ue,e[55]=H,e[56]=Ce,e[57]=ce):ce=e[57],ce},TN=t=>{const e=gt.c(21),{id:n,disabled:r,children:o}=t,a=r===void 0?!1:r;let c;e[0]!==a||e[1]!==n?(c={id:n,disabled:a},e[0]=a,e[1]=n,e[2]=c):c=e[2];const{listeners:l,setNodeRef:d,setActivatorNodeRef:u,transform:m,transition:f,isDragging:g}=ic(c);let y;e[3]!==l||e[4]!==u?(y={listeners:l,setActivatorNodeRef:u},e[3]=l,e[4]=u,e[5]=y):y=e[5];const p=y;let x;e[6]!==m?(x=oc.Transform.toString(m),e[6]=m,e[7]=x):x=e[7];let b;e[8]!==x||e[9]!==f?(b={transform:x,transition:f},e[8]=x,e[9]=f,e[10]=b):b=e[10];const h=g&&"opacity-50";let N;e[11]!==h?(N=De("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]!==d||e[17]!==b||e[18]!==N||e[19]!==w?(S=s.jsx("div",{ref:d,style:b,className:N,children:w}),e[16]=d,e[17]=b,e[18]=N,e[19]=w,e[20]=S):S=e[20],S},RN=i.memo(TN);function EN(t){t.stopPropagation()}function MN(t){t.stopPropagation()}function FN(t){t.stopPropagation()}function LN(t){const{t:e}=At(),n=ga(yo(xa,{activationConstraint:{distance:8}}),yo($h,{coordinateGetter:_h})),r=ga(yo(xa,{activationConstraint:{distance:8}})),o=i.useRef(null),a=i.useRef(new Map),c=(l,d)=>{const u=a.current,m=u.get(l);if(m&&m.groups===d)return m.ordered;const f=t.getOrderedGroups(l,d);if(u.set(l,{groups:d,ordered:f}),u.size>256){const g=u.keys().next().value;g!==void 0&&u.delete(g)}return f};return t.sharedSessionsOnly?s.jsxs(Vn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:De("space-y-1 pb-1 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.hasSharedSessions?null:t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState]}):t.projectSections.length===0?s.jsxs(Vn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:De("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.emptyState]}):t.sectionsForRender.length===0?s.jsx(Vn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:De("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:t.searchEmptyState}):s.jsxs(Vn,{ref:o,useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:De("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const l=t.sectionsForRender.find(f=>f.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!l)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const d=l.groups.find(f=>f.isMain&&f.sessions.length>0)??l.groups.find(f=>f.sessions.length>0)??l.groups.find(f=>f.isMain)??l.groups[0];if(!d)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")});const u=l.groups.find(f=>f.isArchivedBucket);return[d,...u&&u.id!==d.id?[u]:[]].map(f=>{const g=`${l.project.id}:${f.id}`,y=f.id===d.id;return s.jsx(i.Fragment,{children:t.renderGroupSessions(f,g,l.project.id,y,null,!0,o)},g)})})()}):s.jsx(s.Fragment,{children:s.jsxs(ba,{sensors:n,collisionDetection:ya,onDragEnd:l=>{if(t.isInlineEditing)return;const{active:d,over:u}=l;if(!u||d.id===u.id)return;const m=t.sectionsForRender.findIndex(g=>g.project.id===d.id),f=t.sectionsForRender.findIndex(g=>g.project.id===u.id);m===-1||f===-1||m===f||t.reorderProjects(m,f)},children:[s.jsx(Fl,{items:t.sectionsForRender.map(l=>l.project.id),strategy:Ll,children:t.sectionsForRender.map(l=>{const d=l.project,u=d.id,m=gm(d.label?.trim()||Ei(d.normalizedPath,t.homeDirectory)||d.normalizedPath),f=Na(d.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(u),y=u===t.activeProjectId,p=t.projectRepoStatus.get(u),x=c(u,l.groups),b=x.find(N=>N.isMain)??null,h=b?x.filter(N=>N.id!==b.id):x;return s.jsx(PN,{id:u,projectLabel:m,projectDescription:f,projectIcon:d.icon,projectColor:d.color,projectIconImage:d.iconImage,projectIconBackground:d.iconBackground,isCollapsed:g,isActiveProject:y,isRepo:!!p,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(u),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(u),onNewSession:()=>{u!==t.activeProjectId&&t.setActiveProjectIdOnly(u),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:d.normalizedPath})},onNewWorktreeSession:()=>{u!==t.activeProjectId&&t.setActiveProjectIdOnly(u),t.setActiveMainTab("chat"),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(u),onClose:()=>t.removeProject(u),sentinelRef:N=>{t.projectHeaderSentinelRefs.current.set(u,N)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:g?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:l.groups.length>0?s.jsxs(ba,{sensors:r,collisionDetection:ya,onDragEnd:N=>{if(t.isInlineEditing)return;const{active:w,over:S}=N;if(!S||w.id===S.id)return;const j=h.findIndex(A=>A.id===w.id),k=h.findIndex(A=>A.id===S.id);if(j===-1||k===-1||j===k)return;const v=Nf(h,j,k).map(A=>A.id),D=b?[b.id,...v]:v;t.setGroupOrderByProject(A=>{const C=new Map(A);return C.set(u,D),C})},children:[b?t.renderGroupSessions(b,`${u}:${b.id}`,u,!0,null,void 0,o):null,s.jsx(Fl,{items:h.map(N=>N.id),strategy:Ll,children:h.map(N=>{const w=`${u}:${N.id}`;return s.jsx(RN,{id:N.id,disabled:t.isInlineEditing,children:S=>t.renderGroupSessions(N,w,u,!1,S,void 0,o)},N.id)})}),s.jsx(Bl,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")})})},u)})}),s.jsx(Bl,{dropAnimation:null})]})})]})}function ON(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(Zi(),{month:"short"}),r=e.getDate(),o=e.getFullYear(),a=String(e.getHours()).padStart(2,"0"),c=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${o}, ${a}:${c}`}function BN(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 VN(t){const e=t.info.role==="user"?"User":"Assistant",n=ON(t.info.time?.created),r=BN(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
|
|
170
|
+
|
|
171
|
+
*${o}*`:`**${e}**`}function _N(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function rh(t){const e=VN(t),n=_N(t.parts).trim();return n?`${e}
|
|
172
|
+
|
|
173
|
+
${n}`:""}function ih(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",o=`${n} Sub-agent: ${t.title}${r}
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
`,a=t.records.map(rh).filter(Boolean).join(`
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
`),c=[o+a];for(const l of t.children)c.push(ih(l,e+1));return c.join(`
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
`)}function $N(t,e,n){const r=e?.trim()||"Session",o=new Date().toISOString().split("T")[0],a=`# ${r}
|
|
186
|
+
|
|
187
|
+
*Exported on ${o}*
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
`,c=t.map(rh).filter(Boolean).join(`
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
`);let l=a+c;if(n&&n.length>0){const d=n.map(u=>ih(u,1)).join(`
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
`);l+=`
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
`+d}return l}function zN(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 UN(t,e){const n=await rp(e,t);if(n)return n;if(!Wr())return null;try{const r=await Lo()?.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 WN(t){const e=Lo()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await ip(t)?!0:wa(t)}function HN(){return yc()}function GN(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 KN=(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 a=e.get(o);if(a)for(const c of a)r.has(c)||(r.add(c),n.push(c))}return n},On=io()((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 a=e(),c=new Set(a.selectedIds);let l=a.scopeKey,d=a.anchorId;r!==null&&a.scopeKey!==null&&r!==a.scopeKey?(c.clear(),l=r,d=null):l===null&&r!==null&&(l=r);const m=o&&o.length>0?[n,...o]:[n];if(c.has(n)){for(const g of m)c.delete(g);d===n&&(d=null)}else{for(const g of m)c.add(g);d=n}c.size===0?t({selectedIds:c,scopeKey:null,anchorId:null}):t({selectedIds:c,scopeKey:l,anchorId:d})},setRange:(n,r,o,a,c)=>{const l=e();if(o.length===0)return;const d=n&&o.includes(n)?n:o[0],u=o.indexOf(d),m=o.indexOf(r);if(u<0||m<0)return;const[f,g]=u<=m?[u,m]:[m,u],y=o.slice(f,g+1),p=KN(y,c),b=a!==null&&l.scopeKey!==null&&a!==l.scopeKey?new Set:new Set(l.selectedIds);for(const h of p)b.add(h);t({selectedIds:b,scopeKey:a??l.scopeKey,anchorId:d})},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 a of n)o.delete(a);o.size!==r.selectedIds.size&&(o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o}))}})),qN=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,oh=/^g[1-9]\d*$/,xo=(t,e,n,r,o)=>{if(!qN.test(t)||e!==void 0&&!oh.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 a=Number.parseInt(o,10);return!Number.isSafeInteger(a)||a<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:a,fusion:!1}},ha=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 xo(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,l,d,u]=e;return oh.test(l)?xo(n,l,d,u,void 0):xo(n,void 0,l,d,u)}const[,r,o,a,c]=e;return r===""?xo(n,void 0,o,a,c):xo(n,r,o,a,c)},YN=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("/")},QN=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},ah=t=>{const e=gt.c(36),{value:n,onChange:r,className:o,disabled:a,id:c,portalToBody:l}=t,{t:d}=At(),u=es(JN),m=es(XN),f=es(ZN);let g;e[0]!==u?(g=u(),e[0]=u,e[1]=g):g=e[1];const y=g;let p;e[2]!==y?(p=y.filter(e2),e[2]=y,e[3]=p):p=e[3];const x=p;let b,h;e[4]!==y.length||e[5]!==m?(b=()=>{y.length===0&&m()},h=[y.length,m],e[4]=y.length,e[5]=m,e[6]=b,e[7]=h):(b=e[6],h=e[7]),i.useEffect(b,h);let N,w;e[8]!==f||e[9]!==a||e[10]!==r||e[11]!==x||e[12]!==n?(N=()=>{if(a)return;const T=n.trim();if(T.length>0&&x.some(R=>R.name===T))return;const E=typeof f=="string"&&f.trim().length>0?f.trim():null;if(E&&x.some(R=>R.name===E)){r(E);return}const F=x[0]?.name;F&&r(F)},w=[f,a,r,x,n],e[8]=f,e[9]=a,e[10]=r,e[11]=x,e[12]=n,e[13]=N,e[14]=w):(N=e[13],w=e[14]),i.useEffect(N,w);const S=n.trim().length>0?n:void 0;let j;e[15]!==o?(j=De("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]=j):j=e[16];let k;e[17]!==d?(k=d("multirun.agentSelector.placeholder"),e[17]=d,e[18]=k):k=e[18];let v;e[19]!==k?(v=s.jsx(Nn,{placeholder:k}),e[19]=k,e[20]=v):v=e[20];let D;e[21]!==c||e[22]!==j||e[23]!==v?(D=s.jsx($n,{id:c,size:"lg",className:j,children:v}),e[21]=c,e[22]=j,e[23]=v,e[24]=D):D=e[24];let A;e[25]!==x?(A=x.length>0&&s.jsx(_l,{children:x.map(t2)}),e[25]=x,e[26]=A):A=e[26];let C;e[27]!==l||e[28]!==A?(C=s.jsx(zn,{fitContent:!0,portalToBody:l,children:A}),e[27]=l,e[28]=A,e[29]=C):C=e[29];let O;return e[30]!==a||e[31]!==r||e[32]!==S||e[33]!==D||e[34]!==C?(O=s.jsxs(_n,{value:S,onValueChange:r,disabled:a,children:[D,C]}),e[30]=a,e[31]=r,e[32]=S,e[33]=D,e[34]=C,e[35]=O):O=e[35],O};function JN(t){return t.getVisibleAgents}function XN(t){return t.loadAgents}function ZN(t){return t.currentAgentName}function e2(t){return t.mode!=="subagent"}function t2(t){return s.jsx(Is,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const lh="h-7",Ao=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,s2=t=>{const e=gt.c(12),{model:n,instanceIndex:r,totalSameModel:o,onRemove:a}=t,c=n.displayName||`${n.providerID}/${n.modelID}`,l=o>1?`${c} (${r})`:c;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=De("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",lh),e[0]=d):d=e[0];let u;e[1]!==n.providerID?(u=s.jsx(Do,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=u):u=e[2];let m;e[3]!==l?(m=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:l}),e[3]=l,e[4]=m):m=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]!==a?(g=s.jsx("button",{type:"button",onClick:a,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=a,e[7]=g):g=e[7];let y;return e[8]!==u||e[9]!==m||e[10]!==g?(y=s.jsxs("div",{className:d,children:[u,m,g]}),e[8]=u,e[9]=m,e[10]=g,e[11]=y):y=e[11],y},ch=t=>{const e=gt.c(118),{selectedModels:n,onAdd:r,onRemove:o,onUpdate:a,minModels:c,addButtonLabel:l,showChips:d,maxModels:u,addButtonClassName:m,dropdownSide:f,dropdownClassName:g,containerClassName:y,triggerIcon:p}=t,x=d===void 0?!0:d,b=f===void 0?"top":f,{t:h}=At(),N=es(n2),w=es(r2),S=Re(i2),j=Re(o2),{favoriteModelsList:k,recentModelsList:v}=yg(),D=Re(a2),[A,C]=i.useState(!1),[O,T]=i.useState(""),[E,F]=i.useState(null),R=i.useRef(null),L=i.useRef(null),B=u===1,V=u===void 0||n.length<u||B;let M;if(e[0]!==n){M=new Map;for(const P of n){const me=`${P.providerID}:${P.modelID}`;M.set(me,(M.get(me)||0)+1)}e[0]=n,e[1]=M}else M=e[1];const ee=M;let se;e[2]!==n?(se=P=>n.filter(ae=>ae.providerID===P.providerID&&ae.modelID===P.modelID).findIndex(ae=>ae.instanceId===P.instanceId)+1,e[2]=n,e[3]=se):se=e[3];const J=se;let K,Z;e[4]!==b||e[5]!==A?(K=()=>{if(!A||!L.current)return;const P=L.current.getBoundingClientRect();if(b==="bottom"){const Qe=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-P.bottom-16-112;F(Math.max(160,Math.min(320,Qe)));return}let me=L.current.parentElement;for(;me&&!(me.getAttribute("role")==="dialog"||me.hasAttribute("data-scroll-shadow"));){const Ge=getComputedStyle(me);if(Ge.overflow==="auto"||Ge.overflow==="hidden"||Ge.overflowY==="auto"||Ge.overflowY==="hidden")break;me=me.parentElement}const ae=me?me.getBoundingClientRect().top:0,Be=P.top-ae-16;F(Math.max(150,Math.min(300,Be)))},Z=[b,A],e[4]=b,e[5]=A,e[6]=K,e[7]=Z):(K=e[6],Z=e[7]),i.useEffect(K,Z);let re,pe;e[8]!==V||e[9]!==A?(re=()=>{!V&&A&&(C(!1),T(""))},pe=[V,A],e[8]=V,e[9]=A,e[10]=re,e[11]=pe):(re=e[10],pe=e[11]),i.useEffect(re,pe);let Se,te;e[12]!==A?(Se=()=>{if(!A)return;const P=me=>{R.current&&!R.current.contains(me.target)&&(C(!1),T(""))};return document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},te=[A],e[12]=A,e[13]=Se,e[14]=te):(Se=e[13],te=e[14]),i.useEffect(Se,te);let Ne;e[15]!==B||e[16]!==r||e[17]!==a||e[18]!==n.length?(Ne=P=>{const me={providerID:P.providerID,modelID:P.modelID,displayName:P.model.name||P.modelID,instanceId:Ao()};B&&n.length>0&&a?a(0,me):r(me),B&&(C(!1),T(""))},e[15]=B,e[16]=r,e[17]=a,e[18]=n.length,e[19]=Ne):Ne=e[19];const Y=Ne;let G;e[20]!==h?(G=h("multirun.modelMultiSelect.search.placeholder"),e[20]=h,e[21]=G):G=e[21];let q;e[22]!==h?(q=h("multirun.modelMultiSelect.search.noResults"),e[22]=h,e[23]=q):q=e[23];let oe;e[24]!==h?(oe=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=oe):oe=e[25];let le;e[26]!==h?(le=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=le):le=e[27];let ve;e[28]!==h?(ve=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=ve):ve=e[29];let Ee;e[30]!==h?(Ee=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=Ee):Ee=e[31];let _e;e[32]!==h?(_e=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=_e):_e=e[33];let Oe;e[34]!==h?(Oe=h("chat.modelControls.capabilities"),e[34]=h,e[35]=Oe):Oe=e[35];let Me;e[36]!==h?(Me=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=Me):Me=e[37];let he;e[38]!==h?(he=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=he):he=e[39];let Ce;e[40]!==h?(Ce=h("chat.modelControls.input"),e[40]=h,e[41]=Ce):Ce=e[41];let xe;e[42]!==h?(xe=h("chat.modelControls.output"),e[42]=h,e[43]=xe):xe=e[43];let ue;e[44]!==h?(ue=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=ue):ue=e[45];let H;e[46]!==G||e[47]!==q||e[48]!==oe||e[49]!==le||e[50]!==ve||e[51]!==Ee||e[52]!==_e||e[53]!==Oe||e[54]!==Me||e[55]!==he||e[56]!==Ce||e[57]!==xe||e[58]!==ue?(H={searchPlaceholder:G,noResults:q,favorites:oe,recent:le,keyboardHint:ve,favorite:Ee,unfavorite:_e,capabilities:Oe,capabilityToolCalling:Me,capabilityReasoning:he,input:Ce,output:xe,costPerMillion:ue},e[46]=G,e[47]=q,e[48]=oe,e[49]=le,e[50]=ve,e[51]=Ee,e[52]=_e,e[53]=Oe,e[54]=Me,e[55]=he,e[56]=Ce,e[57]=xe,e[58]=ue,e[59]=H):H=e[59];const ce=H;let fe;e[60]!==y?(fe=De("relative",y),e[60]=y,e[61]=fe):fe=e[61];let U;e[62]!==m?(U=De(lh,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",m),e[62]=m,e[63]=U):U=e[63];const z=!V;let be;e[64]!==A?(be=()=>{C(!A)},e[64]=A,e[65]=be):be=e[65];let ge;e[66]!==p?(ge=p??s.jsx(I,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=p,e[67]=ge):ge=e[67];let _;e[68]!==l||e[69]!==h?(_=l??h("multirun.modelMultiSelect.actions.addModel"),e[68]=l,e[69]=h,e[70]=_):_=e[70];let ye;e[71]!==U||e[72]!==z||e[73]!==be||e[74]!==ge||e[75]!==_?(ye=s.jsxs($e,{ref:L,type:"button",variant:"outline",size:"sm",className:U,disabled:z,onClick:be,children:[ge,_]}),e[71]=U,e[72]=z,e[73]=be,e[74]=ge,e[75]=_,e[76]=ye):ye=e[76];let $;e[77]!==E||e[78]!==V||e[79]!==g||e[80]!==b||e[81]!==k||e[82]!==Y||e[83]!==D||e[84]!==j||e[85]!==A||e[86]!==ce||e[87]!==ee||e[88]!==w||e[89]!==N||e[90]!==v||e[91]!==O||e[92]!==S?($=A?s.jsx("div",{className:De("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(wg,{providers:N,favoriteModels:k,recentModels:v,modelsMetadata:w,hiddenModels:D,searchQuery:O,onSearchQueryChange:T,onSelect:Y,labels:ce,selectionCount:P=>ee.get(`${P.providerID}:${P.modelID}`)||0,disabled:!V,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:E?`${E}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:A,isFavorite:P=>j(P.providerID,P.modelID),onToggleFavorite:P=>S(P.providerID,P.modelID),onEscape:()=>{C(!1),T("")}})}):null,e[77]=E,e[78]=V,e[79]=g,e[80]=b,e[81]=k,e[82]=Y,e[83]=D,e[84]=j,e[85]=A,e[86]=ce,e[87]=ee,e[88]=w,e[89]=N,e[90]=v,e[91]=O,e[92]=S,e[93]=$):$=e[93];let Ie;e[94]!==fe||e[95]!==ye||e[96]!==$?(Ie=s.jsxs("div",{className:fe,ref:R,children:[ye,$]}),e[94]=fe,e[95]=ye,e[96]=$,e[97]=Ie):Ie=e[97];let je;e[98]!==J||e[99]!==ee||e[100]!==o||e[101]!==a||e[102]!==N||e[103]!==n||e[104]!==x||e[105]!==h?(je=x&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((P,me)=>{const ae=`${P.providerID}:${P.modelID}`,Be=ee.get(ae)||1,Ge=J(P),Qe=N.find(Ve=>Ve.id===P.providerID)?.models?.find(Ve=>Ve.id===P.modelID),st=Qe?.variants?Object.keys(Qe.variants):[],ut=st.length>0,vt=P.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(s2,{model:P,instanceIndex:Ge,totalSameModel:Be,onRemove:()=>o(me)}),ut&&s.jsxs(_n,{value:vt,onValueChange:Ve=>{if(!a)return;a(me,{...P,variant:Ve==="__default__"?void 0:Ve})},children:[s.jsxs($n,{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:De("h-3.5 w-3.5 flex-shrink-0",vt==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Nn,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:Ve=>Ve==="__default__"?h("multirun.modelMultiSelect.variant.default"):Ve})]}),s.jsxs(zn,{fitContent:!0,children:[s.jsx(Is,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),st.map(l2)]})]})]},P.instanceId)})}),e[98]=J,e[99]=ee,e[100]=o,e[101]=a,e[102]=N,e[103]=n,e[104]=x,e[105]=h,e[106]=je):je=e[106];let Fe;e[107]!==Ie||e[108]!==je?(Fe=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Ie,je]}),e[107]=Ie,e[108]=je,e[109]=Fe):Fe=e[109];let Ae;e[110]!==u||e[111]!==c||e[112]!==n.length||e[113]!==h?(Ae=c!==void 0&&n.length<c&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:u!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:c,max:u}):h("multirun.modelMultiSelect.validation.minOnly",{min:c})}),e[110]=u,e[111]=c,e[112]=n.length,e[113]=h,e[114]=Ae):Ae=e[114];let ne;return e[115]!==Fe||e[116]!==Ae?(ne=s.jsxs("div",{className:"space-y-2",children:[Fe,Ae]}),e[115]=Fe,e[116]=Ae,e[117]=ne):ne=e[117],ne};function n2(t){return t.providers}function r2(t){return t.modelsMetadata}function i2(t){return t.toggleFavoriteModel}function o2(t){return t.isFavoriteModel}function a2(t){return t.hiddenModels}function l2(t){return s.jsx(Is,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const c2=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
204
|
+
|
|
205
|
+
--- RESULT ${n+1}: ${r} ---
|
|
206
|
+
${e.trim()}
|
|
207
|
+
--- END RESULT ${n+1} ---`},nf=(t,e)=>dt.getState().getWorktreeMetadata(t)?.projectDirectory??e,d2=async t=>{const e=t.directory??void 0,n=vg(t.session.id,e);if(n.length===0&&t.directory){const o=(await Bn.withDirectory(t.directory,()=>Bn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let a=o.length-1;a>=0;a-=1){const c=o[a];if(c.info?.role==="assistant")return Dd(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return Dd(jg(o.id,e)).trim()}return""};function u2({session:t,open:e,onOpenChange:n}){const{t:r}=At(),o=fc(),a=xr(V=>V.activeSessions),c=xr(V=>V.archivedSessions),l=es(V=>V.providers),d=es(V=>V.currentProviderId),u=es(V=>V.currentModelId),m=es(V=>V.currentAgentName),[f,g]=i.useState(d??""),[y,p]=i.useState(u??""),[x,b]=i.useState(()=>d&&u?[{providerID:d,modelID:u,instanceId:Ao()}]:[]),[h,N]=i.useState(""),[w,S]=i.useState(m??""),[j,k]=i.useState([]),[v,D]=i.useState(!1),A=i.useMemo(()=>ha(t.title),[t.title]),C=i.useMemo(()=>{const V=new Map;for(const M of o)V.set(M.id,M);for(const M of a)V.set(M.id,M);for(const M of c)V.set(M.id,M);return t.id&&V.set(t.id,t),Array.from(V.values())},[a,c,o,t]);i.useEffect(()=>{if(!e||!A)return;const V=dt.getState().getDirectoryForSession(t.id),M=nf(t.id,V),ee=C.map(se=>{const J=ha(se.title);if(!J||J.groupSlug!==A.groupSlug||J.fusion||(J.runGroup??null)!==(A.runGroup??null))return null;const K=dt.getState().getDirectoryForSession(se.id)??Pr(se),Z=nf(se.id,K);return M&&Z&&M!==Z?null:{session:se,directory:K,projectDirectory:Z}}).filter(se=>se!==null).sort((se,J)=>(se.session.time?.created??0)-(J.session.time?.created??0));k(ee)},[C,e,A,t.id]);const T=l.find(V=>V.id===f)?.models.find(V=>V.id===y),E=T?.variants?Object.keys(T.variants):[],F=!!(A&&f&&y&&j.length>0&&!v),R=i.useCallback(V=>{b([V]),g(V.providerID),p(V.modelID),N("")},[]),L=x[0]?.displayName||x[0]?.modelID||r("multirun.fusion.model.placeholder"),B=async()=>{if(!(!A||!f||!y)){D(!0);try{const V=await Promise.all(j.map(re=>d2(re))),M=j.map((re,pe)=>({source:re,text:V[pe]??""})).filter(re=>re.text.trim().length>0);if(M.length===0){de.error(r("multirun.fusion.toast.noOutputs"));return}const ee=j[0]?.projectDirectory??j[0]?.directory??null,se=QN(A.groupSlug,f,y,A.runGroup),[J,K]=await Promise.all([Rn("session.fusion.visible"),Rn("session.fusion.instructions")]),Z=await dt.getState().createSession(se,ee,null);if(!Z)throw new Error("Failed to create fusion session");dt.getState().setCurrentSession(Z.id,ee),n(!1),await Bn.sendMessage({id:Z.id,providerID:f,modelID:y,variant:h||void 0,agent:w||void 0,text:J,additionalParts:[{text:K,synthetic:!0},...M.map((re,pe)=>({text:c2(re.source,re.text,pe),synthetic:!0})),{text:`
|
|
208
|
+
|
|
209
|
+
--- FUSION INPUTS END ---
|
|
210
|
+
Now write the final fused answer.`,synthetic:!0}],directory:ee??Bn.getDirectory()})}catch(V){console.error("[MultiRunFusion] Failed to start fusion",V),de.error(r("multirun.fusion.toast.failed"))}finally{D(!1)}}};return s.jsx(Ls,{open:e,onOpenChange:n,children:s.jsxs(Fs,{className:"max-w-xl overflow-visible",children:[s.jsxs(Us,{children:[s.jsx($s,{children:r("multirun.fusion.title")}),s.jsx(an,{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(ch,{selectedModels:x,onAdd:R,onUpdate:(V,M)=>R(M),onRemove:()=>{b([]),g(""),p(""),N("")},maxModels:1,addButtonLabel:L,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(Do,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),E.length>0?s.jsxs(_n,{value:h||"__default__",onValueChange:V=>N(V==="__default__"?"":V),children:[s.jsxs($n,{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(Nn,{children:V=>V==="__default__"?r("multirun.modelMultiSelect.variant.default"):V})]}),s.jsxs(zn,{fitContent:!0,portalToBody:!0,children:[s.jsx(Is,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),E.map(V=>s.jsx(Is,{value:V,children:V},V))]})]}):null,s.jsx(ah,{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:j.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:j.map(V=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(Do,{providerId:ha(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:()=>k(M=>M.filter(ee=>ee.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($e,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx($e,{onClick:B,disabled:!F,children:r(v?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function f2(t){const e=gt.c(7);let n,r,o,a,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"}),a=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]=a,e[4]=c):(n=e[0],r=e[1],o=e[2],a=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,a,c]}),e[5]=t,e[6]=l):l=e[6],l}function m2(t){const{t:e}=At(),{node:n,depth:r=0,groupDirectory:o,projectId:a,archivedBucket:c=!1,currentSessionId:l,pinnedSessionIds:d,expandedParents:u,hasSessionSearchQuery:m,normalizedSessionSearchQuery:f,notifyOnSubtasks:g,editingId:y,setEditingId:p,editTitle:x,setEditTitle:b,handleSaveEdit:h,handleCancelEdit:N,toggleParent:w,handleSessionSelect:S,handleSessionDoubleClick:j,togglePinnedSession:k,handleShareSession:v,copiedSessionId:D,handleCopyShareUrl:A,handleUnshareSession:C,openSidebarMenuKey:O,setOpenSidebarMenuKey:T,renamingFolderId:E,getFoldersForScope:F,getSessionFolderId:R,removeSessionFromFolder:L,addSessionToFolder:B,createFolderAndStartRename:V,openContextPanelTab:M,handleDeleteSession:ee,mobileVariant:se,alwaysShowActions:J,renderSessionNode:K,secondaryMeta:Z,renderContext:re="project",subtreeContainsActive:pe,subtreeContainsEditing:Se,menuOpenSessionId:te,childRenderExtrasFor:Ne,liveSessionById:Y}=t,G=!!Z?.projectLabel,q=!!Z?.branchLabel,oe=Ar(He=>He.displayMode),le=i.useMemo(()=>Wr(),[]),ve=oe==="minimal"||le,Ee=i.useMemo(()=>Fa(),[]),_e=i.useContext(Sg),Oe=le?"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",Me=le?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",he=le,Ce=!c&&!se,xe=ve?le?Ce&&he?"group-hover:pr-18":Ce||he?"group-hover:pr-14":"group-hover:pr-8":"group-hover:pr-2 group-focus-within:pr-2":le?Ce&&he?"group-hover:pr-18":Ce||he?"group-hover:pr-12":"group-hover:pr-5":Ce?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",ue=Ce?"pr-13":"pr-7",H=i.useRef(!1),[ce,fe]=i.useState(!1),U=i.useRef(y);U.current=y;const z=i.useRef(null),be=i.useRef(h);be.current=h;const[ge,_]=i.useState(x),ye=i.useRef(ge);ye.current=ge;const $=i.useRef(null),Ie=i.useRef(null),je=n.session,Fe=Y.get(je.id)??je,Ae=as(je.directory??null)??as(o??null),ne=Ng(Ae??void 0,{bootstrap:!c}),P=Nc(),me=On(He=>He.enabled),ae=On(i.useCallback(He=>He.selectedIds.has(je.id),[je.id])),Be=On(He=>He.toggleSelected),Ge=On(He=>He.setRange),Ke=i.useCallback(He=>{const ns=[],ws=vs=>{vs.children.forEach(Ws=>{ns.push(Ws.session.id),ws(Ws)})};return ws(He),ns},[]),[Qe,st]=i.useState(!1),[ut,vt]=i.useState(!0),Ve=`${re}:${c?"archived":"active"}:${je.id}`,tt=tm(i.useCallback(He=>!!He.sessionMemoryState.get(kg(je.id))?.isZombie,[je.id])),nt=Cg(je.id),xt=Ag(je.id,Ae??void 0),Rt=l===je.id,bt=Fe.title||e("sessions.sidebar.session.untitled"),ot=n.children.length>0,at=d.has(je.id),Ut=Ve,Nt=m?!0:u.has(Ut),_t=!!Fe.parentID,Dt=Dg(je.id)>0&&(!_t||g),Ot=Fe.time?.updated||Fe.time?.created||Date.now(),mt=Zx(Ot),Et=eb(Ot),qt=O===Ve,[Vt,Wt]=i.useState(!1),Yt=qt||Vt,Bt=i.useMemo(()=>ha(Fe.title)!==null,[Fe.title]),[Ht,Jt]=i.useState(!1),rs=le&&re==="recent"&&!ve,Qt=le&&re==="recent"&&ve,Xt=i.useMemo(()=>Ke(n).length,[Ke,n]),bs=i.useCallback(async He=>{const ns=[];let ws=0;for(const vs of He)try{await P.ensureSessionRenderable(vs.session.id);const Ws=Id(ne.getState(),vs.session.id).list,Ss=vs.session.title||e("sessions.sidebar.session.export.untitledSubagent"),Bs=vs.session.agent,fs=await bs(vs.children);ws+=fs.skipped,ns.push({title:Ss,agent:Bs,records:Ws,children:fs.children})}catch{ws+=Ke(vs).length+1}return{children:ns,skipped:ws}},[Ke,ne,P,e]),yt=i.useCallback(He=>{He<=0||de.warning(He===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:He}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:He}))},[e]),Ue=i.useCallback(async He=>{if(!Ae){de.error(e("sessions.sidebar.session.export.nothingToExport"));return}await P.ensureSessionRenderable(je.id);const ns=Id(ne.getState(),je.id).list;if(ns.length===0){de.error(e("sessions.sidebar.session.export.nothingToExport"));return}let ws,vs=0;if(He&&n.children.length>0){const fs=await bs(n.children);ws=fs.children,vs=fs.skipped}const Ws=$N(ns,Fe.title??null,ws),Ss=GN(Fe.title??null),Bs=await UN(Ws,Ss);if(Bs){de.success(e("sessions.sidebar.session.export.success"),{action:{label:e(HN()),onClick:()=>{WN(Bs).then(fs=>{fs||de.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),yt(vs);return}zN(Ws,Ss),de.success(e("sessions.sidebar.session.export.success")),yt(vs)},[bs,ne,n.children,Fe.title,je.id,Ae,yt,P,e]),Ye=i.useCallback(async()=>{if(n.children.length>0){vt(!0),st(!0);return}await Ue(!1)},[Ue,n.children.length]),Ct=i.useCallback(()=>{Ae&&zr("desktop_open_session_mini_chat_window",{sessionId:je.id,directory:Ae,apiBaseUrl:$r(),clientToken:Vl()}).catch(He=>{console.warn("[session-sidebar] failed to open mini chat window",He)})},[je.id,Ae]);if(i.useEffect(()=>{if(y!==je.id)return;const He=ns=>{Ie.current&&!Ie.current.contains(ns.target)&&be.current(ye.current)};return document.addEventListener("mousedown",He),()=>document.removeEventListener("mousedown",He)},[y,je.id]),i.useLayoutEffect(()=>{if(y!==je.id){$.current===je.id&&($.current=null);return}$.current!==je.id&&($.current=je.id,_(x))},[y,x,je.id]),y===je.id)return s.jsx("div",{className:De("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:Ie,className:"flex w-full items-center gap-2",onSubmit:He=>{He.preventDefault(),h(ge)},children:[s.jsx("input",{value:ge,onChange:He=>_(He.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:He=>{if(He.stopPropagation(),He.key==="Escape"){N();return}}}),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:N,"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"})})]}),ve?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:[ot?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Nt?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:mt}),G?s.jsx("span",{className:"truncate",children:Z?.projectLabel}):null,q?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:Z?.branchLabel})]}):null]})})]})},je.id);const kt=nt?.type??"idle",It=kt==="busy"||kt==="retry",rt=xt.length,hs=It||!It&&Dt&&!Rt,Gt=It?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")}),nn=hs||at?s.jsxs("span",{className:De("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",ve?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",hs&&at?"left-[-6px] w-6":"left-0.5 w-3.5",ot&&!J?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[hs?Gt:null,at?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,js=ot?s.jsx("span",{role:"button",tabIndex:0,onClick:He=>{He.stopPropagation(),w(Ut)},onKeyDown:He=>{(He.key==="Enter"||He.key===" ")&&(He.preventDefault(),He.stopPropagation(),w(Ut))},className:De("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",rs?"absolute left-1.5 bottom-1":Qt?"relative mr-0.5 shrink-0":De("absolute left-0.5",ve?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2"),!rs&&!Qt&&ve&&hs&&!J?"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(Nt?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Nt?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=tt?s.jsx(I,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Os=He=>{He&&Wt(!1),T(He?Ve:null)},Ps=He=>{if(!He&&z.current){const{id:ns,title:ws}=z.current;z.current=null,p(ns),b(ws)}},As=He=>{Wt(He)},yn=He=>{He.preventDefault(),He.stopPropagation(),T(qt?null:Ve)},Ys=He=>{He.preventDefault(),He.stopPropagation()},un=He=>{He.preventDefault(),He.stopPropagation()},wn=He=>{He.preventDefault(),He.stopPropagation()},zs=He=>{He.preventDefault(),He.stopPropagation()},we=He=>{He.preventDefault(),He.stopPropagation(),T(null),ee(je,{archivedBucket:c})},Je=He=>{He.preventDefault(),He.stopPropagation()},wt=He=>{He.preventDefault(),He.stopPropagation()},Pt=He=>{He.preventDefault(),He.stopPropagation(),_e?.vscode?.executeCommand("openchamber.openSessionInEditor",je.id,bt)},$t=He=>{if(H.current){H.current=!1;return}if(me){if(He?.preventDefault(),He?.stopPropagation(),He?.shiftKey){const ws=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(Ss=>Ss.getAttribute("data-session-row")).filter(Ss=>typeof Ss=="string"&&Ss.length>0),vs=On.getState().anchorId,Ws=new Map;Ws.set(je.id,Ke(n)),Ge(vs,je.id,ws,Ae??null,Ws);return}Be(je.id,Ae??null,Ke(n));return}S(je.id,Ae,a)},ft=He=>{(He.button===2||He.button===0&&He.ctrlKey&&!me)&&(H.current=!0)},ls=He=>{se&&He.pointerType==="touch"&&fe(!0)},cs=He=>{se&&He.pointerType==="touch"&&fe(!1)},Ns=({Item:He,Separator:ns,Sub:ws,SubTrigger:vs,SubContent:Ws})=>s.jsxs(s.Fragment,{children:[s.jsxs(He,{onClick:()=>{z.current={id:je.id,title:bt}},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(He,{onClick:()=>k(je.id),className:"[&>svg]:mr-1",children:[at?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(at?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Fe.share?s.jsxs(s.Fragment,{children:[s.jsx(He,{onClick:()=>{Fe.share?.url&&A(Fe.share.url,je.id)},className:"[&>svg]:mr-1",children:D===je.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(He,{onClick:()=>C(je.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(He,{onClick:()=>v(Fe),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(He,{onClick:()=>{Ye()},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),Bt?s.jsxs(He,{onClick:()=>Jt(!0),className:"[&>svg]:mr-1",children:[s.jsx(f2,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ae&&!c?(()=>{const Ss=F(Ae),Bs=R(Ae,je.id);return s.jsxs(s.Fragment,{children:[s.jsx(ns,{}),s.jsxs(ws,{children:[s.jsxs(vs,{className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ws,{className:"min-w-[180px]",children:[Ss.length===0?s.jsx(He,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Ss.map(fs=>s.jsxs(He,{onClick:()=>{Bs===fs.id?L(Ae,je.id):B(Ae,fs.id,je.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:fs.name}),Bs===fs.id?s.jsx(I,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},fs.id)),s.jsx(ns,{}),s.jsxs(He,{onClick:()=>{const fs=V(Ae);fs&&B(Ae,fs.id,je.id)},children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Bs?s.jsxs(He,{onClick:()=>{L(Ae,je.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,le?null:s.jsxs(He,{disabled:!Ae,onClick:()=>{Ae&&M(Ae,{mode:"chat",dedupeKey:`session:${je.id}`,label:bt})},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")})]}),Ee?s.jsxs(He,{disabled:!Ae,onClick:Ct,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(ns,{}),c?null:s.jsxs(He,{className:"[&>svg]:mr-1",onClick:()=>ee(je,{archivedBucket:c}),children:[s.jsx(I,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),s.jsxs(He,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>ee(je,{archivedBucket:c,hardDelete:!0}),children:[s.jsx(I,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),ms=s.jsx(tn,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(E||U.current),children:Ns({Item:xs,Separator:Tr,Sub:Rg,SubTrigger:Eg,SubContent:Mg})}),Qs=s.jsx(nd,{children:s.jsx(rd,{className:"app-region-no-drag z-50",children:s.jsx(id,{"data-slot":"dropdown-menu-content",finalFocus:()=>!(E||U.current),style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:De(Pd,"min-w-[180px]"),children:Ns({Item:({className:He,...ns})=>s.jsx(Wh,{className:De(Ig,He),...ns}),Separator:({className:He,...ns})=>s.jsx(Hh,{className:De(Pg,He),...ns}),Sub:Gh,SubTrigger:({className:He,children:ns,...ws})=>s.jsxs(Kh,{className:De(Tg,He),...ws,children:[ns,s.jsx(I,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:He,children:ns,...ws})=>s.jsx(nd,{children:s.jsx(rd,{className:"app-region-no-drag z-50",children:s.jsx(id,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:De(Pd,He),...ws,children:ns})})})})})})});return s.jsxs(i.Fragment,{children:[s.jsx(lN,{sessionId:je.id,sessionDirectory:Ae??null,sessionTitle:bt,children:s.jsxs(zh,{open:Vt,onOpenChange:As,onOpenChangeComplete:Ps,children:[s.jsxs(Uh,{render:s.jsx("div",{"data-session-row":je.id,"data-session-scope":Ae??"","data-session-archived":c?"1":"0",className:De("group relative my-0.5 flex items-center rounded-md py-1 pr-1.5","-ml-3",r>0?"pl-[32px]":"pl-[18px]",Rt&&!ae&&"bg-primary/10",ae&&"bg-interactive-selection")}),children:[nn,js,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:ve?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:ls,onPointerUp:cs,onPointerCancel:cs,onMouseDown:ft,onClick:He=>$t(He),onDoubleClick:He=>{He.stopPropagation(),j(je.id,bt)},className:De("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",ce&&"bg-interactive-hover/70",J?le?xe:ue:xe),children:s.jsxs("div",{className:De("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:De("block min-w-0 flex-1 truncate typography-ui-label font-normal",Rt?"text-primary":"text-foreground"),children:vo(bt,f)}),J?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Et}):null,J?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:De("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",Yt?"opacity-0":Me),children:Et})}),rt>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:rt})]}):null]})})}),le?null:s.jsx(Lt,{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:De("flex items-center gap-3 text-left text-muted-foreground",Z?.projectLabel?"justify-between":"justify-start"),children:[Z?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:Z.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:mt})]}),Z?.branchLabel?s.jsx("div",{className:"flex items-center gap-3 text-left text-muted-foreground justify-start",children: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:Z.branchLabel})]})})}):null]})})]}):s.jsxs("button",{type:"button",onPointerDown:ls,onPointerUp:cs,onPointerCancel:cs,onMouseDown:ft,onClick:He=>$t(He),onDoubleClick:He=>{He.stopPropagation(),j(je.id,bt)},className:De("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",ce&&"bg-interactive-hover/70",J?le?xe:ue:xe),children:[s.jsxs("div",{className:De("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:De("block min-w-0 flex-1 truncate typography-ui-label font-normal",Rt?"text-primary":"text-foreground"),children:vo(bt,f)}),rt>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:rt})]}):null]}),ve?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:De("flex min-w-0 items-center gap-1.5 overflow-hidden",rs&&ot?"pl-4":""),children:[s.jsx("span",{className:"flex-shrink-0",children:mt}),G?s.jsx("span",{className:"truncate",children:Z?.projectLabel}):null,q?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:Z?.branchLabel})]}):null]})})]})}),ss&&!se?s.jsx("div",{className:De("absolute top-1/2 -translate-y-1/2 z-10",ve?"right-0":"right-[30px]"),children:ss}):null,s.jsxs("div",{className:De("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Yt||J&&!le?"opacity-100":De("opacity-0",Oe)),children:[Ce?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",className:De("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",ve&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:wn,onMouseDown:zs,onClick:we,onKeyDown:He=>He.stopPropagation(),children:s.jsx(I,{name:"archive",className:De(ve&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Lt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,he?s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",className:De("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",ve&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:Je,onMouseDown:wt,onClick:Pt,onKeyDown:He=>He.stopPropagation(),children:s.jsx(I,{name:"external-link",className:De(ve&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Lt,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(sn,{open:qt,onOpenChange:Os,onOpenChangeComplete:Ps,children:[s.jsx(en,{asChild:!0,children:s.jsx("button",{type:"button",className:De("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",ve&&!J?Yt?"h-4 w-4 opacity-100":De("h-4 w-4 opacity-0",Oe):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Ys,onMouseDown:un,onClick:yn,onKeyDown:He=>He.stopPropagation(),children:s.jsx(I,{name:"more-2",className:De(ve&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),ms]})]})]}),Qs]})}),ot&&Nt?n.children.map(He=>{const ns=Ne?Ne(He):{subtreeContainsActive:pe,subtreeContainsEditing:Se,menuOpenSessionId:te,nodeStructureKey:""};return K(He,r+1,Ae??o,a,c,void 0,re,ns)}):null,s.jsx(Ls,{open:Qe,onOpenChange:st,children:s.jsxs(Fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Us,{children:[s.jsx($s,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(an,{children:Xt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Xt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Xt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:ut,onChange:He=>vt(He.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($e,{type:"button",onClick:()=>st(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx($e,{type:"button",onClick:()=>{st(!1),Ue(ut)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Bt?s.jsx(u2,{session:Fe,open:Ht,onOpenChange:Jt}):null]},je.id)}const rf=t=>as(t.session.directory??null),h2=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),p2=t=>{if(!t.openSidebarMenuKey)return null;const e=t.archivedBucket?"archived":"active",n=`${t.renderContext??"project"}:${e}:`;return t.openSidebarMenuKey.startsWith(n)?t.openSidebarMenuKey.slice(n.length):null},ta=t=>t.menuOpenSessionId??p2(t),zi=(t,e,n)=>e?n.has(t.node.session.id)?!0:_r(t.node,e):!1,Ea=(t,e,n,r,o)=>{if(t.session.id!==e.session.id)return!0;const a=o(t);if(n.has(a)!==r.has(a)||t.children.length!==e.children.length)return!0;for(let c=0;c<t.children.length;c+=1)if(Ea(t.children[c],e.children[c],n,r,o))return!0;return!1},dh=(t,e,n,r)=>{if(t.session.id!==e.session.id)return!0;const o=t.session.id;if((n.get(o)??t.session)!==(r.get(o)??e.session)||t.children.length!==e.children.length)return!0;for(let a=0;a<t.children.length;a+=1)if(dh(t.children[a],e.children[a],n,r))return!0;return!1},g2=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return Ea(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${t.renderContext??"project"}:${n}:${o.session.id}`)||Ea(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${e.renderContext??"project"}:${r}:${o.session.id}`)},x2=(t,e)=>{if(t.node.session.id!==e.node.session.id||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket||(t.renderContext??"project")!==(e.renderContext??"project")||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks||t.nodeStructureKey!==e.nodeStructureKey||rf(t.node)!==rf(e.node)||!h2(t.secondaryMeta,e.secondaryMeta)||t.liveSessionById!==e.liveSessionById&&dh(t.node,e.node,t.liveSessionById,e.liveSessionById)||t.pinnedSessionIds!==e.pinnedSessionIds&&Ea(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,n=>n.session.id)||t.expandedParents!==e.expandedParents&&g2(t,e)||t.currentSessionId!==e.currentSessionId&&(zi(t,t.currentSessionId,t.subtreeContainsActive)||zi(e,e.currentSessionId,e.subtreeContainsActive))||t.editingId!==e.editingId&&(zi(t,t.editingId,t.subtreeContainsEditing)||zi(e,e.editingId,e.subtreeContainsEditing))||t.editTitle!==e.editTitle&&(zi(t,t.editingId,t.subtreeContainsEditing)||zi(e,e.editingId,e.subtreeContainsEditing))||t.copiedSessionId!==e.copiedSessionId&&(_r(t.node,t.copiedSessionId)||_r(e.node,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=ta(t),r=ta(e);if(_r(t.node,n)||_r(e.node,r))return!1}if(t.renamingFolderId!==e.renamingFolderId){const n=ta(t),r=ta(e);if(_r(t.node,n)||_r(e.node,r))return!1}return t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.handleSaveEdit===e.handleSaveEdit&&t.handleCancelEdit===e.handleCancelEdit&&t.toggleParent===e.toggleParent&&t.handleSessionSelect===e.handleSessionSelect&&t.handleSessionDoubleClick===e.handleSessionDoubleClick&&t.togglePinnedSession===e.togglePinnedSession&&t.handleShareSession===e.handleShareSession&&t.handleCopyShareUrl===e.handleCopyShareUrl&&t.handleUnshareSession===e.handleUnshareSession&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.getFoldersForScope===e.getFoldersForScope&&t.getSessionFolderId===e.getSessionFolderId&&t.removeSessionFromFolder===e.removeSessionFromFolder&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.openContextPanelTab===e.openContextPanelTab&&t.handleDeleteSession===e.handleDeleteSession&&t.renderSessionNode===e.renderSessionNode},b2=i.memo(m2,x2);function y2(t){const e=gt.c(71),{t:n}=At(),{value:r,setValue:o,showDeletionDialog:a,setShowDeletionDialog:c,onConfirm:l}=t;let d,u,m,f,g,y,p,x,b,h;if(e[0]!==o||e[1]!==n||e[2]!==r){const M=n("sessions.sidebar.session.untitled");f=Ls,b=!!r,e[13]!==o?(h=se=>{se||o(null)},e[13]=o,e[14]=h):h=e[14],m=Fs,p=!1,x="max-w-sm gap-5",u=Us;let ee;e[15]!==n||e[16]!==r?.archivedBucket?(ee=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=ee):ee=e[17],e[18]!==ee?(y=s.jsx($s,{children:ee}),e[18]=ee,e[19]=y):y=e[19],d=an,g=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||M,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||M,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||M,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||M,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||M}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||M}),e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=u,e[5]=m,e[6]=f,e[7]=g,e[8]=y,e[9]=p,e[10]=x,e[11]=b,e[12]=h}else d=e[3],u=e[4],m=e[5],f=e[6],g=e[7],y=e[8],p=e[9],x=e[10],b=e[11],h=e[12];let N;e[20]!==d||e[21]!==g?(N=s.jsx(d,{children:g}),e[20]=d,e[21]=g,e[22]=N):N=e[22];let w;e[23]!==u||e[24]!==y||e[25]!==N?(w=s.jsxs(u,{children:[y,N]}),e[23]=u,e[24]=y,e[25]=N,e[26]=w):w=e[26];let S;e[27]!==c||e[28]!==a?(S=()=>c(!a),e[27]=c,e[28]=a,e[29]=S):S=e[29];const j=!a;let k;e[30]!==a?(k=a?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]=a,e[31]=k):k=e[31];let v;e[32]!==n?(v=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=v):v=e[33];let D;e[34]!==k||e[35]!==v||e[36]!==S||e[37]!==j?(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":j,children:[k,v]}),e[34]=k,e[35]=v,e[36]=S,e[37]=j,e[38]=D):D=e[38];let A;e[39]!==o?(A=()=>o(null),e[39]=o,e[40]=A):A=e[40];let C;e[41]!==n?(C=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=C):C=e[42];let O;e[43]!==A||e[44]!==C?(O=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:C}),e[43]=A,e[44]=C,e[45]=O):O=e[45];let T;e[46]!==l?(T=()=>{l()},e[46]=l,e[47]=T):T=e[47];let E;e[48]!==n||e[49]!==r?.archivedBucket?(E=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=E):E=e[50];let F;e[51]!==T||e[52]!==E?(F=s.jsx("button",{type:"button",onClick:T,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[51]=T,e[52]=E,e[53]=F):F=e[53];let R;e[54]!==O||e[55]!==F?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[O,F]}),e[54]=O,e[55]=F,e[56]=R):R=e[56];let L;e[57]!==D||e[58]!==R?(L=s.jsxs(sr,{className:"w-full sm:items-center sm:justify-between",children:[D,R]}),e[57]=D,e[58]=R,e[59]=L):L=e[59];let B;e[60]!==m||e[61]!==p||e[62]!==L||e[63]!==x||e[64]!==w?(B=s.jsxs(m,{showCloseButton:p,className:x,children:[w,L]}),e[60]=m,e[61]=p,e[62]=L,e[63]=x,e[64]=w,e[65]=B):B=e[65];let V;return e[66]!==f||e[67]!==B||e[68]!==b||e[69]!==h?(V=s.jsx(f,{open:b,onOpenChange:h,children:B}),e[66]=f,e[67]=B,e[68]=b,e[69]=h,e[70]=V):V=e[70],V}function w2(t){const e=gt.c(57),{t:n}=At(),{value:r,setValue:o,showDeletionDialog:a,setShowDeletionDialog:c,onConfirm:l}=t,d=r?.archivedBucket===!0,u=r?.sessionCount??0;let m;e[0]!==d||e[1]!==u||e[2]!==n?(m=n(d?u===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":u===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=u,e[2]=n,e[3]=m):m=e[3];const f=m;let g;e[4]!==d||e[5]!==u||e[6]!==n?(g=d?u===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:u}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:u}):u===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:u}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:u}),e[4]=d,e[5]=u,e[6]=n,e[7]=g):g=e[7];const y=g,p=!!r;let x;e[8]!==o?(x=V=>{V||o(null)},e[8]=o,e[9]=x):x=e[9];let b;e[10]!==f?(b=s.jsx($s,{children:f}),e[10]=f,e[11]=b):b=e[11];let h;e[12]!==y?(h=s.jsx(an,{children:y}),e[12]=y,e[13]=h):h=e[13];let N;e[14]!==b||e[15]!==h?(N=s.jsxs(Us,{children:[b,h]}),e[14]=b,e[15]=h,e[16]=N):N=e[16];let w;e[17]!==c||e[18]!==a?(w=()=>c(!a),e[17]=c,e[18]=a,e[19]=w):w=e[19];const S=!a;let j;e[20]!==a?(j=a?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]=a,e[21]=j):j=e[21];let k;e[22]!==n?(k=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=k):k=e[23];let v;e[24]!==k||e[25]!==w||e[26]!==S||e[27]!==j?(v=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:[j,k]}),e[24]=k,e[25]=w,e[26]=S,e[27]=j,e[28]=v):v=e[28];let D;e[29]!==o?(D=()=>o(null),e[29]=o,e[30]=D):D=e[30];let A;e[31]!==n?(A=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=A):A=e[32];let C;e[33]!==D||e[34]!==A?(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:A}),e[33]=D,e[34]=A,e[35]=C):C=e[35];let O;e[36]!==l?(O=()=>{l()},e[36]=l,e[37]=O):O=e[37];let T;e[38]!==d||e[39]!==n?(T=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=T):T=e[40];let E;e[41]!==O||e[42]!==T?(E=s.jsx("button",{type:"button",onClick:O,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:T}),e[41]=O,e[42]=T,e[43]=E):E=e[43];let F;e[44]!==C||e[45]!==E?(F=s.jsxs("div",{className:"flex items-center gap-2",children:[C,E]}),e[44]=C,e[45]=E,e[46]=F):F=e[46];let R;e[47]!==v||e[48]!==F?(R=s.jsxs(sr,{className:"w-full sm:items-center sm:justify-between",children:[v,F]}),e[47]=v,e[48]=F,e[49]=R):R=e[49];let L;e[50]!==R||e[51]!==N?(L=s.jsxs(Fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[N,R]}),e[50]=R,e[51]=N,e[52]=L):L=e[52];let B;return e[53]!==p||e[54]!==L||e[55]!==x?(B=s.jsx(Ls,{open:p,onOpenChange:x,children:L}),e[53]=p,e[54]=L,e[55]=x,e[56]=B):B=e[56],B}function v2(t){const e=gt.c(36),{t:n}=At(),{value:r,setValue:o,onConfirm:a}=t,c=!!r;let l;e[0]!==o?(l=j=>{j||o(null)},e[0]=o,e[1]=l):l=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let u;e[4]!==d?(u=s.jsx($s,{children:d}),e[4]=d,e[5]=u):u=e[5];let m;e[6]!==n||e[7]!==r?(m=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]=m):m=e[8];let f;e[9]!==m?(f=s.jsx(an,{children:m}),e[9]=m,e[10]=f):f=e[10];let g;e[11]!==u||e[12]!==f?(g=s.jsxs(Us,{children:[u,f]}),e[11]=u,e[12]=f,e[13]=g):g=e[13];let y;e[14]!==o?(y=()=>o(null),e[14]=o,e[15]=y):y=e[15];let p;e[16]!==n?(p=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=p):p=e[17];let x;e[18]!==y||e[19]!==p?(x=s.jsx("button",{type:"button",onClick:y,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]=y,e[19]=p,e[20]=x):x=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]!==a||e[24]!==b?(h=s.jsx("button",{type:"button",onClick:a,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]=a,e[24]=b,e[25]=h):h=e[25];let N;e[26]!==h||e[27]!==x?(N=s.jsxs(sr,{children:[x,h]}),e[26]=h,e[27]=x,e[28]=N):N=e[28];let w;e[29]!==N||e[30]!==g?(w=s.jsxs(Fs,{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(Ls,{open:c,onOpenChange:l,children:w}),e[32]=c,e[33]=l,e[34]=w,e[35]=S):S=e[35],S}const j2=t=>{const e=gt.c(46),{selectedCount:n,scopeKey:r,scopeFolders:o,archivedBucket:a,onMoveToFolder:c,onCreateFolderAndMove:l,onRemoveFromFolder:d,canRemoveFromFolder:u,onDelete:m,onDone:f}=t,{t:g}=At(),y=!!r&&!a;let p;e[0]!==a||e[1]!==g?(p=g(a?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=a,e[1]=g,e[2]=p):p=e[2];const x=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]!==y||e[9]!==u||e[10]!==l||e[11]!==c||e[12]!==d||e[13]!==o||e[14]!==g?(N=y?s.jsxs(sn,{children:[s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx(en,{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(Lt,{side:"top",sideOffset:4,children:s.jsx("p",{children:g("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(tn,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(xs,{disabled:!0,className:"text-muted-foreground",children:g("sessions.sidebar.folders.none")}):o.map(L=>s.jsx(xs,{onClick:()=>c(L.id),children:s.jsx("span",{className:"flex-1 truncate",children:L.name})},L.id)),s.jsx(Tr,{}),s.jsxs(xs,{onClick:l,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),g("sessions.sidebar.folders.newFolderEllipsis")]}),u?s.jsxs(xs,{onClick:d,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]=y,e[9]=u,e[10]=l,e[11]=c,e[12]=d,e[13]=o,e[14]=g,e[15]=N):N=e[15];let w;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=De("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 j;e[18]!==x||e[19]!==m?(j=s.jsx(Ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:w,"aria-label":x,children:S})}),e[18]=x,e[19]=m,e[20]=j):j=e[20];let k;e[21]!==x?(k=s.jsx(Lt,{side:"top",sideOffset:4,children:s.jsx("p",{children:x})}),e[21]=x,e[22]=k):k=e[22];let v;e[23]!==j||e[24]!==k?(v=s.jsxs(Mt,{children:[j,k]}),e[23]=j,e[24]=k,e[25]=v):v=e[25];let D;e[26]!==g?(D=g("sessions.sidebar.header.actions.exitSelection"),e[26]=g,e[27]=D):D=e[27];let A;e[28]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(I,{name:"close",className:"h-4 w-4"}),e[28]=A):A=e[28];let C;e[29]!==f||e[30]!==D?(C=s.jsx(Ft,{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:A})}),e[29]=f,e[30]=D,e[31]=C):C=e[31];let O;e[32]!==g?(O=g("sessions.sidebar.header.actions.exitSelection"),e[32]=g,e[33]=O):O=e[33];let T;e[34]!==O?(T=s.jsx(Lt,{side:"top",sideOffset:4,children:s.jsx("p",{children:O})}),e[34]=O,e[35]=T):T=e[35];let E;e[36]!==C||e[37]!==T?(E=s.jsxs(Mt,{children:[C,T]}),e[36]=C,e[37]=T,e[38]=E):E=e[38];let F;e[39]!==E||e[40]!==N||e[41]!==v?(F=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[N,v,E]}),e[39]=E,e[40]=N,e[41]=v,e[42]=F):F=e[42];let R;return e[43]!==F||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,F]}),e[43]=F,e[44]=h,e[45]=R):R=e[45],R},S2=t=>{const{t:e}=At(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:o,addSessionsToFolder:a,removeSessionsFromFolders:c,createFolderAndStartRename:l,archiveSessions:d,deleteSessions:u,setBulkDeleteConfirm:m}=t,f=On(T=>T.enabled),g=On(T=>T.selectedIds.size),y=g>0,p=On(T=>T.selectedIds),x=On(T=>T.scopeKey),b=i.useCallback(()=>{On.getState().toggleMode()},[]),h=i.useCallback(()=>{On.getState().disable()},[]),N=i.useMemo(()=>{if(!y||typeof document>"u")return!1;let T=!1,E=!1;for(const F of p){const R=document.querySelectorAll(`[data-session-row="${CSS.escape(F)}"]`);for(const L of R)L.getAttribute("data-session-archived")==="1"?E=!0:T=!0}return E&&!T},[y,p]),w=i.useMemo(()=>{if(x)return x;if(!y||typeof document>"u")return null;for(const T of p){const F=document.querySelector(`[data-session-row="${CSS.escape(T)}"]`)?.getAttribute("data-session-scope");if(F&&F.length>0)return F}return null},[y,p,x]),S=i.useMemo(()=>w?o[w]??[]:[],[o,w]),j=i.useMemo(()=>{if(!w||!y)return!1;const T=o[w]??[];for(const E of T)for(const F of E.sessionIds)if(p.has(F))return!0;return!1},[o,w,y,p]),k=i.useCallback(T=>{!w||!y||a(w,T,Array.from(p))},[a,p,w,y]),v=i.useCallback(()=>{if(!w||!y)return;const T=l(w);T&&a(w,T.id,Array.from(p))},[a,l,p,w,y]),D=i.useCallback(()=>{!w||!y||c(w,Array.from(p))},[c,p,w,y]),A=i.useCallback(async()=>{const T=Array.from(p);if(T.length!==0){if(N){const{deletedIds:E,failedIds:F}=await u(T);E.length>0&&de.success(E.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:E.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:E.length})),F.length>0&&de.error(F.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:F.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:F.length}))}else{const{archivedIds:E,failedIds:F}=await d(T);E.length>0&&de.success(E.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:E.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:E.length})),F.length>0&&de.error(F.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:F.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:F.length}))}On.getState().clear()}},[d,N,u,p,e]),C=i.useCallback(()=>{if(!y)return;const T=p.size;if(!r){A();return}m({sessionCount:T,archivedBucket:N})},[N,A,p,r,m,y]),O=i.useCallback(async()=>{m(null),await A()},[A]);return i.useEffect(()=>{if(!f)return;const T=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),E=F=>{if(n)return;const R=F.target;if(R&&(R.tagName==="INPUT"||R.tagName==="TEXTAREA"||R.isContentEditable))return;const L=T?F.metaKey:F.ctrlKey;if(F.key==="Escape"){F.preventDefault(),On.getState().disable();return}if(L&&F.key==="Backspace"){F.preventDefault(),C();return}if(L&&(F.key==="a"||F.key==="A")){const B=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(B.length===0)return;F.preventDefault();const M=On.getState().scopeKey??B[0]?.getAttribute("data-session-scope")??null,ee=J=>M?J.getAttribute("data-session-scope")===M:!0,se=B.filter(ee).map(J=>J.getAttribute("data-session-row")).filter(J=>typeof J=="string"&&J.length>0);if(se.length===0)return;On.getState().replaceAll(se,M||null)}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[C,n,f]),{selectionModeEnabled:f,hasSelection:y,selectedIdsSize:g,bulkScopeIsArchived:N,derivedSelectionScope:w,bulkScopeFolders:S,bulkCanRemoveFromFolder:j,handleToggleSelectionMode:b,handleExitSelectionMode:h,handleBulkMoveToFolder:k,handleBulkCreateFolderAndMove:v,handleBulkRemoveFromFolder:D,handleBulkDelete:C,confirmBulkDelete:O}},N2=2880*60*1e3,k2=t=>!!t.parentID,C2=t=>!!t.time?.archived,sc=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},A2=t=>[...t].sort((e,n)=>sc(n)-sc(e)),D2=(t,e=Date.now())=>{const n=e-N2,r=t.filter(o=>C2(o)||k2(o)?!1:sc(o)>=n);return A2(r)},sa="oc.sessions.projectCollapse",of="oc.sessions.groupOrder",af="oc.sessions.groupCollapse",lf="oc.sessions.activeSessionByProject",Pl="oc.sessions.expandedParents.v2",I2="oc.sessions.expandedParents",P2="oc.sessions.pinned",T2=(t,e,n)=>{const r=new Set;for(const o of t){const a=as(o.path)?.toLowerCase();a&&r.add(a)}if(n?.includeWorktrees===!1)return r;for(const o of e.values())for(const a of o){const c=as(a.path)?.toLowerCase();c&&r.add(c)}return r},R2=(t,e,n)=>{if(t.time?.archived)return!0;const r=as(Pr(t))?.toLowerCase();return r?e.size===0?n?.allowEmptyDirectorySet??!0:e.has(r):n?.allowUnknownDirectory??!0},E2=5*6e4,cf=new Set,Cr=t=>{const e=i.useRef(t);return e.current=t,i.useCallback((...n)=>e.current(...n),[])},df=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:o=!1})=>{const{t:a}=At(),[c,l]=i.useState(!1),[d,u]=i.useState(""),m=i.useRef(null),f=i.useRef(null),g=i.useRef(new Set),[y,p]=i.useState(null),[x,b]=i.useState(""),[h,N]=i.useState(null),[w,S]=i.useState(new Set),j=i.useMemo(()=>ki(),[]),[k,v]=i.useState(new Set),[D,A]=i.useState(new Map),[C,O]=i.useState(new Map),T=Re(ie=>ie.isNewWorktreeDialogOpen),E=Re(ie=>ie.setNewWorktreeDialogOpen),[F,R]=i.useState(!1),[L,B]=i.useState(null),[V,M]=i.useState(null),[ee,se]=i.useState(""),[J,K]=i.useState(null),[Z,re]=i.useState(null),[pe,Se]=i.useState(null),te=ol(ie=>ie.ids),Ne=ol(ie=>ie.setIds),Y=ol(ie=>ie.toggle),[G,q]=i.useState(()=>{try{const ie=ki().getItem(af);if(!ie)return new Set;const lt=JSON.parse(ie);return new Set(Array.isArray(lt)?lt.filter(Xe=>typeof Xe=="string"):[])}catch{return new Set}}),[oe,le]=i.useState(()=>{try{const ie=ki().getItem(of);if(!ie)return new Map;const lt=JSON.parse(ie),Xe=new Map;return Object.entries(lt).forEach(([St,zt])=>{Array.isArray(zt)&&Xe.set(St,zt.filter(ks=>typeof ks=="string"))}),Xe}catch{return new Map}}),[ve,Ee]=i.useState(()=>{try{const ie=ki().getItem(lf);if(!ie)return new Map;const lt=JSON.parse(ie),Xe=new Map;return Object.entries(lt).forEach(([St,zt])=>{typeof zt=="string"&&zt.length>0&&Xe.set(St,zt)}),Xe}catch{return new Map}}),[_e,Oe]=i.useState(new Map),Me=i.useRef(new Map),he=i.useRef(0),Ce=qs(ie=>ie.homeDirectory),xe=qs(ie=>ie.currentDirectory),ue=qs(ie=>ie.setDirectory),H=ys(ie=>ie.projects),ce=ys(ie=>ie.activeProjectId),fe=ys(ie=>ie.removeProject),U=ys(ie=>ie.setActiveProjectIdOnly),z=ys(ie=>ie.updateProjectMeta),be=ys(ie=>ie.reorderProjects),ge=Re(ie=>ie.setActiveMainTab),_=Re(ie=>ie.openContextPanelTab),ye=Re(ie=>ie.setSettingsDialogOpen),$=Re(ie=>ie.toggleHelpDialog),Ie=Re(ie=>ie.setAboutDialogOpen),je=Re(ie=>ie.setSessionSwitcherOpen),Fe=Re(ie=>ie.setScheduledTasksDialogOpen),Ae=Re(ie=>ie.openMultiRunLauncher),ne=Re(ie=>ie.notifyOnSubtasks),P=Re(ie=>ie.showDeletionDialog),me=Re(ie=>ie.setShowDeletionDialog),ae=Ha(d,120),Be=i.useMemo(()=>ae.trim().toLowerCase(),[ae]),Ge=Be.length>0,Ke=Fn(ie=>ie.collapsedFolderIds),Qe=Fn(ie=>ie.foldersMap),st=Fn(ie=>ie.getFoldersForScope),ut=Fn(ie=>ie.createFolder),vt=Fn(ie=>ie.renameFolder),Ve=Fn(ie=>ie.deleteFolder),tt=Fn(ie=>ie.addSessionToFolder),nt=Fn(ie=>ie.addSessionsToFolder),xt=Fn(ie=>ie.removeSessionFromFolder),Rt=Fn(ie=>ie.removeSessionsFromFolders),bt=Fn(ie=>ie.toggleFolderCollapse),ot=Fn(ie=>ie.cleanupSessions),at=Fn(ie=>ie.getSessionFolderId);kS({isSessionSearchOpen:c,setIsSessionSearchOpen:l,sessionSearchInputRef:f,sessionSearchContainerRef:m});const Ut=Qf(),Nt=Nc(),_t=fc(),Le=i.useMemo(()=>Wr(),[]),Dt=xr(ie=>ie.hasLoaded),Ot=xr(ie=>ie.activeSessions),mt=xr(ie=>ie.archivedSessions),Et=dt(ie=>ie.currentSessionId),qt=dt(ie=>!!ie.newSessionDraft?.open),Vt=dt(ie=>ie.setCurrentSession),Wt=dt(ie=>ie.updateSessionTitle),Yt=dt(ie=>ie.shareSession),Bt=dt(ie=>ie.unshareSession),Ht=dt(ie=>ie.worktreeMetadata),Jt=dt(ie=>ie.availableWorktreesByProject),rs=dt(ie=>ie.openNewSessionDraft),Qt=i.useCallback(ie=>{rs(ie),Le&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[Le,rs]),Xt=wo(Ol(ie=>({checkForUpdates:ie.checkForUpdates,available:ie.available,runtimeType:ie.runtimeType,info:ie.info,downloading:ie.downloading,downloaded:ie.downloaded,progress:ie.progress,error:ie.error,downloadUpdate:ie.downloadUpdate,restartToUpdate:ie.restartToUpdate}))),bs=i.useMemo(()=>T2(H,Jt,{includeWorktrees:!Le}),[Jt,Le,H]),yt=i.useMemo(()=>{const ie=new Map(_t.map(St=>[St.id,St])),lt=Ot.map(St=>{const zt=ie.get(St.id);return zt?Fg(zt,St):St}),Xe=new Set(lt.map(St=>St.id));return _t.forEach(St=>{Xe.has(St.id)||lt.push(St)}),lt.filter(St=>R2(St,bs,{allowUnknownDirectory:!Le,allowEmptyDirectorySet:!Le}))},[Ot,Le,bs,_t]),Ue=i.useMemo(()=>_t.map(ie=>{const lt=as(ie.directory??null)??"";return`${ie.id}:${ie.title??""}:${ie.time?.archived?1:0}:${lt}`}).join("|"),[_t]),Ye=i.useRef(_t);i.useEffect(()=>{Ye.current=_t},[Ue,_t]);const Ct=i.useMemo(()=>new Map(_t.map(ie=>[ie.id,ie])),[_t]),kt=i.useMemo(()=>H.map(ie=>`${ie.id}:${as(ie.path)??""}`).join("|"),[H]),It=i.useRef(!1);i.useEffect(()=>{It.current||(It.current=!0,Sa(Ye.current))},[]);const rt=i.useRef("");i.useEffect(()=>{let ie=!1;const lt=async()=>{const Xe=ys.getState().projects;if(Xe.length===0)return;const St=new Map,zt=[],ks=3;let Gs=0;const Gn=Array.from({length:ks},async()=>{for(;;){const hn=Gs;if(Gs+=1,hn>=Xe.length)return;const pn=Xe[hn],Kn=as(pn.path);if(Kn)try{if(!(xn.getState().directories.get(Kn)?.isGitRepo??await sm(Kn)))continue;const xi=await Og({id:pn.id,path:Kn});if(ie||xi.length===0)continue;St.set(Kn,xi),zt.push(...xi)}catch{}}});await Promise.all(Gn),!ie&&dt.setState({availableWorktrees:zt,availableWorktreesByProject:St})};if(rt.current!==kt)return rt.current=kt,lt(),()=>{ie=!0}},[kt]),i.useEffect(()=>{let ie=null;const lt=th(Xe=>{Xe.type==="scheduled-task-ran"&&(ie&&clearTimeout(ie),ie=setTimeout(()=>{Sa(Ye.current)},500))});return()=>{ie&&clearTimeout(ie),lt()}},[]);const ts=i.useMemo(()=>cr(),[]),{isTablet:hs}=Rr(),Gt=t||hs,{buildGroupSearchText:nn,filterSessionNodesForSearch:js,buildGroupedSessions:ss}=NS({homeDirectory:Ce,worktreeMetadata:Ht,pinnedSessionIds:te,gitBranches:Ut,isVSCode:Le}),{scheduleCollapsedProjectsPersist:Os}=RS({isVSCode:Le,hasLoadedGlobalSessions:Dt,safeStorage:j,keys:{sessionExpanded:Pl,sessionExpandedLegacy:I2,projectCollapse:sa,sessionPinned:P2,groupOrder:of,projectActiveSession:lf,groupCollapse:af},sessions:yt,setPinnedSessionIds:Ne,groupOrderByProject:oe,activeSessionByProject:ve,collapsedGroups:G,setExpandedParents:S,setCollapsedProjects:v}),Ps=i.useMemo(()=>[...yt].sort((ie,lt)=>Ki(ie,lt,te)),[yt,te]),As=i.useMemo(()=>Ps.map(ie=>`${ie.id}:${ie.time?.updated??0}`).join("|"),[Ps]),yn=i.useRef(null),Ys=i.useMemo(()=>{const ie=yn.current;if(ie&&ie.signature===As)return ie.map;const lt=new Map(Ps.map((Xe,St)=>[Xe.id,St]));return yn.current={signature:As,map:lt},lt},[As,Ps]),un=i.useMemo(()=>{const ie=new Map;return Ps.forEach(lt=>{const Xe=lt.parentID;if(!Xe)return;const St=ie.get(Xe)??[];St.push(lt),ie.set(Xe,St)}),ie.forEach(lt=>lt.sort((Xe,St)=>Ki(Xe,St,te))),ie},[Ps,te]),wn=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noSessions.description")})]}),zs=i.useMemo(()=>H.find(ie=>ie.id===h)??null,[H,h]),we=i.useCallback(ie=>{h&&(z(h,ie),N(null))},[h,z]),Je=i.useCallback(()=>{E(!0)},[E]),wt=i.useCallback(()=>{const ie=wo.getState();if(ie.available&&ie.info){R(!0);return}Xt.checkForUpdates().then(()=>{const{available:lt,error:Xe}=wo.getState();if(Xe){de.error(a("sessions.sidebar.updateCheck.errorTitle"),{description:Xe});return}if(!lt){de.success(a("sessions.sidebar.updateCheck.latestVersion"));return}R(!0)})},[a,Xt]),Pt=i.useCallback(()=>{t&&je(!1),ye(!0)},[t,je,ye]),$t=Xt.available&&(Xt.runtimeType==="desktop"||Xt.runtimeType==="web"),ft=dt(ie=>ie.deleteSession),ls=dt(ie=>ie.deleteSessions),cs=dt(ie=>ie.archiveSession),Ns=dt(ie=>ie.archiveSessions),{copiedSessionId:ms,handleSessionSelect:Qs,handleSessionDoubleClick:He,handleSaveEdit:ns,handleCancelEdit:ws,handleShareSession:vs,handleCopyShareUrl:Ws,handleUnshareSession:Ss,handleDeleteSession:Bs,confirmDeleteSession:fs}=CS({activeProjectId:ce,currentDirectory:xe,currentSessionId:Et,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:c,sessionSearchQuery:d,setSessionSearchQuery:u,setIsSessionSearchOpen:l,setActiveProjectIdOnly:U,setDirectory:ue,setActiveMainTab:ge,setSessionSwitcherOpen:je,setCurrentSession:Vt,updateSessionTitle:Wt,shareSession:Yt,unshareSession:Bt,deleteSession:ft,deleteSessions:ls,archiveSession:cs,archiveSessions:Ns,childrenMap:un,showDeletionDialog:P,setDeleteSessionConfirm:K,deleteSessionConfirm:J,setEditingId:p,setEditTitle:b,editingId:y,editTitle:x}),ci=i.useCallback(()=>{if(!Z)return;const{scopeKey:ie,folderId:lt}=Z;re(null),Ve(ie,lt)},[Z,Ve]),br=i.useCallback(()=>{Ir.requestDirectoryDialog()},[]);i.useEffect(()=>{if(!Et)return;const lt=yt.find(St=>St.id===Et)?.parentID;if(!lt)return;const Xe=[`project:active:${lt}`,`project:archived:${lt}`,`recent:active:${lt}`,`recent:archived:${lt}`];S(St=>{if(Xe.every(ks=>St.has(ks)))return St;const zt=new Set(St);Xe.forEach(ks=>zt.add(ks));try{j.setItem(Pl,JSON.stringify(Array.from(zt)))}catch{}return zt})},[Et,yt,j]);const yr=i.useCallback(ie=>{S(lt=>{const Xe=new Set(lt);Xe.has(ie)?Xe.delete(ie):Xe.add(ie);try{j.setItem(Pl,JSON.stringify(Array.from(Xe)))}catch{}return Xe})},[j]),wr=i.useCallback((ie,lt)=>{if(!ie)return null;lt&&Ke.has(lt)&&bt(lt);const Xe=ut(ie,a("sessions.sidebar.folder.newFolderName"),lt);return M(Xe.id),se(Xe.name),Xe},[Ke,bt,ut,a]),Jn=Cr(Qs),vr=Cr(He),Xn=Cr(ns),ur=Cr(ws),Un=Cr(vs),ps=Cr(Ws),Ds=Cr(Ss),Er=Cr(Bs),vn=Cr(wr),rn=i.useCallback((ie,lt)=>{O(Xe=>{const St=new Map(Xe);return St.set(ie,lt+7),St})},[]),nr=i.useCallback(ie=>{O(lt=>{if(!lt.has(ie))return lt;const Xe=new Map(lt);return Xe.delete(ie),Xe})},[]),Mr=i.useCallback(ie=>{O(lt=>{let Xe=!1;const St=new Map(lt),zt=`${ie}:`;for(const ks of St.keys())ks.startsWith(zt)&&(St.delete(ks),Xe=!0);return Xe?St:lt})},[]),Gr=i.useCallback(()=>{he.current=Date.now()+150,O(new Map),v(()=>{const ie=new Set(H.map(lt=>lt.id));try{j.setItem(sa,JSON.stringify(Array.from(ie)))}catch{}return Le||Os(ie),ie})},[H,Le,j,Os]),Fr=i.useCallback(()=>{he.current=Date.now()+150,O(new Map),v(()=>{const ie=new Set;try{j.setItem(sa,JSON.stringify([]))}catch{}return Le||Os(ie),ie})},[Le,j,Os]),gs=i.useCallback(ie=>{he.current=Date.now()+150,Mr(ie),v(lt=>{const Xe=new Set(lt);Xe.has(ie)?Xe.delete(ie):Xe.add(ie);try{j.setItem(sa,JSON.stringify(Array.from(Xe)))}catch{}return Le||Os(Xe),Xe})},[Le,Mr,j,Os]),Ts=i.useMemo(()=>H.map(ie=>({...ie,normalizedPath:as(ie.path)})).filter(ie=>!!ie.normalizedPath),[H]),Wn=i.useMemo(()=>Ts.map(ie=>ie.normalizedPath),[Ts]),fn=i.useMemo(()=>{const ie=new Set;return Ts.forEach(lt=>{if(lt.normalizedPath&&ie.add(lt.normalizedPath),Le)return;(Jt.get(lt.normalizedPath)??[]).forEach(St=>{const zt=as(St.path);zt&&ie.add(zt)})}),[...ie].sort()},[Jt,Le,Ts]),X=i.useRef(null);i.useEffect(()=>{const ie=new Set(fn),lt=X.current;if(X.current=ie,!lt){Le&&fn.length>0&&Td(fn,Ye.current);return}const Xe=fn.filter(St=>!lt.has(St));Xe.length!==0&&Td(Xe,Ye.current)},[Le,fn]);const{github:et}=Qn(),ht=Ti(ie=>ie.status),Tt=Ti(ie=>ie.hasChecked),is=Lg(Wn),os=tr(ie=>ie.ensureEntry),ds=tr(ie=>ie.setParams),Rs=tr(ie=>ie.refreshTargets);ES({normalizedProjects:Ts,gitRepoStatus:is,setProjectRepoStatus:A,setProjectRootBranches:Oe});const Hs=dt(ie=>ie.isLoading);VS({isSessionsLoading:Hs,hasLoadedGlobalSessions:Dt,sessions:yt,archivedSessions:mt,normalizedProjects:Ts,isVSCode:Le,availableWorktreesByProject:Jt,cleanupSessions:ot});const{getSessionsForProject:kn,getArchivedSessionsForProject:jr}=MS({isVSCode:Le,sessions:yt,archivedSessions:mt,availableWorktreesByProject:Jt,normalizedProjects:Ts});gS({normalizedProjects:Ts,sessions:yt,archivedSessions:mt,availableWorktreesByProject:Jt,isVSCode:Le,isSessionsLoading:Hs,foldersMap:Qe,createFolder:ut,addSessionToFolder:tt,cleanupSessions:ot});const Sr=i.useRef(!1);ce&&D.has(ce)&&(Sr.current=!!D.get(ce));const{projectSections:Vs,groupSearchDataByGroup:Lr,sectionsForRender:ln,searchMatchCount:En}=yS({normalizedProjects:Ts,getSessionsForProject:kn,getArchivedSessionsForProject:jr,availableWorktreesByProject:Jt,projectRepoStatus:D,projectRootBranches:_e,lastRepoStatus:Sr.current,buildGroupedSessions:ss,hasSessionSearchQuery:Ge,normalizedSessionSearchQuery:Be,filterSessionNodesForSearch:js,buildGroupSearchText:nn,foldersMap:Qe}),Cn=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noMatches.description")})]});vS({projectSections:Vs,activeProjectId:ce,activeSessionByProject:ve,setActiveSessionByProject:Ee,currentSessionId:Et,handleSessionSelect:Qs,newSessionDraftOpen:qt,mobileVariant:t,openNewSessionDraft:rs,setActiveMainTab:ge,setSessionSwitcherOpen:je});const{getOrderedGroups:jn}=jS(oe),An=i.useRef(!1);i.useEffect(()=>{if(An.current||Vs.length===0)return;const ie=Vs.flatMap(lt=>lt.groups.filter(Xe=>Xe.isArchivedBucket).map(Xe=>`${lt.project.id}:${Xe.id}`));ie.length>0&&q(lt=>new Set([...lt,...ie])),An.current=!0},[Vs]);const rr=i.useMemo(()=>{const ie=new Map,lt=new Map;return Vs.forEach(Xe=>{const St=gm(Xe.project.label?.trim()||Ei(Xe.project.normalizedPath,Ce)||Xe.project.normalizedPath);Xe.groups.forEach(zt=>{const ks=zt.branch&&zt.branch!=="HEAD"&&zt.branch!==St?zt.branch:null,Gs={projectLabel:St,branchLabel:ks},Gn=hn=>{hn.forEach(pn=>{const Kn=Xe.project.normalizedPath.length,qr=lt.get(pn.session.id)??-1;Kn<qr||(ie.set(pn.session.id,{node:pn,projectId:Xe.project.id,groupDirectory:zt.directory,secondaryMeta:Gs}),lt.set(pn.session.id,Kn),pn.children.length>0&&Gn(pn.children))})};Gn(zt.sessions)})}),ie},[Vs,Ce]),cn=Ar(ie=>ie.showRecentSection),di=Ar(ie=>ie.showArchivedSessions),Or=i.useMemo(()=>!cn||Le?[]:D2(yt).sort((ie,lt)=>Ki(ie,lt,te)),[Le,te,yt,cn]),Nr=i.useMemo(()=>{if(Le||!cn)return[];const ie=Or,lt=St=>{const zt=rr.get(St.id),ks=as(St.directory??null),Gs=zt?.node??{session:St,children:[],worktree:null},hn=(Ge?js([Gs],Be):[Gs])[0];if(!hn)return null;const pn=zt?.secondaryMeta?{projectLabel:zt.secondaryMeta.projectLabel,branchLabel:Le?null:zt.secondaryMeta.branchLabel}:null;return{node:hn,projectId:zt?.projectId??null,groupDirectory:zt?.groupDirectory??ks,secondaryMeta:pn}},Xe=ie.map(lt).filter(St=>St!==null);return[{key:"active-now",title:a("sessions.sidebar.activity.recentTitle"),items:Xe}]},[Or,js,Ge,Le,Be,rr,cn,a]),Mi=i.useMemo(()=>Nr.some(ie=>ie.items.length>0),[Nr]),ui=i.useMemo(()=>new Set(Or.map(ie=>ie.id)),[Or]),Dn=i.useMemo(()=>[...ui],[ui]);Ej({currentSessionId:Et,sortedSessions:Ps,recentSessionIds:Dn,ensureSessionRenderable:Nt.ensureSessionRenderable});const ir=i.useMemo(()=>di?ln:ln.map(ie=>({...ie,groups:ie.groups.filter(lt=>!lt.isArchivedBucket)})),[ln,di]),Sn=i.useMemo(()=>{const ie=new Set;return ir.forEach(lt=>{lt.groups.forEach(Xe=>{const St=as(Xe.directory??null),zt=Xe.branch?.trim()||Ut.get(St||"")?.trim();!St||!zt||ie.add(No(St,zt))})}),[...ie]},[Ut,ir]),Hn=xw(Sn);i.useEffect(()=>{if(!Tt||!ht?.connected||!et)return;const ie=[],lt=Date.now();if(ir.forEach(St=>{k.has(St.project.id)||St.groups.forEach(zt=>{const ks=as(zt.directory??null),Gs=zt.branch?.trim()||Ut.get(ks||"")?.trim();if(!ks||!Gs)return;const Gn=No(ks,Gs),hn=tr.getState().entries[Gn],pn=!!hn?.status?.pr,Kn=`${ks}::${Gs}`,qr=Math.max(hn?.lastRefreshAt??0,hn?.lastDiscoveryPollAt??0),gi=!!(hn?.isInitialStatusResolved&&!pn&&(!g.current.has(Kn)||lt-qr>=E2));(!hn||!hn.isInitialStatusResolved||gi)&&(gi&&g.current.add(Kn),ie.push({directory:ks,branch:Gs}))})}),ie.length===0)return;const Xe=new Map;ie.forEach(St=>{const zt=No(St.directory,St.branch,St.remoteName??null);Xe.has(zt)||Xe.set(zt,St)}),Xe.forEach((St,zt)=>{os(zt),ds(zt,{directory:St.directory,branch:St.branch,remoteName:St.remoteName??null,canShow:!0,github:et,githubAuthChecked:Tt,githubConnected:ht.connected})}),Rs([...Xe.values()],{silent:!0,markInitialResolved:!0})},[k,os,et,Tt,ht?.connected,Ut,Rs,ir,ds]);const Fi=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",Mn="h-4.5 w-4.5",mi=US({isDesktopShellRuntime:ts,projectSections:Vs,projectHeaderSentinelRefs:Me}),Js=Cr((ie,lt=0,Xe,St,zt=!1,ks,Gs="project",Gn)=>s.jsx(b2,{node:ie,depth:lt,groupDirectory:Xe,projectId:St,archivedBucket:zt,currentSessionId:Et,pinnedSessionIds:te,expandedParents:w,hasSessionSearchQuery:Ge,normalizedSessionSearchQuery:Be,notifyOnSubtasks:ne,editingId:y,setEditingId:p,editTitle:x,setEditTitle:b,handleSaveEdit:Xn,handleCancelEdit:ur,toggleParent:yr,handleSessionSelect:Jn,handleSessionDoubleClick:vr,togglePinnedSession:Y,handleShareSession:Un,copiedSessionId:ms,handleCopyShareUrl:ps,handleUnshareSession:Ds,openSidebarMenuKey:L,setOpenSidebarMenuKey:B,renamingFolderId:V,getFoldersForScope:st,getSessionFolderId:at,removeSessionFromFolder:xt,addSessionToFolder:tt,createFolderAndStartRename:vn,openContextPanelTab:_,handleDeleteSession:Er,mobileVariant:t,alwaysShowActions:Gt,renderSessionNode:Js,secondaryMeta:ks,renderContext:Gs,subtreeContainsActive:Gn?.subtreeContainsActive??cf,subtreeContainsEditing:Gn?.subtreeContainsEditing??cf,menuOpenSessionId:Gn?.menuOpenSessionId??null,nodeStructureKey:Gn?.nodeStructureKey??"",childRenderExtrasFor:Gn?.childRenderExtrasFor,liveSessionById:Ct})),or=i.useCallback(ie=>{nr(ie),q(lt=>{const Xe=new Set(lt);return Xe.has(ie)?Xe.delete(ie):Xe.add(ie),Xe})},[nr]),hi=i.useMemo(()=>{const ie=new Map;for(const[lt,Xe]of Hn)ie.set(lt,{visualState:Xe.visualState,number:Xe.number,url:Xe.url,state:Xe.prState,draft:Xe.draft,title:Xe.title,base:Xe.base,head:Xe.head,checks:Xe.checks,canMerge:Xe.canMerge,mergeableState:Xe.mergeableState,repo:Xe.repo});return ie},[Hn]),Li=i.useCallback((ie,lt,Xe,St,zt,ks,Gs)=>s.jsx(yN,{group:ie,groupKey:lt,projectId:Xe,hideGroupLabel:St,compactBodyPadding:ks,hasSessionSearchQuery:Ge,normalizedSessionSearchQuery:Be,groupSearchDataByGroup:Lr,visibleSessionCount:C.get(lt),collapsedGroups:G,hideDirectoryControls:r,collapsedFolderIds:Ke,toggleFolderCollapse:bt,renameFolder:vt,deleteFolder:Ve,showDeletionDialog:P,setDeleteFolderConfirm:re,renderSessionNode:Js,projectRepoStatus:D,lastRepoStatus:Sr.current,showMoreGroupSessions:rn,resetGroupSessionLimit:nr,mobileVariant:t,alwaysShowActions:Gt,activeProjectId:ce,setActiveProjectIdOnly:U,setActiveMainTab:ge,setSessionSwitcherOpen:je,openNewSessionDraft:Qt,addSessionToFolder:tt,createFolderAndStartRename:vn,renamingFolderId:V,renameFolderDraft:ee,setRenameFolderDraft:se,setRenamingFolderId:M,pinnedSessionIds:te,expandedParents:w,sessionOrderIndex:Ys,currentSessionId:Et,editingId:y,editTitle:x,openSidebarMenuKey:L,liveSessionById:Ct,prVisualStateByDirectoryBranch:hi,onToggleCollapsedGroup:or,dragHandleProps:zt,scrollContainerRef:Gs}),[Ge,Be,Lr,C,G,r,Ke,bt,vt,Ve,P,Js,D,rn,nr,t,Gt,ce,U,ge,je,Qt,tt,vn,V,ee,te,w,Ys,Et,y,x,L,Ct,hi,or]),Kr=!Le&&cn&&!Ge?s.jsx(DN,{sections:Nr,renderSessionNode:Js,currentSessionId:Et,editingId:y,openSidebarMenuKey:L,variant:"section"}):null,pi=!!(V||y||h),{selectionModeEnabled:Xs,hasSelection:Oi,selectedIdsSize:uo,bulkScopeIsArchived:fo,derivedSelectionScope:Bi,bulkScopeFolders:Q,bulkCanRemoveFromFolder:ke,handleToggleSelectionMode:Pe,handleExitSelectionMode:ze,handleBulkMoveToFolder:pt,handleBulkCreateFolderAndMove:jt,handleBulkRemoveFromFolder:us,handleBulkDelete:Kt,confirmBulkDelete:on}=S2({isInlineEditing:pi,showDeletionDialog:P,foldersMap:Qe,addSessionsToFolder:nt,removeSessionsFromFolders:Rt,createFolderAndStartRename:wr,archiveSessions:Ns,deleteSessions:ls,setBulkDeleteConfirm:Se}),ar=i.useCallback(()=>{ge("chat"),t&&je(!1),Ae()},[t,Ae,ge,je]),kr=i.useCallback(()=>{ge("chat"),t&&je(!1),rs()},[t,rs,ge,je]);return s.jsxs("div",{ref:m,className:De("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[s.jsx(wN,{hideDirectoryControls:r,showRecentControls:!Le,handleOpenDirectoryDialog:br,openNewSessionDraft:kr,canOpenMultiRun:H.length>0,openMultiRunLauncher:ar,headerActionIconClass:Mn,headerActionButtonClass:Fi,isSessionSearchOpen:c,setIsSessionSearchOpen:l,sessionSearchInputRef:f,sessionSearchQuery:d,setSessionSearchQuery:u,hasSessionSearchQuery:Ge,searchMatchCount:En,collapseAllProjects:Gr,expandAllProjects:Fr,openScheduledTasksDialog:()=>Fe(!0),selectionModeEnabled:Xs,onToggleSelectionMode:Pe}),s.jsx(LN,{topContent:Kr,hasSharedSessions:Mi,sectionsForRender:ir,projectSections:Vs,activeProjectId:ce,showOnlyMainWorkspace:o,hasSessionSearchQuery:Ge,emptyState:wn,searchEmptyState:Cn,renderGroupSessions:Li,homeDirectory:Ce,collapsedProjects:k,hideDirectoryControls:r,projectRepoStatus:D,isDesktopShellRuntime:ts,stuckProjectHeaders:mi,mobileVariant:t,alwaysShowActions:Gt,toggleProject:gs,setActiveProjectIdOnly:U,setActiveMainTab:ge,setSessionSwitcherOpen:je,openNewSessionDraft:Qt,openNewWorktreeDialog:Je,openProjectEditDialog:N,removeProject:fe,projectHeaderSentinelRefs:Me,reorderProjects:be,getOrderedGroups:jn,setGroupOrderByProject:le,openSidebarMenuKey:L,setOpenSidebarMenuKey:B,isInlineEditing:pi}),Xs&&Oi?s.jsx(j2,{selectedCount:uo,scopeKey:Bi,scopeFolders:Q,archivedBucket:fo,onMoveToFolder:pt,onCreateFolderAndMove:jt,onRemoveFromFolder:us,canRemoveFromFolder:ke,onDelete:Kt,onDone:ze}):null,s.jsx(IN,{onOpenSettings:Pt,onOpenShortcuts:$,onOpenAbout:()=>Ie(!0),onOpenUpdate:wt,showRuntimeButtons:!Le,showUpdateButton:$t}),s.jsx(cm,{open:F,onOpenChange:R,info:Xt.info,downloading:Xt.downloading,downloaded:Xt.downloaded,progress:Xt.progress,error:Xt.error,onDownload:Xt.downloadUpdate,onRestart:Xt.restartToUpdate,runtimeType:Xt.runtimeType}),zs?s.jsx(HS,{open:!!zs,onOpenChange:ie=>{ie||N(null)},projectId:zs.id,projectName:zs.label||Ei(zs.path,Ce),projectPath:zs.path,initialIcon:zs.icon,initialColor:zs.color,initialIconBackground:zs.iconBackground,onSave:we}):null,s.jsx(Lx,{open:T,onOpenChange:E,onWorktreeCreated:(ie,lt)=>{if(ge("chat"),t&&je(!1),lt?.sessionId){Vt(lt.sessionId,ie);return}rs({directoryOverride:ie,preserveDirectoryOverride:!0})}}),s.jsx(hS,{}),s.jsx(y2,{value:J,setValue:K,showDeletionDialog:P,setShowDeletionDialog:me,onConfirm:fs}),s.jsx(v2,{value:Z,setValue:re,onConfirm:ci}),s.jsx(w2,{value:pe,setValue:Se,showDeletionDialog:P,setShowDeletionDialog:me,onConfirm:on})]})},vi=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(/\/+$/,"")},M2=()=>{const{t}=At(),[e,n]=i.useState(!1),[r,o]=i.useState(!1),[a,c]=i.useState(null),[l,d]=i.useState([]),[u,m]=i.useState(!1),[f,g]=i.useState(!1),[y,p]=i.useState(!1),[x,b]=i.useState(!1),[h,N]=i.useState(new Set),w=dt(ue=>ue.getWorktreeMetadata),S=dt(ue=>ue.newSessionDraft),j=dt(ue=>ue.setNewSessionDraftTarget),k=dt(ue=>ue.setDraftBootstrapPendingDirectory),v=Bg,D=$g,A=dt(ue=>ue.deleteSessions),C=dt(ue=>ue.archiveSessions),O=Re(ue=>ue.showDeletionDialog),T=Re(ue=>ue.setShowDeletionDialog),E=qs(ue=>ue.currentDirectory),F=qs(ue=>ue.homeDirectory),R=qs(ue=>ue.isHomeReady),L=ys(ue=>ue.projects),B=ys(ue=>ue.activeProjectId),{isMobile:V,isTablet:M,hasTouchInput:ee}=Rr(),se=V||M||ee,J=i.useMemo(()=>{const H=(B?L.find(ce=>ce.id===B)??null:null)?.path??E;return hr(H)},[B,E,L]),K=i.useCallback(ue=>{const ce=hr(ue.projectDirectory)||J;return{id:(L.find(U=>hr(U.path)===ce)??null)?.id??`path:${ce}`,path:ce}},[J,L]),Z=x&&h.size>0,re=i.useMemo(()=>{const ue=a?.worktree;return ue&&typeof ue.branch=="string"&&ue.branch.trim().length>0?!0:l.length>0&&l.every(({metadata:H})=>typeof H.branch=="string"&&H.branch.trim().length>0)},[a?.worktree,l]),pe=a?.mode==="worktree",Se=pe,te=y||!pe||!re,Ne=y||!pe;i.useEffect(()=>{r||!R||L.length>0||(o(!0),n(!0))},[r,R,L.length]);const Y=i.useCallback(ue=>{c({sessions:ue.sessions,dateLabel:ue.dateLabel,mode:ue.mode??"session",worktree:ue.worktree??null})},[]),G=i.useCallback(()=>{c(null),d([]),m(!1),g(!1),p(!1),b(!1),N(new Set)},[]),q=i.useCallback(async ue=>{if(ue.sessions.length===0)return;if(ue.sessions.length===1){const U=ue.sessions[0];await v(U.id)?de.success(t("sessions.sidebar.session.delete.success")):de.error(t("sessions.sidebar.session.delete.error"));return}const H=ue.sessions.map(U=>U.id),{deletedIds:ce,failedIds:fe}=await A(H);if(ce.length>0){const U=fe.length>0?fe.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:fe.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:fe.length}):ue.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:ue.dateLabel}):void 0;de.success(ce.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ce.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ce.length}),{description:vi(U)})}fe.length>0&&de.error(fe.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:fe.length}),{description:vi(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[v,A,t]);i.useEffect(()=>Ir.onDeleteRequest(ue=>{if(!O&&(ue.mode??"session")==="session"){q(ue);return}Y(ue)}),[Y,O,q]),i.useEffect(()=>Ir.onDirectoryRequest(()=>{n(!0)}),[]),i.useEffect(()=>{if(!a){d([]),m(!1),g(!1),b(!1),N(new Set);return}const ue=a.sessions.map(fe=>{const U=w(fe.id);return U?{session:fe,metadata:U}:null}).filter(fe=>!!fe);d(ue),m(!1),b(!1),N(new Set);const H=new Map;if(a.worktree?.path&&H.set(hr(a.worktree.path),a.worktree),ue.forEach(({metadata:fe})=>{fe.path&&H.set(hr(fe.path),fe)}),H.size===0){b(!0);return}let ce=!1;return(async()=>{const fe=new Map,U=new Set;await Promise.all(Array.from(H.entries()).map(async([z,be])=>{try{const ge=await Vg(be.path);fe.set(z,ge),ge?.isDirty&&U.add(z)}catch{be.status&&(fe.set(z,be.status),be.status.isDirty&&U.add(z))}})).catch(z=>{console.warn("Failed to inspect worktree status before deletion:",z)}),!ce&&(N(U),b(!0),c(z=>{if(!z?.worktree?.path)return z;const be=hr(z.worktree.path),ge=fe.get(be);if(!ge)return z;const _=z.worktree.status;return _?.isDirty===ge.isDirty&&_?.ahead===ge.ahead&&_?.behind===ge.behind&&_?.upstream===ge.upstream?z:{...z,worktree:{...z.worktree,status:ge}}}),d(z=>z.map(be=>{const ge=hr(be.metadata.path),_=fe.get(ge);return _?{session:be.session,metadata:{...be.metadata,status:_}}:be})))})(),()=>{ce=!0}},[a,w]),i.useEffect(()=>{re||m(!1)},[re]);const oe=i.useCallback(async(ue,H)=>{const ce=u&&re,fe=K(ue),U=hr(ue.path),z=hr(fe.path);try{await _g(fe,ue,{deleteRemoteBranch:ce,deleteLocalBranch:H});const be=hr(S?.directoryOverride);return S?.open&&U&&be===U&&z&&(k(null),j({projectId:fe.id,directoryOverride:z},{force:!0})),hr(E)===U&&z&&qs.getState().setDirectory(z,{showOverlay:!1}),!0}catch(be){return de.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:vi(be instanceof Error?be.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[re,E,u,K,S?.directoryOverride,S?.open,k,j,t]),le=i.useCallback((ue,H)=>{const ce=u&&re;(async()=>{if(!await oe(ue,H))return;const U=t(ce?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");de.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:vi(U)})})()},[re,u,oe,t]),ve=i.useCallback(async()=>{if(a){p(!0);try{const ue=Se,H=ue&&u,ce=ue&&f;if(a.sessions.length===0&&pe&&a.worktree){le(a.worktree,ce),G();return}if(a.sessions.length===1){const fe=a.sessions[0];if(!(pe?await D(fe.id):await v(fe.id,{archiveWorktree:!1,deleteRemoteBranch:H,deleteLocalBranch:ce}))){de.error(t(pe?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),p(!1);return}const z=!pe&&ue?t(H?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;de.success(t(pe?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:vi(z),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const fe=a.sessions.map(be=>be.id);let U=[],z=[];if(pe){const be=await C(fe);U=be.archivedIds,z=be.failedIds}else{const be=await A(fe);U=be.deletedIds,z=be.failedIds}if(pe&&a.worktree&&z.length===0&&le(a.worktree,ce),U.length>0){const be=!pe&&ue?t(H?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,_=[z.length>0?pe?z.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:z.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:z.length}):z.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:z.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:z.length}):a.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:a.dateLabel}):void 0,be].filter(Boolean).join(" ");de.success(pe?U.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:U.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:U.length}):U.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:U.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:U.length}),{description:vi(_||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(z.length>0&&(de.error(pe?z.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:z.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:z.length}):z.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:z.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:z.length}),{description:vi(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),U.length===0)){p(!1);return}}pe&&a.sessions.length===1&&a.worktree&&le(a.worktree,ce),G()}finally{p(!1)}}},[a,u,f,v,A,D,C,G,Se,pe,le,t]),Ee=a?.worktree??l[0]?.metadata??null,_e=a?a.mode==="worktree"?a.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):a.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:a.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:a.sessions.length}):a.sessions.length===1?a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:a.sessions.length,dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:a.sessions.length}):"",Oe=a?s.jsxs("div",{className:De(pe?"space-y-3":"space-y-2"),children:[a.sessions.length>0&&s.jsxs("div",{className:De(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:a.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:a.sessions.length})]}),s.jsxs("ul",{className:De(pe?"mt-2 space-y-1":"space-y-0.5"),children:[a.sessions.slice(0,5).map(ue=>s.jsxs("li",{className:De(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:De(!pe&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:ue.title||t("sessions.sidebar.session.untitled")})]},ue.id)),a.sessions.length>5&&s.jsx("li",{className:De(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:a.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")}),Ee?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Ee.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Ee?Na(Ee.path,F):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Z&&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,Me=pe?re?s.jsxs("button",{type:"button",onClick:()=>{te||m(ue=>!ue)},disabled:te,className:De("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",te?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?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,he=pe?s.jsxs("button",{type:"button",onClick:()=>{Ne||g(ue=>!ue)},disabled:Ne,className:De("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",Ne?"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,Ce=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:[he,Me]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx($e,{variant:"ghost",onClick:G,disabled:y,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx($e,{variant:"destructive",onClick:ve,disabled:y,children:t(y?"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:()=>T(!O),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":!O,children:[O?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($e,{variant:"ghost",onClick:G,disabled:y,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx($e,{variant:"destructive",onClick:ve,disabled:y,children:y?t("sessions.sidebar.sessionDialogs.actions.deleting"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),xe=pe?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[se?s.jsx($a,{open:!!a,onClose:()=>{y||G()},title:xe,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Ce}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[_e&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:_e}),Oe]})}):s.jsx(Ls,{open:!!a,onOpenChange:ue=>{if(!ue){if(y)return;G()}},children:s.jsxs(Fs,{className:De(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(Us,{children:[s.jsxs($s,{className:De(pe&&"flex items-center gap-2"),children:[pe&&s.jsx(I,{name:"delete-bin",className:"h-5 w-5"}),xe]}),_e&&s.jsx(an,{children:_e})]}),s.jsx("div",{className:De(pe&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:Oe}),s.jsx(sr,{className:"mt-2 gap-2 pt-1 pb-1",children:Ce})]})}),s.jsx(Ox,{open:e,onOpenChange:n})]})},nc=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),F2=(t,e)=>{const n=nc(t),r=nc(e);return`${n}-${r}`.substring(0,60)},uf=(t,e)=>`${t}/${e}`,L2=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},ff=(t,e)=>{const n=L2(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Kg(t.id,n),dt.getState().markSessionAsOpenChamberCreated(t.id),xr.getState().upsertSession(o);try{ka().ensureChild(n,{bootstrap:!1}).setState(c=>{const l=c.session.findIndex(u=>u.id===t.id);if(l>=0&&c.session[l]===o)return c;const d=l>=0?c.session.map((u,m)=>m===l?o:u):[...c.session,o].sort((u,m)=>u.id.localeCompare(m.id));return{session:d,sessionTotal:Math.max(c.sessionTotal,d.length),limit:Math.max(c.limit,d.length)}})}catch{}return o},O2=()=>{const t=ys.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=qs.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=io()(jf(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:o,files:a,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=O2();if(!l)return t({error:"Select a project",isLoading:!1}),null;const d=l.path,m=await sm(d)&&e.isolateRuns!==!1,f=nc(n),g=m?await Wa(d):void 0,y=m?await zg(d):null,p=[],x=c?.filter(S=>S.trim().length>0)??[];for(let S=0;S<r.length;S++){const j=r[S],k=j.prompt,v=new Map;for(const A of j.models){const C=`${A.providerID}:${A.modelID}`;v.set(C,(v.get(C)||0)+1)}const D=new Map;for(const A of j.models){const C=`${A.providerID}:${A.modelID}`,O=v.get(C)||1,T=(D.get(C)||0)+1;D.set(C,T);const E=F2(A.providerID,A.modelID),F=r.length>1?`g${S+1}`:void 0,R=O>1?uf(f,`${E}/${T}`):uf(f,E),L=F?`${F}/${R}`:R,B=YN({groupSlug:f,runGroup:F,providerID:A.providerID,modelID:A.modelID,index:O>1?T:void 0});try{if(!m){const se=await Bn.withDirectory(d,()=>Bn.createSession({title:B}));ff(se,d),p.push({sessionId:se.id,worktreePath:d,providerID:A.providerID,modelID:A.modelID,variant:A.variant,prompt:k});continue}const V=await Ug(l,{preferredName:L,mode:"new",branchName:L,worktreeName:L,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:x,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:y}),M={...V,createdFromBranch:g,kind:"standard"},ee=await Bn.withDirectory(V.path,()=>Bn.createSession({title:B}));ff(ee,V.path),dt.getState().setWorktreeMetadata(ee.id,M),p.push({sessionId:ee.id,worktreePath:V.path,providerID:A.providerID,modelID:A.modelID,variant:A.variant,prompt:k})}catch(V){console.warn("[MultiRun] Failed to create session:",V)}}}const b=c?.filter(S=>S.trim().length>0)??[];b.length>0&&Wg(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=a?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{const S=Hg.getState().expandText;await Promise.allSettled(p.map(async j=>{try{const k=await S(j.prompt).catch(()=>j.prompt);await Gg({sessionId:j.sessionId,directory:j.worktreePath,content:k,providerID:j.providerID,modelID:j.modelID,variant:j.variant,agent:o,files:w})}catch(k){console.warn("[MultiRun] Failed to start run:",k)}}))}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"})),B2="oc:lastWorktreeSourceBranch";function uh(t){const e=gt.c(30),{git:n}=Qn(),r=Hf(t),o=xc(t),a=bc(t),c=qg(t),l=xn(U2),d=xn(z2);let u,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==o||e[4]!==a?(u=()=>{!t||!n||o!==null||a||d(t,n,{silent:!0})},m=[t,n,d,o,a],e[0]=t,e[1]=d,e[2]=n,e[3]=o,e[4]=a,e[5]=u,e[6]=m):(u=e[5],m=e[6]),i.useEffect(u,m);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 y;e[13]!==t||e[14]!==l||e[15]!==n||e[16]!==o||e[17]!==g?(y=[t,n,o,g,l],e[13]=t,e[14]=l,e[15]=n,e[16]=o,e[17]=g,e[18]=y):y=e[18],i.useEffect(f,y);const p=a||o===!0&&c;let x;e:{if(!r?.all){let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v=[],e[19]=v):v=e[19],x=v;break e}let k;e[20]!==r.all?(k=r.all.filter($2).sort(),e[20]=r.all,e[21]=k):k=e[21],x=k}const b=x;let h;e:{if(!r?.all){let v;e[22]===Symbol.for("react.memo_cache_sentinel")?(v=[],e[22]=v):v=e[22],h=v;break e}let k;e[23]!==r.all?(k=r.all.filter(_2).map(V2).sort(),e[23]=r.all,e[24]=k):k=e[24],h=k}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 j;return e[25]!==S||e[26]!==p||e[27]!==b||e[28]!==N?(j={localBranches:b,remoteBranches:N,isLoading:p,isGitRepository:S},e[25]=S,e[26]=p,e[27]=b,e[28]=N,e[29]=j):j=e[29],j}function V2(t){return t.replace(/^remotes\//,"")}function _2(t){return t.startsWith("remotes/")}function $2(t){return!t.startsWith("remotes/")}function z2(t){return t.fetchStatus}function U2(t){return t.fetchBranches}const W2=({directory:t,value:e,onChange:n,className:r,disabled:o,id:a})=>{const{t:c}=At(),{localBranches:l,remoteBranches:d,isLoading:u,isGitRepository:m}=uh(t),f=i.useMemo(()=>[...l,...d.map(y=>`remotes/${y}`)],[l,d]);i.useEffect(()=>{if(o||u||f.length===0||e&&f.includes(e))return;(async()=>{try{const p=t?await Wa(t).catch(()=>null):null,x=localStorage.getItem(B2);x&&f.includes(x)?n(x):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,u,n,e]);const g=o||!m||u;return s.jsxs("div",{children:[s.jsxs(_n,{value:e,onValueChange:n,disabled:g,children:[s.jsx($n,{id:a,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(Nn,{placeholder:c(u?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(zn,{className:"max-h-[280px] max-w-[320px]",children:u?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.loadingBranches")}):l.length===0&&d.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(_l,{children:[s.jsx(Rd,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),l.map(y=>s.jsx(Is,{value:y,className:"whitespace-normal break-all",children:y},y))]}),l.length>0&&d.length>0&&s.jsx(Yg,{}),d.length>0&&s.jsxs(_l,{children:[s.jsx(Rd,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),d.map(y=>s.jsx(Is,{value:`remotes/${y}`,className:"whitespace-normal break-all",children:y},`remotes/${y}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},H2=10*1024*1024,Rl=5,pa=t=>{const e=gt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Ft,{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(Mt,{children:[r,s.jsx(Lt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=o):o=e[2],o},Ni=t=>{const e=gt.c(9),{htmlFor:n,required:r,children:o,info:a}=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 d=a&&a;let u;return e[6]!==l||e[7]!==d?(u=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,d]}),e[6]=l,e[7]=d,e[8]=u):u=e[8],u},G2=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=At(),[a,c]=i.useState(""),[l,d]=i.useState(()=>[{id:Ao(),prompt:"",models:[]}]),[u,m]=i.useState(""),[f,g]=i.useState([]),[y,p]=i.useState(!1),[x,b]=i.useState([]),[h,N]=i.useState(!1),[w,S]=i.useState(!1),[j,k]=i.useState(!0),v=i.useRef(null),D=qs(z=>z.currentDirectory??null),A=qs(z=>z.homeDirectory??null),C=i.useMemo(()=>{if(typeof window>"u")return null;const z=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof z=="string"&&z.trim().length>0?z.trim():null},[]),O=ys(z=>z.activeProjectId),T=ys(z=>z.setActiveProjectIdOnly),E=ys(z=>z.projects),[F,R]=i.useState(()=>O??null);i.useEffect(()=>{if(O){R(O);return}!F&&E.length>0&&R(E[0].id)},[O,E,F]);const L=i.useMemo(()=>F?E.find(z=>z.id===F)??null:null,[E,F]),B=L?.path??D,V=i.useCallback(z=>{R(z),z!==O&&T(z)},[O,T]),{currentTheme:M}=Hr(),ee=i.useCallback(z=>{const be=z.label?.trim()||Ei(z.path,A),ge=z.icon?Sc[z.icon]:null,_=z.color?Ga[z.color]:void 0,ye=ge?s.jsx(I,{name:ge,className:"h-3.5 w-3.5 shrink-0",style:_?{color:_}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:_?{color:_}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[z.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:z.iconBackground?{backgroundColor:z.iconBackground}:void 0,children:s.jsx(Ka,{project:{id:z.id,iconImage:z.iconImage??null},options:{themeVariant:M.metadata.variant,iconColor:M.colors.surface.foreground},className:"h-full w-full object-contain",fallback:ye})}):ye,s.jsx("span",{className:"truncate",children:be})]})},[A,M.metadata.variant,M.colors.surface.foreground]),se=i.useMemo(()=>{if(L?.path)return{id:L.id,path:L.path};const z=D??C;return z?{id:`path:${z}`,path:z}:null},[L,D,C]),[J]=i.useState(()=>typeof window<"u"?cr():!1),K=i.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Z=Ef(),re=i.useMemo(()=>{if(typeof window>"u")return null;const z=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof z=="number"&&Number.isFinite(z)&&z>0)return z;if(typeof navigator>"u")return null;const be=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!be)return null;const ge=Number.parseInt(be[1],10),_=Number.parseInt(be[2],10);return Number.isNaN(ge)?null:ge===10?_:ge},[]),pe=i.useMemo(()=>J&&K||Z?"pl-[5.5rem]":"pl-3",[J,K,Z]),Se=i.useMemo(()=>!J||!K||re===null?"":re>=26?"h-12":re<=15?"h-14":"",[J,K,re]),te=i.useCallback(async z=>{z.target.closest("button, a, input, select, textarea")||z.button===0&&J&&await Qg()},[J]);i.useEffect(()=>{if(!n)return;const z=be=>{be.key==="Escape"&&(be.preventDefault(),be.stopPropagation(),n())};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[n]);const[Ne,Y]=i.useState(""),{isLoading:G,isGitRepository:q}=uh(B),oe=i.useRef(!1),le=q===!0,ve=le&&j;i.useEffect(()=>{if(q===!1){oe.current=!0,k(!1);return}q===!0&&oe.current&&(oe.current=!1,k(!0))},[q]);const Ee=Tl(z=>z.createMultiRun),_e=Tl(z=>z.error),Oe=Tl(z=>z.clearError);i.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(z=>{const be=[...z];return be.length>0&&!be[0].prompt.trim()&&(be[0]={...be[0],prompt:t}),be})},[t]),i.useEffect(()=>{if(!se)return;let z=!1;return S(!0),(async()=>{try{const be=await Jg(se);z||b(be)}catch{}finally{z||S(!1)}})(),()=>{z=!0}},[se]);const Me=i.useCallback((z,be)=>{d(ge=>ge.map(_=>_.id===z?{..._,...be}:_))},[]),he=i.useCallback(z=>{d(be=>be.filter(ge=>ge.id!==z))},[]),Ce=i.useCallback(()=>{d(z=>[...z,{id:Ao(),prompt:"",models:[]}])},[]),xe=async z=>{const be=z.target.files;if(!be)return;let ge=0;for(let _=0;_<be.length;_++){const ye=be[_];if(ye.size>H2){de.error(o("multirun.launcher.toast.fileTooLarge",{fileName:ye.name}));continue}try{const $=await new Promise((Ie,je)=>{const Fe=new FileReader;Fe.onload=()=>Ie(Fe.result),Fe.onerror=je,Fe.readAsDataURL(ye)});g(Ie=>[...Ie,{id:Ao(),filename:ye.name,mimeType:ye.type||"application/octet-stream",size:ye.size,dataUrl:$}]),ge++}catch($){console.error("File attach failed",$),de.error(o("multirun.launcher.toast.attachFailed",{fileName:ye.name}))}}ge>0&&de.success(ge===1?o("multirun.launcher.toast.attachedSingle",{count:ge}):o("multirun.launcher.toast.attachedPlural",{count:ge})),v.current&&(v.current.value="")},ue=z=>{g(be=>be.filter(ge=>ge.id!==z))},H=i.useMemo(()=>l.reduce((z,be)=>z+be.models.length,0),[l]),ce=async z=>{z.preventDefault();const be=l.filter(ge=>ge.prompt.trim()&&ge.models.length>=1);if(be.length!==0&&!(H<1)){p(!0),Oe();try{F&&F!==O&&T(F);const ge=f.map(je=>({mime:je.mimeType,filename:je.filename,url:je.dataUrl})),_=x.filter(je=>je.trim().length>0),ye=be.map(je=>({prompt:je.prompt.trim(),models:je.models.map(Fe=>({providerID:Fe.providerID,modelID:Fe.modelID,displayName:Fe.displayName,variant:Fe.variant}))})),$={name:a.trim(),groups:ye,agent:u||void 0,worktreeBaseBranch:ve?Ne:void 0,isolateRuns:ve,files:ge.length>0?ge:void 0,setupCommands:_.length>0?_:void 0},Ie=await Ee($);Ie&&(Ie.firstSessionId&&dt.getState().setCurrentSession(Ie.firstSessionId),e?.())}finally{p(!1)}}},fe=!!(a.trim()&&l.some(z=>z.prompt.trim()&&z.models.length>=1)&&H>=1&&B&&!G&&(q===!1||!ve||Ne)),U=x.filter(z=>z.trim()).length;return s.jsxs("form",{onSubmit:ce,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:te,className:De("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",pe,Se),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(Mt,{children:[s.jsx(Ft,{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(Lt,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(za,{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(Ni,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),E.length>0?s.jsxs(_n,{value:F??void 0,onValueChange:V,children:[s.jsx($n,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:L?s.jsx(Nn,{children:ee(L)}):s.jsx(Nn,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx(zn,{fitContent:!0,children:E.map(z=>s.jsx(Is,{value:z.id,className:"max-w-[24rem]",children:ee(z)},z.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(Ni,{htmlFor:"group-name",required:!0,info:s.jsx(pa,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(bn,{id:"group-name",value:a,onChange:z=>c(z.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(Ni,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(pa,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(W2,{directory:B,value:Ne,onChange:Y,disabled:!ve,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(Ri,{checked:j,onChange:k,disabled:!le,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(Ni,{htmlFor:"multirun-agent",info:s.jsx(pa,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(ah,{value:u,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(to,{open:h,onOpenChange:N,children:[s.jsxs(Bo,{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")}),U>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:U}),s.jsx(I,{name:"arrow-down-s",className:De("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx(so,{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:[x.map((z,be)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(bn,{value:z,onChange:ge=>{const _=[...x];_[be]=ge.target.value,b(_)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>b(x.filter((ge,_)=>_!==be)),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"})})]},`${z}-${be}`)),s.jsxs("button",{type:"button",onClick:()=>b([...x,""]),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(Ni,{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:v,type:"file",multiple:!0,className:"hidden",onChange:xe,accept:"*/*"}),s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>v.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(Lt,{children:o("multirun.launcher.attachments.tooltip")})]}),f.map(z=>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:[z.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:z.filename,children:z.filename}),s.jsx("button",{type:"button",onClick:()=>ue(z.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(I,{name:"close",className:"h-3 w-3"})})]},z.id))]})]}),l.map((z,be)=>s.jsx(K2,{group:z,groupIndex:be,canRemove:l.length>1,onUpdate:Me,onRemove:he},z.id)),s.jsxs("button",{type:"button",onClick:Ce,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")]}),_e&&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:_e})]})})}),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:[!ve&&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($e,{type:"button",variant:"ghost",size:"sm",onClick:n,children:o("multirun.launcher.actions.cancel")}),s.jsx($e,{type:"submit",size:"sm",disabled:!fe||y,children:y?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:H})})})]})})]})},K2=t=>{const e=gt.c(99),{group:n,groupIndex:r,canRemove:o,onUpdate:a,onRemove:c}=t,{t:l}=At(),[d,u]=i.useState(!1),[m,f]=i.useState(""),[g,y]=i.useState(!1),[p,x]=i.useState(""),[b,h]=i.useState(!1),[N,w]=i.useState(""),S=i.useRef(null),j=i.useRef(null),k=i.useRef(null),v=i.useRef(null);let D;e[0]!==n.id||e[1]!==n.models||e[2]!==a?(D=_=>{n.models.length>=Rl||a(n.id,{models:[...n.models,_]})},e[0]=n.id,e[1]=n.models,e[2]=a,e[3]=D):D=e[3];const A=D;let C;e[4]!==n.id||e[5]!==n.models||e[6]!==a?(C=_=>{a(n.id,{models:n.models.filter((ye,$)=>$!==_)})},e[4]=n.id,e[5]=n.models,e[6]=a,e[7]=C):C=e[7];const O=C;let T;e[8]!==n.id||e[9]!==n.models||e[10]!==a?(T=(_,ye)=>{a(n.id,{models:n.models.map(($,Ie)=>Ie===_?ye:$)})},e[8]=n.id,e[9]=n.models,e[10]=a,e[11]=T):T=e[11];const E=T;let F;e[12]===Symbol.for("react.memo_cache_sentinel")?(F=(_,ye)=>{if(_.startsWith("/")){const Fe=_.indexOf(" "),Ae=_.indexOf(`
|
|
211
|
+
`),ne=Math.min(Fe===-1?_.length:Fe,Ae===-1?_.length:Ae);if(ye<=ne&&Fe===-1){x(_.substring(1,ne)),y(!0),u(!1),h(!1);return}}y(!1);const $=_.substring(0,ye),Ie=$.lastIndexOf("#");if(Ie!==-1){const Fe=Ie>0?$[Ie-1]:null,Ae=$.substring(Ie+1);if((!Fe||/\s/.test(Fe))&&!Ae.includes(" ")&&!Ae.includes(`
|
|
212
|
+
`)){w(Ae),h(!0),u(!1);return}}h(!1);const je=$.lastIndexOf("@");if(je!==-1){const Fe=je>0?$[je-1]:null,Ae=$.substring(je+1);(!Fe||/\s/.test(Fe))&&!Ae.includes(" ")&&!Ae.includes(`
|
|
213
|
+
`)?(f(Ae),u(!0)):u(!1);return}u(!1)},e[12]=F):F=e[12];const R=F;let L;e[13]!==n.id||e[14]!==a?(L=_=>{a(n.id,{prompt:_})},e[13]=n.id,e[14]=a,e[15]=L):L=e[15];const B=L;let V;e[16]!==n.prompt||e[17]!==B?(V=_=>{const ye=n.prompt,Ie=S.current?.selectionStart??ye.length,Fe=ye.substring(0,Ie).lastIndexOf("@"),Ae=_.relativePath&&_.relativePath.trim().length>0?_.relativePath.trim():_.path||_.name,ne=Fe!==-1?Fe:Ie,P=`${ye.substring(0,ne)}@${Ae} ${ye.substring(Ie)}`,me=ne+Ae.length+2;B(P),u(!1),f(""),requestAnimationFrame(()=>{const ae=S.current;ae&&(ae.selectionStart=me,ae.selectionEnd=me,ae.focus()),R(P,me)})},e[16]=n.prompt,e[17]=B,e[18]=V):V=e[18];const M=V;let ee;e[19]!==n.prompt||e[20]!==B?(ee=_=>{const ye=n.prompt,Ie=S.current?.selectionStart??ye.length,Fe=ye.substring(0,Ie).lastIndexOf("@"),Ae=Fe!==-1?Fe:Ie,ne=`${ye.substring(0,Ae)}@${_} ${ye.substring(Ie)}`,P=Ae+_.length+2;B(ne),u(!1),f(""),requestAnimationFrame(()=>{const me=S.current;me&&(me.selectionStart=P,me.selectionEnd=P,me.focus()),R(ne,P)})},e[19]=n.prompt,e[20]=B,e[21]=ee):ee=e[21];const se=ee;let J;e[22]!==B?(J=_=>{const ye=`/${_.name} `;B(ye),y(!1),x(""),h(!1),requestAnimationFrame(()=>{const $=S.current;$&&($.focus(),$.selectionStart=$.value.length,$.selectionEnd=$.value.length),R(ye,ye.length)})},e[22]=B,e[23]=J):J=e[23];const K=J;let Z;e[24]!==n.prompt||e[25]!==B?(Z=(_,ye)=>{const $=n.prompt,je=S.current?.selectionStart??$.length,Ae=$.substring(0,je).lastIndexOf("#"),ne=Ae!==-1?Ae:je,P=`${$.substring(0,ne)}#${ye} ${$.substring(je)}`,me=ne+ye.length+2;B(P),h(!1),w(""),requestAnimationFrame(()=>{const ae=S.current;ae&&(ae.selectionStart=me,ae.selectionEnd=me,ae.focus()),R(P,me)})},e[24]=n.prompt,e[25]=B,e[26]=Z):Z=e[26];const re=Z;let pe;e[27]!==g||e[28]!==d||e[29]!==b?(pe=_=>{if(g&&k.current&&(_.key==="Enter"||_.key==="ArrowUp"||_.key==="ArrowDown"||_.key==="Escape"||_.key==="Tab")){_.preventDefault(),k.current.handleKeyDown(_.key);return}d&&j.current&&(_.key==="Enter"||_.key==="ArrowUp"||_.key==="ArrowDown"||_.key==="Escape"||_.key==="Tab")&&(_.preventDefault(),j.current.handleKeyDown(_.key)),b&&v.current&&(_.key==="Enter"||_.key==="ArrowUp"||_.key==="ArrowDown"||_.key==="Escape"||_.key==="Tab")&&(_.preventDefault(),v.current.handleKeyDown(_.key))},e[27]=g,e[28]=d,e[29]=b,e[30]=pe):pe=e[30];const Se=pe,te=r+1;let Ne;e[31]!==l||e[32]!==te?(Ne=l("multirun.launcher.groups.groupLabel",{index:te}),e[31]=l,e[32]=te,e[33]=Ne):Ne=e[33];let Y;e[34]!==Ne?(Y=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:Ne}),e[34]=Ne,e[35]=Y):Y=e[35];let G;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==l?(G=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]=G):G=e[40];let q;e[41]!==Y||e[42]!==G?(q=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Y,G]}),e[41]=Y,e[42]=G,e[43]=q):q=e[43];let oe;e[44]!==l?(oe=l("multirun.launcher.groups.prompt.label"),e[44]=l,e[45]=oe):oe=e[45];let le;e[46]!==oe?(le=s.jsx(Ni,{required:!0,children:oe}),e[46]=oe,e[47]=le):le=e[47];const ve=n.prompt;let Ee;e[48]!==B?(Ee=_=>{const ye=_.target.value;B(ye);const $=_.target.selectionStart??ye.length;R(ye,$)},e[48]=B,e[49]=Ee):Ee=e[49];let _e;e[50]!==l?(_e=l("multirun.launcher.groups.prompt.placeholder"),e[50]=l,e[51]=_e):_e=e[51];let Oe;e[52]!==n.prompt||e[53]!==Se||e[54]!==Ee||e[55]!==_e?(Oe=s.jsx(Ci,{ref:S,value:ve,onChange:Ee,onKeyDown:Se,placeholder:_e,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]=Se,e[54]=Ee,e[55]=_e,e[56]=Oe):Oe=e[56];let Me;e[57]!==p||e[58]!==K||e[59]!==g?(Me=g?s.jsx(Xf,{ref:k,searchQuery:p,onCommandSelect:K,onClose:()=>y(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=p,e[58]=K,e[59]=g,e[60]=Me):Me=e[60];let he;e[61]!==se||e[62]!==M||e[63]!==m||e[64]!==d?(he=d?s.jsx(Zf,{ref:j,searchQuery:m,onFileSelect:M,onAgentSelect:se,onClose:()=>u(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=se,e[62]=M,e[63]=m,e[64]=d,e[65]=he):he=e[65];let Ce;e[66]!==re||e[67]!==b||e[68]!==N?(Ce=b?s.jsx(em,{ref:v,searchQuery:N,onSnippetSelect:re,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=re,e[67]=b,e[68]=N,e[69]=Ce):Ce=e[69];let xe;e[70]!==Oe||e[71]!==Me||e[72]!==he||e[73]!==Ce?(xe=s.jsxs("div",{className:"relative",children:[Oe,Me,he,Ce]}),e[70]=Oe,e[71]=Me,e[72]=he,e[73]=Ce,e[74]=xe):xe=e[74];let ue;e[75]!==le||e[76]!==xe?(ue=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[le,xe]}),e[75]=le,e[76]=xe,e[77]=ue):ue=e[77];let H;e[78]!==l?(H=l("multirun.launcher.models.info",{max:Rl}),e[78]=l,e[79]=H):H=e[79];let ce;e[80]!==H?(ce=s.jsx(pa,{children:H}),e[80]=H,e[81]=ce):ce=e[81];let fe;e[82]!==l?(fe=l("multirun.launcher.models.label"),e[82]=l,e[83]=fe):fe=e[83];let U;e[84]!==ce||e[85]!==fe?(U=s.jsx(Ni,{required:!0,info:ce,children:fe}),e[84]=ce,e[85]=fe,e[86]=U):U=e[86];let z;e[87]!==n.models||e[88]!==A||e[89]!==O||e[90]!==E?(z=s.jsx(ch,{selectedModels:n.models,onAdd:A,onRemove:O,onUpdate:E,minModels:1,maxModels:Rl}),e[87]=n.models,e[88]=A,e[89]=O,e[90]=E,e[91]=z):z=e[91];let be;e[92]!==U||e[93]!==z?(be=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[U,z]}),e[92]=U,e[93]=z,e[94]=be):be=e[94];let ge;return e[95]!==q||e[96]!==ue||e[97]!==be?(ge=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[q,ue,be]}),e[95]=q,e[96]=ue,e[97]=be,e[98]=ge):ge=e[98],ge},q2=i.createContext(null),Y2=t=>{const e=gt.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(q2.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},mf=ao(()=>oo(()=>import("./TerminalView-CZYwjWYc.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])).then(t=>({default:t.TerminalView}))),Q2=ao(()=>oo(()=>import("./DiagramView-l49NCoWI.js"),__vite__mapDeps([9,1,2,4,5,3,6,7,8])).then(t=>({default:t.DiagramView}))),J2=ao(()=>oo(()=>import("./NewWorktreeDialog-B2o615D_.js").then(t=>t.a7),__vite__mapDeps([6,1,2,3,4,5,7])).then(t=>({default:t.SettingsView}))),X2=ao(()=>oo(()=>import("./SettingsWindow-L-jJDG3k.js"),__vite__mapDeps([10,1,2,3,4,5,6,7])).then(t=>({default:t.SettingsWindow}))),Z2=ao(()=>oo(()=>import("./MultiRunWindow-BP1L8slG.js"),__vite__mapDeps([11,1,2,3,4,5,6,7,8])).then(t=>({default:t.MultiRunWindow}))),ek=()=>{const o=Re(Z=>Z.isSidebarOpen),a=Re(Z=>Z.isRightSidebarOpen),c=Re(Z=>Z.isBottomTerminalOpen),l=Re(Z=>Z.setRightSidebarOpen),d=Re(Z=>Z.setBottomTerminalOpen),u=Re(Z=>Z.activeMainTab),m=Re(Z=>Z.setIsMobile),f=Re(Z=>Z.isSessionSwitcherOpen),g=Re(Z=>Z.isSettingsDialogOpen),y=Re(Z=>Z.setSettingsDialogOpen),p=Re(Z=>Z.isMultiRunLauncherOpen),x=Re(Z=>Z.setMultiRunLauncherOpen),b=Re(Z=>Z.multiRunLauncherPrefillPrompt),{isMobile:h,isTablet:N}=Rr(),w=i.useRef(!1),S=i.useRef(!1),j=i.useRef(!1),[k,v]=i.useState(!1),[D,A]=i.useState(!1),[C,O]=i.useState(!1),[T,E]=i.useState(!1),F=i.useCallback(Z=>{v(Z),Re.getState().setSessionSwitcherOpen(Z)},[]),R=i.useRef(!1),L=i.useRef(typeof window>"u"?0:window.innerWidth),B=od(-L.current),V=Ze.useRef(0),M=od(L.current),ee=Ze.useRef(0);Ze.useEffect(()=>{h&&(V.current=window.innerWidth,ee.current=window.innerWidth)},[h]),Ze.useEffect(()=>{if(!h){O(!1);return}k&&O(!0),ad(B,k?0:-V.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[k,h,B]),Ze.useEffect(()=>{if(!h){E(!1);return}R.current=D,D&&E(!0),ad(M,D?0:ee.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,D,M]),Ze.useEffect(()=>{if(h)return B.on("change",Z=>{const re=V.current||L.current,pe=k||Z>-re+.5;O(Se=>Se===pe?Se:pe)})},[h,B,k]),Ze.useEffect(()=>{if(h)return M.on("change",Z=>{const re=ee.current||L.current,pe=D||Z<re-.5;E(Se=>Se===pe?Se:pe)})},[h,D,M]),Ze.useEffect(()=>{h&&!f&&k&&F(!1)},[f,h,k,F]),Ze.useEffect(()=>{if(!h){j.current=!1;return}j.current||(j.current=!0,F(!1),A(!1),Re.getState().isRightSidebarOpen&&l(!1))},[h,F,l]),Ze.useEffect(()=>{if(!h||u!=="chat"||k||D||g)return;let Z=!1,re;const pe=Se=>{re=window.setTimeout(()=>{if(Z)return;const te=dt.getState(),Ne=Re.getState();if(!(Ne.activeMainTab!=="chat"||Ne.isSettingsDialogOpen||te.currentSessionId||te.newSessionDraft?.open)){if(te.isLoading){pe(250);return}te.openNewSessionDraft()}},Se)};return pe(500),()=>{Z=!0,re!==void 0&&window.clearTimeout(re)}},[u,h,g,k,D]),Ze.useEffect(()=>{!h||!g||(F(!1),A(!1),a&&l(!1))},[h,g,a,F,l]),Bx(),i.useEffect(()=>{Re.getState().isMobile!==h&&m(h)},[h,m]),i.useEffect(()=>{if(typeof window>"u")return;let Z;const re=()=>{Z===void 0&&(Z=window.requestAnimationFrame(()=>{Z=void 0,Re.getState().updateProportionalSidebarWidths()}))};return window.addEventListener("resize",re),()=>{window.removeEventListener("resize",re),Z!==void 0&&window.cancelAnimationFrame(Z)}},[]),i.useEffect(()=>{if(typeof window>"u")return;let Z;const re=()=>{const Se=Re.getState(),te=window.innerWidth,Ne=window.innerHeight;if(!h&&!N){const Y=te<1140,G=te>=1220;Y?Se.isRightSidebarOpen&&(l(!1),w.current=!0):G&&w.current&&(l(!0),w.current=!1);const q=Ne<640,oe=Ne>=700;q?Se.isBottomTerminalOpen&&(d(!1),S.current=!0):oe&&S.current&&(d(!0),S.current=!1)}},pe=()=>{Z===void 0&&(Z=window.requestAnimationFrame(()=>{Z=void 0,re()}))};return re(),window.addEventListener("resize",pe),()=>{window.removeEventListener("resize",pe),Z!==void 0&&window.cancelAnimationFrame(Z)}},[h,N,d,l]),i.useEffect(()=>{if(typeof window>"u")return;const Z=Re.subscribe((re,pe)=>{const Se=window.innerWidth,te=window.innerHeight,Ne=Se>=1220,Y=te>=700;re.isRightSidebarOpen!==pe.isRightSidebarOpen&&Ne&&(w.current=!1),re.isBottomTerminalOpen!==pe.isBottomTerminalOpen&&Y&&(S.current=!1)});return()=>{Z()}},[h,N,d,l]);const se=i.useCallback(()=>{k&&F(!1),A(!D)},[k,D,F]),J=i.useMemo(()=>{switch(u){case"plan":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(_m,{})});case"git":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(Yl,{isActive:!D})});case"diff":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(Fm,{})});case"terminal":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(mf,{})});case"files":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(Vm,{})});case"context":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(Tm,{})});case"diagram":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(Q2,{})});default:return null}},[u,D]),K=u==="chat";return s.jsx(Vx,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:De("main-content-safe-area",h?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[s.jsx(F0,{}),s.jsx(jj,{}),s.jsx(Cj,{}),s.jsx(M2,{}),h?s.jsxs(Y2,{value:{leftDrawerOpen:k,rightDrawerOpen:D,toggleLeftDrawer:()=>{const Z=!k;D&&A(!1),F(Z)},toggleRightDrawer:se,leftDrawerX:B,rightDrawerX:M,leftDrawerWidth:V,rightDrawerWidth:ee,setMobileLeftDrawerOpen:F,setRightSidebarOpen:A},children:[!g&&s.jsx(Hd,{onToggleLeftDrawer:()=>{const Z=!k;D&&A(!1),F(Z)},onToggleRightDrawer:()=>{se()},leftDrawerOpen:k,rightDrawerOpen:D}),s.jsx("div",{"data-page-scroll-lock":"true",className:De("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:De("absolute inset-0",!K&&"invisible"),children:s.jsx(Zs,{children:s.jsx(Wl,{})})}),J&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Zs,{children:J})}),p&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Zs,{children:s.jsx(G2,{initialPrompt:b,onCreated:()=>x(!1),onCancel:()=>x(!1)})})}),C&&s.jsx(ld.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:B},"aria-hidden":!k,children:s.jsx(Zs,{children:s.jsx(df,{mobileVariant:!0})})}),T&&s.jsx(ld.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:M},"aria-hidden":!D,children:s.jsx(Zs,{children:s.jsx(i.Suspense,{fallback:null,children:s.jsx(Yl,{isActive:D})})})})]})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Zs,{children:s.jsx(i.Suspense,{fallback:null,children:s.jsx(J2,{onClose:()=>y(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx(qb,{}),s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsx(Hb,{isOpen:o,isMobile:h,className:"border-border/50",topBar:s.jsx(Gb,{}),children:s.jsx(df,{})}),s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsx(Hd,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border/50 bg-background","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:De("absolute inset-0",!K&&"invisible"),children:s.jsx(Zs,{children:s.jsx(Wl,{})})}),J&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Zs,{children:J})})]}),s.jsx(M0,{})]})}),s.jsx(_b,{isOpen:c,isMobile:h,children:c?s.jsx(Zs,{children:s.jsx(i.Suspense,{fallback:null,children:s.jsx(mf,{})})}):null})]}),s.jsx(ey,{isOpen:a,className:"bg-background border-t border-border/50",children:s.jsx(Zs,{children:s.jsx(bv,{})})})]})]})]}),s.jsx(i.Suspense,{fallback:null,children:s.jsx(X2,{open:g,onOpenChange:y})}),s.jsx(i.Suspense,{fallback:null,children:s.jsx(Z2,{open:p,onOpenChange:x,initialPrompt:b})})]})]})})},tk=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`},Ln=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 a;e[1]!==n?(a=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=a):a=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]!==a||e[6]!==c?(l=s.jsxs("div",{className:"rounded-md p-2",style:o,children:[a,c]}),e[5]=a,e[6]=c,e[7]=l):l=e[7],l},hf=t=>{const e=gt.c(43),{title:n,snapshot:r,emptyLabel:o}=t,{t:a}=At();let c;if(e[0]!==o||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==a||e[6]!==n){const l=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(rk,0),e[8]=r.entries,e[9]=d):d=e[9];const u=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==a?(f=r.startedAt?tk(r.durationMs):a("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=a,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 y;e[18]!==m||e[19]!==g?(y=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,g]}),e[18]=m,e[19]=g,e[20]=y):y=e[20];let p;e[21]!==a?(p=a("memoryDebugPanel.metric.metrics"),e[21]=a,e[22]=p):p=e[22];let x;e[23]!==r.entries.length||e[24]!==p?(x=s.jsx(Ln,{label:p,value:r.entries.length}),e[23]=r.entries.length,e[24]=p,e[25]=x):x=e[25];let b;e[26]!==a?(b=a("memoryDebugPanel.metric.samples"),e[26]=a,e[27]=b):b=e[27];let h;e[28]!==b||e[29]!==u?(h=s.jsx(Ln,{label:b,value:u}),e[28]=b,e[29]=u,e[30]=h):h=e[30];let N;e[31]!==a?(N=a("memoryDebugPanel.metric.lastUpdate"),e[31]=a,e[32]=N):N=e[32];let w;e[33]!==r.lastUpdatedAt||e[34]!==a?(w=r.lastUpdatedAt?a("memoryDebugPanel.common.live"):a("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=a,e[35]=w):w=e[35];let S;e[36]!==N||e[37]!==w?(S=s.jsx(Ln,{label:N,value:w}),e[36]=N,e[37]=w,e[38]=S):S=e[38];let j;e[39]!==h||e[40]!==S||e[41]!==x?(j=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[x,h,S]}),e[39]=h,e[40]=S,e[41]=x,e[42]=j):j=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:[y,j,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(Vn,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:l.map(k=>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:k.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:a("memoryDebugPanel.metric.countValue",{value:k.count})}),s.jsx("span",{children:a("memoryDebugPanel.metric.avgValue",{value:k.avg})}),s.jsx("span",{children:a("memoryDebugPanel.metric.maxValue",{value:k.max})}),s.jsx("span",{children:a("memoryDebugPanel.metric.totalValue",{value:k.total})})]})]},k.metric))})})]}),e[0]=o,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=a,e[6]=n,e[7]=c}else c=e[7];return c},sk=t=>{const e=gt.c(99),{onClose:n}=t,{t:r}=At(),[o,a]=i.useState("memory"),[c,l]=i.useState("idle"),d=dt(ik),u=tm(ok),m=wc(),f=Xg(ak),g=tr(lk),[y,p]=i.useState(ck),[x,b]=i.useState(dk);let h;e[0]!==y.entries?(h=new Map,y.entries.forEach(fe=>{h.set(fe.metric,fe.count)}),e[0]=y.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 j;e[8]!==h?(j=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=j):j=e[9];let k;e[10]!==h?(k=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=k):k=e[11];let v;e[12]!==h?(v=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=v):v=e[13];let D;e[14]!==N||e[15]!==w||e[16]!==S||e[17]!==j||e[18]!==k||e[19]!==v?(D={messageListRender:N,messageListRenderStreaming:w,chatMessageRender:S,chatMessageRenderStreaming:j,chatMessageRenderStaticDuringStream:k,chatMessageRenderStaticOutsideActiveTurnDuringStream:v},e[14]=N,e[15]=w,e[16]=S,e[17]=j,e[18]=k,e[19]=v,e[20]=D):D=e[20];const A=D;let C,O;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const fe=()=>{p(na()),b(ra())};fe();const U=window.setInterval(fe,500);return()=>window.clearInterval(U)},O=[],e[21]=C,e[22]=O):(C=e[21],O=e[22]),i.useEffect(C,O);let T,E;e[23]!==c?(T=()=>{if(c==="idle")return;const fe=window.setTimeout(()=>{l("idle")},1500);return()=>window.clearTimeout(fe)},E=[c],e[23]=c,e[24]=T,e[25]=E):(T=e[24],E=e[25]),i.useEffect(T,E);let F=0,R=0,L=0;for(const fe of Object.keys(f)){const U=f[fe]??[];R=R+U.length;for(const z of U)z.role==="user"?L=L+1:z.role==="assistant"&&(F=F+1)}let B;e[26]!==F||e[27]!==R||e[28]!==L?(B={assistant:F,total:R,user:L},e[26]=F,e[27]=R,e[28]=L,e[29]=B):B=e[29];const V=B;let M;if(e[30]!==d||e[31]!==f||e[32]!==u||e[33]!==m||e[34]!==r){let fe;e[36]!==d||e[37]!==f||e[38]!==u||e[39]!==r?(fe=U=>{const z=f[U.id]??[];let be=0,ge=0;for(const ye of z)ye.role==="user"?ge=ge+1:ye.role==="assistant"&&(be=be+1);const _=u.get(U.id);return{id:U.id,title:U.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:be,messageCount:z.length,userMessageCount:ge,isStreaming:_?.isStreaming||!1,isZombie:_?.isZombie||!1,backgroundCount:_?.backgroundMessageCount||0,lastAccessed:_?.lastAccessedAt||0,isCurrent:U.id===d}},e[36]=d,e[37]=f,e[38]=u,e[39]=r,e[40]=fe):fe=e[40],M=m.map(fe).sort(uk),e[30]=d,e[31]=f,e[32]=u,e[33]=m,e[34]=r,e[35]=M}else M=e[35];const ee=M;let se;e[41]!==f?(se=Object.keys(f),e[41]=f,e[42]=se):se=e[42];const J=se.length;let K;e[43]===Symbol.for("react.memo_cache_sentinel")?(K=async()=>{try{const fe={generatedAt:new Date().toISOString(),ui:na(),vscode:ra()};await navigator.clipboard.writeText(JSON.stringify(fe,null,2)),l("copied")}catch{l("error")}},e[43]=K):K=e[43];const Z=K;let re;e[44]===Symbol.for("react.memo_cache_sentinel")?(re={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[44]=re):re=e[44];let pe;e[45]!==o?(pe=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[45]=o,e[46]=pe):pe=e[46];let Se;e[47]!==r?(Se=r("memoryDebugPanel.title"),e[47]=r,e[48]=Se):Se=e[48];let te;e[49]!==Se?(te=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:Se}),e[49]=Se,e[50]=te):te=e[50];let Ne;e[51]!==pe||e[52]!==te?(Ne=s.jsxs("div",{className:"flex items-center gap-2",children:[pe,te]}),e[51]=pe,e[52]=te,e[53]=Ne):Ne=e[53];let Y;e[54]!==o?(Y=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx($e,{size:"xs",variant:"ghost",onClick:Z,children:s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx($e,{size:"xs",variant:"ghost",onClick:()=>{op(),p(na()),b(ra())},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[54]=o,e[55]=Y):Y=e[55];let G;e[56]!==n?(G=n?s.jsx($e,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,e[56]=n,e[57]=G):G=e[57];let q;e[58]!==Y||e[59]!==G?(q=s.jsxs("div",{className:"flex items-center gap-1",children:[Y,G]}),e[58]=Y,e[59]=G,e[60]=q):q=e[60];let oe;e[61]!==Ne||e[62]!==q?(oe=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[Ne,q]}),e[61]=Ne,e[62]=q,e[63]=oe):oe=e[63];let le;e[64]===Symbol.for("react.memo_cache_sentinel")?(le={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[64]=le):le=e[64];const ve=o==="memory"?"secondary":"ghost";let Ee;e[65]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>a("memory"),e[65]=Ee):Ee=e[65];let _e;e[66]!==r?(_e=r("memoryDebugPanel.tabs.memory"),e[66]=r,e[67]=_e):_e=e[67];let Oe;e[68]!==ve||e[69]!==_e?(Oe=s.jsx($e,{size:"sm",variant:ve,className:"flex-1",onClick:Ee,children:_e}),e[68]=ve,e[69]=_e,e[70]=Oe):Oe=e[70];const Me=o==="streaming"?"secondary":"ghost";let he;e[71]===Symbol.for("react.memo_cache_sentinel")?(he=()=>a("streaming"),e[71]=he):he=e[71];let Ce;e[72]!==r?(Ce=r("memoryDebugPanel.tabs.streaming"),e[72]=r,e[73]=Ce):Ce=e[73];let xe;e[74]!==Me||e[75]!==Ce?(xe=s.jsx($e,{size:"sm",variant:Me,className:"flex-1",onClick:he,children:Ce}),e[74]=Me,e[75]=Ce,e[76]=xe):xe=e[76];let ue;e[77]!==Oe||e[78]!==xe?(ue=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:le,children:[Oe,xe]}),e[77]=Oe,e[78]=xe,e[79]=ue):ue=e[79];let H;e[80]!==o||e[81]!==J||e[82]!==c||e[83]!==d||e[84]!==f||e[85]!==V||e[86]!==u||e[87]!==ee||e[88]!==m||e[89]!==A||e[90]!==y||e[91]!==r||e[92]!==g||e[93]!==x?(H=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(Ln,{label:r("memoryDebugPanel.metric.totalMessages"),value:V.total}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${J} / ${Ed.MAX_SESSIONS}`}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.userMessages"),value:V.user}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.assistantMessages"),value:V.assistant})]}),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:Zg()})})]}),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:Ed.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(Vn,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:ee.map(fe=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:fe.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:fe.title}),fe.isStreaming?s.jsx(I,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,fe.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-muted-foreground)]",children:r("memoryDebugPanel.metric.roleMsgsValue",{assistant:fe.assistantMessageCount,user:fe.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:fe.messageCount})}),fe.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",fe.backgroundCount]}):null]})]},fe.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Mt,{children:[s.jsx(Ft,{asChild:!0,children:s.jsx($e,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(fk),currentSessionId:d,cachedSessions:Object.keys(f),messageRoleCounts:V,sessionMessageRoleCounts:ee.map(mk),memoryStates:Object.fromEntries(u)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Lt,{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($e,{size:"xs",variant:"outline",onClick:Z,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(Ln,{label:r("memoryDebugPanel.metric.uiMetrics"),value:y.entries.length}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:x.entries.length}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.messageListRenders"),value:A.messageListRender}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:A.messageListRenderStreaming}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:A.chatMessageRender}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:A.chatMessageRenderStreaming}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:A.chatMessageRenderStaticDuringStream}),s.jsx(Ln,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:A.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(hf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:y,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),x.entries.length>0?s.jsx(hf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[80]=o,e[81]=J,e[82]=c,e[83]=d,e[84]=f,e[85]=V,e[86]=u,e[87]=ee,e[88]=m,e[89]=A,e[90]=y,e[91]=r,e[92]=g,e[93]=x,e[94]=H):H=e[94];let ce;return e[95]!==oe||e[96]!==ue||e[97]!==H?(ce=s.jsxs(ex,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:re,children:[oe,ue,H]}),e[95]=oe,e[96]=ue,e[97]=H,e[98]=ce):ce=e[98],ce},nk=sk;function rk(t,e){return t+e.count}function ik(t){return t.currentSessionId}function ok(t){return t.sessionMemoryState}function ak(t){return t.message}function lk(t){return t.totalRequestCount}function ck(){return na()}function dk(){return ra()}function uk(t,e){return e.lastAccessed-t.lastAccessed}function fk(t){return{id:t.id,title:t.title}}function mk(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}const hk=()=>{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()??"":""},pk=async()=>{const t=hk()||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")},pf="openchamber:menu-action",El="openchamber:check-for-updates",gk=t=>{const e=dt(v=>v.openNewSessionDraft),n=Re(v=>v.toggleCommandPalette),r=Re(v=>v.setCommandPaletteOpen),o=Re(v=>v.toggleHelpDialog),a=Re(v=>v.toggleSidebar),c=Re(v=>v.setSessionSwitcherOpen),l=Re(v=>v.setActiveMainTab),d=Re(v=>v.setSettingsDialogOpen),u=Re(v=>v.setAboutDialogOpen),m=Re(v=>v.toggleRightSidebar),f=Re(v=>v.setRightSidebarOpen),g=Re(v=>v.setRightSidebarTab),y=Re(v=>v.toggleBottomTerminal),p=Re(v=>v.setBottomTerminalExpanded),x=wo(v=>v.checkForUpdates),{setThemeMode:b}=Hr(),h=i.useRef(!1),N=i.useCallback(()=>{h.current||(h.current=!0,x().then(()=>{const{available:v,error:D}=wo.getState();if(D){de.error("Failed to check for updates",{description:D});return}v||de.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[x]),w=i.useCallback(()=>{Ir.requestDirectoryDialog()},[]),S=i.useCallback(v=>{const D=tx();if(D.length===0)return;const A=dt.getState().currentSessionId,C=D.findIndex(E=>E.id===A);let O=v>0?0:D.length-1;C>=0&&(O=(C+v+D.length)%D.length);const T=D[O];T&&(l("chat"),c(!1),dt.getState().setCurrentSession(T.id))},[l,c]),j=i.useCallback(v=>{const{activeProjectId:D,projects:A,setActiveProject:C}=ys.getState();if(A.length===0)return;const O=A.findIndex(F=>F.id===D);let T=v>0?0:A.length-1;O>=0&&(T=(O+v+A.length)%A.length);const E=A[T];E&&C(E.id)},[]),k=i.useCallback(v=>{switch(v){case"about":u(!0);break;case"settings":d(!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),Jf();break;case"change-workspace":w();break;case"toggle-right-sidebar":m();break;case"open-right-sidebar-git":f(!0),g("git");break;case"open-right-sidebar-files":f(!0),g("files");break;case"toggle-terminal":y();break;case"toggle-terminal-expanded":p(!Re.getState().isBottomTerminalExpanded);break;case"copy":{const D=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(D)||pk();break}case"theme-light":b("light");break;case"theme-dark":b("dark");break;case"theme-system":b("system");break;case"toggle-sidebar":a();break;case"toggle-memory-debug":t?.();break;case"go-back":qs.getState().goBack();break;case"go-forward":qs.getState().goForward();break;case"previous-session":S(-1);break;case"next-session":S(1);break;case"previous-project":j(-1);break;case"next-project":j(1);break;case"help-dialog":o();break;case"download-logs":{sx().catch(()=>{de.error("Failed to collect OpenCode status")});break}}},[w,j,S,t,e,u,l,c,r,d,p,f,g,b,y,n,o,m,a]);i.useEffect(()=>{const v=A=>{const C=A.detail;C&&k(C)},D=()=>{N()};return window.addEventListener(pf,v),window.addEventListener(El,D),()=>{window.removeEventListener(pf,v),window.removeEventListener(El,D)}},[k,N]),i.useEffect(()=>{if(typeof window>"u")return;const D=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof D!="function")return;let A=null,C=null;return D("openchamber:menu-action",O=>{const T=O?.payload;typeof T=="string"&&k(T)}).then(O=>{A=O}).catch(()=>{}),D("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(El))}).then(O=>{C=O}).catch(()=>{}),()=>{(async()=>{try{const T=A?.();T instanceof Promise&&await T}catch{}try{const T=C?.();T instanceof Promise&&await T}catch{}})()}},[k])},xk="openchamber:tray-action",gf=5e3,bk=120,yk=45e3,fh=20,xf=()=>typeof window>"u"?!1:window.__OPENCHAMBER_PLATFORM__==="darwin",wk=t=>{const e=typeof t.permission=="string"?t.permission:"Permission",n=Array.isArray(t.patterns)?t.patterns.find(r=>typeof r=="string"&&r.trim()):"";return n?`${e}: ${n}`:e},vk=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},Ma=t=>t.time?.updated??t.time?.created??0,jk=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},Sk=(t,e,n,r,o)=>{if(!t)return"";const a=ox(n,r,t),c=e.project?.name,l=a?.label?.trim()||c?.trim()||jk(t),d=oa(t);let u=d&&o.get(d)||"";if(!u){for(const[m,f]of xn.getState().directories)if(oa(m)===d){u=f.status?.current??"";break}}if(!u)for(const m of r.values()){const f=m.find(g=>oa(g.path)===d);if(f?.branch){u=f.branch;break}}return u?`${l} · ${u}`:l},Nk=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=dn.getState(),r=n==="remaining"?"remaining":"usage";if(!e.length)return{mode:r,groups:[]};const o=new Map(t.map(c=>[c.providerId,c])),a=[];for(const c of Of){if(!e.includes(c.id))continue;const l=o.get(c.id);if(!l||l.configured!==!0)continue;const d=[];for(const[m,f]of Object.entries(l.usage?.windows??{})){const g=r==="remaining"?f.remainingPercent:f.usedPercent;d.push({label:uc(m),value:Io(f.valueLabel,g)})}const u=!l.ok&&l.error?l.error:d.length===0?"No rate limits reported":null;a.push({provider:c.name,rows:d,status:u})}return{mode:r,groups:a}},kk=async()=>{try{if(Xi())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=$r();if(e&&ja(e,t))return"Local OpenChamber";const r=(await Mf()).hosts.find(o=>e?ja(e,Ff(o)):!1);return r?.label?.trim()?Lf(r.label.trim()):"Instance"}catch{return""}},Ck=()=>{const t=new Map,e=new Map,n=[],r=new Map;let o;try{o=ka()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[a,c]of o.children.entries()){const l=c.getState();l.vcs?.branch&&e.set(oa(a)??a,l.vcs.branch);for(const d of l.session)d?.id&&r.set(d.id,d.title);for(const[d,u]of Object.entries(l.session_status??{})){const m=u?.type,f=m==="busy"?"busy":m==="retry"?"retry":"idle",g=t.get(d);(!g||g==="idle")&&t.set(d,f)}for(const[d,u]of Object.entries(l.permission??{}))for(const m of u??[]){if(!m?.id)continue;const f=m.sessionID||d;n.push({kind:"permission",id:m.id,sessionId:f,sessionTitle:"",label:wk(m),directory:a})}for(const[d,u]of Object.entries(l.question??{}))for(const m of u??[]){if(!m?.id)continue;const f=m.sessionID||d;n.push({kind:"question",id:m.id,sessionId:f,sessionTitle:"",label:vk(m),directory:a})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},Ak=()=>{const t=xr.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort((r,o)=>Ma(o)-Ma(r)).slice(0,fh).forEach(r=>{const o=Pr(r);o&&e.add(o)});const n=new Map;for(const r of t){if(!r?.id)continue;const o=Pr(r);if(!o||!e.has(o))continue;const a=n.get(o)??[];a.push(r.id),n.set(o,a)}return n},Dk=t=>{const e=Ck(),n=nm.getState().index.session,r=xr.getState().activeSessions,o=new Map(e.titleById),a=new Map;for(const p of r)if(p?.id&&(p.title&&o.set(p.id,p.title),p.parentID)){const x=a.get(p.parentID)??[];x.push(p.id),a.set(p.parentID,x)}const c=p=>{const x=[],b=[...a.get(p)??[]],h=new Set;for(;b.length;){const N=b.pop();h.has(N)||(h.add(N),x.push(N),b.push(...a.get(N)??[]))}return x},l=rm.getState().statusById,d=p=>{const x=e.statusById.get(p);return x&&x!=="idle"?x:l.get(p)?.status??x??"idle"},u=p=>{const x=p.map(b=>d(b));return x.includes("busy")?"busy":x.includes("retry")?"retry":"idle"},m=ys.getState().projects,f=dt.getState().availableWorktreesByProject,g=r.filter(p=>p?.id&&!p.parentID).slice().sort((p,x)=>Ma(x)-Ma(p)).slice(0,fh).map(p=>{const x=[p.id,...c(p.id)],b=Pr(p)??"";return{id:p.id,title:p.title||"Untitled session",status:u(x),branch:b?e.branchByDirectory.get(b)??"":"",unseen:x.reduce((h,N)=>h+(n.unseenCount[N]??0),0),hasError:x.some(h=>n.unseenHasError[h]??!1),directory:b,subtitle:Sk(b,p,m,f,e.branchByDirectory)}}),y=e.approvals.map(p=>({...p,sessionTitle:o.get(p.sessionId)||""}));return{sessions:g,approvals:y,instanceName:t,usage:Nk()}},Ik=()=>{i.useEffect(()=>{if(!xf()||!Fa())return;let t=!1,e="",n=null,r="";const o=()=>{if(t)return;const j=Dk(r),k=JSON.stringify(j);k!==e&&(e=k,zr("desktop_tray_update",j))};kk().then(j=>{t||(r=j,o())});const a=async()=>{const j=Ak();await Promise.all([...j.entries()].map(async([k,v])=>{const D=await Bn.getSessionStatusForDirectory(k).catch(()=>null);t||D===null||rx(k,D,v)}))},c=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,o()},bk))},l=new Map,d=()=>{if(t)return;let j;try{j=ka()}catch{return}const k=new Set;for(const[v,D]of j.children.entries())k.add(v),l.has(v)||l.set(v,D.subscribe(()=>c()));for(const[v,D]of l)k.has(v)||(D(),l.delete(v))};let u=null;try{u=ka().subscribeRegistry(()=>{d(),c()})}catch{}d();const m=nm.subscribe(()=>c()),f=xr.subscribe(()=>c()),g=ys.subscribe(()=>c()),y=dt.subscribe(()=>c()),p=xn.subscribe(()=>c()),x=rm.subscribe(()=>c());nx(Bf());const b=window.setInterval(()=>{Sa()},yk);a();const h=window.setInterval(()=>{a()},gf),N=dn.subscribe(()=>c());dn.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:j,results:k}=dn.getState();j.length>0&&j.some(D=>!k.some(A=>A.providerId===D))&&dn.getState().fetchAllQuotas()});const w=window.setInterval(()=>{const j=dn.getState();j.autoRefresh&&j.dropdownProviderIds.length>0&&j.fetchAllQuotas()},Math.max(3e4,dn.getState().refreshIntervalMs||6e4)),S=window.setInterval(()=>{d(),o()},gf);return o(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(S),window.clearInterval(b),window.clearInterval(h),window.clearInterval(w),m(),f(),g(),y(),p(),x(),N(),u?.();for(const j of l.values())j();l.clear()}},[]),i.useEffect(()=>{if(!xf()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=o=>{o.type==="respond-permission"&&ix(o.sessionId,o.id,o.response).catch(()=>{de.error("Failed to respond to permission request")})};let r=null;return e(xk,o=>{const a=o?.payload;!a||typeof a!="object"||typeof a.type!="string"||n(a)}).then(o=>{r=o}).catch(()=>{}),()=>{try{const o=r?.();o instanceof Promise&&o.catch(()=>{})}catch{}}},[])},Pk="/api/notifications/stream",Tk=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),Rk=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}},Ek=t=>{const e=gt.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||cr()||!dc()||typeof window>"u"||typeof EventSource>"u")return;const a=new EventSource(Ai().sse(Pk));return a.onmessage=Mk,()=>{a.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),i.useEffect(r,o)};function Mk(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Re.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&Tk())return;const r=Rk(e);if(!r)return;Lo()?.notifications?.notifyAgentCompletion(r)}const bf="pwa-install-toast-shown",yf="pwa-install-toast-dismissed",Fk=()=>{const t=gt.c(6),{browserTab:e}=_x(),{t:n}=At(),r=i.useRef(n);let o,a;t[0]!==n?(o=()=>{r.current=n},a=[n],t[0]=n,t[1]=o,t[2]=a):(o=t[1],a=t[2]),i.useEffect(o,a);let c,l;t[3]!==e?(c=()=>{if(typeof window>"u"||!dc()||!e)return;let d=null,u=null;const m=()=>{u!==null&&(de.dismiss(u),u=null)},f=async()=>{if(!d)return;const p=d;d=null,m(),await p.prompt();const{outcome:x}=await p.userChoice;x==="accepted"&&de.success(r.current("pwa.installPrompt.started"))},g=p=>{const x=p;if(typeof x.prompt!="function")return;x.preventDefault(),d=x;const b=ki(),h=Cf();$x({dismissed:b.getItem(yf),sessionShown:h.getItem(bf),hasActiveToast:u!==null})&&(h.setItem(bf,"true"),u=de.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:()=>{ki().setItem(yf,"true"),m()}}}))},y=()=>{d=null,m(),de.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",g),window.addEventListener("appinstalled",y),()=>{m(),window.removeEventListener("beforeinstallprompt",g),window.removeEventListener("appinstalled",y)}},l=[e],t[3]=e,t[4]=c,t[5]=l):(c=t[4],l=t[5]),i.useEffect(c,l)},Lk=({open:t,onOpenChange:e})=>{const{t:n}=At(),r=!1,[o,a]=i.useState(null),[c,l]=i.useState(null),[d,u]=i.useState(!1),[m,f]=i.useState(!1),[g,y]=i.useState(null),[p,x]=i.useState(!1);i.useCallback(async()=>{},[g,d,r,n]),i.useEffect(()=>{if(!t)return;(async()=>{try{const N=await Cs("/api/system/info");if(N.ok){const w=await N.json();if(typeof w.openchamberVersion=="string"&&w.openchamberVersion.trim()){a(w.openchamberVersion);return}}}catch{}a(await ax())})()},[t]),i.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const w=await Cs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!w.ok)return;const S=await w.json().catch(()=>null),j=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!h&&j&&l(j)}catch{}})(),()=>{h=!0}},[t]),i.useEffect(()=>{{y(null),x(!1);return}},[t,r]);const b=o;return s.jsx(Ls,{open:t,onOpenChange:e,children:s.jsx(Fs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(jc,{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")})]})})})},Ml=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},Ok=(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},Bk=()=>{const t=zx(a=>a.completeAuth),[e,n]=i.useState("working"),[r,o]=i.useState("Completing MCP authorization...");return i.useEffect(()=>{if(typeof window>"u"){n("error"),o("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),c=Ml(a,"code"),l=Ux(a),d=Wx(a),u=Ml(a,"error"),m=Ml(a,"error_description");if(u){d&&Cs(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(m??u);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&&d){const g=await Cs(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(g.ok){const y=await g.json().catch(()=>null);y?.name?.trim()&&(f={name:y.name.trim(),directory:typeof y.directory=="string"&&y.directory.trim()?y.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),d&&await Cs(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),o("Authorization completed. You can close this tab and return to OpenChamber.")}catch(f){d&&await Cs(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(Ok(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($e,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},wf=ao(()=>oo(()=>import("./OnboardingScreen-DNQQWFmn.js"),__vite__mapDeps([12,1,2,4,5,3])).then(t=>({default:t.OnboardingScreen}))),Vk=()=>{const t=gt.c(3),e=Re(Hk),n=Re(Gk);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(Lk,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},_k=t=>{const e=gt.c(21),{onRetry:n,isRetrying:r}=t,{t:o}=At();let a;e[0]!==o?(a=o("startup.initRecovery.title"),e[0]=o,e[1]=a):a=e[1];let c;e[2]!==a?(c=s.jsx("h1",{className:"typography-title text-foreground",children:a}),e[2]=a,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 d;e[6]!==l?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:l}),e[6]=l,e[7]=d):d=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsxs("div",{className:"flex flex-col gap-2",children:[c,d]}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let m;e[11]!==r||e[12]!==o?(m=o(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=o,e[13]=m):m=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==m?(f=s.jsx($e,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=f):f=e[17];let g;return e[18]!==u||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:[u,f]})}),e[18]=u,e[19]=f,e[20]=g):g=e[20],g},vf=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",$k=()=>{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"}},zk=()=>typeof window>"u"?!1:window.location.pathname===Kx,Uk=t=>{const e=gt.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,a=qs(Kk),c=dt(qk),l=dt(Yk),d=Nc(),u=i.useRef(null);let m;e[0]!==n.directory?(m=vf(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const f=m;let g;e[2]!==a?(g=vf(a),e[2]=a,e[3]=g):g=e[3];const y=g;let p,x;if(e[4]!==y||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==l||e[11]!==d?(p=()=>{if(r||f&&y!==f)return;const j=`${f}
|
|
214
|
+
${n.sessionId}`;u.current===j&&c===n.sessionId||(u.current=j,l(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},x=[y,c,n.directory,n.sessionId,f,r,l,d],e[4]=y,e[5]=c,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=l,e[11]=d,e[12]=p,e[13]=x):(p=e[12],x=e[13]),i.useEffect(p,x),f&&y!==f)return null;let b;e[14]!==o?(b=s.jsx(im,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=b):b=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(pm,{}),e[16]=h):h=e[16];let N;e[17]!==n.readOnly?(N=s.jsx(Wl,{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(om,{}),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 Wk({apis:t}){i.useEffect(()=>{ap("App:mounted"),lp()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=es(G=>G.initializeApp),n=es(G=>G.isInitialized),r=es(G=>G.isConnected),o=es(G=>G.providers.length),a=es(G=>G.agents.length),c=es(G=>G.loadProviders),l=es(G=>G.loadAgents),d=dt(G=>G.error),u=dt(G=>G.clearError),m=qs(G=>G.currentDirectory),f=qs(G=>G.setDirectory),g=qs(G=>G.isSwitchingDirectory),[y,p]=i.useState(!1),x=Ti(G=>G.refreshStatus),[b,h]=i.useState(()=>t.runtime.isVSCode),[N,w]=i.useState(!0),[S,j]=i.useState(!1),[k,v]=i.useState(0),[D,A]=i.useState(0),[C,O]=i.useState(!1),T=Re(G=>G.wideChatLayoutEnabled),E=Re(G=>G.mobileKeyboardMode),F=i.useMemo(()=>cr(),[]),R=mc(G=>G.setPlanModeEnabled),[L,B]=i.useState(()=>fd()),[V,M]=i.useState(()=>{const G=md();return G!==null?hd({isDesktopShell:!0,bootOutcome:G}):null}),ee=i.useRef(!1),se=i.useMemo(()=>$k(),[]),J=!se||N,K=i.useMemo(()=>zk(),[]);i.useEffect(()=>(pd(y),()=>{pd(!1)}),[y]),i.useEffect(()=>{cp(E)},[E]),i.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),i.useEffect(()=>If(G=>{dt.getState().prepareForRuntimeSwitch(G.previousRuntimeKey),Re.getState().prepareForRuntimeSwitch(G.previousRuntimeKey),dp(),Bn.reconnectToRuntimeBaseUrl(),es.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),ys.getState().resetForRuntimeSwitch(),dt.getState().restoreForRuntimeSwitch(G.runtimeKey),Re.getState().restoreForRuntimeSwitch(G.runtimeKey),lx(),A(q=>q+1),j(!1),v(q=>q+1)}),[]),i.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",T),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[T]),i.useEffect(()=>(gd(t),()=>gd(null)),[t]),i.useEffect(()=>{se||x(t.github,{force:!0})},[t.github,se,x]),cx();const Z=L==="valid",re=V?.screen==="main";i.useEffect(()=>{if(!up({isDesktopShell:F,isInitialized:n,bootOutcomeKnown:Z,bootViewIsMain:re}))return;const G=setTimeout(()=>{const q=document.getElementById("initial-loading");q&&(q.classList.add("fade-out"),setTimeout(()=>{q.remove()},300))},150);return()=>clearTimeout(G)},[F,n,Z,re]),i.useEffect(()=>{if(!F||L!=="malformed")return;const G=document.getElementById("initial-loading");G&&(G.textContent="Desktop startup failed — please restart the app.")},[F,L]),i.useEffect(()=>{if(F)return;const G=setTimeout(()=>{const q=document.getElementById("initial-loading");q&&!n&&(q.classList.add("fade-out"),setTimeout(()=>{q.remove()},300))},5e3);return()=>clearTimeout(G)},[F,n]),i.useEffect(()=>{let G=!1;return(async()=>{const oe=await Cs("/health",{method:"GET"}).catch(()=>null);if(!oe||!oe.ok||G)return;const le=await oe.json().catch(()=>null);if(!le||G)return;const ve=le.planModeExperimentalEnabled;R(ve===!0||ve===1||ve==="1"||ve==="true")})(),()=>{G=!0}},[R]),i.useEffect(()=>{b||e()},[e,b]),i.useEffect(()=>{if(b||n)return;let G=!0,q,oe=0;const le=10,ve=1e3,Ee=async()=>{if(!G)return;if(oe>=le){j(!0);return}const _e=es.getState();if(_e.isInitialized){j(!1);return}oe+=1,await _e.initializeApp();const Oe=es.getState();if(!G)return;if(Oe.isInitialized){j(!1);return}if(oe>=le){j(!0);return}const Me=Math.min(ve*Math.pow(2,oe-1),16e3);q=setTimeout(Ee,Me)};return q=setTimeout(Ee,ve),()=>{G=!1,q&&clearTimeout(q)}},[k,n,b]),i.useEffect(()=>{n&&j(!1)},[n]),i.useEffect(()=>{if(!S)return;const G=document.getElementById("initial-loading");G&&(G.classList.add("fade-out"),setTimeout(()=>{G.remove()},300))},[S]),i.useEffect(()=>{if(b||!r||o>0&&a>0)return;let G=!0,q=0;const oe=15,le=async()=>{const Ee=es.getState();if(!(Ee.providers.length>0&&Ee.agents.length>0))try{Ee.providers.length===0&&await c({source:"startupRecovery"}),es.getState().agents.length===0&&await l({source:"startupRecovery"})}catch{}};le();const ve=setInterval(()=>{if(G){if(++q>=oe){clearInterval(ve);return}le()}},2e3);return()=>{G=!1,clearInterval(ve)}},[r,b,l,c,o,a]),i.useEffect(()=>{g||b||r&&Bn.setDirectory(m)},[m,g,r,b]),i.useEffect(()=>{if(!se||typeof window>"u")return;const G=le=>{const ve=le?.visible===!0;w(ve)},q=le=>{if(le.origin!==window.location.origin)return;const ve=le.data;ve?.type==="openchamber:embedded-visibility"&&G(ve.payload)},oe=window;return oe.__openchamberSetEmbeddedVisibility=G,window.addEventListener("message",q),()=>{window.removeEventListener("message",q),oe.__openchamberSetEmbeddedVisibility===G&&delete oe.__openchamberSetEmbeddedVisibility}},[se]),i.useEffect(()=>{!se?.directory||b||m!==se.directory&&f(se.directory,{showOverlay:!1})},[m,se,b,f]),i.useEffect(()=>{if(!se||typeof window>"u")return;const G=q=>{q.storageArea===window.localStorage&&q.key==="ui-store"&&Re.persist.rehydrate()};return window.addEventListener("storage",G),()=>{window.removeEventListener("storage",G)}},[se]),i.useEffect(()=>{if(typeof window>"u")return;const G=q=>{const oe=q.detail,le=typeof oe?.sessionId=="string"?oe.sessionId.trim():"";if(!le)return;const ve=typeof oe?.directory=="string"&&oe.directory.trim().length>0?oe.directory.trim():null;Re.getState().setActiveMainTab("chat"),dt.getState().setCurrentSession(le,ve)};return window.addEventListener("openchamber:open-session",G),()=>window.removeEventListener("openchamber:open-session",G)},[]),i.useEffect(()=>{if(typeof window>"u")return;const G=()=>{const q=qs.getState().currentDirectory,{activeProjectId:oe,projects:le}=ys.getState(),ve=le.find(Ee=>Ee.id===oe)??null;zr("desktop_open_draft_mini_chat_window",{directory:q||ve?.path||"",projectId:ve?.id??null})};return window.addEventListener("openchamber:open-mini-chat",G),()=>window.removeEventListener("openchamber:open-mini-chat",G)},[]),i.useEffect(()=>{if(typeof window>"u")return;const G=()=>{const q=dt.getState().currentSessionId;q&&mx(q)};return window.addEventListener("focus",G),()=>window.removeEventListener("focus",G)},[]),i.useEffect(()=>{if(typeof window>"u")return;const G=q=>{const oe=q.detail,le=typeof oe?.directory=="string"&&oe.directory.trim().length>0?oe.directory.trim():null,ve=typeof oe?.projectId=="string"&&oe.projectId.trim().length>0?oe.projectId.trim():null;Re.getState().setActiveMainTab("chat"),Re.getState().setSessionSwitcherOpen(!1),dt.getState().openNewSessionDraft({selectedProjectId:ve,directoryOverride:le,preserveDirectoryOverride:!!le})};return window.addEventListener("openchamber:open-draft-session",G),()=>window.removeEventListener("openchamber:open-draft-session",G)},[]),i.useEffect(()=>{if(typeof window>"u")return;const G=q=>{const oe=q.detail,le=typeof oe?.projectPath=="string"?oe.projectPath.trim():"";if(!le)return;const ve=ys.getState(),Ee=ve.projects.find(_e=>_e.path===le);Ee?ve.setActiveProject(Ee.id):ve.addProject(le)};return window.addEventListener("openchamber:open-project",G),()=>window.removeEventListener("openchamber:open-project",G)},[]),i.useEffect(()=>{typeof window>"u"||!n||g||ee.current||(ee.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,g]),dx({enabled:J}),Ek({enabled:J}),Fk(),ux(),Hx();const pe=i.useCallback(()=>{p(G=>!G)},[]);gk(pe),Ik(),i.useEffect(()=>{if(se)return;const G=q=>{hc(q)&&q.shiftKey&&!q.altKey&&(q.code==="KeyD"||q.key.toLowerCase()==="d")&&(q.preventDefault(),p(le=>!le))};return window.addEventListener("keydown",G,!0),()=>window.removeEventListener("keydown",G,!0)},[se]),i.useEffect(()=>{se||d&&setTimeout(()=>u(),5e3)},[u,se,d]),i.useEffect(()=>{if(!F||L!=="not-injected")return;let G=!1,q=0;const oe=200,le=2e3,ve=50,Ee=()=>{if(G)return;q++;const _e=fd();if(_e!=="not-injected"){if(G=!0,B(_e),_e==="valid"){const Me=md();Me&&M(hd({isDesktopShell:!0,bootOutcome:Me}))}return}const Oe=Math.min(oe*Math.pow(1.1,q),le);if(q>=ve){const Me=document.getElementById("initial-loading");Me&&!Me.textContent?.includes("taking longer")&&(Me.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(Ee,Oe)};return window.setTimeout(Ee,oe),()=>{G=!0}},[F,L]);const Se=i.useCallback(async()=>{if(fp({isDesktopShell:cr(),isDesktopLocalOriginActive:Xi()})){await mp();return}window.location.reload()},[]),te=i.useCallback(async()=>{if(!C){j(!1),O(!0);try{await es.getState().initializeApp()}finally{O(!1)}es.getState().isInitialized||v(G=>G+1)}},[C]),Ne=G=>{if(G.screen==="recovery")return G.variant};if(F&&V&&V.screen!=="main"){if(V.screen==="chooser")return s.jsx(Zs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(i.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(wf,{mode:"first-launch",onCliAvailable:Se,onChooseRemote:()=>{}})})})});const G=Ne(V),q=V.screen==="recovery"&&"url"in V?V.url:void 0;return s.jsx(Zs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(i.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(wf,{mode:"recovery",recoveryVariant:G,recoveryHostUrl:q,recoveryHostLabel:void 0,onCliAvailable:Se})})})})}if(se)return s.jsx(Zs,{children:s.jsx(Md,{sdk:Bn.getSdkClient(),directory:m||"",children:s.jsx(Fd,{apis:t,children:s.jsx(Ld,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(Uk,{embeddedSessionChat:se,isVSCodeRuntime:b,embeddedBackgroundWorkEnabled:J})})})})},D)});if(K)return s.jsx(Zs,{children:s.jsx(Bk,{})});if(S&&!n&&!b&&!se)return s.jsx(Zs,{children:s.jsx(_k,{onRetry:()=>{te()},isRetrying:C})});const Y=!n&&!F;return s.jsx(Zs,{children:s.jsx(Md,{sdk:Bn.getSdkClient(),directory:m||"",children:s.jsx(Fd,{apis:t,children:s.jsx(Sy,{children:s.jsx(fx,{children:s.jsx(Ld,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:F?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(im,{embeddedBackgroundWorkEnabled:J}),s.jsx(pm,{}),s.jsx(ek,{}),s.jsx(om,{}),!Y&&s.jsxs(s.Fragment,{children:[s.jsx(Gx,{}),s.jsx(Vk,{}),y&&s.jsx(nk,{onClose:()=>p(!1)})]})]})})})})})},D)})}function Hk(t){return t.isAboutDialogOpen}function Gk(t){return t.setAboutDialogOpen}function Kk(t){return t.currentDirectory}function qk(t){return t.currentSessionId}function Yk(t){return t.setCurrentSession}const Qk=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();hx();hp().then(()=>{Promise.all([pp(),px()]).catch(t=>{console.error("[main] settings init failed:",t)}),gx(),xx(),bx()}).catch(t=>{console.error("[main] appearance init failed:",t)});const mh=document.getElementById("root");if(!mh)throw new Error("Root element not found");qh.createRoot(mh).render(s.jsx(Ze.StrictMode,{children:s.jsx(yx,{children:s.jsx(wx,{children:s.jsx(vx,{children:s.jsx(jx,{children:s.jsx(Wk,{apis:Qk})})})})})}));const iC=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{e1 as D,G2 as M,iC as m,Ms as u};
|